aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java36
-rw-r--r--src/core/lombok/eclipse/handlers/HandleBuilder.java12
-rw-r--r--src/core/lombok/eclipse/handlers/HandleConstructor.java12
-rw-r--r--src/core/lombok/eclipse/handlers/HandleGetter.java12
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java8
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSuperBuilder.java9
-rw-r--r--src/core/lombok/eclipse/handlers/HandleWither.java8
7 files changed, 52 insertions, 45 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index e7a58de3..a972c1fe 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -48,6 +48,7 @@ import lombok.core.AnnotationValues;
import lombok.core.AnnotationValues.AnnotationValue;
import lombok.core.TypeResolver;
import lombok.core.configuration.NullCheckExceptionType;
+import lombok.core.configuration.TypeName;
import lombok.core.debug.ProblemReporter;
import lombok.core.handlers.HandlerUtil;
import lombok.eclipse.Eclipse;
@@ -672,19 +673,42 @@ public class EclipseHandlerUtil {
}
}
+ public static boolean hasNonNullAnnotations(EclipseNode node) {
+ AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get();
+ if (avd.annotations == null) return false;
+ for (Annotation annotation : avd.annotations) {
+ TypeReference typeRef = annotation.type;
+ if (typeRef != null && typeRef.getTypeName() != null) {
+ for (String bn : NONNULL_ANNOTATIONS) if (typeMatches(bn, node, typeRef)) return true;
+ }
+ }
+ return false;
+ }
+
private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0];
/**
- * Searches the given field node for annotations and returns each one that matches the provided list of names.
+ * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list).
*/
- public static Annotation[] findExactAnnotations(AbstractVariableDeclaration field, List<String> names) {
+ public static Annotation[] findCopyableAnnotations(EclipseNode node) {
+ AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get();
+ if (avd.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
List<Annotation> result = new ArrayList<Annotation>();
- if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
- for (Annotation annotation : field.annotations) {
+ List<TypeName> configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS);
+
+ for (Annotation annotation : avd.annotations) {
TypeReference typeRef = annotation.type;
+ boolean match = false;
if (typeRef != null && typeRef.getTypeName() != null) {
- String annoName = toQualifiedName(typeRef.getTypeName());
- if (names.contains(annoName)) result.add(annotation);
+ for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, typeRef)) {
+ result.add(annotation);
+ match = true;
+ break;
+ }
+ if (!match) for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, typeRef)) {
+ result.add(annotation);
+ break;
+ }
}
}
return result.toArray(EMPTY_ANNOTATIONS_ARRAY);
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index f05896ab..280afc26 100644
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -200,14 +200,12 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
EclipseNode isDefault = findAnnotation(Builder.Default.class, fieldNode);
boolean isFinal = ((fd.modifiers & ClassFileConstants.AccFinal) != 0) || (valuePresent && !hasAnnotation(NonFinal.class, fieldNode));
- Annotation[] nonNulls = findAnnotations(fd, NON_NULL_PATTERN);
- Annotation[] nullables = findAnnotations(fd, NULLABLE_PATTERN);
- Annotation[] copyAnnotations = findExactAnnotations(fd, getCopyableAnnotationNames(fieldNode.getAst()));
+ Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode);
BuilderFieldData bfd = new BuilderFieldData();
bfd.rawName = fieldNode.getName().toCharArray();
bfd.name = removePrefixFromField(fieldNode);
- bfd.annotations = copyAnnotations(fd, nonNulls, nullables, copyAnnotations);
+ bfd.annotations = copyAnnotations(fd, copyableAnnotations);
bfd.type = fd.type;
bfd.singularData = getSingularData(fieldNode, ast);
bfd.originalFieldNode = fieldNode;
@@ -381,13 +379,11 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
BuilderFieldData bfd = new BuilderFieldData();
Argument arg = (Argument) param.get();
- Annotation[] nonNulls = findAnnotations(arg, NON_NULL_PATTERN);
- Annotation[] nullables = findAnnotations(arg, NULLABLE_PATTERN);
- Annotation[] copyAnnotations = findExactAnnotations(arg, getCopyableAnnotationNames(param.getAst()));
+ Annotation[] copyableAnnotations = findCopyableAnnotations(param);
bfd.rawName = arg.name;
bfd.name = arg.name;
- bfd.annotations = copyAnnotations(arg, nonNulls, nullables, copyAnnotations);
+ bfd.annotations = copyAnnotations(arg, copyableAnnotations);
bfd.type = arg.type;
bfd.singularData = getSingularData(param, ast);
bfd.originalFieldNode = param;
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java
index 3d947a73..cb07115a 100644
--- a/src/core/lombok/eclipse/handlers/HandleConstructor.java
+++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java
@@ -139,7 +139,7 @@ public class HandleConstructor {
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
if (!filterField(fieldDecl)) continue;
boolean isFinal = (fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0;
- boolean isNonNull = nullMarked && findAnnotations(fieldDecl, NON_NULL_PATTERN).length != 0;
+ boolean isNonNull = nullMarked && hasNonNullAnnotations(child);
if ((isFinal || isNonNull) && fieldDecl.initialization == null) fields.add(child);
}
return fields;
@@ -403,14 +403,12 @@ public class HandleConstructor {
assigns.add(assignment);
long fieldPos = (((long) field.sourceStart) << 32) | field.sourceEnd;
Argument parameter = new Argument(fieldName, fieldPos, copyType(field.type, source), Modifier.FINAL);
- Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
- Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
- Annotation[] copyAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst()));
- if (nonNulls.length != 0) {
+ Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode);
+ if (hasNonNullAnnotations(fieldNode)) {
Statement nullCheck = generateNullCheck(parameter, sourceNode);
if (nullCheck != null) nullChecks.add(nullCheck);
}
- parameter.annotations = copyAnnotations(source, nonNulls, nullables, copyAnnotations);
+ parameter.annotations = copyAnnotations(source, copyableAnnotations);
params.add(parameter);
}
@@ -547,7 +545,7 @@ public class HandleConstructor {
assigns.add(nameRef);
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));
+ parameter.annotations = copyAnnotations(source, findCopyableAnnotations(fieldNode));
params.add(parameter);
}
diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java
index 58af8c1e..7d3fe62f 100644
--- a/src/core/lombok/eclipse/handlers/HandleGetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleGetter.java
@@ -236,8 +236,6 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> {
}
public MethodDeclaration createGetter(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, ASTNode source, boolean lazy, List<Annotation> onMethod) {
- FieldDeclaration field = (FieldDeclaration) fieldNode.get();
-
// Remember the type; lazy will change it;
TypeReference returnType = copyType(((FieldDeclaration) fieldNode.get()).type, source);
@@ -271,12 +269,10 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> {
}
method.annotations = copyAnnotations(source,
- onMethod.toArray(new Annotation[0]),
- findAnnotations(field, NON_NULL_PATTERN),
- findAnnotations(field, NULLABLE_PATTERN),
- findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())),
- findDelegatesAndMarkAsHandled(fieldNode),
- deprecated);
+ onMethod.toArray(new Annotation[0]),
+ findCopyableAnnotations(fieldNode),
+ findDelegatesAndMarkAsHandled(fieldNode),
+ deprecated);
}
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 ca81fef7..529a7d19 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -236,11 +236,9 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
- Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
- Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
- Annotation[] copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst()));
+ Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode);
List<Statement> statements = new ArrayList<Statement>(5);
- if (nonNulls.length == 0) {
+ if (!hasNonNullAnnotations(fieldNode)) {
statements.add(assignment);
} else {
Statement nullCheck = generateNullCheck(field, sourceNode);
@@ -256,7 +254,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
statements.add(returnStatement);
}
method.statements = statements.toArray(new Statement[0]);
- param.annotations = copyAnnotations(source, nonNulls, nullables, copyableAnnotations, onParam.toArray(new Annotation[0]));
+ param.annotations = copyAnnotations(source, copyableAnnotations, onParam.toArray(new Annotation[0]));
method.traverse(new SetGeneratedByVisitor(source), parent.scope);
return method;
diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
index 3c07ac55..559cca20 100644
--- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
@@ -493,12 +493,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
statements.add(assignment);
}
- Annotation[] nonNulls = findAnnotations((FieldDeclaration)fieldNode.originalFieldNode.get(), NON_NULL_PATTERN);
- if (nonNulls.length != 0) {
- Statement nullCheck = generateNullCheck((FieldDeclaration)fieldNode.originalFieldNode.get(), sourceNode);
- if (nullCheck != null) {
- statements.add(nullCheck);
- }
+ if (hasNonNullAnnotations(fieldNode.originalFieldNode)) {
+ Statement nullCheck = generateNullCheck((FieldDeclaration) fieldNode.originalFieldNode.get(), sourceNode);
+ if (nullCheck != null) statements.add(nullCheck);
}
}
diff --git a/src/core/lombok/eclipse/handlers/HandleWither.java b/src/core/lombok/eclipse/handlers/HandleWither.java
index 11032e9c..a99789a6 100644
--- a/src/core/lombok/eclipse/handlers/HandleWither.java
+++ b/src/core/lombok/eclipse/handlers/HandleWither.java
@@ -240,9 +240,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> {
method.typeParameters = null;
method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
- Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
- Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
- Annotation[] copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst()));
+ Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode);
if (!makeAbstract) {
List<Expression> args = new ArrayList<Expression>();
@@ -278,7 +276,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> {
method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
List<Statement> statements = new ArrayList<Statement>(5);
- if (nonNulls.length > 0) {
+ if (hasNonNullAnnotations(fieldNode)) {
Statement nullCheck = generateNullCheck(field, sourceNode);
if (nullCheck != null) statements.add(nullCheck);
}
@@ -286,7 +284,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> {
method.statements = statements.toArray(new Statement[0]);
}
- param.annotations = copyAnnotations(source, nonNulls, nullables, copyableAnnotations, onParam.toArray(new Annotation[0]));
+ param.annotations = copyAnnotations(source, copyableAnnotations, onParam.toArray(new Annotation[0]));
method.traverse(new SetGeneratedByVisitor(source), parent.scope);
return method;