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/HandleNonNull.java54
1 files changed, 24 insertions, 30 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleNonNull.java b/src/core/lombok/eclipse/handlers/HandleNonNull.java
index 365eef33..0138c7fb 100644
--- a/src/core/lombok/eclipse/handlers/HandleNonNull.java
+++ b/src/core/lombok/eclipse/handlers/HandleNonNull.java
@@ -65,7 +65,6 @@ import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
import lombok.core.HandlerPriority;
import lombok.eclipse.EcjAugments;
-import lombok.eclipse.EclipseAST;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseNode;
import lombok.spi.Provides;
@@ -221,9 +220,16 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
// As we need both for @NonNull we reset the handled flag during diet parse.
if (!annotationNode.isCompleteParse()) {
- if (annotationNode.up().getKind() == Kind.FIELD) {
+ final EclipseNode node;
+ if (annotationNode.up().getKind() == Kind.TYPE_USE) {
+ node = annotationNode.directUp().directUp();
+ } else {
+ node = annotationNode.up();
+ }
+
+ if (node.getKind() == Kind.FIELD) {
//Check if this is a record and we need to generate the compact form constructor.
- EclipseNode typeNode = annotationNode.up().up();
+ EclipseNode typeNode = node.up();
if (typeNode.getKind() == Kind.TYPE) {
if (isRecord(typeNode)) {
addCompactConstructorIfNeeded(typeNode, annotationNode);
@@ -251,16 +257,23 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
private void handle0(Annotation ast, EclipseNode annotationNode, boolean force) {
handleFlagUsage(annotationNode, ConfigurationKeys.NON_NULL_FLAG_USAGE, "@NonNull");
- if (annotationNode.up().getKind() == Kind.FIELD) {
+ final EclipseNode node;
+ if (annotationNode.up().getKind() == Kind.TYPE_USE) {
+ node = annotationNode.directUp().directUp();
+ } else {
+ node = annotationNode.up();
+ }
+
+ if (node.getKind() == Kind.FIELD) {
// This is meaningless unless the field is used to generate a method (@Setter, @RequiredArgsConstructor, etc),
// but in that case those handlers will take care of it. However, we DO check if the annotation is applied to
// a primitive, because those handlers trigger on any annotation named @NonNull and we only want the warning
// behaviour on _OUR_ 'lombok.NonNull'.
- EclipseNode fieldNode = annotationNode.up();
+ EclipseNode fieldNode = node;
EclipseNode typeNode = fieldNode.up();
try {
- if (isPrimitive(((AbstractVariableDeclaration) annotationNode.up().get()).type)) {
+ if (isPrimitive(((AbstractVariableDeclaration) node.get()).type)) {
annotationNode.addWarning("@NonNull is meaningless on a primitive.");
return;
}
@@ -279,33 +292,14 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
return;
}
+ if (node.getKind() != Kind.ARGUMENT) return;
+
Argument param;
- EclipseNode paramNode;
AbstractMethodDeclaration declaration;
- switch (annotationNode.up().getKind()) {
- case ARGUMENT:
- paramNode = annotationNode.up();
- break;
- case TYPE_USE:
- EclipseNode typeNode = annotationNode.directUp();
- boolean ok = false;
- ASTNode astNode = typeNode.get();
- if (astNode instanceof TypeReference) {
- Annotation[] anns = EclipseAST.getTopLevelTypeReferenceAnnotations((TypeReference) astNode);
- if (anns == null) return;
- for (Annotation ann : anns) if (ast == ann) ok = true;
- }
- if (!ok) return;
- paramNode = typeNode.directUp();
- break;
- default:
- return;
- }
-
try {
- param = (Argument) paramNode.get();
- declaration = (AbstractMethodDeclaration) paramNode.up().get();
+ param = (Argument) node.get();
+ declaration = (AbstractMethodDeclaration) node.up().get();
} catch (Exception e) {
return;
}
@@ -318,7 +312,7 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
}
addNullCheckIfNeeded(declaration, param, annotationNode);
- paramNode.up().rebuild();
+ node.up().rebuild();
}
private void addNullCheckIfNeeded(AbstractMethodDeclaration declaration, AbstractVariableDeclaration param, EclipseNode annotationNode) {