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.
This commit is contained in:
Reinier Zwitserloot
2011-11-20 21:56:04 +01:00
parent 246b4cc2bc
commit ef820d8d5a
2 changed files with 38 additions and 3 deletions
+1
View File
@@ -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)
@@ -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;