CompiledClasses now compute local class status from JDT.

Review by: amitmanjhi

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6652 8db76d5a-ed1c-0410-87a9-c151d255dfc7
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 e8a70cf..ad46c6e 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
@@ -56,8 +56,6 @@
  */
 public abstract class CompilationUnit {
 
-  protected static final DiskCache diskCache = new DiskCache();
-
   /**
    * Encapsulates the functionality to find all nested classes of this class
    * that have compiler-generated names. All class bytes are loaded from the
@@ -264,6 +262,8 @@
     }
   }
 
+  protected static final DiskCache diskCache = new DiskCache();
+
   private static final Pattern GENERATED_CLASSNAME_PATTERN = Pattern.compile(".+\\$\\d.*");
 
   /**
@@ -321,14 +321,13 @@
   private List<JsniMethod> jsniMethods = null;
   private State state = State.FRESH;
 
-  /*
-   * Check if the unit has one or more classes with generated names. 'javac'
-   * below refers to the compiler that was used to compile the java files on
-   * disk. Returns true if our heuristic for constructing the anonymous class
-   * mappings worked.
-   */
   public boolean constructAnonymousClassMappings(TreeLogger logger) {
-    // map from the name in javac to the name in jdt
+    /*
+     * Check if the unit has one or more classes with generated names. 'javac'
+     * below refers to the compiler that was used to compile the java files on
+     * disk. Returns true if our heuristic for constructing the anonymous class
+     * mappings worked.
+     */
     anonymousClassMap = new HashMap<String, String>();
     for (String topLevelClass : getTopLevelClasses()) {
       // Generate a mapping for each top-level class separately
@@ -578,10 +577,13 @@
     }
   }
 
+  /**
+   * TODO(amitmanjhi): what is the difference between an anonymous and local
+   * class for our purposes? All our unit tests pass whether or not we do the
+   * additional {@link #isClassnameGenerated} check. We either need to find the
+   * real difference and add a unit test, or else simply this.
+   */
   private boolean isAnonymousClass(CompiledClass cc) {
-    if (!cc.getRealClassType().isLocalType()) {
-      return false;
-    }
-    return isClassnameGenerated(cc.getBinaryName());
+    return cc.isLocal() && isClassnameGenerated(cc.getBinaryName());
   }
 }
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java b/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
index 359dd36..e5eadc4 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
@@ -25,6 +25,8 @@
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
 import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
+import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
+import org.eclipse.jdt.internal.compiler.lookup.NestedTypeBinding;
 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
 
 /**
@@ -47,8 +49,24 @@
     return null;
   }
 
+  /**
+   * Returns <code>true</code> if this is a local type, or if this type is
+   * nested inside of any local type.
+   */
+  private static boolean isLocalType(SourceTypeBinding binding) {
+    SourceTypeBinding b = binding;
+    while (!b.isStatic()) {
+      if (b instanceof LocalTypeBinding) {
+        return true;
+      }
+      b = ((NestedTypeBinding) b).enclosingType;
+    }
+    return false;
+  }
+
   protected final String binaryName;
   protected final CompiledClass enclosingClass;
+  protected final boolean isLocal;
   protected final String location;
   protected final CompilationUnit unit;
 
@@ -74,6 +92,7 @@
     byte[] bytes = classFile.getBytes();
     this.cacheToken = diskCache.writeByteArray(bytes);
     this.location = String.valueOf(classFile.fileName());
+    this.isLocal = isLocalType(binding);
   }
 
   /**
@@ -112,6 +131,14 @@
     return unit;
   }
 
+  /**
+   * Returns <code>true</code> if this is a local type, or if this type is
+   * nested inside of any local type.
+   */
+  public boolean isLocal() {
+    return isLocal;
+  }
+
   @Override
   public String toString() {
     return binaryName;