diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2014-05-22 03:30:01 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2014-05-22 03:30:27 +0200 |
commit | 0e673c6b3004a67c760bcbbabdc8abbf35c70722 (patch) | |
tree | c838bf12b37bbd86bc3511afab742f88ef961eb8 /src | |
parent | 29c555805246bda4482a040ef85c4332ad40cfea (diff) | |
download | lombok-0e673c6b3004a67c760bcbbabdc8abbf35c70722.tar.gz lombok-0e673c6b3004a67c760bcbbabdc8abbf35c70722.tar.bz2 lombok-0e673c6b3004a67c760bcbbabdc8abbf35c70722.zip |
added conf keys (and implementation to make them work) for lombok.getter.lazy.flagUsage and lombok.equalsAndHashCode.doNotUseGetters.
Diffstat (limited to 'src')
5 files changed, 26 insertions, 8 deletions
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index dd339301..608bedd1 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -103,6 +103,13 @@ public class ConfigurationKeys { */ public static final ConfigurationKey<FlagUsageType> GETTER_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.getter.flagUsage", "Emit a warning or error if @Getter is used.") {}; + /** + * lombok configuration: {@code lombok.getter.lazy.flagUsage} = {@code WARNING} | {@code ERROR}. + * + * If set, <em>any</em> usage of {@code @Getter(lazy=true)} results in a warning / error. + */ + public static final ConfigurationKey<FlagUsageType> GETTER_LAZY_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.getter.lazy.flagUsage", "Emit a warning or error if @Getter(lazy=true) is used.") {}; + // ----- Setter ----- /** @@ -115,6 +122,13 @@ public class ConfigurationKeys { // ----- EqualsAndHashCode ----- /** + * lombok configuration: {@code lombok.equalsAndHashCode.doNotUseGetters} = {@code true} | {@code false}. + * + * For any class without an {@code @EqualsAndHashCode} that explicitly defines the {@code doNotUseGetters} option, this value is used. + */ + public static final ConfigurationKey<Boolean> EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS = new ConfigurationKey<Boolean>("lombok.equalsAndHashCode.doNotUseGetters", "Don't call the getters but use the fields directly in the generated equalsAndHashCode method.") {}; + + /** * lombok configuration: {@code lombok.equalsAndHashCode.flagUsage} = {@code WARNING} | {@code ERROR}. * * If set, <em>any</em> usage of {@code @EqualsAndHashCode} results in a warning / error. diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index f34e70b9..e1b02051 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -140,7 +140,9 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored."); } - FieldAccess fieldAccess = ann.doNotUseGetters() ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER; + Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS); + boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration; + FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER; generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess, onParam); } diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index d3d974c9..031fff82 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -139,10 +139,10 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { Getter annotationInstance = annotation.getInstance(); AccessLevel level = annotationInstance.value(); boolean lazy = annotationInstance.lazy(); + if (lazy) handleFlagUsage(annotationNode, ConfigurationKeys.GETTER_LAZY_FLAG_USAGE, "@Getter(lazy=true)"); + if (level == AccessLevel.NONE) { - if (lazy) { - annotationNode.addWarning("'lazy' does not work with AccessLevel.NONE."); - } + if (lazy) annotationNode.addWarning("'lazy' does not work with AccessLevel.NONE."); return; } diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index d267a29a..1a6f4a8f 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -107,7 +107,9 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored."); } - FieldAccess fieldAccess = ann.doNotUseGetters() ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER; + Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS); + boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration; + FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER; generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess, onParam); } diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index 063741e2..a330dbc1 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -137,10 +137,10 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { Getter annotationInstance = annotation.getInstance(); AccessLevel level = annotationInstance.value(); boolean lazy = annotationInstance.lazy(); + if (lazy) handleFlagUsage(annotationNode, ConfigurationKeys.GETTER_LAZY_FLAG_USAGE, "@Getter(lazy=true)"); + if (level == AccessLevel.NONE) { - if (lazy) { - annotationNode.addWarning("'lazy' does not work with AccessLevel.NONE."); - } + if (lazy) annotationNode.addWarning("'lazy' does not work with AccessLevel.NONE."); return; } |