Skip to content

Commit

Permalink
for lombok v2, make generation of ConstructorProperties an optional e…
Browse files Browse the repository at this point in the history
…xtra, instead of default on.
  • Loading branch information
rzwitserloot committed Dec 4, 2017
1 parent 1deb55a commit d7c019c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
15 changes: 15 additions & 0 deletions src/core/lombok/ConfigurationKeys.java
Expand Up @@ -93,9 +93,24 @@ private ConfigurationKeys() {}
* 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.
*
* <br />
* <em>BREAKING CHANGE</em>: Starting with lombok v2.0.0, defaults to {@code false} instead of {@code true}, as {@code @ConstructorProperties} requires extra modules in JDK9.
*
* @see ConfigurationKeys#ANY_CONSTRUCTOR_ADD_CONSTRUCTOR_PROPERTIES
* @deprecated Since version 2.0, use {@link #ANY_CONSTRUCTOR_ADD_CONSTRUCTOR_PROPERTIES} instead.
*/
@Deprecated
public static final ConfigurationKey<Boolean> ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES = new ConfigurationKey<Boolean>("lombok.anyConstructor.suppressConstructorProperties", "Suppress the generation of @ConstructorProperties for generated constructors (default: false).") {};

/**
* lombok configuration: {@code lombok.anyConstructor.addConstructorProperties} = {@code true} | {@code false}.
*
* If {@code true}, all generated constructors with at least 1 argument get a {@code @ConstructorProperties}.
*
*/
public static final ConfigurationKey<Boolean> ANY_CONSTRUCTOR_ADD_CONSTRUCTOR_PROPERTIES = new ConfigurationKey<Boolean>("lombok.anyConstructor.addConstructorProperties", "Generate @ConstructorProperties for generated constructors (default: false).") {};

/**
* lombok configuration: {@code lombok.allArgsConstructor.flagUsage} = {@code WARNING} | {@code ERROR}.
*
Expand Down
12 changes: 7 additions & 5 deletions src/core/lombok/eclipse/handlers/HandleConstructor.java
Expand Up @@ -293,7 +293,7 @@ public static Annotation[] createConstructorProperties(ASTNode source, Collectio
return new Annotation[] { ann };
}

public static ConstructorDeclaration createConstructor(
@SuppressWarnings("deprecation") public static ConstructorDeclaration createConstructor(
AccessLevel level, EclipseNode type, Collection<EclipseNode> fields, boolean allToDefault,
EclipseNode sourceNode, List<Annotation> onConstructor) {

Expand All @@ -305,11 +305,13 @@ public static ConstructorDeclaration createConstructor(

if (isEnum) level = AccessLevel.PRIVATE;

boolean suppressConstructorProperties;
boolean addConstructorProperties;
if (fields.isEmpty()) {
suppressConstructorProperties = false;
addConstructorProperties = false;
} else {
suppressConstructorProperties = Boolean.TRUE.equals(type.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES));
Boolean v = type.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_ADD_CONSTRUCTOR_PROPERTIES);
addConstructorProperties = v != null ? v.booleanValue() :
Boolean.FALSE.equals(type.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES));
}

ConstructorDeclaration constructor = new ConstructorDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult);
Expand Down Expand Up @@ -364,7 +366,7 @@ public static ConstructorDeclaration createConstructor(

/* Generate annotations that must be put on the generated method, and attach them. */ {
Annotation[] constructorProperties = null;
if (!allToDefault && !suppressConstructorProperties && !isLocalType(type)) {
if (!allToDefault && addConstructorProperties && !isLocalType(type)) {
constructorProperties = createConstructorProperties(source, fields);
}

Expand Down
12 changes: 7 additions & 5 deletions src/core/lombok/javac/handlers/HandleConstructor.java
Expand Up @@ -260,18 +260,20 @@ public static void addConstructorProperties(JCModifiers mods, JavacNode node, Li
mods.annotations = mods.annotations.append(annotation);
}

public static JCMethodDecl createConstructor(AccessLevel level, List<JCAnnotation> onConstructor, JavacNode typeNode, List<JavacNode> fields, boolean allToDefault, JavacNode source) {
@SuppressWarnings("deprecation") public static JCMethodDecl createConstructor(AccessLevel level, List<JCAnnotation> onConstructor, JavacNode typeNode, List<JavacNode> fields, boolean allToDefault, JavacNode source) {
JavacTreeMaker maker = typeNode.getTreeMaker();

boolean isEnum = (((JCClassDecl) typeNode.get()).mods.flags & Flags.ENUM) != 0;
if (isEnum) level = AccessLevel.PRIVATE;

boolean suppressConstructorProperties;
boolean addConstructorProperties;

if (fields.isEmpty()) {
suppressConstructorProperties = false;
addConstructorProperties = false;
} else {
suppressConstructorProperties = Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES));
Boolean v = typeNode.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_ADD_CONSTRUCTOR_PROPERTIES);
addConstructorProperties = v != null ? v.booleanValue() :
Boolean.FALSE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES));
}

ListBuffer<JCStatement> nullChecks = new ListBuffer<JCStatement>();
Expand Down Expand Up @@ -299,7 +301,7 @@ public static JCMethodDecl createConstructor(AccessLevel level, List<JCAnnotatio
}

JCModifiers mods = maker.Modifiers(toJavacModifier(level), List.<JCAnnotation>nil());
if (!allToDefault && !suppressConstructorProperties && !isLocalType(typeNode) && LombokOptionsFactory.getDelombokOptions(typeNode.getContext()).getFormatPreferences().generateConstructorProperties()) {
if (!allToDefault && addConstructorProperties && !isLocalType(typeNode) && LombokOptionsFactory.getDelombokOptions(typeNode.getContext()).getFormatPreferences().generateConstructorProperties()) {
addConstructorProperties(mods, typeNode, fields);
}
if (onConstructor != null) mods.annotations = mods.annotations.appendList(copyAnnotations(onConstructor));
Expand Down

0 comments on commit d7c019c

Please sign in to comment.