aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/changelog.markdown1
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java40
2 files changed, 38 insertions, 3 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index 97edca99..e99e6f6b 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -8,6 +8,7 @@ Lombok Changelog
* BUGFIX: Renaming a @Data-annotated class in eclipse no longer mangles the data annotation. [Issue #286](http://code.google.com/p/projectlombok/issues/detail?id=286)
* BUGFIX: Eclipse save action *Add final modifier to private fields* no longer adds final keyword to `@Setter` fields. [Issue #263](http://code.google.com/p/projectlombok/issues/detail?id=263)
* BUGFIX: Mixing labels and `lombok.val` would cause NPEs in javac. [Issue #299](http://code.google.com/p/projectlombok/issues/detail?id=299)
+* BUGFIX: Writing `lombok.val` out in full (vs. using an import statement) did not work in eclipse. [Issue #300](http://code.google.com/p/projectlombok/issues/detail?id=300)
### v0.10.2 (November 1st, 2011)
* BUGFIX: Delombok will no longer jumble up comments from different files when using -sourcepath option. [Issue #284](http://code.google.com/p/projectlombok/issues/detail?id=284)
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java b/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java
index 863af59d..1bc3904e 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java
@@ -35,9 +35,11 @@ import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.IExtendedModifier;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.Modifier;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
@@ -197,10 +199,20 @@ public class PatchValEclipse {
}
if (out != null) {
+ SimpleName valName = ast.newSimpleName("val");
+ valName.setSourceRange(start, end - start + 1);
if (original.type instanceof SingleTypeReference) {
- out.setTypeName(ast.newSimpleName("val"));
+ out.setTypeName(valName);
+ setIndex(valName, 1);
} else {
- out.setTypeName(ast.newQualifiedName(ast.newSimpleName("lombok"), ast.newSimpleName("val")));
+ SimpleName lombokName = ast.newSimpleName("lombok");
+ lombokName.setSourceRange(start, end - start + 1);
+ setIndex(lombokName, 1);
+ setIndex(valName, 2);
+ QualifiedName fullName = ast.newQualifiedName(lombokName, valName);
+ setIndex(fullName, 1);
+ fullName.setSourceRange(start, end - start + 1);
+ out.setTypeName(fullName);
}
out.setSourceRange(start, end - start + 1);
}
@@ -208,6 +220,28 @@ public class PatchValEclipse {
return out;
}
+ private static final Field FIELD_NAME_INDEX;
+
+ static {
+ Field f = null;
+ try {
+ f = Name.class.getDeclaredField("index");
+ f.setAccessible(true);
+ } catch (Exception e) {
+ // Leave it null, in which case we don't set index. That'll result in error log messages but its better than crashing here.
+ }
+
+ FIELD_NAME_INDEX = f;
+ }
+
+ private static void setIndex(Name name, int index) {
+ try {
+ if (FIELD_NAME_INDEX != null) FIELD_NAME_INDEX.set(name, index);
+ } catch (Exception e) {
+ // Don't do anything - safest fallback behaviour.
+ }
+ }
+
public static final class Reflection {
private static final Field initCopyField, iterableCopyField;
private static final Field astStackField, astPtrField;