[config: lombok.CheckReturnValue]: setting is now a list of possible flavours, do not apply if building for a method, add to getter/hc/equals/toString.

This commit is contained in:
Reinier Zwitserloot committed 2026-08-21 02:42:00 +02:00
1 parent 5aa26873fd
commit e76ba71721
20 files changed
+77 -46

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2025 The Project Lombok Authors. * Copyright (C) 2025-2026 The Project Lombok Authors.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+13 -7
View File
@@ -90,16 +90,22 @@ public class ConfigurationKeys {
* If {@code true}, lombok generates {@code @lombok.Generated} on all fields, methods, and types that are generated. * If {@code true}, lombok generates {@code @lombok.Generated} on all fields, methods, and types that are generated.
*/ */
public static final ConfigurationKey<Boolean> ADD_LOMBOK_GENERATED_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addLombokGeneratedAnnotation", "Generate @lombok.Generated on all generated code (default: true).") {}; public static final ConfigurationKey<Boolean> ADD_LOMBOK_GENERATED_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addLombokGeneratedAnnotation", "Generate @lombok.Generated on all generated code (default: true).") {};
/** /**
* lombok configuration: {@code lombok.checkReturnValueAnnotation} = [{@code none} | {@code lombok}]. * lombok configuration: {@code lombok.checkReturnValueAnnotation} += {@code lombok} / {@code androidx}.
* *
* If set to {@code lombok}, lombok generates {@code @lombok.CheckReturnValue} on generated methods where the return value should not be ignored, * If set, lombok generates all requested annotation flavors indicating that a caller must use the returned value on all methods where it is sensible, such as {@code @With} methods and {@code @Builder}'s {@code build()} method.
* such as {@code @With} methods and {@code @Builder}'s {@code build()} method. * <p>
* If set to {@code none} (the current default), no such annotation is emitted. A future lombok release may flip the default to {@code lombok}. * If value {@code lombok} is added, lombok generates {@code @lombok.CheckReturnValue}.
* <p>
* If value {@code androidx} is added, lombok generates {@code @androidx.annotation.CheckResult}.
* <p>
* The current default is no flavors (no annotations are added), but a future lombok release may flip the default {@code lombok}.
* <p>
* NB: {@code build()} methods only get these annotations if the thing they are building for is a type or constructor. Applying {@code @Builder} to a method will not result in these annotations unless that method is itself so annotated.
*/ */
public static final ConfigurationKey<CheckReturnValueFlavor> CHECK_RETURN_VALUE_ANNOTATION = new ConfigurationKey<CheckReturnValueFlavor>("lombok.checkReturnValueAnnotation", "Which @CheckReturnValue annotation flavor to emit on generated methods. Values: none, lombok (default: none).") {}; public static final ConfigurationKey<List<CheckReturnValueFlavor>> CHECK_RETURN_VALUE_ANNOTATION = new ConfigurationKey<List<CheckReturnValueFlavor>>("lombok.checkReturnValueAnnotation", "Which @CheckReturnValue annotation flavor(s) to emit on generated methods. Values: lombok, androidx (default: none).") {};
/** /**
* lombok configuration: {@code lombok.extern.findbugs.addSuppressFBWarnings} = {@code true} | {@code false}. * lombok configuration: {@code lombok.extern.findbugs.addSuppressFBWarnings} = {@code true} | {@code false}.
* *
@@ -21,7 +21,23 @@
*/ */
package lombok.core.configuration; package lombok.core.configuration;
/** Used for lombok configuration to select which {@code @CheckReturnValue} annotation flavor to emit on generated methods. */ /** Used for lombok configuration to select which {@code @CheckReturnValue} annotation flavor(s) to emit on generated methods. */
public enum CheckReturnValueFlavor { public enum CheckReturnValueFlavor implements MappedConfigEnum {
NONE, LOMBOK; LOMBOK,
ANDROIDX,
;
@Override public boolean matches(String value) {
return value.equals(this.name().toLowerCase());
}
@Override public String toString() {
return this.name().toLowerCase();
}
public String getMarkerAnnotationFullyQualifiedName() {
if (this == LOMBOK) return "lombok.CheckReturnValue";
if (this == ANDROIDX) return "androidx.annotation.CheckResult";
throw new IllegalStateException("bug");
}
} }
@@ -31,11 +31,13 @@ public enum JacksonVersion implements MappedConfigEnum {
@Override public boolean matches(String value) { @Override public boolean matches(String value) {
if (this == TWO) return "2".equals(value); if (this == TWO) return "2".equals(value);
return "3".equals(value); if (this == THREE) return "3".equals(value);
throw new IllegalStateException("bug");
} }
@Override public String toString() { @Override public String toString() {
if (this == TWO) return "2"; if (this == TWO) return "2";
return "3"; if (this == THREE) return "3";
throw new IllegalStateException("bug");
} }
} }
@@ -2108,7 +2108,7 @@ public class EclipseHandlerUtil {
private static final char[][] JAKARTA_ANNOTATION_GENERATED = Eclipse.fromQualifiedName("jakarta.annotation.Generated"); private static final char[][] JAKARTA_ANNOTATION_GENERATED = Eclipse.fromQualifiedName("jakarta.annotation.Generated");
private static final char[][] LOMBOK_GENERATED = Eclipse.fromQualifiedName("lombok.Generated"); private static final char[][] LOMBOK_GENERATED = Eclipse.fromQualifiedName("lombok.Generated");
private static final char[][] EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS = Eclipse.fromQualifiedName("edu.umd.cs.findbugs.annotations.SuppressFBWarnings"); private static final char[][] EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS = Eclipse.fromQualifiedName("edu.umd.cs.findbugs.annotations.SuppressFBWarnings");
private static final char[][] LOMBOK_CHECK_RETURN_VALUE = Eclipse.fromQualifiedName("lombok.CheckReturnValue"); private static final Map<CheckReturnValueFlavor, char[][]> checkReturnValueQualifiedNameCache = new HashMap<CheckReturnValueFlavor, char[][]>();
public static Annotation[] addSuppressWarningsAll(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) { public static Annotation[] addSuppressWarningsAll(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
Annotation[] anns = originalAnnotationArray; Annotation[] anns = originalAnnotationArray;
@@ -2140,17 +2140,17 @@ public class EclipseHandlerUtil {
} }
public static Annotation[] addCheckReturnValue(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) { public static Annotation[] addCheckReturnValue(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
CheckReturnValueFlavor flavor = node.getAst().readConfiguration(ConfigurationKeys.CHECK_RETURN_VALUE_ANNOTATION); Annotation[] out = originalAnnotationArray;
if (flavor == null) flavor = CheckReturnValueFlavor.NONE; List<CheckReturnValueFlavor> flavors = node.getAst().readConfiguration(ConfigurationKeys.CHECK_RETURN_VALUE_ANNOTATION);
switch (flavor) { for (CheckReturnValueFlavor flavor : flavors) {
case LOMBOK: char[][] fqn = checkReturnValueQualifiedNameCache.get(flavor);
return addAnnotation(source, originalAnnotationArray, LOMBOK_CHECK_RETURN_VALUE); if (fqn == null) checkReturnValueQualifiedNameCache.put(flavor, fqn = Eclipse.fromQualifiedName(flavor.getMarkerAnnotationFullyQualifiedName()));
case NONE: out = addAnnotation(source, out, fqn);
default:
return originalAnnotationArray;
} }
return out;
} }
static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn) { static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn) {
return addAnnotation(source, originalAnnotationArray, annotationTypeFqn, (ASTNode[]) null); return addAnnotation(source, originalAnnotationArray, annotationTypeFqn, (ASTNode[]) null);
} }
@@ -897,12 +897,12 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
out.annotations = new Annotation[] {generateNamedAnnotation(job.source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE)}; out.annotations = new Annotation[] {generateNamedAnnotation(job.source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE)};
} }
out.receiver = generateBuildReceiver(job); out.receiver = generateBuildReceiver(job);
out.annotations = addCheckReturnValue(job.builderType, job.source, out.annotations); if (job.checkReturnValue) out.annotations = addCheckReturnValue(job.builderType, job.source, out.annotations);
if (staticName == null) createRelevantNonNullAnnotation(job.builderType, out); if (staticName == null) createRelevantNonNullAnnotation(job.builderType, out);
out.traverse(new SetGeneratedByVisitor(job.source), (ClassScope) null); out.traverse(new SetGeneratedByVisitor(job.source), (ClassScope) null);
return out; return out;
} }
private TypeReference[] typeParameterNames(TypeParameter[] typeParameters) { private TypeReference[] typeParameterNames(TypeParameter[] typeParameters) {
if (typeParameters == null) return null; if (typeParameters == null) return null;
@@ -272,6 +272,8 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
} else { } else {
method.annotations = new Annotation[] { overrideAnnotation }; method.annotations = new Annotation[] { overrideAnnotation };
} }
method.annotations = EclipseHandlerUtil.addCheckReturnValue(type, method, method.annotations);
method.selector = "hashCode".toCharArray(); method.selector = "hashCode".toCharArray();
method.thrownExceptions = null; method.thrownExceptions = null;
method.typeParameters = null; method.typeParameters = null;
@@ -635,6 +637,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
} else { } else {
method.annotations = new Annotation[] { overrideAnnotation }; method.annotations = new Annotation[] { overrideAnnotation };
} }
method.annotations = EclipseHandlerUtil.addCheckReturnValue(type, method, method.annotations);
method.selector = "equals".toCharArray(); method.selector = "equals".toCharArray();
method.thrownExceptions = null; method.thrownExceptions = null;
method.typeParameters = null; method.typeParameters = null;
@@ -291,6 +291,7 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> {
findDelegatesAndMarkAsHandled(fieldNode), findDelegatesAndMarkAsHandled(fieldNode),
checkerFramework, checkerFramework,
deprecated); deprecated);
method.annotations = EclipseHandlerUtil.addCheckReturnValue(fieldNode, method, method.annotations);
} }
if (addSuppressWarningsUnchecked) { if (addSuppressWarningsUnchecked) {
@@ -27,7 +27,6 @@ import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -163,7 +162,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
AnnotationValues<Accessors> accessors = getAccessorsForField(fieldNode); AnnotationValues<Accessors> accessors = getAccessorsForField(fieldNode);
String setterName = toSetterName(fieldNode, isBoolean, accessors); String setterName = toSetterName(fieldNode, isBoolean, accessors);
boolean shouldReturnThis = shouldReturnThis(fieldNode, accessors); boolean shouldReturnThis = shouldReturnThis(fieldNode, accessors);
boolean fluent = accessors.isExplicit("fluent"); boolean fluent = accessors.isExplicit("fluent");
if (setterName == null) { if (setterName == null) {
fieldNode.addWarning("Not generating setter for this field: It does not fit your @Accessors prefix list."); fieldNode.addWarning("Not generating setter for this field: It does not fit your @Accessors prefix list.");
@@ -868,6 +868,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
else if (overrideAnn != null) out.annotations = new Annotation[] {overrideAnn}; else if (overrideAnn != null) out.annotations = new Annotation[] {overrideAnn};
else if (sefAnn != null) out.annotations = new Annotation[] {sefAnn}; else if (sefAnn != null) out.annotations = new Annotation[] {sefAnn};
out.receiver = HandleBuilder.generateBuildReceiver(job); out.receiver = HandleBuilder.generateBuildReceiver(job);
out.annotations = addCheckReturnValue(job.builderType, job.source, out.annotations);
out.traverse(new SetGeneratedByVisitor(job.source), (ClassScope) null); out.traverse(new SetGeneratedByVisitor(job.source), (ClassScope) null);
return out; return out;
} }
@@ -298,6 +298,8 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> {
} else { } else {
method.annotations = new Annotation[] { overrideAnnotation }; method.annotations = new Annotation[] { overrideAnnotation };
} }
method.annotations = EclipseHandlerUtil.addCheckReturnValue(type, method, method.annotations);
method.arguments = null; method.arguments = null;
method.selector = "toString".toCharArray(); method.selector = "toString".toCharArray();
method.thrownExceptions = null; method.thrownExceptions = null;
@@ -293,7 +293,7 @@ public class HandleWith extends EclipseAnnotationHandler<With> {
EclipseHandlerUtil.createRelevantNonNullAnnotation(fieldNode, method); EclipseHandlerUtil.createRelevantNonNullAnnotation(fieldNode, method);
method.annotations = EclipseHandlerUtil.addCheckReturnValue(fieldNode, source, method.annotations); method.annotations = EclipseHandlerUtil.addCheckReturnValue(fieldNode, source, method.annotations);
method.traverse(new SetGeneratedByVisitor(source), parent.scope); method.traverse(new SetGeneratedByVisitor(source), parent.scope);
copyJavadoc(fieldNode, method, CopyJavadoc.WITH); copyJavadoc(fieldNode, method, CopyJavadoc.WITH);
return method; return method;
@@ -376,7 +376,7 @@ public class HandleWithBy extends EclipseAnnotationHandler<WithBy> {
createRelevantNonNullAnnotation(sourceNode, param, method); createRelevantNonNullAnnotation(sourceNode, param, method);
createRelevantNonNullAnnotation(fieldNode, method); createRelevantNonNullAnnotation(fieldNode, method);
method.annotations = addCheckReturnValue(fieldNode, source, method.annotations); method.annotations = addCheckReturnValue(fieldNode, source, method.annotations);
method.traverse(new SetGeneratedByVisitor(source), parent.scope); method.traverse(new SetGeneratedByVisitor(source), parent.scope);
copyJavadoc(fieldNode, method, CopyJavadoc.WITH_BY); copyJavadoc(fieldNode, method, CopyJavadoc.WITH_BY);
return method; return method;
@@ -347,7 +347,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
} }
if (job.builderClassName.indexOf('*') > -1) { if (job.builderClassName.indexOf('*') > -1) {
String replStr = returnTypeToBuilderClassName(annotationNode, td, buildMethodReturnType, job.typeParams); String replStr = returnTypeToBuilderClassName(annotationNode, td, buildMethodReturnType, job.typeParams);
if (replStr == null) return; // shuold not happen if (replStr == null) return; // should not happen
job.builderClassName = job.builderClassName.replace("*", replStr); job.builderClassName = job.builderClassName.replace("*", replStr);
} }
if (job.toBuilder) { if (job.toBuilder) {
@@ -810,11 +810,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
} else { } else {
methodDef = maker.MethodDef(maker.Modifiers(toJavacModifier(job.accessInners), annsOnMethod), job.toName(job.buildMethodName), returnTypeCopy, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), thrownExceptions, body, null); methodDef = maker.MethodDef(maker.Modifiers(toJavacModifier(job.accessInners), annsOnMethod), job.toName(job.buildMethodName), returnTypeCopy, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), thrownExceptions, body, null);
} }
addCheckReturnValue(methodDef.mods, job.builderType, job.sourceNode); if (job.checkReturnValue) addCheckReturnValue(methodDef.mods, job.builderType, job.sourceNode);
if (staticName == null) createRelevantNonNullAnnotation(job.builderType, methodDef); if (staticName == null) createRelevantNonNullAnnotation(job.builderType, methodDef);
return methodDef; return methodDef;
} }
public static JCMethodDecl generateDefaultProvider(Name methodName, JavacNode fieldNode, List<JCTypeParameter> params, BuilderJob job) { public static JCMethodDecl generateDefaultProvider(Name methodName, JavacNode fieldNode, List<JCTypeParameter> params, BuilderJob job) {
JavacTreeMaker maker = fieldNode.getTreeMaker(); JavacTreeMaker maker = fieldNode.getTreeMaker();
JCVariableDecl field = (JCVariableDecl) fieldNode.get(); JCVariableDecl field = (JCVariableDecl) fieldNode.get();
@@ -228,6 +228,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())); annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
} }
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod); JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod);
addCheckReturnValue(mods, typeNode, source);
JCExpression returnType = maker.TypeIdent(CTC_INT); JCExpression returnType = maker.TypeIdent(CTC_INT);
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
@@ -439,6 +440,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())); annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
} }
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod); JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod);
addCheckReturnValue(mods, typeNode, source);
JCExpression objectType; JCExpression objectType;
if (annsOnParamOnMethod.isEmpty()) { if (annsOnParamOnMethod.isEmpty()) {
objectType = genJavaLangTypeRef(typeNode, "Object"); objectType = genJavaLangTypeRef(typeNode, "Object");
@@ -56,6 +56,7 @@ import com.sun.tools.javac.tree.JCTree.JCExpressionStatement;
import com.sun.tools.javac.tree.JCTree.JCIf; import com.sun.tools.javac.tree.JCTree.JCIf;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree;
import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCSynchronized; import com.sun.tools.javac.tree.JCTree.JCSynchronized;
@@ -264,9 +265,11 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
if (getCheckerFrameworkVersion(field).generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genTypeRef(field, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())); if (getCheckerFrameworkVersion(field).generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genTypeRef(field, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
} }
if (isFieldDeprecated(field)) annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil())); if (isFieldDeprecated(field)) annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
JCModifiers mods = treeMaker.Modifiers(access, annsOnMethod);
addCheckReturnValue(mods, field, source);
if (makeFinal) access |= Flags.FINAL; if (makeFinal) access |= Flags.FINAL;
JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(mods, methodName, methodType,
methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source); methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source);
decl.mods.annotations = decl.mods.annotations.appendList(delegates); decl.mods.annotations = decl.mods.annotations.appendList(delegates);
@@ -841,6 +841,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
} else { } else {
methodDef = maker.MethodDef(modifiers, name, returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null); methodDef = maker.MethodDef(modifiers, name, returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null);
} }
addCheckReturnValue(methodDef.mods, job.builderType, job.sourceNode);
return methodDef; return methodDef;
} }
@@ -873,7 +874,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
createRelevantNonNullAnnotation(job.builderType, methodDef); createRelevantNonNullAnnotation(job.builderType, methodDef);
return methodDef; return methodDef;
} }
private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JavacNode source) { private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JavacNode source) {
JavacTreeMaker maker = type.getTreeMaker(); JavacTreeMaker maker = type.getTreeMaker();
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
@@ -153,6 +153,7 @@ public class HandleToString extends JavacAnnotationHandler<ToString> {
List<JCAnnotation> annsOnMethod = List.of(overrideAnnotation); List<JCAnnotation> annsOnMethod = List.of(overrideAnnotation);
if (getCheckerFrameworkVersion(typeNode).generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())); if (getCheckerFrameworkVersion(typeNode).generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod); JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod);
addCheckReturnValue(mods, typeNode, source);
JCExpression returnType = genJavaLangTypeRef(typeNode, "String"); JCExpression returnType = genJavaLangTypeRef(typeNode, "String");
boolean first = true; boolean first = true;
@@ -281,9 +281,9 @@ public class HandleWith extends JavacAnnotationHandler<With> {
List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod, maker); List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod, maker);
CheckerFrameworkVersion checkerFramework = getCheckerFrameworkVersion(source); CheckerFrameworkVersion checkerFramework = getCheckerFrameworkVersion(source);
if (checkerFramework.generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())); if (checkerFramework.generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
if (isFieldDeprecated(field)) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil())); if (isFieldDeprecated(field)) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
if (makeAbstract) access |= Flags.ABSTRACT; if (makeAbstract) access |= Flags.ABSTRACT;
AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field); AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field);
boolean makeFinal = shouldMakeFinal(field, accessors); boolean makeFinal = shouldMakeFinal(field, accessors);
@@ -1556,18 +1556,12 @@ public class JavacHandlerUtil {
} }
public static void addCheckReturnValue(JCModifiers mods, JavacNode node, JavacNode source) { public static void addCheckReturnValue(JCModifiers mods, JavacNode node, JavacNode source) {
CheckReturnValueFlavor flavor = node.getAst().readConfiguration(ConfigurationKeys.CHECK_RETURN_VALUE_ANNOTATION); java.util.List<CheckReturnValueFlavor> flavors = node.getAst().readConfiguration(ConfigurationKeys.CHECK_RETURN_VALUE_ANNOTATION);
if (flavor == null) flavor = CheckReturnValueFlavor.NONE; for (CheckReturnValueFlavor flavor : flavors) {
switch (flavor) { addAnnotation(mods, node, source, flavor.getMarkerAnnotationFullyQualifiedName(), null);
case LOMBOK:
addAnnotation(mods, node, source, "lombok.CheckReturnValue", null);
return;
case NONE:
default:
return;
} }
} }
public static void addAnnotation(JCModifiers mods, JavacNode node, JavacNode source, String annotationTypeFqn, JCExpression arg) { public static void addAnnotation(JCModifiers mods, JavacNode node, JavacNode source, String annotationTypeFqn, JCExpression arg) {
boolean isJavaLangBased; boolean isJavaLangBased;
String simpleName; { String simpleName; {