diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-11-08 22:32:22 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-11-08 22:52:07 +0100 |
commit | cc60afa1eb4b14998e72c4fd5adf9def32e0e0f8 (patch) | |
tree | cae9a00aa7e5f8cfa08adfe22f3da98c5e0fcb4a /src/core/lombok/javac/handlers | |
parent | dee834a39780f61a0357c42f61592cd3c3598bd3 (diff) | |
download | lombok-cc60afa1eb4b14998e72c4fd5adf9def32e0e0f8.tar.gz lombok-cc60afa1eb4b14998e72c4fd5adf9def32e0e0f8.tar.bz2 lombok-cc60afa1eb4b14998e72c4fd5adf9def32e0e0f8.zip |
'val' now also works in foreach loops, on both javac and ecj / eclipse.
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleVal.java | 18 |
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. } } |