diff options
Diffstat (limited to 'src')
29 files changed, 202 insertions, 193 deletions
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 05550a06..457246e7 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -291,6 +291,13 @@ public class ConfigurationKeys { */ public static final ConfigurationKey<Boolean> TO_STRING_INCLUDE_FIELD_NAMES = new ConfigurationKey<Boolean>("lombok.toString.includeFieldNames", "Include the field names in the generated toString method (default = true).") {}; + /** + * lombok configuration: {@code lombok.toString.onlyExplicitlyIncluded} = {@code true} | {@code false}. + * + * If {@code true}, require a {@code @ToString.Include} annotation on any fields/no-args methods you want to include in lombok's generated `@ToString` method. Otherwise, every (non-static, non-dollar-named) field is included by default (default = false). + */ + public static final ConfigurationKey<Boolean> TO_STRING_ONLY_EXPLICITLY_INCLUDED = new ConfigurationKey<Boolean>("lombok.toString.onlyExplicitlyIncluded", "Include only fields/methods explicitly marked with @ToString.Include. Otherwise, include all non-static, non-dollar-named fields (default = false).") {}; + // ----- Builder ----- /** diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java index 07d035c5..738241e2 100755 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -454,4 +454,9 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>, if (configTracker != null) configTracker.end(start); } } + + public boolean getBooleanAnnotationValue(AnnotationValues<?> annotation, String annoMethod, ConfigurationKey<Boolean> confKey) { + Boolean conf = readConfiguration(confKey); + return annotation.isExplicit(annoMethod) || conf == null ? annotation.getAsBoolean(annoMethod) : conf; + } } diff --git a/src/core/lombok/core/AnnotationValues.java b/src/core/lombok/core/AnnotationValues.java index 78bb1fb5..f5db553c 100644 --- a/src/core/lombok/core/AnnotationValues.java +++ b/src/core/lombok/core/AnnotationValues.java @@ -165,7 +165,7 @@ public class AnnotationValues<A extends Annotation> { AnnotationValue v = values.get(methodName); if (v == null) { - String[] s = getDefaultIf(methodName, String[].class, new String[0]); + String[] s = getDefaultIf(methodName, new String[0]); return Collections.unmodifiableList(Arrays.asList(s)); } @@ -175,7 +175,7 @@ public class AnnotationValues<A extends Annotation> { Object result = guess == null ? null : guessToType(guess, String.class, v, idx); if (result == null) { if (v.valueGuesses.size() == 1) { - String[] s = getDefaultIf(methodName, String[].class, new String[0]); + String[] s = getDefaultIf(methodName, new String[0]); return Collections.unmodifiableList(Arrays.asList(s)); } throw new AnnotationValueDecodeFail(v, @@ -190,28 +190,29 @@ public class AnnotationValues<A extends Annotation> { public String getAsString(String methodName) { AnnotationValue v = values.get(methodName); if (v == null || v.valueGuesses.size() != 1) { - return getDefaultIf(methodName, String.class, ""); + return getDefaultIf(methodName, ""); } Object guess = guessToType(v.valueGuesses.get(0), String.class, v, 0); if (guess instanceof String) return (String) guess; - return getDefaultIf(methodName, String.class, ""); + return getDefaultIf(methodName, ""); } public boolean getAsBoolean(String methodName) { AnnotationValue v = values.get(methodName); if (v == null || v.valueGuesses.size() != 1) { - return getDefaultIf(methodName, boolean.class, false); + return getDefaultIf(methodName, false); } Object guess = guessToType(v.valueGuesses.get(0), boolean.class, v, 0); if (guess instanceof Boolean) return ((Boolean) guess).booleanValue(); - return getDefaultIf(methodName, boolean.class, false); + return getDefaultIf(methodName, false); } - public <T> T getDefaultIf(String methodName, Class<T> type, T defaultValue) { + @SuppressWarnings("unchecked") + public <T> T getDefaultIf(String methodName, T defaultValue) { try { - return type.cast(Permit.getMethod(type, methodName).getDefaultValue()); + return (T) Permit.getMethod(type, methodName).getDefaultValue(); } catch (Exception e) { return defaultValue; } diff --git a/src/core/lombok/core/configuration/CheckerFrameworkVersion.java b/src/core/lombok/core/configuration/CheckerFrameworkVersion.java index c37ba91d..e69476ac 100644 --- a/src/core/lombok/core/configuration/CheckerFrameworkVersion.java +++ b/src/core/lombok/core/configuration/CheckerFrameworkVersion.java @@ -33,7 +33,6 @@ public final class CheckerFrameworkVersion implements ConfigurationValueType { public static final String NAME__PURE = "org.checkerframework.dataflow.qual.Pure"; public static final String NAME__UNIQUE = "org.checkerframework.common.aliasing.qual.Unique"; public static final String NAME__RETURNS_RECEIVER = "org.checkerframework.common.returnsreceiver.qual.This"; - public static final String NAME__NOT_CALLED = "org.checkerframework.checker.calledmethods.qual.NotCalledMethods"; public static final String NAME__CALLED = "org.checkerframework.checker.calledmethods.qual.CalledMethods"; public static final CheckerFrameworkVersion NONE = new CheckerFrameworkVersion(0); @@ -57,11 +56,11 @@ public final class CheckerFrameworkVersion implements ConfigurationValueType { } public boolean generateReturnsReceiver() { - return version > 3999; + return version >= 3100; } public boolean generateCalledMethods() { - return version > 3999; + return version >= 3100; } public static CheckerFrameworkVersion valueOf(String versionString) { diff --git a/src/core/lombok/core/configuration/ConfigurationApp.java b/src/core/lombok/core/configuration/ConfigurationApp.java index 8d794c8a..268e83b5 100644 --- a/src/core/lombok/core/configuration/ConfigurationApp.java +++ b/src/core/lombok/core/configuration/ConfigurationApp.java @@ -232,6 +232,7 @@ public class ConfigurationApp extends LombokApp { if (!problems.isEmpty()) { err.printf("Problems in the configuration files:%n"); for (String problem : problems) err.printf("- %s%n", problem); + return 2; } return 0; diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index f90a7caf..2415b750 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -902,7 +902,7 @@ public class HandlerUtil { public static String stripLinesWithTagFromJavadoc(String javadoc, JavadocTag tag) { if (javadoc == null || javadoc.isEmpty()) return javadoc; - return tag.pattern.matcher(javadoc).replaceAll(""); + return tag.pattern.matcher(javadoc).replaceAll("").trim(); } public static String stripSectionsFromJavadoc(String javadoc) { diff --git a/src/core/lombok/core/handlers/InclusionExclusionUtils.java b/src/core/lombok/core/handlers/InclusionExclusionUtils.java index 0aa6c47b..2a519b82 100644 --- a/src/core/lombok/core/handlers/InclusionExclusionUtils.java +++ b/src/core/lombok/core/handlers/InclusionExclusionUtils.java @@ -113,10 +113,14 @@ public class InclusionExclusionUtils { } private static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N, I extends Annotation> List<Included<L, I>> handleIncludeExcludeMarking(Class<I> inclType, String replaceName, Class<? extends Annotation> exclType, LombokNode<A, L, N> typeNode, AnnotationValues<?> annotation, LombokNode<A, L, N> annotationNode, boolean includeTransient) { + boolean onlyExplicitlyIncluded = annotation != null ? annotation.getAsBoolean("onlyExplicitlyIncluded") : false; + return handleIncludeExcludeMarking(inclType, onlyExplicitlyIncluded, replaceName, exclType, typeNode, annotation, annotationNode, includeTransient); + } + + private static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N, I extends Annotation> List<Included<L, I>> handleIncludeExcludeMarking(Class<I> inclType, boolean onlyExplicitlyIncluded, String replaceName, Class<? extends Annotation> exclType, LombokNode<A, L, N> typeNode, AnnotationValues<?> annotation, LombokNode<A, L, N> annotationNode, boolean includeTransient) { List<String> oldExcludes = (annotation != null && annotation.isExplicit("exclude")) ? annotation.getAsStringList("exclude") : null; List<String> oldIncludes = (annotation != null && annotation.isExplicit("of")) ? annotation.getAsStringList("of") : null; - boolean onlyExplicitlyIncluded = annotation != null ? annotation.getAsBoolean("onlyExplicitlyIncluded") : false; boolean memberAnnotationMode = onlyExplicitlyIncluded; List<Included<L, I>> members = new ArrayList<Included<L, I>>(); List<String> namesToAutoExclude = new ArrayList<String>(); @@ -203,14 +207,14 @@ public class InclusionExclusionUtils { return members; } - public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> List<Included<L, ToString.Include>> handleToStringMarking(LombokNode<A, L, N> typeNode, AnnotationValues<ToString> annotation, LombokNode<A, L, N> annotationNode) { - List<Included<L, ToString.Include>> members = handleIncludeExcludeMarking(ToString.Include.class, "name", ToString.Exclude.class, typeNode, annotation, annotationNode, true); + public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> List<Included<L, ToString.Include>> handleToStringMarking(LombokNode<A, L, N> typeNode, boolean onlyExplicitlyIncluded, AnnotationValues<ToString> annotation, LombokNode<A, L, N> annotationNode) { + List<Included<L, ToString.Include>> members = handleIncludeExcludeMarking(ToString.Include.class, onlyExplicitlyIncluded, "name", ToString.Exclude.class, typeNode, annotation, annotationNode, true); Collections.sort(members, new Comparator<Included<L, ToString.Include>>() { @Override public int compare(Included<L, ToString.Include> a, Included<L, ToString.Include> b) { int ra = a.getInc() == null ? 0 : a.getInc().rank(); int rb = b.getInc() == null ? 0 : b.getInc().rank(); - + return compareRankOrPosition(ra, rb, a.getNode(), b.getNode()); } }); @@ -219,28 +223,28 @@ public class InclusionExclusionUtils { public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> List<Included<L, EqualsAndHashCode.Include>> handleEqualsAndHashCodeMarking(LombokNode<A, L, N> typeNode, AnnotationValues<EqualsAndHashCode> annotation, LombokNode<A, L, N> annotationNode) { List<Included<L, EqualsAndHashCode.Include>> members = handleIncludeExcludeMarking(EqualsAndHashCode.Include.class, "replaces", EqualsAndHashCode.Exclude.class, typeNode, annotation, annotationNode, false); - + Collections.sort(members, new Comparator<Included<L, EqualsAndHashCode.Include>>() { @Override public int compare(Included<L, EqualsAndHashCode.Include> a, Included<L, EqualsAndHashCode.Include> b) { int ra = a.hasExplicitRank() ? a.getInc().rank() : HandlerUtil.defaultEqualsAndHashcodeIncludeRank(a.node.fieldOrMethodBaseType()); int rb = b.hasExplicitRank() ? b.getInc().rank() : HandlerUtil.defaultEqualsAndHashcodeIncludeRank(b.node.fieldOrMethodBaseType()); - + return compareRankOrPosition(ra, rb, a.getNode(), b.getNode()); } }); return members; } - + private static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> int compareRankOrPosition(int ra, int rb, LombokNode<A, L, N> nodeA, LombokNode<A, L, N> nodeB) { if (ra < rb) return +1; if (ra > rb) return -1; - + int pa = nodeA.getStartPos(); int pb = nodeB.getStartPos(); - + if (pa < pb) return -1; if (pa > pb) return +1; - + return 0; } } diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index f8cde6c8..6483a749 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -447,16 +447,18 @@ public class EclipseHandlerUtil { // arrays if (in instanceof ArrayInitializer) { - Expression[] exprs = ((ArrayInitializer) in).expressions; - Expression[] copy = new Expression[exprs.length]; - for (int i = 0; i < exprs.length; i++) copy[i] = copyAnnotationMemberValue(exprs[i]); ArrayInitializer out = new ArrayInitializer(); out.sourceStart = s; out.sourceEnd = e; out.bits = in.bits; out.implicitConversion = in.implicitConversion; out.statementEnd = e; - out.expressions = copy; + Expression[] exprs = ((ArrayInitializer) in).expressions; + if (exprs != null) { + Expression[] copy = new Expression[exprs.length]; + for (int i = 0; i < exprs.length; i++) copy[i] = copyAnnotationMemberValue(exprs[i]); + out.expressions = copy; + } return out; } @@ -2094,6 +2096,15 @@ public class EclipseHandlerUtil { return newAnnotationArray; } + public static void addCheckerFrameworkReturnsReceiver(TypeReference returnType, ASTNode source, CheckerFrameworkVersion cfv) { + if (cfv.generateReturnsReceiver()) { + Annotation rrAnn = generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__RETURNS_RECEIVER); + int levels = returnType.getAnnotatableLevels(); + returnType.annotations = new Annotation[levels][]; + returnType.annotations[levels-1] = new Annotation[] {rrAnn}; + } + } + private static boolean arrayHasOnlyElementsOfType(Object[] array, Class<?> clazz) { for (Object element : array) { if (!clazz.isInstance(element)) diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java index d099cab2..998c1274 100755 --- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java +++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java @@ -300,13 +300,10 @@ public class EclipseSingularsRecipes { // -- Utility methods -- - protected Annotation[] generateSelfReturnAnnotations(boolean deprecate, CheckerFrameworkVersion cfv, ASTNode source) { + protected Annotation[] generateSelfReturnAnnotations(boolean deprecate, ASTNode source) { Annotation deprecated = deprecate ? generateDeprecatedAnnotation(source) : null; - Annotation returnsReceiver = cfv.generateReturnsReceiver() ? generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__RETURNS_RECEIVER) : null; - if (deprecated == null && returnsReceiver == null) return null; - if (deprecated == null) return new Annotation[] {returnsReceiver}; - if (returnsReceiver == null) return new Annotation[] {deprecated}; - return new Annotation[] {deprecated, returnsReceiver}; + if (deprecated == null) return null; + return new Annotation[] {deprecated}; } /** diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 2bfe1e8b..a2dd5057 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -767,18 +767,6 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { return decl; } - static Receiver generateNotCalledReceiver(BuilderJob job, String setterName) { - char[][] nameNotCalled = fromQualifiedName(CheckerFrameworkVersion.NAME__NOT_CALLED); - SingleMemberAnnotation ann = new SingleMemberAnnotation(new QualifiedTypeReference(nameNotCalled, poss(job.source, nameNotCalled.length)), job.source.sourceStart); - ann.memberValue = new StringLiteral(setterName.toCharArray(), 0, 0, 0); - - TypeReference typeReference = job.createBuilderTypeReference(); - int trLen = typeReference.getTypeName().length; - typeReference.annotations = new Annotation[trLen][]; - typeReference.annotations[trLen - 1] = new Annotation[] {ann}; - return new Receiver(new char[] { 't', 'h', 'i', 's' }, 0, typeReference, null, 0); - } - static Receiver generateBuildReceiver(BuilderJob job) { if (!job.checkerFramework.generateCalledMethods()) return null; @@ -1050,7 +1038,6 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { ASTNode source = job.sourceNode.get(); MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, bfd.name, bfd.nameOfSetFlag, job.oldChain, toEclipseModifier(job.accessInners), job.sourceNode, methodAnnsList, bfd.annotations != null ? Arrays.asList(copyAnnotations(source, bfd.annotations)) : Collections.<Annotation>emptyList()); - if (job.checkerFramework.generateCalledMethods()) setter.receiver = generateNotCalledReceiver(job, setterName); if (job.sourceNode.up().getKind() == Kind.METHOD) { copyJavadocFromParam(bfd.originalFieldNode.up(), setter, td, bfd.name.toString()); } else { diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index ddae21fb..0fdd058f 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -34,7 +34,6 @@ import lombok.AccessLevel; import lombok.ConfigurationKeys; import lombok.Setter; import lombok.core.AST.Kind; -import lombok.core.configuration.CheckerFrameworkVersion; import lombok.core.AnnotationValues; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; @@ -191,14 +190,12 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { ReturnStatement returnThis = null; if (shouldReturnThis) { returnType = cloneSelfType(fieldNode, source); + addCheckerFrameworkReturnsReceiver(returnType, source, getCheckerFrameworkVersion(sourceNode)); ThisReference thisRef = new ThisReference(pS, pE); returnThis = new ReturnStatement(thisRef, pS, pE); } MethodDeclaration d = createSetter(parent, deprecate, fieldNode, name, paramName, booleanFieldToSet, returnType, returnThis, modifier, sourceNode, onMethod, onParam); - if (shouldReturnThis && getCheckerFrameworkVersion(sourceNode).generateReturnsReceiver()) { - d.annotations = copyAnnotations(source, d.annotations, new Annotation[] { generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__RETURNS_RECEIVER) }); - } return d; } diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 26b62cbf..558c6ec2 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -51,6 +51,7 @@ import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldReference; import org.eclipse.jdt.internal.compiler.ast.IfStatement; import org.eclipse.jdt.internal.compiler.ast.Initializer; +import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation; import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.NullLiteral; @@ -838,16 +839,12 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; out.modifiers = ClassFileConstants.AccAbstract | ClassFileConstants.AccProtected | ExtraCompilerModifiers.AccSemicolonBody; Annotation overrideAnn = override ? makeMarkerAnnotation(TypeConstants.JAVA_LANG_OVERRIDE, job.parentType.get()) : null; - Annotation rrAnn = job.checkerFramework.generateReturnsReceiver() ? generateNamedAnnotation(job.parentType.get(), CheckerFrameworkVersion.NAME__RETURNS_RECEIVER): null; Annotation sefAnn = job.checkerFramework.generatePure() ? generateNamedAnnotation(job.parentType.get(), CheckerFrameworkVersion.NAME__PURE): null; - if (overrideAnn != null && rrAnn != null && sefAnn != null) out.annotations = new Annotation[] {overrideAnn, rrAnn, sefAnn}; - else if (overrideAnn != null && rrAnn != null) out.annotations = new Annotation[] {overrideAnn, rrAnn}; - else if (overrideAnn != null && sefAnn != null) out.annotations = new Annotation[] {overrideAnn, sefAnn}; + if (overrideAnn != null && sefAnn != null) out.annotations = new Annotation[] {overrideAnn, sefAnn}; else if (overrideAnn != null) out.annotations = new Annotation[] {overrideAnn}; - else if (rrAnn != null && sefAnn != null) out.annotations = new Annotation[] {rrAnn, sefAnn}; - else if (rrAnn != null) out.annotations = new Annotation[] {rrAnn}; else if (sefAnn != null) out.annotations = new Annotation[] {sefAnn}; out.returnType = new SingleTypeReference(builderGenericName.toCharArray(), 0); + addCheckerFrameworkReturnsReceiver(out.returnType, job.parentType.get(), job.checkerFramework); return out; } @@ -857,13 +854,11 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; out.modifiers = ClassFileConstants.AccProtected; Annotation overrideAnn = makeMarkerAnnotation(TypeConstants.JAVA_LANG_OVERRIDE, job.builderType.get()); - Annotation rrAnn = job.checkerFramework.generateReturnsReceiver() ? generateNamedAnnotation(job.builderType.get(), CheckerFrameworkVersion.NAME__RETURNS_RECEIVER) : null; Annotation sefAnn = job.checkerFramework.generatePure() ? generateNamedAnnotation(job.builderType.get(), CheckerFrameworkVersion.NAME__PURE) : null; - if (rrAnn != null && sefAnn != null) out.annotations = new Annotation[] {overrideAnn, rrAnn, sefAnn}; - else if (rrAnn != null) out.annotations = new Annotation[] {overrideAnn, rrAnn}; - else if (sefAnn != null) out.annotations = new Annotation[] {overrideAnn, sefAnn}; + if (sefAnn != null) out.annotations = new Annotation[] {overrideAnn, sefAnn}; else out.annotations = new Annotation[] {overrideAnn}; out.returnType = namePlusTypeParamsToTypeReference(job.builderType, job.typeParams, job.getPos()); + addCheckerFrameworkReturnsReceiver(out.returnType, job.parentType.get(), job.checkerFramework); out.statements = new Statement[] {new ReturnStatement(new ThisReference(0, 0), 0, 0)}; return out; } @@ -1013,13 +1008,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { } List<Annotation> methodAnnsList = Arrays.asList(EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode)); - if (job.checkerFramework.generateReturnsReceiver()) { - methodAnnsList = new ArrayList<Annotation>(methodAnnsList); - methodAnnsList.add(generateNamedAnnotation(job.source, CheckerFrameworkVersion.NAME__RETURNS_RECEIVER)); - } + addCheckerFrameworkReturnsReceiver(returnType, job.source, job.checkerFramework); MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, paramName, nameOfSetFlag, returnType, returnStatement, ClassFileConstants.AccPublic, job.sourceNode, methodAnnsList, annosOnParam != null ? Arrays.asList(copyAnnotations(job.source, annosOnParam)) : Collections.<Annotation>emptyList()); - if (job.checkerFramework.generateCalledMethods()) setter.receiver = generateNotCalledReceiver(job, setterName); injectMethod(job.builderType, setter); } diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java index 05b0e069..b22d162f 100644 --- a/src/core/lombok/eclipse/handlers/HandleToString.java +++ b/src/core/lombok/eclipse/handlers/HandleToString.java @@ -76,7 +76,8 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> { handleFlagUsage(annotationNode, ConfigurationKeys.TO_STRING_FLAG_USAGE, "@ToString"); ToString ann = annotation.getInstance(); - List<Included<EclipseNode, ToString.Include>> members = InclusionExclusionUtils.handleToStringMarking(annotationNode.up(), annotation, annotationNode); + boolean onlyExplicitlyIncluded = annotationNode.getAst().getBooleanAnnotationValue(annotation, "onlyExplicitlyIncluded", ConfigurationKeys.TO_STRING_ONLY_EXPLICITLY_INCLUDED); + List<Included<EclipseNode, ToString.Include>> members = InclusionExclusionUtils.handleToStringMarking(annotationNode.up(), onlyExplicitlyIncluded, annotation, annotationNode); if (members == null) return; Boolean callSuper = ann.callSuper(); @@ -99,16 +100,14 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> { return; } - boolean includeFieldNames = true; - try { - Boolean configuration = typeNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_INCLUDE_FIELD_NAMES); - includeFieldNames = configuration != null ? configuration : ((Boolean)ToString.class.getMethod("includeFieldNames").getDefaultValue()).booleanValue(); - } catch (Exception ignore) {} + AnnotationValues<ToString> anno = AnnotationValues.of(ToString.class); + boolean includeFieldNames = typeNode.getAst().getBooleanAnnotationValue(anno, "includeFieldNames", ConfigurationKeys.TO_STRING_INCLUDE_FIELD_NAMES); + boolean onlyExplicitlyIncluded = typeNode.getAst().getBooleanAnnotationValue(anno, "onlyExplicitlyIncluded", ConfigurationKeys.TO_STRING_ONLY_EXPLICITLY_INCLUDED); Boolean doNotUseGettersConfiguration = typeNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_DO_NOT_USE_GETTERS); FieldAccess access = doNotUseGettersConfiguration == null || !doNotUseGettersConfiguration ? FieldAccess.GETTER : FieldAccess.PREFER_FIELD; - List<Included<EclipseNode, ToString.Include>> members = InclusionExclusionUtils.handleToStringMarking(typeNode, null, null); + List<Included<EclipseNode, ToString.Include>> members = InclusionExclusionUtils.handleToStringMarking(typeNode, onlyExplicitlyIncluded, null, null); generateToString(typeNode, errorNode, members, includeFieldNames, null, false, access); } @@ -204,7 +203,7 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> { if (!prefix.isEmpty()) { StringLiteral px = new StringLiteral(prefix.toCharArray(), pS, pE, 0); - setGeneratedBy(px, source); + setGeneratedBy(px, source); current = new BinaryExpression(current, px, PLUS); current.sourceStart = pS; current.sourceEnd = pE; setGeneratedBy(current, source); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java index 9b464a25..47822ff3 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java @@ -93,7 +93,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { } @Override protected char[][] getEmptyMakerReceiver(String targetFqn) { - return CGCC; + return makeGuavaTypeName(GuavaTypeMap.getGuavaTypeName(targetFqn), false); } @Override public List<EclipseNode> generateFields(SingularData data, EclipseNode builderType) { @@ -129,13 +129,14 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.selector = HandlerUtil.buildAccessorName(builderType, "clear", new String(data.getPluralName())).toCharArray(); md.statements = returnStatement != null ? new Statement[] {a, returnStatement} : new Statement[] {a}; md.returnType = returnType; - md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + addCheckerFrameworkReturnsReceiver(md.returnType, data.getSource(), cfv); + md.annotations = generateSelfReturnAnnotations(deprecate, data.getSource()); data.setGeneratedByRecursive(md); if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); injectMethod(builderType, md); } - + void generateSingularMethod(CheckerFrameworkVersion cfv, boolean deprecate, TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent, AccessLevel access) { LombokImmutableList<String> suffixes = getArgumentSuffixes(); char[][] names = new char[suffixes.size()][]; @@ -173,9 +174,10 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.arguments[i].annotations = typeUseAnns; } md.returnType = returnType; + addCheckerFrameworkReturnsReceiver(md.returnType, data.getSource(), cfv); char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray(); md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName(builderType, "add", new String(data.getSingularName())).toCharArray(); - Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, data.getSource()); Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToBuilderSingularSetterAnnotations(data.getAnnotation().up())); md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class); @@ -213,9 +215,10 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.arguments = new Argument[] {param}; md.returnType = returnType; + addCheckerFrameworkReturnsReceiver(md.returnType, data.getSource(), cfv); char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray(); md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName(builderType, "addAll", new String(data.getPluralName())).toCharArray(); - Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, data.getSource()); Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up())); md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java index 6f5e9add..fbde3021 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java |
