Now the type resolver also finds top-level types in a compilation unit that name-shadow. Added tests for the type resolver.

This commit is contained in:
Reinier Zwitserloot committed 2011-12-19 20:09:40 +01:00
1 parent 6b91620d9e
commit ae87a26456
17 files changed
+194 -3

No files matched your search

+3 -3
View File
@@ -73,7 +73,7 @@ public class TypeResolver {
// because if you want to know if 'Foo' could refer to 'bar.Foo' when 'baz.Foo' is explicitly imported, the answer is no.
if (nameConflictInImportList(typeRef, potentialMatches)) return Collections.emptyList();
// Check if any of our potentials is even imported in the first place. If not: no matches.
// Check if any of our potentials are even imported in the first place. If not: no matches.
// Note that (ourPackage.*) is added to the imports.
potentialMatches = eliminateImpossibleMatches(potentialMatches, library);
if (potentialMatches.isEmpty()) return Collections.emptyList();
@@ -84,7 +84,7 @@ public class TypeResolver {
LombokNode<?, ?, ?> n = context;
mainLoop:
while (n != null && n.getKind() != Kind.COMPILATION_UNIT) {
while (n != null) {
if (n.getKind() == Kind.TYPE && typeRef.equals(n.getName())) {
// Our own class or one of our outer classes is named 'typeRef' so that's what 'typeRef' is referring to, not one of our type library classes.
return Collections.emptyList();
@@ -106,7 +106,7 @@ public class TypeResolver {
continue mainLoop;
}
if (n.getKind() == Kind.TYPE) {
if (n.getKind() == Kind.TYPE || n.getKind() == Kind.COMPILATION_UNIT) {
for (LombokNode<?, ?, ?> child : n.down()) {
// Inner class that's visible to us has 'typeRef' as name, so that's the one being referred to, not one of our type library classes.
if (child.getKind() == Kind.TYPE && typeRef.equals(child.getName())) return Collections.emptyList();
@@ -108,6 +108,7 @@ public class PatchDelegate {
for (Annotation ann : field.annotations) {
if (ann.type == null) continue;
TypeBinding tb = ann.type.resolveType(decl.initializerScope);
if (tb == null) continue;
if (!charArrayEquals("lombok", tb.qualifiedPackageName())) continue;
if (!charArrayEquals("Delegate", tb.qualifiedSourceName())) continue;
return true;
@@ -0,0 +1,11 @@
class SimpleTypeResolutionFail {
@Getter
private int x;
}
class SimpleTypeResolutionSuccess {
private int x;
@java.lang.SuppressWarnings("all")
public int getX() {
return this.x;
}
}
@@ -0,0 +1,54 @@
import lombok.*;
class TrickyDoNothing {
@interface Getter {
}
@Getter
int x;
}
class TrickyDoNothing2 {
@Getter
int x;
@interface Getter {
}
}
class TrickySuccess {
int x;
@java.lang.SuppressWarnings("all")
public int getX() {
return this.x;
}
}
class TrickyDoNothing3 {
void test() {
class val {
}
val x = null;
}
}
class TrickyDoSomething {
void test() {
final java.lang.Object x = null;
class val {
}
}
}
class DoubleTrickyDoNothing {
void test() {
class val {
}
for (int i = 10; i < 20; i++) {
val y = null;
}
}
}
class DoubleTrickyDoSomething {
void test() {
for (int j = 10; j < 20; j++) {
class val {
}
}
for (int i = 10; i < 20; i++) {
final java.lang.Object y = null;
}
}
}
@@ -0,0 +1,8 @@
import lombok.*;
class DoNothingDueToTopLevel {
void test() {
val x = null;
}
}
class val {
}
@@ -0,0 +1,15 @@
class SimpleTypeResolutionFail {
private @Getter int x;
SimpleTypeResolutionFail() {
super();
}
}
class SimpleTypeResolutionSuccess {
private @lombok.Getter int x;
public @java.lang.SuppressWarnings("all") int getX() {
return this.x;
}
SimpleTypeResolutionSuccess() {
super();
}
}
@@ -0,0 +1 @@
//ignore
@@ -0,0 +1 @@
//ignore
@@ -0,0 +1,15 @@
class SimpleTypeResolutionFail {
private @Getter int x;
SimpleTypeResolutionFail() {
super();
}
}
class SimpleTypeResolutionSuccess {
private @lombok.Getter int x;
public @java.lang.SuppressWarnings("all") int getX() {
return this.x;
}
SimpleTypeResolutionSuccess() {
super();
}
}
@@ -0,0 +1 @@
//ignore
@@ -0,0 +1 @@
//ignore
@@ -0,0 +1,7 @@
class SimpleTypeResolutionFail {
@Getter private int x;
}
class SimpleTypeResolutionSuccess {
@lombok.Getter private int x;
}
@@ -0,0 +1,49 @@
import lombok.*;
class TrickyDoNothing {
@interface Getter {}
@Getter int x;
}
class TrickyDoNothing2 {
@Getter int x;
@interface Getter {}
}
class TrickySuccess {
@Getter int x;
}
class TrickyDoNothing3 {
void test() {
class val {}
val x = null;
}
}
class TrickyDoSomething {
void test() {
val x = null;
class val {}
}
}
class DoubleTrickyDoNothing {
void test() {
class val {}
for (int i = 10; i < 20; i++) {
val y = null;
}
}
}
class DoubleTrickyDoSomething {
void test() {
for (int j = 10; j < 20; j++) {
class val {}
}
for (int i = 10; i < 20; i++) {
val y = null;
}
}
}
@@ -0,0 +1,8 @@
import lombok.*;
class DoNothingDueToTopLevel {
void test() {
val x = null;
}
}
class val {}
@@ -0,0 +1,9 @@
2:10 ERROR cannot find symbol
symbol : class Getter
location: class SimpleTypeResolutionFail
2:10 ERROR cannot find symbol
symbol : class Getter
location: class SimpleTypeResolutionFail
2:10 ERROR cannot find symbol
symbol : class Getter
location: class SimpleTypeResolutionFail
@@ -0,0 +1 @@
2 error Getter cannot be resolved to a type
@@ -0,0 +1,9 @@
2:10 ERROR cannot find symbol
symbol : class Getter
location: class SimpleTypeResolutionFail
2:10 ERROR cannot find symbol
symbol : class Getter
location: class SimpleTypeResolutionFail
2:10 ERROR cannot find symbol
symbol : class Getter
location: class SimpleTypeResolutionFail