aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/changelog.markdown1
-rw-r--r--src/core/lombok/eclipse/handlers/HandleVal.java10
-rw-r--r--src/core/lombok/javac/handlers/HandleVal.java8
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchVal.java2
4 files changed, 18 insertions, 3 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index f2c99a59..bf9ccab2 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -2,6 +2,7 @@ Lombok Changelog
----------------
### v0.10.9 (edge)
+* ENHANCEMENT: `val` is no longer legal inside basic for loops (the old kind, not the foreach kind). These variables should rarely be final, and in practice it wasn't possible to delombok this code properly. [Issue #346](http://code.google.com/p/projectlombok/issues/detail?id=346)
* FEATURE: The combination of `@Delegate` and `@Getter` or `@Data` will now delegate to the result of a generated getter. [Issue #328](http://code.google.com/p/projectlombok/issues/detail?id=328)
### v0.10.8 (January 19th, 2012)
diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java
index 41c34aee..a5cf29b2 100644
--- a/src/core/lombok/eclipse/handlers/HandleVal.java
+++ b/src/core/lombok/eclipse/handlers/HandleVal.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2011 The Project Lombok Authors.
+ * Copyright (C) 2010-2012 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
@@ -27,12 +27,13 @@ import lombok.eclipse.EclipseASTVisitor;
import lombok.eclipse.EclipseNode;
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
+import org.eclipse.jdt.internal.compiler.ast.ForStatement;
import org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.mangosdk.spi.ProviderFor;
/*
- * This class just handles 2 basic error cases. The real meat of eclipse 'val' support is in {@code EclipsePatcher}'s {@code patchHandleVal} method.
+ * This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}.
*/
@ProviderFor(EclipseASTVisitor.class)
public class HandleVal extends EclipseASTAdapter {
@@ -58,5 +59,10 @@ public class HandleVal extends EclipseASTAdapter {
localNode.addError("'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })");
return;
}
+
+ if (localNode.directUp().get() instanceof ForStatement) {
+ localNode.addError("'val' is not allowed in old-style for loops");
+ return;
+ }
}
}
diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java
index 7d4d9004..4feaa3ac 100644
--- a/src/core/lombok/javac/handlers/HandleVal.java
+++ b/src/core/lombok/javac/handlers/HandleVal.java
@@ -37,6 +37,7 @@ import com.sun.tools.javac.tree.JCTree;
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.JCNewArray;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
@@ -54,9 +55,14 @@ public class HandleVal extends JavacASTAdapter {
if (!typeMatches(val.class, localNode, local.vartype)) return;
+ JCTree parentRaw = localNode.directUp().get();
+ if (parentRaw instanceof JCForLoop) {
+ localNode.addError("'val' is not allowed in old-style for loops");
+ return;
+ }
+
JCExpression rhsOfEnhancedForLoop = null;
if (local.init == null) {
- JCTree parentRaw = localNode.directUp().get();
if (parentRaw instanceof JCEnhancedForLoop) {
JCEnhancedForLoop efl = (JCEnhancedForLoop) parentRaw;
if (efl.var == local) rhsOfEnhancedForLoop = efl.expr;
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index d59ff735..6563c20a 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -120,6 +120,8 @@ public class PatchVal {
if (!isVal(local.type, scope)) return false;
+ if (new Throwable().getStackTrace()[2].getClassName().contains("ForStatement")) return false;
+
Expression init = local.initialization;
if (init == null && Reflection.initCopyField != null) {
try {