aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r--src/core/lombok/javac/handlers/HandleVal.java18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java
index 7161a7c3..5da6fec0 100644
--- a/src/core/lombok/javac/handlers/HandleVal.java
+++ b/src/core/lombok/javac/handlers/HandleVal.java
@@ -64,7 +64,6 @@ public class HandleVal extends JavacASTAdapter {
}
local.mods.flags |= Flags.FINAL;
- JCExpression oldVarType = local.vartype;
local.vartype = JavacResolution.createJavaLangObject(localNode.getTreeMaker(), localNode.getAst());
Type type;
@@ -89,25 +88,26 @@ public class HandleVal extends JavacASTAdapter {
JCExpression replacement;
if (rhsOfEnhancedForLoop != null) {
- localNode.addError("For now 'val' cannot be used in enhanced for loops. Fixing this is a high priority lombok issue though!");
- return;
- // TODO: Fix enhanced for loops - then uncomment a bunch of lines in test/transform/resource/*/ValInFor.java
+ Type componentType = JavacResolution.ifTypeIsIterableToComponent(type, localNode.getAst());
+ if (componentType == null) replacement = JavacResolution.createJavaLangObject(localNode.getTreeMaker(), localNode.getAst());
+ else replacement = JavacResolution.typeToJCTree(componentType, localNode.getTreeMaker(), localNode.getAst());
+ } else {
+ replacement = JavacResolution.typeToJCTree(type, localNode.getTreeMaker(), localNode.getAst());
}
- replacement = JavacResolution.typeToJCTree(type, localNode.getTreeMaker(), localNode.getAst());
+
if (replacement != null) {
local.vartype = replacement;
localNode.getAst().setChanged();
}
- else local.vartype = oldVarType;
+ else local.vartype = JavacResolution.createJavaLangObject(localNode.getTreeMaker(), localNode.getAst());;
} catch (JavacResolution.TypeNotConvertibleException e) {
localNode.addError("Cannot use 'val' here because initializer expression does not have a representable type: " + e.getMessage());
- local.vartype = oldVarType;
+ local.vartype = JavacResolution.createJavaLangObject(localNode.getTreeMaker(), localNode.getAst());;
}
} catch (RuntimeException e) {
- local.vartype = oldVarType;
+ local.vartype = JavacResolution.createJavaLangObject(localNode.getTreeMaker(), localNode.getAst());;
throw e;
}
}
- // TODO search for val decls in either kind of for.
}
}