Skip to content

Commit

Permalink
Fixed issue 300: 'lombok.val' (vs. just val and an import statement) …
Browse files Browse the repository at this point in the history
…didn't fix auto-complete dialogs.

However, now the auto-highlight feature will crash with an IOOBE if you click in lombok.val.
  • Loading branch information
rzwitserloot committed Nov 20, 2011
1 parent 0139c62 commit 246b4cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
Expand Up @@ -70,7 +70,7 @@ public static boolean matches(String key, char[] array) {
return true;
}

private static boolean couldBeVal(TypeReference ref) {
public static boolean couldBeVal(TypeReference ref) {
if (ref instanceof SingleTypeReference) {
char[] token = ((SingleTypeReference)ref).token;
return matches("val", token);
Expand Down
29 changes: 6 additions & 23 deletions src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java
Expand Up @@ -44,7 +44,6 @@
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.parser.Parser;
Expand All @@ -64,10 +63,7 @@ public static void copyInitializationOfForEachIterable(Parser parser) {
ForeachStatement foreachDecl = (ForeachStatement) astStack[astPtr];
ASTNode init = foreachDecl.collection;
if (init == null) return;
if (foreachDecl.elementVariable != null && foreachDecl.elementVariable.type instanceof SingleTypeReference) {
SingleTypeReference ref = (SingleTypeReference) foreachDecl.elementVariable.type;
if (ref.token == null || ref.token.length != 3 || ref.token[0] != 'v' || ref.token[1] != 'a' || ref.token[2] != 'l') return;
} else return;
if (foreachDecl.elementVariable == null || !PatchVal.couldBeVal(foreachDecl.elementVariable.type)) return;

try {
if (Reflection.iterableCopyField != null) Reflection.iterableCopyField.set(foreachDecl.elementVariable, init);
Expand All @@ -90,10 +86,7 @@ public static void copyInitializationOfLocalDeclaration(Parser parser) {
if (!(variableDecl instanceof LocalDeclaration)) return;
ASTNode init = variableDecl.initialization;
if (init == null) return;
if (variableDecl.type instanceof SingleTypeReference) {
SingleTypeReference ref = (SingleTypeReference) variableDecl.type;
if (ref.token == null || ref.token.length != 3 || ref.token[0] != 'v' || ref.token[1] != 'a' || ref.token[2] != 'l') return;
} else return;
if (!PatchVal.couldBeVal(variableDecl.type)) return;

try {
if (Reflection.initCopyField != null) Reflection.initCopyField.set(variableDecl, init);
Expand All @@ -120,20 +113,10 @@ public static void addFinalAndValAnnotationToModifierList(Object converter, List
Annotation valAnnotation = null;

for (Annotation ann : in.annotations) {
if (ann.type instanceof SingleTypeReference) {
if (PatchVal.matches("val", ((SingleTypeReference)ann.type).token)) {
found = true;
valAnnotation = ann;
break;
}
}
if (ann.type instanceof QualifiedTypeReference) {
char[][] tokens = ((QualifiedTypeReference)ann.type).tokens;
if (tokens != null && tokens.length == 2 && PatchVal.matches("lombok", tokens[0]) && PatchVal.matches("val", tokens[1])) {
found = true;
valAnnotation = ann;
break;
}
if (PatchVal.couldBeVal(ann.type)) {
found = true;
valAnnotation = ann;
break;
}
}

Expand Down

0 comments on commit 246b4cc

Please sign in to comment.