aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2016-11-21 21:46:59 +0100
committerRoel Spilker <r.spilker@gmail.com>2016-11-21 21:46:59 +0100
commitb63dd315b34e26faeaea935930f07c20f1e700e1 (patch)
tree43a17f0518cfc0e2aab75de393e6415d9dfc1108 /src
parent29e73a7915790ed27b2b68710dbe8e39f0e37e0d (diff)
downloadlombok-b63dd315b34e26faeaea935930f07c20f1e700e1.tar.gz
lombok-b63dd315b34e26faeaea935930f07c20f1e700e1.tar.bz2
lombok-b63dd315b34e26faeaea935930f07c20f1e700e1.zip
Some refinement on var
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleVal.java22
-rw-r--r--src/core/lombok/javac/handlers/HandleVal.java18
2 files changed, 17 insertions, 23 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java
index 49820f60..d8901067 100644
--- a/src/core/lombok/eclipse/handlers/HandleVal.java
+++ b/src/core/lombok/eclipse/handlers/HandleVal.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2014 The Project Lombok Authors.
+ * Copyright (C) 2010-2016 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,15 +21,17 @@
*/
package lombok.eclipse.handlers;
+import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
+import static lombok.eclipse.handlers.EclipseHandlerUtil.typeMatches;
import lombok.ConfigurationKeys;
+import lombok.val;
import lombok.core.HandlerPriority;
-import lombok.core.LombokNode;
import lombok.eclipse.DeferUntilPostDiet;
import lombok.eclipse.EclipseASTAdapter;
import lombok.eclipse.EclipseASTVisitor;
import lombok.eclipse.EclipseNode;
import lombok.experimental.var;
-import lombok.val;
+
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
import org.eclipse.jdt.internal.compiler.ast.ForStatement;
import org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
@@ -38,10 +40,6 @@ import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.mangosdk.spi.ProviderFor;
-import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
-import static lombok.eclipse.handlers.EclipseHandlerUtil.typeMatches;
-import static lombok.javac.handlers.HandleVal.VARIABLE_INITIALIZER_IS_NULL;
-
/*
* This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}.
*/
@@ -83,12 +81,12 @@ public class HandleVal extends EclipseASTAdapter {
if (local.initialization != null && local.initialization.getClass().getName().equals("org.eclipse.jdt.internal.compiler.ast.LambdaExpression")) {
localNode.addError("'" + annotation + "' is not allowed with lambda expressions.");
+ return;
}
- if(isVar && local.initialization instanceof NullLiteral) addVarNullInitMessage(localNode);
- }
-
- public static void addVarNullInitMessage(LombokNode localNode) {
- localNode.addError(VARIABLE_INITIALIZER_IS_NULL);
+ if(isVar && local.initialization instanceof NullLiteral) {
+ localNode.addError("variable initializer is 'null'");
+ return;
+ }
}
}
diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java
index 2ff3bf38..2976eabe 100644
--- a/src/core/lombok/javac/handlers/HandleVal.java
+++ b/src/core/lombok/javac/handlers/HandleVal.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2015 The Project Lombok Authors.
+ * Copyright (C) 2010-2016 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,15 +21,12 @@
*/
package lombok.javac.handlers;
-import static lombok.core.handlers.HandlerUtil.*;
-import static lombok.eclipse.handlers.HandleVal.addVarNullInitMessage;
+import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
import static lombok.javac.handlers.JavacHandlerUtil.*;
-
-import com.sun.tools.javac.tree.JCTree.JCLiteral;
import lombok.ConfigurationKeys;
-import lombok.experimental.var;
import lombok.val;
import lombok.core.HandlerPriority;
+import lombok.experimental.var;
import lombok.javac.JavacASTAdapter;
import lombok.javac.JavacASTVisitor;
import lombok.javac.JavacNode;
@@ -46,6 +43,7 @@ import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCForLoop;
+import com.sun.tools.javac.tree.JCTree.JCLiteral;
import com.sun.tools.javac.tree.JCTree.JCNewArray;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
@@ -55,12 +53,10 @@ import com.sun.tools.javac.util.List;
@ResolutionResetNeeded
public class HandleVal extends JavacASTAdapter {
- public static final String VARIABLE_INITIALIZER_IS_NULL = "variable initializer is 'null'";
-
private static boolean eq(String typeTreeToString, String key) {
return (typeTreeToString.equals(key) || typeTreeToString.equals("lombok." + key));
}
-
+
@Override
public void visitLocal(JavacNode localNode, JCVariableDecl local) {
JCTree typeTree = local.vartype;
@@ -124,7 +120,7 @@ public class HandleVal extends JavacASTAdapter {
if (rhsOfEnhancedForLoop == null) {
if (local.init.type == null) {
if (isVar && local.init instanceof JCLiteral && ((JCLiteral) local.init).value == null) {
- addVarNullInitMessage(localNode);
+ localNode.addError("variable initializer is 'null'");
}
JavacResolution resolver = new JavacResolution(localNode.getContext());
try {
@@ -173,7 +169,7 @@ public class HandleVal extends JavacASTAdapter {
}
localNode.getAst().setChanged();
} catch (JavacResolution.TypeNotConvertibleException e) {
- localNode.addError("Cannot use 'val' here because initializer expression does not have a representable type: " + e.getMessage());
+ localNode.addError("Cannot use '" + annotation + "' here because initializer expression does not have a representable type: " + e.getMessage());
local.vartype = JavacResolution.createJavaLangObject(localNode.getAst());
}
} catch (RuntimeException e) {