Issue 3936: work around JDT by not computing CUD from scope chain.
It appears JDT has a bug where it will pass you a null scope while visiting the expression of an empty switch statement. See:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3936
It turns out, however, that TypeRefVisitor was only using the scope chain to compute the containing CUD on the fly. Since this visitor always traverses entire CUDs, we can work around the JDT scope issue by just requiring the CUD to be set up front.
Review by: spoon
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5967 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/javac/BinaryTypeReferenceRestrictionsChecker.java b/dev/core/src/com/google/gwt/dev/javac/BinaryTypeReferenceRestrictionsChecker.java
index 3fc0ba4..5f8e178 100644
--- a/dev/core/src/com/google/gwt/dev/javac/BinaryTypeReferenceRestrictionsChecker.java
+++ b/dev/core/src/com/google/gwt/dev/javac/BinaryTypeReferenceRestrictionsChecker.java
@@ -66,8 +66,9 @@
static class BinaryTypeReferenceVisitor extends TypeRefVisitor {
private final List<BinaryTypeReferenceSite> binaryTypeReferenceSites;
- public BinaryTypeReferenceVisitor(
+ public BinaryTypeReferenceVisitor(CompilationUnitDeclaration cud,
List<BinaryTypeReferenceSite> binaryTypeReferenceSites) {
+ super(cud);
this.binaryTypeReferenceSites = binaryTypeReferenceSites;
}
@@ -140,7 +141,7 @@
CompilationUnitDeclaration cud) {
List<BinaryTypeReferenceSite> binaryTypeReferenceSites = new ArrayList<BinaryTypeReferenceSite>();
BinaryTypeReferenceVisitor binaryTypeReferenceVisitor = new BinaryTypeReferenceVisitor(
- binaryTypeReferenceSites);
+ cud, binaryTypeReferenceSites);
cud.traverse(binaryTypeReferenceVisitor, cud.scope);
return binaryTypeReferenceSites;
}
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
index 86f42a6..e8a70cf 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
@@ -289,7 +289,7 @@
CompilationUnitDeclaration cud,
final Map<String, String> binaryTypeToSourceFileMap) {
final Set<String> result = new HashSet<String>();
- cud.traverse(new TypeRefVisitor() {
+ cud.traverse(new TypeRefVisitor(cud) {
@Override
protected void onBinaryTypeRef(BinaryTypeBinding referencedType,
CompilationUnitDeclaration unitOfReferrer, Expression expression) {
diff --git a/dev/core/src/com/google/gwt/dev/jdt/TypeRefVisitor.java b/dev/core/src/com/google/gwt/dev/jdt/TypeRefVisitor.java
index d72f031..8aabe9f 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/TypeRefVisitor.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/TypeRefVisitor.java
@@ -35,7 +35,6 @@
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding;
-import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
@@ -44,24 +43,31 @@
*/
public abstract class TypeRefVisitor extends ASTVisitor {
+ private final CompilationUnitDeclaration cud;
+
+ public TypeRefVisitor(CompilationUnitDeclaration cud) {
+ assert (cud != null);
+ this.cud = cud;
+ }
+
@Override
public void endVisit(ArrayQualifiedTypeReference x, BlockScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(ArrayQualifiedTypeReference x, ClassScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(ArrayTypeReference x, BlockScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(ArrayTypeReference x, ClassScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
@@ -77,65 +83,75 @@
* scope in some cases, which would cause compiler errors.
*/
if (messageSend.binding != null && messageSend.binding.isStatic()) {
- maybeDispatch(scope, messageSend, messageSend.actualReceiverType);
+ maybeDispatch(messageSend, messageSend.actualReceiverType);
}
}
@Override
public void endVisit(ParameterizedQualifiedTypeReference x, BlockScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(ParameterizedQualifiedTypeReference x, ClassScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(ParameterizedSingleTypeReference x, BlockScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(ParameterizedSingleTypeReference x, ClassScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(QualifiedNameReference x, BlockScope scope) {
if (x.binding instanceof FieldBinding) {
- maybeDispatch(scope, x, x.fieldBinding().declaringClass);
+ maybeDispatch(x, x.fieldBinding().declaringClass);
}
}
@Override
public void endVisit(QualifiedTypeReference x, BlockScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(QualifiedTypeReference x, ClassScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(SingleTypeReference x, BlockScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(SingleTypeReference x, ClassScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(Wildcard x, BlockScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
}
@Override
public void endVisit(Wildcard x, ClassScope scope) {
- maybeDispatch(scope, x, x.resolvedType);
+ maybeDispatch(x, x.resolvedType);
+ }
+
+ @Override
+ public boolean visit(CompilationUnitDeclaration cud,
+ CompilationUnitScope scope) {
+ if (this.cud != cud) {
+ throw new IllegalStateException(
+ "I will only visit the cud I was initialized with");
+ }
+ return true;
}
@SuppressWarnings("unused")
@@ -146,40 +162,24 @@
protected abstract void onTypeRef(SourceTypeBinding referencedType,
CompilationUnitDeclaration unitOfReferrer);
- private CompilationUnitScope findUnitScope(Scope referencedFrom) {
- assert (referencedFrom != null);
- Scope scope = referencedFrom;
- while (scope.parent != null) {
- scope = scope.parent;
- }
- assert (scope instanceof CompilationUnitScope);
- return (CompilationUnitScope) scope;
- }
-
- private void maybeDispatch(Scope referencedFrom, Expression expression,
- TypeBinding binding) {
- assert (referencedFrom != null);
+ private void maybeDispatch(Expression expression, TypeBinding binding) {
assert (binding != null);
if (binding instanceof SourceTypeBinding) {
SourceTypeBinding type = (SourceTypeBinding) binding;
- CompilationUnitScope from = findUnitScope(referencedFrom);
- onTypeRef(type, from.referenceContext);
+ onTypeRef(type, cud);
} else if (binding instanceof ArrayBinding) {
- maybeDispatch(referencedFrom, expression,
- ((ArrayBinding) binding).leafComponentType);
+ maybeDispatch(expression, ((ArrayBinding) binding).leafComponentType);
} else if (binding instanceof BinaryTypeBinding) {
- CompilationUnitScope from = findUnitScope(referencedFrom);
- onBinaryTypeRef((BinaryTypeBinding) binding, from.referenceContext,
- expression);
+ onBinaryTypeRef((BinaryTypeBinding) binding, cud, expression);
} else if (binding instanceof ParameterizedTypeBinding) {
// Make sure that we depend on the generic version of the class.
ParameterizedTypeBinding ptBinding = (ParameterizedTypeBinding) binding;
- maybeDispatch(referencedFrom, expression, ptBinding.genericType());
+ maybeDispatch(expression, ptBinding.genericType());
} else if (binding instanceof RawTypeBinding) {
// Make sure that we depend on the generic version of the class.
RawTypeBinding rawTypeBinding = (RawTypeBinding) binding;
- maybeDispatch(referencedFrom, expression, rawTypeBinding.genericType());
+ maybeDispatch(expression, rawTypeBinding.genericType());
} else {
// We don't care about other cases.
}