Fixes build break caused by r2191.  We were actually warning on binary type refs in annotations.  Also, we were doing the binary type ref checks in the ByteCodeCompiler, which was bad.

Review by: scottb

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2195 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jdt/AbstractCompiler.java b/dev/core/src/com/google/gwt/dev/jdt/AbstractCompiler.java
index defb5fe..a8caf35 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/AbstractCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/AbstractCompiler.java
@@ -179,7 +179,7 @@
 
       JSORestrictionsChecker.check(cud);
 
-      BinaryTypeReferenceRestrictionsChecker.check(cud);
+      doCompilationUnitDeclarationValidation(cud);
 
       // Optionally remember this cud.
       //
@@ -541,6 +541,12 @@
     //
   }
 
+  protected void doCompilationUnitDeclarationValidation(
+      CompilationUnitDeclaration cud) {
+    // Do nothing by default.
+    //
+  }
+
   protected String[] doFindAdditionalTypesUsingJsni(TreeLogger logger,
       CompilationUnitDeclaration cud) {
     return Empty.STRINGS;
diff --git a/dev/core/src/com/google/gwt/dev/jdt/AstCompiler.java b/dev/core/src/com/google/gwt/dev/jdt/AstCompiler.java
index 2b034de..4c7edb9 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/AstCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/AstCompiler.java
@@ -117,4 +117,10 @@
     cachedResults.removeAll(changedFiles);
     invalidateUnitsInFiles(changedFiles, typeNames);
   }
+
+  @Override
+  protected void doCompilationUnitDeclarationValidation(
+      CompilationUnitDeclaration cud) {
+    BinaryTypeReferenceRestrictionsChecker.check(cud);
+  }
 }
diff --git a/dev/core/src/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsChecker.java b/dev/core/src/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsChecker.java
index d9b909f..eed88f9 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsChecker.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsChecker.java
@@ -18,10 +18,13 @@
 import org.eclipse.jdt.core.compiler.IProblem;
 import org.eclipse.jdt.internal.compiler.CompilationResult;
 import org.eclipse.jdt.internal.compiler.ast.ASTNode;
-import org.eclipse.jdt.internal.compiler.ast.Annotation;
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.Expression;
+import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
+import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation;
+import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
 import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
 import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
 import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
@@ -61,7 +64,8 @@
 
   /**
    * Visits a {@link CompilationUnitDeclaration} and records all expressions
-   * which use a {@link BinaryTypeBinding}.
+   * which use a {@link BinaryTypeBinding} that are not part of an annotation
+   * context.
    */
   static class BinaryTypeReferenceVisitor extends TypeRefVisitor {
     private final List<BinaryTypeReferenceSite> binaryTypeReferenceSites;
@@ -72,12 +76,28 @@
     }
 
     @Override
+    public boolean visit(MarkerAnnotation annotation, BlockScope scope) {
+      // Ignore annotations
+      return false;
+    }
+
+    @Override
+    public boolean visit(NormalAnnotation annotation, BlockScope scope) {
+      // Ignore annotations
+      return false;
+    }
+
+    @Override
+    public boolean visit(SingleMemberAnnotation annotation, BlockScope scope) {
+      // Ignore annotations
+      return false;
+    }
+
+    @Override
     protected void onBinaryTypeRef(BinaryTypeBinding binding,
         CompilationUnitDeclaration unitOfReferrer, Expression expression) {
-      if (!isValidBinaryTypeUsage(expression)) {
-        binaryTypeReferenceSites.add(new BinaryTypeReferenceSite(expression,
-            binding));
-      }
+      binaryTypeReferenceSites.add(new BinaryTypeReferenceSite(expression,
+          binding));
     }
 
     @Override
@@ -89,9 +109,9 @@
 
   /**
    * Scans a {@link CompilationUnitDeclaration} for expressions that use
-   * {@link BinaryTypeBinding}s outside the context of an annotation.  For 
-   * each unique use of a given {@link BinaryTypeBinding}, a error is reported
-   * against the {@link CompilationUnitDeclaration}.
+   * {@link BinaryTypeBinding}s outside the context of an annotation. An error
+   * is reported against the {@link CompilationUnitDeclaration} for the first
+   * instance of each unique {@link BinaryTypeBinding}.
    */
   public static void check(CompilationUnitDeclaration cud) {
     List<BinaryTypeReferenceSite> binaryTypeReferenceSites = findInvalidBinaryTypeReferenceSites(cud);
@@ -125,14 +145,6 @@
         + "; did you forget to inherit a required module?";
   }
 
-  /**
-   * Returns <code>true</code> if a {@link BinaryTypeBinding} can be used from
-   * this particular {@link ASTNode} type.
-   */
-  static boolean isValidBinaryTypeUsage(Expression expression) {
-    return expression instanceof Annotation;
-  }
-
   static void recordError(CompilationUnitDeclaration cud, ASTNode node,
       String error) {
     CompilationResult compResult = cud.compilationResult();
diff --git a/dev/core/test/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsCheckerTest.java b/dev/core/test/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsCheckerTest.java
index 999c402..bfca795 100644
--- a/dev/core/test/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsCheckerTest.java
+++ b/dev/core/test/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsCheckerTest.java
@@ -26,9 +26,7 @@
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.Expression;
 import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
 import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation;
 import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
 import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
 import org.eclipse.jdt.internal.compiler.ast.Statement;
@@ -173,6 +171,7 @@
 
     TypeDeclaration typeDeclaration = new TypeDeclaration(compilationResult);
     typeDeclaration.scope = new ClassScope(cud.scope, null);
+    typeDeclaration.staticInitializerScope = new MethodScope(typeDeclaration.scope, null, false);
     cud.types = new TypeDeclaration[] {typeDeclaration};
 
     BinaryTypeBinding binaryTypeBinding = new BinaryTypeBinding(null,
@@ -189,8 +188,9 @@
     localDeclaration.type = createMockBinaryTypeReference(binaryTypeBinding);
     methodDeclaration.statements = new Statement[] {localDeclaration};
 
-    Annotation annotation = new MarkerAnnotation(
+    SingleMemberAnnotation annotation = new SingleMemberAnnotation(
         createMockBinaryTypeReference(binaryTypeBinding), 0);
+    annotation.memberValue = annotation.type;
     typeDeclaration.annotations = new Annotation[] {annotation};
 
     typeDeclaration.methods = new AbstractMethodDeclaration[] {methodDeclaration};
@@ -218,19 +218,6 @@
     assertEquals(expectedMessage, actualMessage);
   }
 
-  public void testIsValidBinaryTypeUsage() {
-    TypeReference typeReference = createMockBinaryTypeReference(null);
-
-    assertTrue(BinaryTypeReferenceRestrictionsChecker.isValidBinaryTypeUsage(new MarkerAnnotation(
-        typeReference, 0)));
-    assertTrue(BinaryTypeReferenceRestrictionsChecker.isValidBinaryTypeUsage(new SingleMemberAnnotation(
-        typeReference, 0)));
-    assertTrue(BinaryTypeReferenceRestrictionsChecker.isValidBinaryTypeUsage(new NormalAnnotation(
-        typeReference, 0)));
-    assertFalse(BinaryTypeReferenceRestrictionsChecker.isValidBinaryTypeUsage(new Wildcard(
-        Wildcard.UNBOUND)));
-  }
-
   public void testRecordError() {
     String fileName = "TestCompilationUnit.java";
     String errorMessage = "Unit has errors";