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/Eclipse.java12
-rw-r--r--src/core/lombok/eclipse/TransformEclipseAST.java2
-rw-r--r--src/core/lombok/eclipse/handlers/HandleVal.java38
3 files changed, 31 insertions, 21 deletions
diff --git a/src/core/lombok/eclipse/Eclipse.java b/src/core/lombok/eclipse/Eclipse.java
index 5dcd9de8..ddba726a 100644
--- a/src/core/lombok/eclipse/Eclipse.java
+++ b/src/core/lombok/eclipse/Eclipse.java
@@ -533,7 +533,17 @@ public class Eclipse {
*/
public static boolean annotationTypeMatches(Class<? extends java.lang.annotation.Annotation> type, EclipseNode node) {
if (node.getKind() != Kind.ANNOTATION) return false;
- TypeReference typeRef = ((Annotation)node.get()).type;
+ return typeMatches(type, node, ((Annotation)node.get()).type);
+ }
+
+ /**
+ * Checks if the given TypeReference node is likely to be a reference to the provided class.
+ *
+ * @param type An actual type. This method checks if {@code typeNode} is likely to be a reference to this type.
+ * @param node A Lombok AST node. Any node in the appropriate compilation unit will do (used to get access to import statements).
+ * @param typeNode A type reference to check.
+ */
+ public static boolean typeMatches(Class<?> type, EclipseNode node, TypeReference typeRef) {
if (typeRef == null || typeRef.getTypeName() == null) return false;
String typeName = toQualifiedName(typeRef.getTypeName());
diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java
index bfc35244..1f31bd59 100644
--- a/src/core/lombok/eclipse/TransformEclipseAST.java
+++ b/src/core/lombok/eclipse/TransformEclipseAST.java
@@ -123,6 +123,8 @@ public class TransformEclipseAST {
if (Symbols.hasSymbol("lombok.disable")) return;
+ // Do NOT abort if (ast.bits & ASTNode.HasAllMethodBodies) != 0 - that doesn't work.
+
try {
EclipseAST existing = getAST(ast);
new TransformEclipseAST(existing).go();
diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java
index 7f4f36fb..8ab43131 100644
--- a/src/core/lombok/eclipse/handlers/HandleVal.java
+++ b/src/core/lombok/eclipse/handlers/HandleVal.java
@@ -21,6 +21,8 @@
*/
package lombok.eclipse.handlers;
+import lombok.val;
+import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseASTAdapter;
import lombok.eclipse.EclipseASTVisitor;
import lombok.eclipse.EclipseNode;
@@ -28,7 +30,6 @@ import lombok.eclipse.EclipseNode;
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
import org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
import org.mangosdk.spi.ProviderFor;
/*
@@ -37,25 +38,22 @@ import org.mangosdk.spi.ProviderFor;
@ProviderFor(EclipseASTVisitor.class)
public class HandleVal extends EclipseASTAdapter {
@Override public void visitLocal(EclipseNode localNode, LocalDeclaration local) {
- if (local.type instanceof SingleTypeReference) {
- char[] token = ((SingleTypeReference)local.type).token;
- if (token == null || token.length != 3) return;
- else if (token[0] != 'v' || token[1] != 'a' || token[2] != 'l') return;
-
- boolean variableOfForEach = false;
-
- if (localNode.directUp().get() instanceof ForeachStatement) {
- ForeachStatement fs = (ForeachStatement) localNode.directUp().get();
- variableOfForEach = fs.elementVariable == local;
- }
-
- if (local.initialization == null && !variableOfForEach) {
- localNode.addError("'val' on a local variable requires an initializer expression");
- }
-
- if (local.initialization instanceof ArrayInitializer) {
- localNode.addError("'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })");
- }
+ if (!Eclipse.typeMatches(val.class, localNode, local.type)) return;
+ boolean variableOfForEach = false;
+
+ if (localNode.directUp().get() instanceof ForeachStatement) {
+ ForeachStatement fs = (ForeachStatement) localNode.directUp().get();
+ variableOfForEach = fs.elementVariable == local;
+ }
+
+ if (local.initialization == null && !variableOfForEach) {
+ localNode.addError("'val' on a local variable requires an initializer expression");
+ return;
+ }
+
+ if (local.initialization instanceof ArrayInitializer) {
+ localNode.addError("'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })");
+ return;
}
}
}