From 637298300039a4b943e49c654cb4d2b26161ba60 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 12 Jun 2009 09:54:24 +0200 Subject: Now everything works; handlers are called via SPI, and annotations are being parsed. w00t! --- src/lombok/transformations/TypeLibrary.java | 3 ++- src/lombok/transformations/TypeResolver.java | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/lombok/transformations') diff --git a/src/lombok/transformations/TypeLibrary.java b/src/lombok/transformations/TypeLibrary.java index 00ae64b0..9b5c8e57 100644 --- a/src/lombok/transformations/TypeLibrary.java +++ b/src/lombok/transformations/TypeLibrary.java @@ -33,6 +33,7 @@ public class TypeLibrary { } public Collection findCompatible(String typeReference) { - return simpleToQualifiedMap.get(typeReference); + Set result = simpleToQualifiedMap.get(typeReference); + return result == null ? Collections.emptySet() : result; } } diff --git a/src/lombok/transformations/TypeResolver.java b/src/lombok/transformations/TypeResolver.java index 2a012f57..3c3617a6 100644 --- a/src/lombok/transformations/TypeResolver.java +++ b/src/lombok/transformations/TypeResolver.java @@ -6,23 +6,21 @@ import java.util.HashSet; import java.util.Set; import lombok.eclipse.EclipseAST; +import lombok.eclipse.EclipseAST.Node; -import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.ImportReference; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; -import org.eclipse.jdt.internal.compiler.parser.Parser; public class TypeResolver { private final TypeLibrary library; - private final EclipseAST ast; private Collection imports; - public TypeResolver(TypeLibrary library, Parser parser, EclipseAST ast) { + public TypeResolver(TypeLibrary library, EclipseAST.Node top) { this.library = library; - this.ast = ast; - this.imports = makeImportList((CompilationUnitDeclaration) ast.top().getEclipseNode()); + this.imports = makeImportList((CompilationUnitDeclaration) top.getEclipseNode()); } private static Collection makeImportList(CompilationUnitDeclaration declaration) { @@ -33,8 +31,8 @@ public class TypeResolver { } return imports; } - - public Collection findTypeMatches(ASTNode context, TypeReference type) { + + public Collection findTypeMatches(Node context, TypeReference type) { Collection potentialMatches = library.findCompatible(toQualifiedName(type.getTypeName())); if ( potentialMatches.isEmpty() ) return Collections.emptyList(); @@ -50,7 +48,14 @@ public class TypeResolver { if ( potentialMatches.isEmpty() ) return Collections.emptyList(); //Find a lexically accessible type of the same simple name in the same Compilation Unit. If it exists: no matches. - + Node n = context; + while ( n != null ) { + if ( n.getEclipseNode() instanceof TypeDeclaration ) { + char[] name = ((TypeDeclaration)n.getEclipseNode()).name; + if ( name != null && new String(name).equals(simpleName) ) return Collections.emptyList(); + } + n = n.up(); + } // The potential matches we found by comparing the import statements is our matching set. Return it. return potentialMatches; -- cgit