diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2014-06-01 09:50:18 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2014-06-01 09:50:18 +0200 |
commit | fe25bb153326d657ad98d9bd55c801d8815f39b3 (patch) | |
tree | 5a7034ab5afe1249b086a9a25557381bf7222748 /src/core/lombok/eclipse | |
parent | 6159508d40ed2a79bae98ea4a7f24edc4af36d88 (diff) | |
download | lombok-fe25bb153326d657ad98d9bd55c801d8815f39b3.tar.gz lombok-fe25bb153326d657ad98d9bd55c801d8815f39b3.tar.bz2 lombok-fe25bb153326d657ad98d9bd55c801d8815f39b3.zip |
Revert "Remove a wrong test for copyAnnotations returning empty array."
While Maaartinus' thoughts are obviously correct (far better to use an empty array to convey 'this list-like construct has 0 items in it right now', vs. a null pointer),
eclipse actually uses null-as-empty almost everywhere, and a lot of eclipse code will simply break if you don't do it right.
This reverts commit 842a4759165c5cd05aae63da3921ee11a3641a4b.
Diffstat (limited to 'src/core/lombok/eclipse')
4 files changed, 21 insertions, 12 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index d21c1125..b72d000f 100644 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -333,9 +333,8 @@ public class HandleConstructor { Statement nullCheck = generateNullCheck(field, sourceNode); if (nullCheck != null) nullChecks.add(nullCheck); } - - parameter.annotations = copyAnnotations(source, nonNulls, nullables); - + Annotation[] copiedAnnotations = copyAnnotations(source, nonNulls, nullables); + if (copiedAnnotations.length != 0) parameter.annotations = copiedAnnotations; params.add(parameter); } @@ -349,9 +348,10 @@ public class HandleConstructor { constructorProperties = createConstructorProperties(source, fields); } - constructor.annotations = copyAnnotations(source, + Annotation[] copiedAnnotations = copyAnnotations(source, onConstructor.toArray(new Annotation[0]), constructorProperties); + if (copiedAnnotations.length != 0) constructor.annotations = copiedAnnotations; } constructor.traverse(new SetGeneratedByVisitor(source), typeDeclaration.scope); @@ -397,7 +397,8 @@ public class HandleConstructor { Argument parameter = new Argument(field.name, fieldPos, copyType(field.type, source), Modifier.FINAL); - parameter.annotations = copyAnnotations(source, findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN)); + Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN)); + if (copiedAnnotations.length != 0) parameter.annotations = copiedAnnotations; params.add(parameter); } diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 14f2fb72..031fff82 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -270,12 +270,14 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { deprecated = new Annotation[] { generateDeprecatedAnnotation(source) }; } - method.annotations = copyAnnotations(source, + Annotation[] copiedAnnotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN), findDelegatesAndMarkAsHandled(fieldNode), deprecated); + + if (copiedAnnotations.length != 0) method.annotations = copiedAnnotations; } method.traverse(new SetGeneratedByVisitor(source), parent.scope); diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index e2bbea37..c22af676 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -216,8 +216,10 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { if (isFieldDeprecated(fieldNode)) { deprecated = new Annotation[] { generateDeprecatedAnnotation(source) }; } - method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated); - + Annotation[] copiedAnnotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated); + if (copiedAnnotations.length != 0) { + method.annotations = copiedAnnotations; + } Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL); param.sourceStart = pS; param.sourceEnd = pE; method.arguments = new Argument[] { param }; @@ -251,7 +253,8 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { } method.statements = statements.toArray(new Statement[0]); - param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0])); + Annotation[] copiedAnnotationsParam = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0])); + if (copiedAnnotationsParam.length != 0) param.annotations = copiedAnnotationsParam; method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; diff --git a/src/core/lombok/eclipse/handlers/HandleWither.java b/src/core/lombok/eclipse/handlers/HandleWither.java index 851ab75b..8b038676 100644 --- a/src/core/lombok/eclipse/handlers/HandleWither.java +++ b/src/core/lombok/eclipse/handlers/HandleWither.java @@ -227,8 +227,10 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { if (isFieldDeprecated(fieldNode)) { deprecated = new Annotation[] { generateDeprecatedAnnotation(source) }; } - method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated); - + Annotation[] copiedAnnotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated); + if (copiedAnnotations.length != 0) { + method.annotations = copiedAnnotations; + } Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL); param.sourceStart = pS; param.sourceEnd = pE; method.arguments = new Argument[] { param }; @@ -281,7 +283,8 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { method.statements = statements.toArray(new Statement[0]); - param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0])); + Annotation[] copiedAnnotationsParam = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0])); + if (copiedAnnotationsParam.length != 0) param.annotations = copiedAnnotationsParam; method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; |