diff options
author | Roel Spilker <r.spilker@gmail.com> | 2014-03-26 22:33:00 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2014-03-26 22:33:00 +0100 |
commit | d41ef4bf8370a16121d00146f905e866ac7e5a0b (patch) | |
tree | 614ca16c4187d7ed7adb50625230a80bdef4b68b /src/core/lombok/eclipse | |
parent | 4d24542dac058fcd7c341f9d17c4e8170a8d83a2 (diff) | |
download | lombok-d41ef4bf8370a16121d00146f905e866ac7e5a0b.tar.gz lombok-d41ef4bf8370a16121d00146f905e866ac7e5a0b.tar.bz2 lombok-d41ef4bf8370a16121d00146f905e866ac7e5a0b.zip |
[i659] suppression of @ConstructorProperties should use config instead. Also modified all onX examples to use two underscores.
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleBuilder.java | 4 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleConstructor.java | 40 |
2 files changed, 30 insertions, 14 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 12b16934..59540d67 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -120,7 +120,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { fields.add(fieldNode); } - new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, fields, null, SkipIfConstructorExists.I_AM_BUILDER, true, Collections.<Annotation>emptyList(), ast); + new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, fields, null, SkipIfConstructorExists.I_AM_BUILDER, null, Collections.<Annotation>emptyList(), ast); returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); typeParams = td.typeParameters; @@ -209,7 +209,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { } if (constructorExists(builderType) == MemberExistsResult.NOT_EXISTS) { - ConstructorDeclaration cd = HandleConstructor.createConstructor(AccessLevel.PACKAGE, builderType, Collections.<EclipseNode>emptyList(), true, ast, Collections.<Annotation>emptyList()); + ConstructorDeclaration cd = HandleConstructor.createConstructor(AccessLevel.PACKAGE, builderType, Collections.<EclipseNode>emptyList(), null, ast, Collections.<Annotation>emptyList()); if (cd != null) injectMethod(builderType, cd); } diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index 6b7df349..4e35ebb6 100644 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -82,7 +82,7 @@ public class HandleConstructor { List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor=", annotationNode); - new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, SkipIfConstructorExists.NO, false, onConstructor, ast); + new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, SkipIfConstructorExists.NO, null, onConstructor, ast); } } @@ -95,10 +95,14 @@ public class HandleConstructor { if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return; RequiredArgsConstructor ann = annotation.getInstance(); AccessLevel level = ann.access(); - String staticName = ann.staticName(); - @SuppressWarnings("deprecation") - boolean suppressConstructorProperties = ann.suppressConstructorProperties(); if (level == AccessLevel.NONE) return; + String staticName = ann.staticName(); + Boolean suppressConstructorProperties = null; + if (annotation.isExplicit("suppressConstructorProperties")) { + @SuppressWarnings("deprecation") + boolean suppress = ann.suppressConstructorProperties(); + suppressConstructorProperties = suppress; + } List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor=", annotationNode); @@ -143,10 +147,14 @@ public class HandleConstructor { if (!checkLegality(typeNode, annotationNode, AllArgsConstructor.class.getSimpleName())) return; AllArgsConstructor ann = annotation.getInstance(); AccessLevel level = ann.access(); - String staticName = ann.staticName(); - @SuppressWarnings("deprecation") - boolean suppressConstructorProperties = ann.suppressConstructorProperties(); if (level == AccessLevel.NONE) return; + String staticName = ann.staticName(); + Boolean suppressConstructorProperties = null; + if (annotation.isExplicit("suppressConstructorProperties")) { + @SuppressWarnings("deprecation") + boolean suppress = ann.suppressConstructorProperties(); + suppressConstructorProperties = suppress; + } List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor=", annotationNode); @@ -169,18 +177,18 @@ public class HandleConstructor { } public void generateRequiredArgsConstructor(EclipseNode typeNode, AccessLevel level, String staticName, SkipIfConstructorExists skipIfConstructorExists, List<Annotation> onConstructor, ASTNode source) { - generateConstructor(typeNode, level, findRequiredFields(typeNode), staticName, skipIfConstructorExists, false, onConstructor, source); + generateConstructor(typeNode, level, findRequiredFields(typeNode), staticName, skipIfConstructorExists, null, onConstructor, source); } public void generateAllArgsConstructor(EclipseNode typeNode, AccessLevel level, String staticName, SkipIfConstructorExists skipIfConstructorExists, List<Annotation> onConstructor, ASTNode source) { - generateConstructor(typeNode, level, findAllFields(typeNode), staticName, skipIfConstructorExists, false, onConstructor, source); + generateConstructor(typeNode, level, findAllFields(typeNode), staticName, skipIfConstructorExists, null, onConstructor, source); } public enum SkipIfConstructorExists { YES, NO, I_AM_BUILDER; } - public void generateConstructor(EclipseNode typeNode, AccessLevel level, List<EclipseNode> fields, String staticName, SkipIfConstructorExists skipIfConstructorExists, boolean suppressConstructorProperties, List<Annotation> onConstructor, ASTNode source) { + public void generateConstructor(EclipseNode typeNode, AccessLevel level, List<EclipseNode> fields, String staticName, SkipIfConstructorExists skipIfConstructorExists, Boolean suppressConstructorProperties, List<Annotation> onConstructor, ASTNode source) { boolean staticConstrRequired = staticName != null && !staticName.equals(""); if (skipIfConstructorExists != SkipIfConstructorExists.NO && constructorExists(typeNode) != MemberExistsResult.NOT_EXISTS) return; @@ -251,7 +259,7 @@ public class HandleConstructor { public static ConstructorDeclaration createConstructor( AccessLevel level, EclipseNode type, Collection<EclipseNode> fields, - boolean suppressConstructorProperties, ASTNode source, List<Annotation> onConstructor) { + Boolean suppressConstructorProperties, ASTNode source, List<Annotation> onConstructor) { TypeDeclaration typeDeclaration = ((TypeDeclaration)type.get()); long p = (long)source.sourceStart << 32 | source.sourceEnd; @@ -260,6 +268,14 @@ public class HandleConstructor { if (isEnum) level = AccessLevel.PRIVATE; + if (suppressConstructorProperties == null) { + if (fields.isEmpty()) { + suppressConstructorProperties = false; + } else { + suppressConstructorProperties = Boolean.TRUE.equals(type.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES)); + } + } + ConstructorDeclaration constructor = new ConstructorDeclaration( ((CompilationUnitDeclaration) type.top().get()).compilationResult); @@ -309,7 +325,7 @@ public class HandleConstructor { /* Generate annotations that must be put on the generated method, and attach them. */ { Annotation[] constructorProperties = null; - if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && !isLocalType(type)) { + if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && level != AccessLevel.PACKAGE && !isLocalType(type)) { constructorProperties = createConstructorProperties(source, fields); } |