aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/javac/JavacResolution.java17
-rw-r--r--src/core/lombok/javac/handlers/HandleVal.java6
2 files changed, 23 insertions, 0 deletions
diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java
index 6c60b11e..14de1ff8 100644
--- a/src/core/lombok/javac/JavacResolution.java
+++ b/src/core/lombok/javac/JavacResolution.java
@@ -12,6 +12,7 @@ import javax.tools.DiagnosticListener;
import com.sun.tools.javac.code.BoundKind;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
+import com.sun.tools.javac.code.Type.ArrayType;
import com.sun.tools.javac.code.Type.CapturedType;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Type;
@@ -388,6 +389,22 @@ public class JavacResolution {
}
private static JCExpression typeToJCTree(Type type, TreeMaker maker, JavacAST ast, boolean allowCompound) throws TypeNotConvertibleException {
+ int dims = 0;
+ Type type0 = type;
+ while (type0 instanceof ArrayType) {
+ dims++;
+ type0 = ((ArrayType)type0).elemtype;
+ }
+
+ JCExpression result = typeToJCTree0(type0, maker, ast, allowCompound);
+ while (dims > 0) {
+ result = maker.TypeArray(result);
+ dims--;
+ }
+ return result;
+ }
+
+ private static JCExpression typeToJCTree0(Type type, TreeMaker maker, JavacAST ast, boolean allowCompound) throws TypeNotConvertibleException {
// NB: There's such a thing as maker.Type(type), but this doesn't work very well; it screws up anonymous classes, captures, and adds an extra prefix dot for some reason too.
// -- so we write our own take on that here.
diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java
index a6f22093..f806ae6c 100644
--- a/src/core/lombok/javac/handlers/HandleVal.java
+++ b/src/core/lombok/javac/handlers/HandleVal.java
@@ -33,6 +33,7 @@ import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop;
import com.sun.tools.javac.tree.JCTree.JCExpression;
+import com.sun.tools.javac.tree.JCTree.JCNewArray;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
@ProviderFor(JavacASTVisitor.class)
@@ -57,6 +58,11 @@ public class HandleVal extends JavacASTAdapter {
return;
}
+ if (local.init instanceof JCNewArray && ((JCNewArray)local.init).elemtype == null) {
+ localNode.addError("'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })");
+ return;
+ }
+
local.mods.flags |= Flags.FINAL;
JCExpression oldVarType = local.vartype;
local.vartype = JavacResolution.createJavaLangObject(localNode.getTreeMaker(), localNode.getAst());