Revision: 6652 Author: sco...@google.com Date: Wed Nov 4 11:05:23 2009 Log: CompiledClasses now compute local class status from JDT.
Review by: amitmanjhi http://code.google.com/p/google-web-toolkit/source/detail?r=6652 Modified: /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java ======================================= --- /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Fri Aug 14 14:43:27 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Wed Nov 4 11:05:23 2009 @@ -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 @@ -263,6 +261,8 @@ return true; } } + + 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()); } } ======================================= --- /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java Thu Apr 2 13:40:27 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java Wed Nov 4 11:05:23 2009 @@ -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; /** @@ -46,9 +48,25 @@ assert false; 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); } /** @@ -111,6 +130,14 @@ public CompilationUnit getUnit() { 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() { --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---