aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok/eclipse
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2011-11-20 21:55:01 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2011-11-20 21:56:04 +0100
commitef820d8d5ab76c6db8335201da3c7ab9de7cb56a (patch)
treef8373f53b709e04d0f77b2203d70957cb34480f1 /src/eclipseAgent/lombok/eclipse
parent246b4cc2bc03e5cccfd7ccca5aa48a3e8bb55b0c (diff)
downloadlombok-ef820d8d5ab76c6db8335201da3c7ab9de7cb56a.tar.gz
lombok-ef820d8d5ab76c6db8335201da3c7ab9de7cb56a.tar.bz2
lombok-ef820d8d5ab76c6db8335201da3c7ab9de7cb56a.zip
Additional fix for issue 300: Using 'lombok.val' written out in full would cause ArrayIndexOutOfBoundsException: 0 errors to pop up in the editor.
Also updated changelog.
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java40
1 files changed, 37 insertions, 3 deletions
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;