diff options
Diffstat (limited to 'src/lombok/eclipse/handlers')
-rw-r--r-- | src/lombok/eclipse/handlers/HandleData.java | 19 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 8 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandleGetter.java | 7 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandleSetter.java | 20 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/PKG.java | 9 |
5 files changed, 30 insertions, 33 deletions
diff --git a/src/lombok/eclipse/handlers/HandleData.java b/src/lombok/eclipse/handlers/HandleData.java index 0296d5e4..38e3135d 100644 --- a/src/lombok/eclipse/handlers/HandleData.java +++ b/src/lombok/eclipse/handlers/HandleData.java @@ -89,7 +89,7 @@ public class HandleData implements EclipseAnnotationHandler<Data> { //Skip static fields. if ( (fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0 ) continue; boolean isFinal = (fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0; - boolean isNonNull = findNonNullAnnotations(fieldDecl).length != 0; + boolean isNonNull = findAnnotations(fieldDecl, NON_NULL_PATTERN).length != 0; if ( (isFinal || isNonNull) && fieldDecl.initialization == null ) nodesForConstructor.add(child); new HandleGetter().generateGetterForField(child, annotationNode.get()); if ( !isFinal ) new HandleSetter().generateSetterForField(child, annotationNode.get()); @@ -151,11 +151,11 @@ public class HandleData implements EclipseAnnotationHandler<Data> { assigns.add(new Assignment(thisX, new SingleNameReference(field.name, p), (int)p)); long fieldPos = (((long)field.sourceStart) << 32) | field.sourceEnd; Argument argument = new Argument(field.name, fieldPos, copyType(field.type), 0); - Annotation[] nonNulls = findNonNullAnnotations(field); - if (nonNulls.length != 0) { - nullChecks.add(generateNullCheck(field)); - argument.annotations = copyAnnotations(nonNulls); - } + Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); + Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); + if (nonNulls.length != 0) nullChecks.add(generateNullCheck(field)); + Annotation[] copiedAnnotations = copyAnnotations(nonNulls, nullables); + if (copiedAnnotations.length != 0) argument.annotations = copiedAnnotations; args.add(argument); } @@ -200,10 +200,9 @@ public class HandleData implements EclipseAnnotationHandler<Data> { assigns.add(new SingleNameReference(field.name, fieldPos)); Argument argument = new Argument(field.name, fieldPos, copyType(field.type), 0); - Annotation[] nonNulls = findNonNullAnnotations(field); - if (nonNulls.length != 0) { - argument.annotations = copyAnnotations(nonNulls); - } + Annotation[] copiedAnnotations = copyAnnotations( + findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN)); + if (copiedAnnotations.length != 0) argument.annotations = copiedAnnotations; args.add(new Argument(field.name, fieldPos, copyType(field.type), 0)); } diff --git a/src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index d8e1562e..f837d4a6 100644 --- a/src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -153,19 +153,19 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA return false; } - boolean isDirectDescendentOfObject = true; + boolean isDirectDescendantOfObject = true; if ( typeDecl.superclass != null ) { String p = typeDecl.superclass.toString(); - isDirectDescendentOfObject = p.equals("Object") || p.equals("java.lang.Object"); + isDirectDescendantOfObject = p.equals("Object") || p.equals("java.lang.Object"); } - if ( isDirectDescendentOfObject && callSuper ) { + if ( isDirectDescendantOfObject && callSuper ) { errorNode.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless."); return true; } - if ( !isDirectDescendentOfObject && !callSuper ) { + if ( !isDirectDescendantOfObject && !callSuper ) { errorNode.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object."); } diff --git a/src/lombok/eclipse/handlers/HandleGetter.java b/src/lombok/eclipse/handlers/HandleGetter.java index 6a4c5ceb..5fb7876a 100644 --- a/src/lombok/eclipse/handlers/HandleGetter.java +++ b/src/lombok/eclipse/handlers/HandleGetter.java @@ -113,9 +113,10 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> { } MethodDeclaration method = generateGetter((TypeDeclaration) fieldNode.up().get(), field, getterName, modifier, pos); - Annotation[] nonNulls = findNonNullAnnotations(field); - if (nonNulls.length != 0) { - method.annotations = copyAnnotations(nonNulls); + Annotation[] copiedAnnotations = copyAnnotations( + findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN)); + if (copiedAnnotations.length != 0) { + method.annotations = copiedAnnotations; } injectMethod(fieldNode.up(), method); diff --git a/src/lombok/eclipse/handlers/HandleSetter.java b/src/lombok/eclipse/handlers/HandleSetter.java index d850e549..6214c86d 100644 --- a/src/lombok/eclipse/handlers/HandleSetter.java +++ b/src/lombok/eclipse/handlers/HandleSetter.java @@ -21,15 +21,8 @@ */ package lombok.eclipse.handlers; -import static lombok.eclipse.Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; -import static lombok.eclipse.Eclipse.annotationTypeMatches; -import static lombok.eclipse.Eclipse.copyAnnotations; -import static lombok.eclipse.Eclipse.copyType; -import static lombok.eclipse.handlers.PKG.findNonNullAnnotations; -import static lombok.eclipse.handlers.PKG.generateNullCheck; -import static lombok.eclipse.handlers.PKG.injectMethod; -import static lombok.eclipse.handlers.PKG.methodExists; -import static lombok.eclipse.handlers.PKG.toModifier; +import static lombok.eclipse.Eclipse.*; +import static lombok.eclipse.handlers.PKG.*; import lombok.AccessLevel; import lombok.Setter; import lombok.core.AnnotationValues; @@ -146,14 +139,15 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> { method.bodyStart = method.declarationSourceStart = method.sourceStart = ast.sourceStart; method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = ast.sourceEnd; - Annotation[] nonNulls = findNonNullAnnotations(field); + Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); + Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); if (nonNulls.length == 0) { method.statements = new Statement[] { assignment }; - } - else { - param.annotations = copyAnnotations(nonNulls); + } else { method.statements = new Statement[] { generateNullCheck(field), assignment }; } + Annotation[] copiedAnnotations = copyAnnotations(nonNulls, nullables); + if (copiedAnnotations.length != 0) param.annotations = copiedAnnotations; return method; } } diff --git a/src/lombok/eclipse/handlers/PKG.java b/src/lombok/eclipse/handlers/PKG.java index 2eae1edf..17096b70 100644 --- a/src/lombok/eclipse/handlers/PKG.java +++ b/src/lombok/eclipse/handlers/PKG.java @@ -26,6 +26,7 @@ import static lombok.eclipse.Eclipse.fromQualifiedName; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import lombok.AccessLevel; import lombok.core.AST.Kind; @@ -231,14 +232,17 @@ class PKG { type.add(method, Kind.METHOD).recursiveSetHandled(); } - static Annotation[] findNonNullAnnotations(FieldDeclaration field) { + static final Pattern NON_NULL_PATTERN = Pattern.compile("^no[tn]null$", Pattern.CASE_INSENSITIVE); + static final Pattern NULLABLE_PATTERN = Pattern.compile("^nullable$", Pattern.CASE_INSENSITIVE); + + static Annotation[] findAnnotations(FieldDeclaration field, Pattern namePattern) { List<Annotation> result = new ArrayList<Annotation>(); for (Annotation annotation : field.annotations) { TypeReference typeRef = annotation.type; if ( typeRef != null && typeRef.getTypeName()!= null ) { char[][] typeName = typeRef.getTypeName(); String suspect = new String(typeName[typeName.length - 1]); - if (suspect.equalsIgnoreCase("NonNull") || suspect.equalsIgnoreCase("NotNull")) { + if ( namePattern.matcher(suspect).matches() ) { result.add(annotation); } } @@ -246,7 +250,6 @@ class PKG { return result.toArray(new Annotation[0]); } - static Statement generateNullCheck(AbstractVariableDeclaration variable) { AllocationExpression exception = new AllocationExpression(); exception.type = new QualifiedTypeReference(fromQualifiedName("java.lang.NullPointerException"), new long[]{0, 0, 0}); |