From d41ef4bf8370a16121d00146f905e866ac7e5a0b Mon Sep 17 00:00:00 2001
From: Roel Spilker
Date: Wed, 26 Mar 2014 22:33:00 +0100
Subject: [i659] suppression of @ConstructorProperties should use config
instead. Also modified all onX examples to use two underscores.
---
doc/changelog.markdown | 1 +
src/core/lombok/AllArgsConstructor.java | 5 +--
src/core/lombok/ConfigurationKeys.java | 10 +++++
src/core/lombok/Getter.java | 2 +-
src/core/lombok/NoArgsConstructor.java | 2 +-
src/core/lombok/RequiredArgsConstructor.java | 5 +--
src/core/lombok/Setter.java | 4 +-
.../lombok/eclipse/handlers/HandleBuilder.java | 4 +-
.../lombok/eclipse/handlers/HandleConstructor.java | 40 ++++++++++++++------
src/core/lombok/experimental/Wither.java | 4 +-
src/core/lombok/javac/handlers/HandleBuilder.java | 5 ++-
.../lombok/javac/handlers/HandleConstructor.java | 43 +++++++++++++++-------
.../resource/after-delombok/Constructors.java | 13 ++++---
.../after-delombok/ConstructorsConfiguration.java | 15 ++++++++
.../resource/after-delombok/DataConfiguration.java | 38 +++++++++++++++++++
.../transform/resource/after-ecj/Constructors.java | 7 ++++
.../after-ecj/ConstructorsConfiguration.java | 14 +++++++
.../resource/after-ecj/DataConfiguration.java | 34 +++++++++++++++++
test/transform/resource/before/Constructors.java | 3 ++
.../resource/before/ConstructorsConfiguration.java | 9 +++++
.../resource/before/DataConfiguration.java | 5 +++
usage_examples/experimental/onXExample_pre.jpage | 6 +--
website/features/Constructor.html | 2 +-
website/features/GetterSetter.html | 2 +-
website/features/experimental/Wither.html | 2 +-
website/features/experimental/onX.html | 4 +-
26 files changed, 225 insertions(+), 54 deletions(-)
create mode 100644 test/transform/resource/after-delombok/ConstructorsConfiguration.java
create mode 100644 test/transform/resource/after-delombok/DataConfiguration.java
create mode 100644 test/transform/resource/after-ecj/ConstructorsConfiguration.java
create mode 100644 test/transform/resource/after-ecj/DataConfiguration.java
create mode 100644 test/transform/resource/before/ConstructorsConfiguration.java
create mode 100644 test/transform/resource/before/DataConfiguration.java
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index d2fd6bcd..a3c9afd4 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -2,6 +2,7 @@ Lombok Changelog
----------------
### v1.12.7 "Edgy Guinea Pig"
+* CHANGE: suppressConstructorProperties should now be configured via lombok configuration.
* CHANGE: The `canEqual` method generated by `@EqualsAndHashCode`, `@Value` and `@Data` is now `protected` instead of `public`. [Issue #660](https://code.google.com/p/projectlombok/issues/detail?id=660)
* BUGFIX: Deadlocks would occasionally occur in eclipse when using lazy getters [Issue #590](https://code.google.com/p/projectlombok/issues/detail?id=590)
diff --git a/src/core/lombok/AllArgsConstructor.java b/src/core/lombok/AllArgsConstructor.java
index 068b7a68..cc494967 100644
--- a/src/core/lombok/AllArgsConstructor.java
+++ b/src/core/lombok/AllArgsConstructor.java
@@ -49,7 +49,7 @@ public @interface AllArgsConstructor {
String staticName() default "";
/**
- * Any annotations listed here are put on the generated constructor. The syntax for this feature is: {@code @AllArgsConstructor(onConstructor=@_({@AnnotationsGoHere}))}
+ * Any annotations listed here are put on the generated constructor. The syntax for this feature is: {@code @AllArgsConstructor(onConstructor=@__({@AnnotationsGoHere}))}
*/
AnyAnnotation[] onConstructor() default {};
@@ -63,8 +63,7 @@ public @interface AllArgsConstructor {
* However, this annotation is new in 1.6 which means those compiling for 1.5 will need
* to set this value to true.
*
- * @deprecated Java 1.5 has already been end-of-lifed. As java 1.5 loses ground this
- * method will eventually be removed.
+ * @deprecated THIS FEATURE WILL BE REMOVED after March 31st 2015. Use configuration key {@link ConfigurationKeys#ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES} instead.
*/
@Deprecated
boolean suppressConstructorProperties() default false;
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java
index 639d2dda..dd339301 100644
--- a/src/core/lombok/ConfigurationKeys.java
+++ b/src/core/lombok/ConfigurationKeys.java
@@ -43,6 +43,16 @@ public class ConfigurationKeys {
*/
public static final ConfigurationKey ANY_CONSTRUCTOR_FLAG_USAGE = new ConfigurationKey("lombok.anyConstructor.flagUsage", "Emit a warning or error if any of the XxxArgsConstructor annotations are used.") {};
+ /**
+ * lombok configuration: {@code lombok.anyConstructor.suppressConstructorProperties} = {@code true} | {@code false}.
+ *
+ * If {@code false} or this configuration is omitted, all generated constructors with at least 1 argument get a {@code @ConstructorProperties}.
+ * To suppress the generation of it, set this configuration to {@code true}.
+ *
+ * NB: GWT projects, and probably android projects, should explicitly set this key to {@code true} for the entire project.
+ */
+ public static final ConfigurationKey ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES = new ConfigurationKey("lombok.anyConstructor.suppressConstructorProperties", "Suppress the generation of @ConstructorProperties for generated constructors (default: false).") {};
+
/**
* lombok configuration: {@code lombok.allArgsConstructor.flagUsage} = {@code WARNING} | {@code ERROR}.
*
diff --git a/src/core/lombok/Getter.java b/src/core/lombok/Getter.java
index 57f5e40a..428f53ef 100644
--- a/src/core/lombok/Getter.java
+++ b/src/core/lombok/Getter.java
@@ -58,7 +58,7 @@ public @interface Getter {
lombok.AccessLevel value() default lombok.AccessLevel.PUBLIC;
/**
- * Any annotations listed here are put on the generated method. The syntax for this feature is: {@code @Getter(onMethod=@_({@AnnotationsGoHere}))}
+ * Any annotations listed here are put on the generated method. The syntax for this feature is: {@code @Getter(onMethod=@__({@AnnotationsGoHere}))}
*/
AnyAnnotation[] onMethod() default @AnyAnnotation;
diff --git a/src/core/lombok/NoArgsConstructor.java b/src/core/lombok/NoArgsConstructor.java
index bbf2d9e6..cd3e5568 100644
--- a/src/core/lombok/NoArgsConstructor.java
+++ b/src/core/lombok/NoArgsConstructor.java
@@ -51,7 +51,7 @@ public @interface NoArgsConstructor {
String staticName() default "";
/**
- * Any annotations listed here are put on the generated constructor. The syntax for this feature is: {@code @NoArgsConstructor(onConstructor=@_({@AnnotationsGoHere}))}
+ * Any annotations listed here are put on the generated constructor. The syntax for this feature is: {@code @NoArgsConstructor(onConstructor=@__({@AnnotationsGoHere}))}
*/
AnyAnnotation[] onConstructor() default {};
diff --git a/src/core/lombok/RequiredArgsConstructor.java b/src/core/lombok/RequiredArgsConstructor.java
index 31c4b81d..8bb57c1a 100644
--- a/src/core/lombok/RequiredArgsConstructor.java
+++ b/src/core/lombok/RequiredArgsConstructor.java
@@ -49,7 +49,7 @@ public @interface RequiredArgsConstructor {
String staticName() default "";
/**
- * Any annotations listed here are put on the generated constructor. The syntax for this feature is: {@code @RequiredArgsConstructor(onConstructor=@_({@AnnotationsGoHere}))}
+ * Any annotations listed here are put on the generated constructor. The syntax for this feature is: {@code @RequiredArgsConstructor(onConstructor=@__({@AnnotationsGoHere}))}
*/
AnyAnnotation[] onConstructor() default {};
@@ -63,8 +63,7 @@ public @interface RequiredArgsConstructor {
* However, this annotation is new in 1.6 which means those compiling for 1.5 will need
* to set this value to true.
*
- * @deprecated Java 1.5 has already been end-of-lifed. As java 1.5 loses ground this
- * method will eventually be removed.
+ * @deprecated THIS FEATURE WILL BE REMOVED after March 31st 2015. Use configuration key {@link ConfigurationKeys#ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES} instead.
*/
@Deprecated
boolean suppressConstructorProperties() default false;
diff --git a/src/core/lombok/Setter.java b/src/core/lombok/Setter.java
index 22622520..5e07b802 100644
--- a/src/core/lombok/Setter.java
+++ b/src/core/lombok/Setter.java
@@ -59,12 +59,12 @@ public @interface Setter {
lombok.AccessLevel value() default lombok.AccessLevel.PUBLIC;
/**
- * Any annotations listed here are put on the generated method. The syntax for this feature is: {@code @Setter(onMethod=@_({@AnnotationsGoHere}))}
+ * Any annotations listed here are put on the generated method. The syntax for this feature is: {@code @Setter(onMethod=@__({@AnnotationsGoHere}))}
*/
AnyAnnotation[] onMethod() default {};
/**
- * Any annotations listed here are put on the generated method's parameter. The syntax for this feature is: {@code @Setter(onParam=@_({@AnnotationsGoHere}))}
+ * Any annotations listed here are put on the generated method's parameter. The syntax for this feature is: {@code @Setter(onParam=@__({@AnnotationsGoHere}))}
*/
AnyAnnotation[] onParam() default {};
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 {
fields.add(fieldNode);
}
- new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, fields, null, SkipIfConstructorExists.I_AM_BUILDER, true, Collections.emptyList(), ast);
+ new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, fields, null, SkipIfConstructorExists.I_AM_BUILDER, null, Collections.emptyList(), ast);
returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p);
typeParams = td.typeParameters;
@@ -209,7 +209,7 @@ public class HandleBuilder extends EclipseAnnotationHandler {
}
if (constructorExists(builderType) == MemberExistsResult.NOT_EXISTS) {
- ConstructorDeclaration cd = HandleConstructor.createConstructor(AccessLevel.PACKAGE, builderType, Collections.emptyList(), true, ast, Collections.emptyList());
+ ConstructorDeclaration cd = HandleConstructor.createConstructor(AccessLevel.PACKAGE, builderType, Collections.emptyList(), null, ast, Collections.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 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 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 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 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 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 fields, String staticName, SkipIfConstructorExists skipIfConstructorExists, boolean suppressConstructorProperties, List onConstructor, ASTNode source) {
+ public void generateConstructor(EclipseNode typeNode, AccessLevel level, List fields, String staticName, SkipIfConstructorExists skipIfConstructorExists, Boolean suppressConstructorProperties, List 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 fields,
- boolean suppressConstructorProperties, ASTNode source, List onConstructor) {
+ Boolean suppressConstructorProperties, ASTNode source, List 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);
}
diff --git a/src/core/lombok/experimental/Wither.java b/src/core/lombok/experimental/Wither.java
index f667cb1f..fe113bb0 100644
--- a/src/core/lombok/experimental/Wither.java
+++ b/src/core/lombok/experimental/Wither.java
@@ -60,12 +60,12 @@ public @interface Wither {
AccessLevel value() default AccessLevel.PUBLIC;
/**
- * Any annotations listed here are put on the generated method. The syntax for this feature is: {@code @Setter(onMethod=@_({@AnnotationsGoHere}))}
+ * Any annotations listed here are put on the generated method. The syntax for this feature is: {@code @Setter(onMethod=@__({@AnnotationsGoHere}))}
*/
AnyAnnotation[] onMethod() default {};
/**
- * Any annotations listed here are put on the generated method's parameter. The syntax for this feature is: {@code @Setter(onParam=@_({@AnnotationsGoHere}))}
+ * Any annotations listed here are put on the generated method's parameter. The syntax for this feature is: {@code @Setter(onParam=@__({@AnnotationsGoHere}))}
*/
AnyAnnotation[] onParam() default {};
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index b382395e..bf3b39dc 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -114,7 +114,8 @@ public class HandleBuilder extends JavacAnnotationHandler {
allFields.append(fieldNode);
}
- new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, List.nil(), allFields.toList(), null, SkipIfConstructorExists.I_AM_BUILDER, true, annotationNode);
+
+ new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, List.nil(), allFields.toList(), null, SkipIfConstructorExists.I_AM_BUILDER, null, annotationNode);
returnType = namePlusTypeParamsToTypeReference(tdParent.getTreeMaker(), td.name, td.typarams);
typeParams = td.typarams;
@@ -198,7 +199,7 @@ public class HandleBuilder extends JavacAnnotationHandler {
}
if (constructorExists(builderType) == MemberExistsResult.NOT_EXISTS) {
- JCMethodDecl cd = HandleConstructor.createConstructor(AccessLevel.PACKAGE, List.nil(), builderType, List.nil(), true, ast);
+ JCMethodDecl cd = HandleConstructor.createConstructor(AccessLevel.PACKAGE, List.nil(), builderType, List.nil(), null, ast);
if (cd != null) injectMethod(builderType, cd);
}
diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java
index adfa253f..0618706e 100644
--- a/src/core/lombok/javac/handlers/HandleConstructor.java
+++ b/src/core/lombok/javac/handlers/HandleConstructor.java
@@ -69,10 +69,10 @@ public class HandleConstructor {
List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor=", annotationNode);
NoArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
- String staticName = ann.staticName();
if (level == AccessLevel.NONE) return;
+ String staticName = ann.staticName();
List fields = List.nil();
- new HandleConstructor().generateConstructor(typeNode, level, onConstructor, fields, staticName, SkipIfConstructorExists.NO, false, annotationNode);
+ new HandleConstructor().generateConstructor(typeNode, level, onConstructor, fields, staticName, SkipIfConstructorExists.NO, null, annotationNode);
}
}
@@ -88,10 +88,15 @@ public class HandleConstructor {
List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor=", annotationNode);
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;
+ }
+
new HandleConstructor().generateConstructor(typeNode, level, onConstructor, findRequiredFields(typeNode), staticName, SkipIfConstructorExists.NO, suppressConstructorProperties, annotationNode);
}
}
@@ -125,10 +130,14 @@ public class HandleConstructor {
List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor=", annotationNode);
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;
+ }
new HandleConstructor().generateConstructor(typeNode, level, onConstructor, findAllFields(typeNode), staticName, SkipIfConstructorExists.NO, suppressConstructorProperties, annotationNode);
}
}
@@ -165,7 +174,7 @@ public class HandleConstructor {
}
public void generateRequiredArgsConstructor(JavacNode typeNode, AccessLevel level, String staticName, SkipIfConstructorExists skipIfConstructorExists, JavacNode source) {
- generateConstructor(typeNode, level, List.nil(), findRequiredFields(typeNode), staticName, skipIfConstructorExists, false, source);
+ generateConstructor(typeNode, level, List.nil(), findRequiredFields(typeNode), staticName, skipIfConstructorExists, null, source);
}
public enum SkipIfConstructorExists {
@@ -173,10 +182,10 @@ public class HandleConstructor {
}
public void generateAllArgsConstructor(JavacNode typeNode, AccessLevel level, String staticName, SkipIfConstructorExists skipIfConstructorExists, JavacNode source) {
- generateConstructor(typeNode, level, List.nil(), findAllFields(typeNode), staticName, skipIfConstructorExists, false, source);
+ generateConstructor(typeNode, level, List.nil(), findAllFields(typeNode), staticName, skipIfConstructorExists, null, source);
}
- public void generateConstructor(JavacNode typeNode, AccessLevel level, List onConstructor, List fields, String staticName, SkipIfConstructorExists skipIfConstructorExists, boolean suppressConstructorProperties, JavacNode source) {
+ public void generateConstructor(JavacNode typeNode, AccessLevel level, List onConstructor, List fields, String staticName, SkipIfConstructorExists skipIfConstructorExists, Boolean suppressConstructorProperties, JavacNode source) {
boolean staticConstrRequired = staticName != null && !staticName.equals("");
if (skipIfConstructorExists != SkipIfConstructorExists.NO && constructorExists(typeNode) != MemberExistsResult.NOT_EXISTS) return;
@@ -227,12 +236,20 @@ public class HandleConstructor {
mods.annotations = mods.annotations.append(annotation);
}
- public static JCMethodDecl createConstructor(AccessLevel level, List onConstructor, JavacNode typeNode, List fields, boolean suppressConstructorProperties, JCTree source) {
+ public static JCMethodDecl createConstructor(AccessLevel level, List onConstructor, JavacNode typeNode, List fields, Boolean suppressConstructorProperties, JCTree source) {
JavacTreeMaker maker = typeNode.getTreeMaker();
boolean isEnum = (((JCClassDecl) typeNode.get()).mods.flags & Flags.ENUM) != 0;
if (isEnum) level = AccessLevel.PRIVATE;
+ if (suppressConstructorProperties == null) {
+ if (fields.isEmpty()) {
+ suppressConstructorProperties = false;
+ } else {
+ suppressConstructorProperties = Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES));
+ }
+ }
+
ListBuffer nullChecks = new ListBuffer();
ListBuffer assigns = new ListBuffer();
ListBuffer params = new ListBuffer();
@@ -257,7 +274,7 @@ public class HandleConstructor {
}
JCModifiers mods = maker.Modifiers(toJavacModifier(level), List.nil());
- if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && !isLocalType(typeNode) && LombokOptionsFactory.getDelombokOptions(typeNode.getContext()).getFormatPreferences().generateConstructorProperties()) {
+ if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && level != AccessLevel.PACKAGE && !isLocalType(typeNode) && LombokOptionsFactory.getDelombokOptions(typeNode.getContext()).getFormatPreferences().generateConstructorProperties()) {
addConstructorProperties(mods, typeNode, fields);
}
if (onConstructor != null) mods.annotations = mods.annotations.appendList(copyAnnotations(onConstructor));
diff --git a/test/transform/resource/after-delombok/Constructors.java b/test/transform/resource/after-delombok/Constructors.java
index 12aa75ab..4ffdc62b 100644
--- a/test/transform/resource/after-delombok/Constructors.java
+++ b/test/transform/resource/after-delombok/Constructors.java
@@ -58,12 +58,10 @@ class NoArgsConstructor1 {
class RequiredArgsConstructorStaticNameGenerics {
final T x;
String name;
-
@java.lang.SuppressWarnings("all")
private RequiredArgsConstructorStaticNameGenerics(final T x) {
this.x = x;
}
-
@java.lang.SuppressWarnings("all")
public static RequiredArgsConstructorStaticNameGenerics of(final T x) {
return new RequiredArgsConstructorStaticNameGenerics(x);
@@ -72,14 +70,19 @@ class RequiredArgsConstructorStaticNameGenerics {
class RequiredArgsConstructorStaticNameGenerics2 {
final Class x;
String name;
-
@java.lang.SuppressWarnings("all")
private RequiredArgsConstructorStaticNameGenerics2(final Class x) {
this.x = x;
}
-
@java.lang.SuppressWarnings("all")
public static RequiredArgsConstructorStaticNameGenerics2 of(final Class x) {
return new RequiredArgsConstructorStaticNameGenerics2(x);
}
-}
\ No newline at end of file
+}
+class AllArgsConstructorPackageAccess {
+ final String x;
+ @java.lang.SuppressWarnings("all")
+ AllArgsConstructorPackageAccess(final String x) {
+ this.x = x;
+ }
+}
diff --git a/test/transform/resource/after-delombok/ConstructorsConfiguration.java b/test/transform/resource/after-delombok/ConstructorsConfiguration.java
new file mode 100644
index 00000000..5bec3ae3
--- /dev/null
+++ b/test/transform/resource/after-delombok/ConstructorsConfiguration.java
@@ -0,0 +1,15 @@
+class ConstructorsConfiguration {
+ int x;
+ @java.lang.SuppressWarnings("all")
+ public ConstructorsConfiguration(final int x) {
+ this.x = x;
+ }
+}
+class ConstructorsConfigurationExplicit {
+ int x;
+ @java.beans.ConstructorProperties({"x"})
+ @java.lang.SuppressWarnings("all")
+ public ConstructorsConfigurationExplicit(final int x) {
+ this.x = x;
+ }
+}
diff --git a/test/transform/resource/after-delombok/DataConfiguration.java b/test/transform/resource/after-delombok/DataConfiguration.java
new file mode 100644
index 00000000..230083ec
--- /dev/null
+++ b/test/transform/resource/after-delombok/DataConfiguration.java
@@ -0,0 +1,38 @@
+class DataConfiguration {
+ final int x;
+ @java.lang.SuppressWarnings("all")
+ public DataConfiguration(final int x) {
+ this.x = x;
+ }
+ @java.lang.SuppressWarnings("all")
+ public int getX() {
+ return this.x;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof DataConfiguration)) return false;
+ final DataConfiguration other = (DataConfiguration)o;
+ if (!other.canEqual((java.lang.Object)this)) return false;
+ if (this.getX() != other.getX()) return false;
+ return true;
+ }
+ @java.lang.SuppressWarnings("all")
+ protected boolean canEqual(final java.lang.Object other) {
+ return other instanceof DataConfiguration;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = result * PRIME + this.getX();
+ return result;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public java.lang.String toString() {
+ return "DataConfiguration(x=" + this.getX() + ")";
+ }
+}
diff --git a/test/transform/resource/after-ecj/Constructors.java b/test/transform/resource/after-ecj/Constructors.java
index 540c2407..a4597ce6 100644
--- a/test/transform/resource/after-ecj/Constructors.java
+++ b/test/transform/resource/after-ecj/Constructors.java
@@ -70,4 +70,11 @@
public static @java.lang.SuppressWarnings("all") RequiredArgsConstructorStaticNameGenerics2 of(final Class x) {
return new RequiredArgsConstructorStaticNameGenerics2(x);
}
+}
+@lombok.AllArgsConstructor(access = lombok.AccessLevel.PACKAGE) class AllArgsConstructorPackageAccess {
+ final String x;
+ @java.lang.SuppressWarnings("all") AllArgsConstructorPackageAccess(final String x) {
+ super();
+ this.x = x;
+ }
}
\ No newline at end of file
diff --git a/test/transform/resource/after-ecj/ConstructorsConfiguration.java b/test/transform/resource/after-ecj/ConstructorsConfiguration.java
new file mode 100644
index 00000000..b55d3e03
--- /dev/null
+++ b/test/transform/resource/after-ecj/ConstructorsConfiguration.java
@@ -0,0 +1,14 @@
+@lombok.AllArgsConstructor class ConstructorsConfiguration {
+ int x;
+ public @java.lang.SuppressWarnings("all") ConstructorsConfiguration(final int x) {
+ super();
+ this.x = x;
+ }
+}
+@lombok.AllArgsConstructor(suppressConstructorProperties = false) class ConstructorsConfigurationExplicit {
+ int x;
+ public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") ConstructorsConfigurationExplicit(final int x) {
+ super();
+ this.x = x;
+ }
+}
diff --git a/test/transform/resource/after-ecj/DataConfiguration.java b/test/transform/resource/after-ecj/DataConfiguration.java
new file mode 100644
index 00000000..f2733a88
--- /dev/null
+++ b/test/transform/resource/after-ecj/DataConfiguration.java
@@ -0,0 +1,34 @@
+@lombok.Data class DataConfiguration {
+ final int x;
+ public @java.lang.SuppressWarnings("all") int getX() {
+ return this.x;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
+ if ((o == this))
+ return true;
+ if ((! (o instanceof DataConfiguration)))
+ return false;
+ final @java.lang.SuppressWarnings("all") DataConfiguration other = (DataConfiguration) o;
+ if ((! other.canEqual((java.lang.Object) this)))
+ return false;
+ if ((this.getX() != other.getX()))
+ return false;
+ return true;
+ }
+ protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
+ return (other instanceof DataConfiguration);
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = ((result * PRIME) + this.getX());
+ return result;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
+ return (("DataConfiguration(x=" + this.getX()) + ")");
+ }
+ public @java.lang.SuppressWarnings("all") DataConfiguration(final int x) {
+ super();
+ this.x = x;
+ }
+}
diff --git a/test/transform/resource/before/Constructors.java b/test/transform/resource/before/Constructors.java
index 45b3a199..c80acf2b 100644
--- a/test/transform/resource/before/Constructors.java
+++ b/test/transform/resource/before/Constructors.java
@@ -30,3 +30,6 @@
final Class x;
String name;
}
+@lombok.AllArgsConstructor(access=lombok.AccessLevel.PACKAGE) class AllArgsConstructorPackageAccess {
+ final String x;
+}
\ No newline at end of file
diff --git a/test/transform/resource/before/ConstructorsConfiguration.java b/test/transform/resource/before/ConstructorsConfiguration.java
new file mode 100644
index 00000000..8fae10fc
--- /dev/null
+++ b/test/transform/resource/before/ConstructorsConfiguration.java
@@ -0,0 +1,9 @@
+//CONF: lombok.anyConstructor.suppressConstructorProperties = true
+@lombok.AllArgsConstructor
+class ConstructorsConfiguration {
+ int x;
+}
+@lombok.AllArgsConstructor(suppressConstructorProperties=false)
+class ConstructorsConfigurationExplicit {
+ int x;
+}
diff --git a/test/transform/resource/before/DataConfiguration.java b/test/transform/resource/before/DataConfiguration.java
new file mode 100644
index 00000000..660d6d18
--- /dev/null
+++ b/test/transform/resource/before/DataConfiguration.java
@@ -0,0 +1,5 @@
+//CONF: lombok.anyConstructor.suppressConstructorProperties = true
+@lombok.Data
+class DataConfiguration {
+ final int x;
+}
diff --git a/usage_examples/experimental/onXExample_pre.jpage b/usage_examples/experimental/onXExample_pre.jpage
index fa03e2cd..f8fcb435 100644
--- a/usage_examples/experimental/onXExample_pre.jpage
+++ b/usage_examples/experimental/onXExample_pre.jpage
@@ -7,9 +7,9 @@ import javax.persistence.Id;
import javax.persistence.Column;
import javax.validation.constraints.Max;
-@AllArgsConstructor(onConstructor=@_(@Inject))
+@AllArgsConstructor(onConstructor=@__(@Inject))
public class OnXExample {
- @Getter(onMethod=@_({@Id, @Column(name="unique-id")}))
- @Setter(onParam=@_(@Max(10000)))
+ @Getter(onMethod=@__({@Id, @Column(name="unique-id")}))
+ @Setter(onParam=@__(@Max(10000)))
private long unid;
}
diff --git a/website/features/Constructor.html b/website/features/Constructor.html
index 272df06e..c7e40dfb 100644
--- a/website/features/Constructor.html
+++ b/website/features/Constructor.html
@@ -35,7 +35,7 @@
Such a static factory method will infer generics, unlike a normal constructor. This means your API users get write MapEntry.of("foo", 5)
instead of the much longer
new MapEntry<String, Integer>("foo", 5)
.
- To put annotations on the generated constructor, you can use onConstructor=@_({@AnnotationsHere})
, but be careful; this is an experimental feature. For more details see the documentation on the onX feature.
+ To put annotations on the generated constructor, you can use onConstructor=@__({@AnnotationsHere})
, but be careful; this is an experimental feature. For more details see the documentation on the onX feature.
Static fields are skipped by these annotations. Also, a @java.beans.ConstructorProperties
annotation is added for all constructors with at least 1 argument,
which allows bean editor tools to call the generated constructors. @ConstructorProperties
is now in Java 1.6, which means that if your code is intended for
diff --git a/website/features/GetterSetter.html b/website/features/GetterSetter.html
index 7e2ff226..2e39e1ad 100644
--- a/website/features/GetterSetter.html
+++ b/website/features/GetterSetter.html
@@ -29,7 +29,7 @@
You can always manually disable getter/setter generation for any field by using the special AccessLevel.NONE
access level. This lets you override the
behaviour of a @Getter
, @Setter
or @Data
annotation on a class.
- To put annotations on the generated method, you can use onMethod=@_({@AnnotationsHere})
; to put annotations on the only parameter of a generated setter method, you can use onParam=@_({@AnnotationsHere})
. Be careful though! This is an experimental feature. For more details see the documentation on the onX feature.
+ To put annotations on the generated method, you can use onMethod=@__({@AnnotationsHere})
; to put annotations on the only parameter of a generated setter method, you can use onParam=@__({@AnnotationsHere})
. Be careful though! This is an experimental feature. For more details see the documentation on the onX feature.
NEW in lombok v1.12.0: javadoc on the field will now be copied to generated getters and setters. Normally, all text is copied, and @return
is moved to the getter, whilst @param
lines are moved to the setter. Moved means: Deleted from the field's javadoc. It is also possible to define unique text for each getter/setter. To do that, you create a 'section' named GETTER
and/or SETTER
. A section is a line in your javadoc containing 2 or more dashes, then the text 'GETTER' or 'SETTER', followed by 2 or more dashes, and nothing else on the line. If you use sections, @return
and @param
stripping for that section is no longer done (move the @return
or @param
line into the section).
diff --git a/website/features/experimental/Wither.html b/website/features/experimental/Wither.html
index b334cd7c..46d3b08b 100644
--- a/website/features/experimental/Wither.html
+++ b/website/features/experimental/Wither.html
@@ -45,7 +45,7 @@
@Wither(level = AccessLevel.PROTECTED)
. Also like @Setter
, you can also put a @Wither
annotation on a type, which means
a 'wither' is generated for each field (even non-final fields).
- To put annotations on the generated method, you can use onMethod=@_({@AnnotationsHere})
; to put annotations on the only parameter of a generated wither method, you can use onParam=@_({@AnnotationsHere})
. Be careful though! This is an experimental feature. For more details see the documentation on the onX feature.
+ To put annotations on the generated method, you can use onMethod=@__({@AnnotationsHere})
; to put annotations on the only parameter of a generated wither method, you can use onParam=@__({@AnnotationsHere})
. Be careful though! This is an experimental feature. For more details see the documentation on the onX feature.
NEW in lombok v1.12.0: javadoc on the field will now be copied to generated withers. Normally, all text is copied, and @param
is moved to the wither, whilst @return
lines are stripped from the wither's javadoc. Moved means: Deleted from the field's javadoc. It is also possible to define unique text for the wither's javadoc. To do that, you create a 'section' named WITHER
. A section is a line in your javadoc containing 2 or more dashes, then the text 'WITHER', followed by 2 or more dashes, and nothing else on the line. If you use sections, @return
and @param
stripping / copying for that section is no longer done (move the @param
line into the section).
diff --git a/website/features/experimental/onX.html b/website/features/experimental/onX.html
index 66b0164f..530d98a4 100644
--- a/website/features/experimental/onX.html
+++ b/website/features/experimental/onX.html
@@ -42,7 +42,7 @@
@Setter
and @Wither
support onParam
in addition to onMethod
; annotations listed will be put on the only parameter that the generated method has.
- The syntax is a little strange; to use any of the 3 onX
features, you must wrap the annotations to be applied to the constructor / method / parameter in @_(@AnnotationGoesHere)
. To apply multiple annotations, use @_({@Annotation1, @Annotation2})
. The annotations can themselves obviously have parameters as well.
+ The syntax is a little strange; to use any of the 3 onX
features, you must wrap the annotations to be applied to the constructor / method / parameter in @__(@AnnotationGoesHere)
. To apply multiple annotations, use @__({@Annotation1, @Annotation2})
. The annotations can themselves obviously have parameters as well.
@@ -60,7 +60,7 @@
Small print
- The reason of the weird syntax is to make this feature work in javac 7 compilers; the @_
type is an annotation reference to the annotation type _
(underscore) which doesn't actually exist; this makes javac 7 delay aborting the compilation process due to an error because it is possible an annotation processor will later create the _
type. Instead, lombok applies the annotations and removes the references so that the error will never actually occur. The point is: The _
type must not exist, otherwise the feature does not work. In the rare case that the _
type does exist (and is imported or in the package), you can simply add more underscores. Technically any non-existent type would work, but to maintain consistency and readability and catch erroneous use, lombok considers it an error if the 'wrapper' annotation is anything but a series of underscores.
+ The reason of the weird syntax is to make this feature work in javac 7 compilers; the @__
type is an annotation reference to the annotation type _
(underscore) which doesn't actually exist; this makes javac 7 delay aborting the compilation process due to an error because it is possible an annotation processor will later create the _
type. Instead, lombok applies the annotations and removes the references so that the error will never actually occur. The point is: The _
type must not exist, otherwise the feature does not work. In the rare case that the _
type does exist (and is imported or in the package), you can simply add more underscores. Technically any non-existent type would work, but to maintain consistency and readability and catch erroneous use, lombok considers it an error if the 'wrapper' annotation is anything but a series of underscores.
To reiterate: This feature can disappear at any time; if you use this feature, be prepared to adjust your code when we find a nicer way of implementing this feature, or, if a future version of javac forces us to remove this feature entirely with no alternative.
--
cgit