Refactored JReferenceType hierarchy in compiler. - JDeclaredType is a common supertype for JClassType & JInterfaceType. It represents real, declared types that have source code, like Object, String, ArrayList, or Comparable. - JDeclaredType is now used at many call sites instead of JReferenceType; significantly JProgram.getDeclaredTypes() and HasEnclosingType.getEnclosingType() now return a JDeclaredType. - JArrayType is no long a subtype of JClassType; instead it's a direct subtype of JReferenceType. - Much of the JReferenceType interface and almost of of its implementation was pushed down into JDeclaredType. Combined the moving JArrayType, this should save memory since array types no longer need any collections. - The former direct field accesses in JReferenceType are now encapsulated. - Memory-light collections used to hold the list of fields and methods in a type. Review by: spoon Suggestions by: spoon git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5264 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/soyc/impl/StandardClassMember.java b/dev/core/src/com/google/gwt/core/ext/soyc/impl/StandardClassMember.java index 8a0a46f..7d940d0 100644 --- a/dev/core/src/com/google/gwt/core/ext/soyc/impl/StandardClassMember.java +++ b/dev/core/src/com/google/gwt/core/ext/soyc/impl/StandardClassMember.java
@@ -19,7 +19,7 @@ import com.google.gwt.core.ext.soyc.FieldMember; import com.google.gwt.core.ext.soyc.Member; import com.google.gwt.core.ext.soyc.MethodMember; -import com.google.gwt.dev.jjs.ast.JReferenceType; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import java.util.Collections; import java.util.HashSet; @@ -47,7 +47,7 @@ /** * Constructed by {@link MemberFactory#get(JReferenceType)}. */ - public StandardClassMember(MemberFactory factory, JReferenceType type) { + public StandardClassMember(MemberFactory factory, JDeclaredType type) { super(type.getSourceInfo()); int index = type.getName().lastIndexOf('.'); @@ -58,28 +58,26 @@ } sourceName = type.getName().intern(); - Set<JReferenceType> seen = new HashSet<JReferenceType>(); - Set<JReferenceType> toTraverse = new HashSet<JReferenceType>(); + Set<JDeclaredType> seen = new HashSet<JDeclaredType>(); + Set<JDeclaredType> toTraverse = new HashSet<JDeclaredType>(); toTraverse.add(type); SortedSet<ClassMember> overrides = new TreeSet<ClassMember>( Member.SOURCE_NAME_COMPARATOR); while (!toTraverse.isEmpty()) { - JReferenceType currentType = toTraverse.iterator().next(); + JDeclaredType currentType = toTraverse.iterator().next(); seen.add(currentType); if (currentType != type) { overrides.add(factory.get(currentType)); } - if (currentType.extnds != null) { - toTraverse.add(currentType.extnds); + if (currentType.getSuperClass() != null) { + toTraverse.add(currentType.getSuperClass()); } - if (currentType.implments != null) { - toTraverse.addAll(currentType.implments); - } + toTraverse.addAll(currentType.getImplements()); toTraverse.removeAll(seen); }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java index 4ad8fe6..78008d7 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java +++ b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
@@ -38,6 +38,7 @@ import com.google.gwt.dev.jjs.ast.JBinaryOperator; import com.google.gwt.dev.jjs.ast.JBlock; import com.google.gwt.dev.jjs.ast.JClassType; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JGwtCreate; @@ -124,8 +125,8 @@ import java.util.TreeSet; /** - * Compiles the Java <code>JProgram</code> representation into its corresponding - * JavaScript source. + * Compiles the Java <code>JProgram</code> representation into its + * corresponding JavaScript source. */ public class JavaToJavaScriptCompiler { @@ -298,17 +299,21 @@ // get method dependencies DependencyRecorderImpl dr = new DependencyRecorderImpl(); - File depFile = dr.recordDependencies(jprogram, options.getWorkDir(), permutationId, logger); - + File depFile = dr.recordDependencies(jprogram, options.getWorkDir(), + permutationId, logger); + StoryRecorder sr = new StoryRecorderImpl(); - File storyFile = sr.recordStories(jprogram, options.getWorkDir(), permutationId, logger, sourceInfoMaps, js); - + File storyFile = sr.recordStories(jprogram, options.getWorkDir(), + permutationId, logger, sourceInfoMaps, js); + SplitPointRecorder spr = new SplitPointRecorderImpl(); - File splitPointsFile = spr.recordSplitPoints(jprogram, options.getWorkDir(), permutationId, logger); - + File splitPointsFile = spr.recordSplitPoints(jprogram, + options.getWorkDir(), permutationId, logger); + toReturn.getArtifacts().add( - new StandardCompilationAnalysis(logger, depFile, storyFile, splitPointsFile)); - } + new StandardCompilationAnalysis(logger, depFile, storyFile, + splitPointsFile)); + } return toReturn; } catch (Throwable e) { throw logAndTranslateException(logger, e); @@ -621,7 +626,7 @@ } private static JMethodCall createReboundModuleLoad(TreeLogger logger, - JReferenceType reboundEntryType, String originalMainClassName) + JDeclaredType reboundEntryType, String originalMainClassName) throws UnableToCompleteException { if (!(reboundEntryType instanceof JClassType)) { logger.log(TreeLogger.ERROR, "Module entry point class '" @@ -685,7 +690,7 @@ JBlock block = body.getBlock(); for (String mainClassName : mainClassNames) { block.addStmt(makeStatsCalls(program, mainClassName)); - JReferenceType mainType = program.getFromTypeMap(mainClassName); + JDeclaredType mainType = program.getFromTypeMap(mainClassName); if (mainType == null) { logger.log(TreeLogger.ERROR, @@ -707,7 +712,7 @@ List<JClassType> resultTypes = new ArrayList<JClassType>(); List<JExpression> entryCalls = new ArrayList<JExpression>(); for (String resultTypeName : resultTypeNames) { - JReferenceType resultType = program.getFromTypeMap(resultTypeName); + JDeclaredType resultType = program.getFromTypeMap(resultTypeName); if (resultType == null) { logger.log(TreeLogger.ERROR, "Could not find module entry point class '" + resultTypeName @@ -731,9 +736,8 @@ program.addEntryMethod(bootStrapMethod); } - private static JMethod findMainMethod(JReferenceType referenceType) { - for (int j = 0; j < referenceType.methods.size(); ++j) { - JMethod method = referenceType.methods.get(j); + private static JMethod findMainMethod(JDeclaredType declaredType) { + for (JMethod method : declaredType.getMethods()) { if (method.getName().equals("onModuleLoad")) { if (method.getParams().size() == 0) { return method; @@ -743,8 +747,8 @@ return null; } - private static JMethod findMainMethodRecurse(JReferenceType referenceType) { - for (JReferenceType it = referenceType; it != null; it = it.extnds) { + private static JMethod findMainMethodRecurse(JDeclaredType declaredType) { + for (JDeclaredType it = declaredType; it != null; it = it.getSuperClass()) { JMethod result = findMainMethod(it); if (result != null) { return result;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/HasEnclosingType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/HasEnclosingType.java index c3a11ce..5279c66 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/HasEnclosingType.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/HasEnclosingType.java
@@ -19,5 +19,5 @@ * Interface implemented by anything that can be enclosed by a type. */ public interface HasEnclosingType { - JReferenceType getEnclosingType(); + JDeclaredType getEnclosingType(); }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java index 4bf5750..71d9dfa 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java
@@ -15,10 +15,11 @@ */ package com.google.gwt.dev.jjs.ast; + /** * Instances are shared. */ -public class JArrayType extends JClassType { +public class JArrayType extends JReferenceType { private static String calcName(JType leafType, int dims) { String name = leafType.getName(); @@ -37,7 +38,7 @@ */ JArrayType(JType elementType, JType leafType, int dims) { super(leafType.getSourceInfo().makeChild(JArrayType.class, "Array type"), - calcName(leafType, dims), false, false); + calcName(leafType, dims)); this.elementType = elementType; this.leafType = leafType; this.dims = dims; @@ -71,16 +72,11 @@ } return s; } - + public JType getLeafType() { return leafType; } - @Override - public boolean hasClinit() { - return false; - } - public boolean isAbstract() { return false; } @@ -91,7 +87,6 @@ public void traverse(JVisitor visitor, Context ctx) { if (visitor.visit(this, ctx)) { - visitor.acceptWithInsertRemove(fields); } visitor.endVisit(this, ctx); }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java index 4bab76f..83ff78b 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
@@ -56,19 +56,12 @@ call.addArgs(program.getLiteralString(info, getPackageName(typeName)), program.getLiteralString(info, getClassName(typeName))); - if (type instanceof JClassType && !(type instanceof JArrayType)) { - /* - * For non-array classes and enums, determine the class literal of the - * supertype, if there is one. Arrays are excluded because they always - * have Object as their superclass. - */ - assert (type instanceof JClassType); + if (type instanceof JClassType) { JClassType classType = (JClassType) type; JLiteral superclassLiteral; - - if (classType.extnds != null) { - superclassLiteral = program.getLiteralClass(classType.extnds); + if (classType.getSuperClass() != null) { + superclassLiteral = program.getLiteralClass(classType.getSuperClass()); } else { superclassLiteral = program.getLiteralNull(); } @@ -78,7 +71,7 @@ if (classType instanceof JEnumType) { JEnumType enumType = (JEnumType) classType; JMethod valuesMethod = null; - for (JMethod methodIt : enumType.methods) { + for (JMethod methodIt : enumType.getMethods()) { if ("values".equals(methodIt.getName())) { if (methodIt.getParams().size() != 0) { continue;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java index af7dd9a..016b463 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java
@@ -20,7 +20,7 @@ /** * Java class type reference expression. */ -public class JClassType extends JReferenceType implements CanBeSetFinal { +public class JClassType extends JDeclaredType implements CanBeSetFinal { private final boolean isAbstract; private boolean isFinal; @@ -42,8 +42,8 @@ } public JEnumType isEnumOrSubclass() { - if (extnds != null) { - return extnds.isEnumOrSubclass(); + if (getSuperClass() != null) { + return getSuperClass().isEnumOrSubclass(); } return null; } @@ -58,10 +58,9 @@ public void traverse(JVisitor visitor, Context ctx) { if (visitor.visit(this, ctx)) { - visitor.acceptWithInsertRemove(fields); - visitor.acceptWithInsertRemove(methods); + fields = visitor.acceptWithInsertRemoveImmutable(fields); + methods = visitor.acceptWithInsertRemoveImmutable(methods); } visitor.endVisit(this, ctx); } - }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclaredType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclaredType.java new file mode 100755 index 0000000..1880b5f --- /dev/null +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclaredType.java
@@ -0,0 +1,230 @@ +/* + * Copyright 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.dev.jjs.ast; + +import com.google.gwt.dev.jjs.SourceInfo; +import com.google.gwt.dev.util.collect.Lists; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +/** + * Base class for any reference type. + */ +public abstract class JDeclaredType extends JReferenceType { + + /** + * This type's fields. + */ + protected List<JField> fields = Lists.create(); + + /** + * This type's methods. + */ + protected List<JMethod> methods = Lists.create(); + + /** + * Tracks whether this class has a dynamic clinit. Defaults to true until + * shown otherwise. + */ + private boolean hasClinit = true; + + /** + * This type's super class. + */ + private JClassType superClass; + + /** + * This type's implemented interfaces. + */ + private List<JInterfaceType> superInterfaces = Lists.create(); + + public JDeclaredType(SourceInfo info, String name) { + super(info, name); + } + + /** + * Adds a field to this type. + */ + public void addField(JField field) { + assert field.getEnclosingType() == this; + fields = Lists.add(fields, field); + } + + /** + * Adds an implemented interface to this type. + */ + public void addImplements(JInterfaceType superInterface) { + superInterfaces = Lists.add(superInterfaces, superInterface); + } + + /** + * Adds a method to this type. + */ + public void addMethod(JMethod method) { + assert method.getEnclosingType() == this; + methods = Lists.add(methods, method); + } + + /** + * Returns <code>true</code> if a static field access of + * <code>targetType</code> from within this type should generate a clinit + * call. This will be true in cases where <code>targetType</code> has a live + * clinit method which we cannot statically know has already run. We can + * statically know the clinit method has already run when: + * <ol> + * <li><code>this == targetType</code></li> + * <li><code>this</code> is a subclass of <code>targetType</code>, + * because my clinit would have already run this <code>targetType</code>'s + * clinit; see JLS 12.4</li> + * </ol> + */ + public boolean checkClinitTo(JDeclaredType targetType) { + if (this == targetType) { + // Call to self (very common case). + return false; + } + if (targetType == null || !targetType.hasClinit()) { + // Target has no clinit (common case). + return false; + } + + // See if I'm a subclass. + JClassType checkType = this.getSuperClass(); + while (checkType != null) { + if (checkType == targetType) { + // I am a subclass. + return false; + } + checkType = checkType.getSuperClass(); + } + return true; + } + + /** + * Returns this type's fields;does not include fields defined in a super type + * unless they are overridden by this type. + */ + public List<JField> getFields() { + return fields; + } + + /** + * Returns this type's implemented interfaces. Returns an empty list if this + * type implements no interfaces. + */ + public List<JInterfaceType> getImplements() { + return superInterfaces; + } + + @Override + public String getJavahSignatureName() { + return "L" + name.replaceAll("_", "_1").replace('.', '_') + "_2"; + } + + @Override + public String getJsniSignatureName() { + return "L" + name.replace('.', '/') + ';'; + } + + /** + * Returns this type's declared methods; does not include methods defined in a + * super type unless they are overridden by this type. + */ + public List<JMethod> getMethods() { + return methods; + } + + @Override + public String getShortName() { + int dotpos = name.lastIndexOf('.'); + return name.substring(dotpos + 1); + } + + /** + * Returns this type's super class, or <code>null</code> if this type is + * {@link Object} or the {@link JNullType}. + */ + @Override + public JClassType getSuperClass() { + return superClass; + } + + /** + * Returns <code>true</code> when this class's clinit must be run + * dynamically. + */ + public boolean hasClinit() { + return hasClinit; + } + + /** + * Removes the field at the specified index. + */ + public void removeField(int i) { + fields = Lists.remove(fields, i); + } + + /** + * Removes the method at the specified index. + */ + public void removeMethod(int i) { + methods = Lists.remove(methods, i); + } + + /** + * Sets this type's super class. + */ + @Override + public void setSuperClass(JClassType superClass) { + this.superClass = superClass; + } + + /** + * Sorts this type's fields according to the specified sort. + */ + public void sortFields(Comparator<? super JField> sort) { + fields = Lists.sort(fields, sort); + } + + /** + * Sorts this type's methods according to the specified sort. + */ + public void sortMethods(Comparator<? super JMethod> sort) { + // Sort the methods manually to avoid sorting clinit out of place! + JMethod a[] = methods.toArray(new JMethod[methods.size()]); + Arrays.sort(a, 1, a.length, sort); + methods = Lists.create(a); + } + + /** + * Clears all existing implemented interfaces. + */ + void clearImplements() { + superInterfaces = Lists.create(); + } + + /** + * Called when this class's clinit is empty or can be run at the top level. + */ + void removeClinit() { + assert hasClinit(); + JMethod clinitMethod = methods.get(0); + assert JProgram.isClinit(clinitMethod); + hasClinit = false; + } +}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumType.java index 8334c33..31c82de 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumType.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumType.java
@@ -16,8 +16,8 @@ package com.google.gwt.dev.jjs.ast; import com.google.gwt.dev.jjs.SourceInfo; +import com.google.gwt.dev.util.collect.Lists; -import java.util.ArrayList; import java.util.List; /** @@ -28,17 +28,37 @@ * TODO: implement traverse? */ - public final List<JEnumField> enumList = new ArrayList<JEnumField>(); + private List<JEnumField> enumList = Lists.create(); public JEnumType(SourceInfo info, String name) { super(info, name, false, false); } @Override + public void addField(JField field) { + if (field instanceof JEnumField) { + JEnumField enumField = (JEnumField) field; + int ordinal = enumField.ordinal(); + while (ordinal >= enumList.size()) { + enumList = Lists.add(enumList, null); + } + enumList = Lists.set(enumList, ordinal, enumField); + } + super.addField(field); + } + + @Override public String getClassLiteralFactoryMethod() { return "Class.createForEnum"; } + /** + * Returns the list of enum fields in this enum. + */ + public List<JEnumField> getEnumList() { + return enumList; + } + @Override public JEnumType isEnumOrSubclass() { return this;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java index ff63c3f..c769783 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
@@ -42,12 +42,12 @@ } } - private final JReferenceType enclosingType; + private final JDeclaredType enclosingType; private final boolean isCompileTimeConstant; private final boolean isStatic; private boolean isVolatile; - JField(SourceInfo info, String name, JReferenceType enclosingType, + JField(SourceInfo info, String name, JDeclaredType enclosingType, JType type, boolean isStatic, Disposition disposition) { super(info, name, type, disposition.isFinal()); this.enclosingType = enclosingType; @@ -57,7 +57,7 @@ // Disposition is not cached because we can be set final later. } - public JReferenceType getEnclosingType() { + public JDeclaredType getEnclosingType() { return enclosingType; }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java index 1eda77b..73695ab 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java
@@ -25,7 +25,7 @@ /** * The enclosing type of this reference. */ - private final JReferenceType enclosingType; + private final JDeclaredType enclosingType; /** * The referenced field. @@ -45,12 +45,12 @@ private final JType overriddenType; public JFieldRef(SourceInfo info, JExpression instance, JField field, - JReferenceType enclosingType) { + JDeclaredType enclosingType) { this(info, instance, field, enclosingType, null); } public JFieldRef(SourceInfo info, JExpression instance, JField field, - JReferenceType enclosingType, JType overriddenType) { + JDeclaredType enclosingType, JType overriddenType) { super(info, field); assert (instance != null || field.isStatic()); assert (enclosingType != null); @@ -60,7 +60,7 @@ this.overriddenType = overriddenType; } - public JReferenceType getEnclosingType() { + public JDeclaredType getEnclosingType() { return enclosingType; }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java index b3826ff..cb46c35 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java
@@ -34,11 +34,11 @@ * instance methods that should be qualified with a new expression. */ JMethod noArgCtor = null; - for (int i = 0; i < classType.methods.size(); ++i) { - JMethod ctor = classType.methods.get(i); + for (JMethod ctor : classType.getMethods()) { if (ctor.getName().equals(classType.getShortName())) { if (ctor.getParams().size() == 0) { noArgCtor = ctor; + break; } } }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java index ce4886c..134f81f 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java
@@ -20,7 +20,7 @@ /** * Java interface type definition. */ -public class JInterfaceType extends JReferenceType { +public class JInterfaceType extends JDeclaredType { JInterfaceType(SourceInfo info, String name) { super(info, name); @@ -41,8 +41,8 @@ public void traverse(JVisitor visitor, Context ctx) { if (visitor.visit(this, ctx)) { - visitor.acceptWithInsertRemove(fields); - visitor.acceptWithInsertRemove(methods); + fields = visitor.acceptWithInsertRemoveImmutable(fields); + methods = visitor.acceptWithInsertRemoveImmutable(methods); } visitor.endVisit(this, ctx); }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java index 97e2bfd..d3eeea3 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
@@ -40,7 +40,7 @@ } private JAbstractMethodBody body = null; - private final JReferenceType enclosingType; + private final JDeclaredType enclosingType; private final boolean isAbstract; private boolean isFinal; private final boolean isPrivate; @@ -64,7 +64,7 @@ /** * These are only supposed to be constructed by JProgram. */ - public JMethod(SourceInfo info, String name, JReferenceType enclosingType, + public JMethod(SourceInfo info, String name, JDeclaredType enclosingType, JType returnType, boolean isAbstract, boolean isStatic, boolean isFinal, boolean isPrivate) { super(info); @@ -110,7 +110,7 @@ return body; } - public JReferenceType getEnclosingType() { + public JDeclaredType getEnclosingType() { return enclosingType; }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java index dc64ced..2a2c513 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java
@@ -44,11 +44,6 @@ return "N"; } - @Override - public boolean hasClinit() { - return false; - } - public boolean isAbstract() { return false; }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java index 2f8b5ea..655f362 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
@@ -129,8 +129,9 @@ } public static boolean isClinit(JMethod method) { - JReferenceType enclosingType = method.getEnclosingType(); - if ((enclosingType != null) && (method == enclosingType.methods.get(0))) { + JDeclaredType enclosingType = method.getEnclosingType(); + if ((enclosingType != null) + && (method == enclosingType.getMethods().get(0))) { assert (method.getName().equals("$clinit")); return true; } else { @@ -174,7 +175,7 @@ private final Set<JArrayType> allArrayTypes = new TreeSet<JArrayType>( ARRAYTYPE_COMPARATOR); - private final List<JReferenceType> allTypes = new ArrayList<JReferenceType>(); + private final List<JDeclaredType> allTypes = new ArrayList<JDeclaredType>(); private final Map<JType, JClassLiteral> classLiterals = new IdentityHashMap<JType, JClassLiteral>(); @@ -194,7 +195,7 @@ private final Map<String, JMethod> indexedMethods = new HashMap<String, JMethod>(); - private final Map<String, JReferenceType> indexedTypes = new HashMap<String, JReferenceType>(); + private final Map<String, JDeclaredType> indexedTypes = new HashMap<String, JDeclaredType>(); private final Map<JMethod, JMethod> instanceToStaticMap = new IdentityHashMap<JMethod, JMethod>(); @@ -226,13 +227,13 @@ private JClassType typeClass; - private Map<JClassType, Integer> typeIdMap = new HashMap<JClassType, Integer>(); + private Map<JReferenceType, Integer> typeIdMap = new HashMap<JReferenceType, Integer>(); private JClassType typeJavaLangEnum; private JClassType typeJavaLangObject; - private final Map<String, JReferenceType> typeNameMap = new HashMap<String, JReferenceType>(); + private final Map<String, JDeclaredType> typeNameMap = new HashMap<String, JDeclaredType>(); private JClassType typeSpecialClassLiteralHolder; @@ -331,7 +332,7 @@ public JEnumType createEnum(SourceInfo info, char[][] name) { String sname = dotify(name); JEnumType x = new JEnumType(info, sname); - x.extnds = getTypeJavaLangEnum(); + x.setSuperClass(getTypeJavaLangEnum()); allTypes.add(x); putIntoTypeMap(sname, x); @@ -347,19 +348,12 @@ String sname = String.valueOf(name); JEnumField x = new JEnumField(info, sname, ordinal, enclosingType, type); - List<JEnumField> enumList = enclosingType.enumList; - while (ordinal >= enumList.size()) { - enumList.add(null); - } - - enumList.set(ordinal, x); - - enclosingType.fields.add(x); + enclosingType.addField(x); return x; } public JField createField(SourceInfo info, char[] name, - JReferenceType enclosingType, JType type, boolean isStatic, + JDeclaredType enclosingType, JType type, boolean isStatic, Disposition disposition) { assert (name != null); assert (enclosingType != null); @@ -373,7 +367,7 @@ indexedFields.put(enclosingType.getShortName() + '.' + sname, x); } - enclosingType.fields.add(x); + enclosingType.addField(x); return x; } @@ -405,7 +399,7 @@ } public JMethod createMethod(SourceInfo info, char[] name, - JReferenceType enclosingType, JType returnType, boolean isAbstract, + JDeclaredType enclosingType, JType returnType, boolean isAbstract, boolean isStatic, boolean isFinal, boolean isPrivate, boolean isNative) { String sname = String.valueOf(name); assert (sname != null); @@ -424,7 +418,7 @@ indexedMethods.put(enclosingType.getShortName() + '.' + sname, x); } - enclosingType.methods.add(x); + enclosingType.addMethod(x); return x; } @@ -583,16 +577,16 @@ int distance1 = countSuperTypes(type1); int distance2 = countSuperTypes(type2); for (; distance1 > distance2; --distance1) { - type1 = type1.extnds; + type1 = type1.getSuperClass(); } for (; distance1 < distance2; --distance2) { - type2 = type2.extnds; + type2 = type2.getSuperClass(); } while (type1 != type2) { - type1 = type1.extnds; - type2 = type2.extnds; + type1 = type1.getSuperClass(); + type2 = type2.getSuperClass(); } return type1; @@ -645,7 +639,7 @@ return correlator; } - public List<JReferenceType> getDeclaredTypes() { + public List<JDeclaredType> getDeclaredTypes() { return allTypes; } @@ -661,7 +655,7 @@ return entryMethods.size(); } - public JReferenceType getFromTypeMap(String qualifiedBinaryOrSourceName) { + public JDeclaredType getFromTypeMap(String qualifiedBinaryOrSourceName) { String srcTypeName = qualifiedBinaryOrSourceName.replace('$', '.'); return typeNameMap.get(srcTypeName); @@ -685,8 +679,8 @@ return method; } - public JReferenceType getIndexedType(String string) { - JReferenceType type = indexedTypes.get(string); + public JDeclaredType getIndexedType(String string) { + JDeclaredType type = indexedTypes.get(string); if (type == null) { throw new InternalCompilerException("Unable to locate index type: " + string); @@ -738,14 +732,14 @@ JField field = new JField(info, type.getJavahSignatureName() + "_classLit", typeSpecialClassLiteralHolder, getTypeJavaLangClass(), true, Disposition.FINAL); - typeSpecialClassLiteralHolder.fields.add(field); + typeSpecialClassLiteralHolder.addField(field); // Initialize the field. JFieldRef fieldRef = new JFieldRef(info, null, field, typeSpecialClassLiteralHolder); JDeclarationStatement decl = new JDeclarationStatement(info, fieldRef, alloc); - JMethodBody clinitBody = (JMethodBody) typeSpecialClassLiteralHolder.methods.get( + JMethodBody clinitBody = (JMethodBody) typeSpecialClassLiteralHolder.getMethods().get( 0).getBody(); clinitBody.getBlock().addStmt(decl); @@ -758,7 +752,7 @@ // Make sure the field hasn't been pruned. JField field = classLiteral.getField(); if (optimizationsStarted - && !field.getEnclosingType().fields.contains(field)) { + && !field.getEnclosingType().getFields().contains(field)) { throw new InternalCompilerException( "Getting a class literal whose field holder has already been pruned; type '" + type + " '"); @@ -870,7 +864,7 @@ elementType = getTypeArray(leafType, dimensions - 1); } arrayType = new JArrayType(elementType, leafType, dimensions); - arrayType.extnds = typeJavaLangObject; + arrayType.setSuperClass(typeJavaLangObject); allArrayTypes.add(arrayType); /* @@ -929,8 +923,8 @@ } } - public int getTypeId(JClassType classType) { - Integer integer = typeIdMap.get(classType); + public int getTypeId(JReferenceType referenceType) { + Integer integer = typeIdMap.get(referenceType); if (integer == null) { return 0; } @@ -994,10 +988,10 @@ return JPrimitiveType.VOID; } - public void initTypeInfo(List<JClassType> classes, + public void initTypeInfo(List<JReferenceType> types, List<JsonObject> jsonObjects) { - for (int i = 0, c = classes.size(); i < c; ++i) { - typeIdMap.put(classes.get(i), new Integer(i)); + for (int i = 0, c = types.size(); i < c; ++i) { + typeIdMap.put(types.get(i), new Integer(i)); } this.jsonTypeTable = jsonObjects; } @@ -1014,9 +1008,8 @@ return staticToInstanceMap.containsKey(method); } - public void putIntoTypeMap(String qualifiedBinaryName, JReferenceType type) { + public void putIntoTypeMap(String qualifiedBinaryName, JDeclaredType type) { // Make it into a source type name. - // String srcTypeName = qualifiedBinaryName.replace('$', '.'); typeNameMap.put(srcTypeName, type); } @@ -1067,7 +1060,6 @@ public void traverse(JVisitor visitor, Context ctx) { if (visitor.visit(this, ctx)) { visitor.accept(allTypes); - visitor.accept(new ArrayList<JArrayType>(allArrayTypes)); } visitor.endVisit(this, ctx); } @@ -1097,7 +1089,7 @@ } } int count = 0; - while ((type = type.extnds) != null) { + while ((type = type.getSuperClass()) != null) { ++count; } return count;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java index ae9c70d..e70f1d7 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java
@@ -17,64 +17,20 @@ import com.google.gwt.dev.jjs.SourceInfo; -import java.util.ArrayList; -import java.util.List; - /** * Base class for any reference type. */ public abstract class JReferenceType extends JType implements CanBeAbstract { - public JClassType extnds; - public List<JField> fields = new ArrayList<JField>(); - public List<JInterfaceType> implments = new ArrayList<JInterfaceType>(); - public List<JMethod> methods = new ArrayList<JMethod>(); - /** - * Tracks whether this class has a dynamic clinit. Defaults to true until - * shown otherwise. + * This type's super class. */ - private boolean hasClinit = true; + private JClassType superClass; public JReferenceType(SourceInfo info, String name) { super(info, name, JNullLiteral.INSTANCE); } - /** - * Returns <code>true</code> if a static field access of - * <code>targetType</code> from within this type should generate a clinit - * call. This will be true in cases where <code>targetType</code> has a live - * clinit method which we cannot statically know has already run. We can - * statically know the clinit method has already run when: - * <ol> - * <li><code>this == targetType</code></li> - * <li><code>this</code> is a subclass of <code>targetType</code>, - * because my clinit would have already run this <code>targetType</code>'s - * clinit; see JLS 12.4</li> - * </ol> - */ - public boolean checkClinitTo(JReferenceType targetType) { - if (this == targetType) { - // Call to self (very common case). - return false; - } - if (targetType == null || !targetType.hasClinit()) { - // Target has no clinit (common case). - return false; - } - - // See if I'm a subclass. - JClassType checkType = this.extnds; - while (checkType != null) { - if (checkType == targetType) { - // I am a subclass. - return false; - } - checkType = checkType.extnds; - } - return true; - } - @Override public String getJavahSignatureName() { return "L" + name.replaceAll("_", "_1").replace('.', '_') + "_2"; @@ -91,20 +47,17 @@ } /** - * Returns <code>true</code> when this method's clinit must be run - * dynamically. + * Returns this type's super class, or <code>null</code> if this type is + * {@link Object} or the {@link JNullType}. */ - public boolean hasClinit() { - return hasClinit; + public JClassType getSuperClass() { + return superClass; } /** - * Called when this class's clinit is empty or can be run at the top level. + * Sets this type's super class. */ - void removeClinit() { - assert hasClinit(); - JMethod clinitMethod = methods.get(0); - assert JProgram.isClinit(clinitMethod); - hasClinit = false; + public void setSuperClass(JClassType superClass) { + this.superClass = superClass; } }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java index a64321e..2ddff85 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
@@ -46,7 +46,7 @@ */ private static final class CheckClinitVisitor extends JVisitor { - private final Set<JReferenceType> clinitTargets = new IdentityHashSet<JReferenceType>(); + private final Set<JDeclaredType> clinitTargets = new IdentityHashSet<JDeclaredType>(); /** * Tracks whether any live code is run in this clinit. This is only reliable @@ -58,8 +58,8 @@ */ private boolean hasLiveCode = false; - public JReferenceType[] getClinitTargets() { - return clinitTargets.toArray(new JReferenceType[clinitTargets.size()]); + public JDeclaredType[] getClinitTargets() { + return clinitTargets.toArray(new JDeclaredType[clinitTargets.size()]); } public boolean hasLiveCode() { @@ -238,29 +238,6 @@ this.program = program; } - /** - * Collect all supertypes and superinterfaces for a type. - */ - public Set<JReferenceType> allAssignableFrom(JReferenceType type) { - Set<JReferenceType> toReturn = new IdentityHashSet<JReferenceType>(); - List<JReferenceType> q = new LinkedList<JReferenceType>(); - q.add(type); - - while (!q.isEmpty()) { - JReferenceType t = q.remove(0); - - if (toReturn.add(t)) { - if (t.extnds != null) { - q.add(t.extnds); - } - - q.addAll(t.implments); - } - } - - return toReturn; - } - public boolean canTheoreticallyCast(JReferenceType type, JReferenceType qType) { JClassType jlo = program.getTypeJavaLangObject(); if (type == qType || type == jlo) { @@ -427,7 +404,7 @@ public JMethod findConcreteImplementation(JMethod method, JClassType concreteType) { - for (JMethod m : concreteType.methods) { + for (JMethod m : concreteType.getMethods()) { if (getAllOverrides(m).contains(method)) { if (!m.isAbstract()) { return m; @@ -515,9 +492,9 @@ * associated JProgram. */ public void recomputeAfterOptimizations() { - Set<JReferenceType> computed = new IdentityHashSet<JReferenceType>(); + Set<JDeclaredType> computed = new IdentityHashSet<JDeclaredType>(); for (int i = 0; i < program.getDeclaredTypes().size(); ++i) { - JReferenceType type = program.getDeclaredTypes().get(i); + JDeclaredType type = program.getDeclaredTypes().get(i); if (type.hasClinit()) { computeHasClinit(type, computed); } @@ -536,6 +513,29 @@ } /** + * Collect all supertypes and superinterfaces for a type. + */ + private Set<JDeclaredType> allAssignableFrom(JDeclaredType type) { + Set<JDeclaredType> toReturn = new IdentityHashSet<JDeclaredType>(); + List<JDeclaredType> q = new LinkedList<JDeclaredType>(); + q.add(type); + + while (!q.isEmpty()) { + JDeclaredType t = q.remove(0); + + if (toReturn.add(t)) { + if (t.getSuperClass() != null) { + q.add(t.getSuperClass()); + } + + q.addAll(t.getImplements()); + } + } + + return toReturn; + } + + /** * Compute all of the things I might conceivably implement, either through * super types or sub types. */ @@ -546,7 +546,7 @@ List<JClassType> subclasses = new ArrayList<JClassType>(); subclasses.addAll(get(subClassMap, type)); for (JClassType subclass : subclasses) { - for (JInterfaceType intf : subclass.implments) { + for (JInterfaceType intf : subclass.getImplements()) { couldImplementSet.add(intf); for (JInterfaceType isup : get(superInterfaceMap, intf)) { couldImplementSet.add(isup); @@ -561,29 +561,28 @@ } } - private void computeHasClinit(JReferenceType type, - Set<JReferenceType> computed) { + private void computeHasClinit(JDeclaredType type, Set<JDeclaredType> computed) { if (computeHasClinitRecursive(type, computed, - new IdentityHashSet<JReferenceType>())) { + new IdentityHashSet<JDeclaredType>())) { computed.add(type); } else { type.removeClinit(); } } - private boolean computeHasClinitRecursive(JReferenceType type, - Set<JReferenceType> computed, Set<JReferenceType> alreadySeen) { + private boolean computeHasClinitRecursive(JDeclaredType type, + Set<JDeclaredType> computed, Set<JDeclaredType> alreadySeen) { // Track that we've been seen. alreadySeen.add(type); - JMethod method = type.methods.get(0); + JMethod method = type.getMethods().get(0); assert (JProgram.isClinit(method)); CheckClinitVisitor v = new CheckClinitVisitor(); v.accept(method); if (v.hasLiveCode()) { return true; } - for (JReferenceType target : v.getClinitTargets()) { + for (JDeclaredType target : v.getClinitTargets()) { if (!target.hasClinit()) { // A false result is always accurate. continue; @@ -625,7 +624,7 @@ list.add(type); list.addAll(get(superClassMap, type)); for (JClassType superclass : list) { - for (JInterfaceType intf : superclass.implments) { + for (JInterfaceType intf : superclass.getImplements()) { implementsSet.add(intf); for (JInterfaceType isup : get(superInterfaceMap, intf)) { implementsSet.add(isup); @@ -649,12 +648,12 @@ return; } - jsoType.implments.clear(); + jsoType.clearImplements(); - for (JReferenceType type : program.getDeclaredTypes()) { + for (JDeclaredType type : program.getDeclaredTypes()) { if (!program.isJavaScriptObject(type)) { if (type instanceof JClassType) { - dualImpl.addAll(type.implments); + dualImpl.addAll(type.getImplements()); } continue; } @@ -665,16 +664,16 @@ } JInterfaceType intr = (JInterfaceType) refType; - if (intr.methods.size() <= 1) { + if (intr.getMethods().size() <= 1) { /* * Record a tag interface as being implemented by JSO, since they * don't actually have any methods and we want to avoid spurious * messages about multiple JSO types implementing a common interface. */ - assert intr.methods.size() == 0 - || intr.methods.get(0).getName().equals("$clinit"); + assert intr.getMethods().size() == 0 + || intr.getMethods().get(0).getName().equals("$clinit"); jsoSingleImpls.put(intr, program.getJavaScriptObject()); - jsoType.implments.add(intr); + jsoType.addImplements(intr); continue; } @@ -709,7 +708,7 @@ * pruned. */ private void computeVirtualUpRefs(JClassType type) { - if (type.extnds == null || type.extnds == javaLangObject) { + if (type.getSuperClass() == null || type.getSuperClass() == javaLangObject) { return; } @@ -718,7 +717,7 @@ * I define implementations for them. If I don't, then check all my super * classes to find virtual overrides. */ - for (JInterfaceType intf : type.implments) { + for (JInterfaceType intf : type.getImplements()) { computeVirtualUpRefs(type, intf); for (JInterfaceType superIntf : get(superInterfaceMap, intf)) { computeVirtualUpRefs(type, superIntf); @@ -732,8 +731,8 @@ * classes to find virtual overrides. */ private void computeVirtualUpRefs(JClassType type, JInterfaceType intf) { - outer : for (JMethod intfMethod : intf.methods) { - for (JMethod classMethod : type.methods) { + outer : for (JMethod intfMethod : intf.getMethods()) { + for (JMethod classMethod : type.getMethods()) { if (methodsDoMatch(intfMethod, classMethod)) { // this class directly implements the interface method continue outer; @@ -742,8 +741,8 @@ // this class does not directly implement the interface method // if any super classes do, create a virtual up ref - for (JClassType superType = type.extnds; superType != javaLangObject; superType = superType.extnds) { - for (JMethod superMethod : superType.methods) { + for (JClassType superType = type.getSuperClass(); superType != javaLangObject; superType = superType.getSuperClass()) { + for (JMethod superMethod : superType.getMethods()) { if (methodsDoMatch(intfMethod, superMethod)) { // this super class directly implements the interface method // create a virtual up ref @@ -818,7 +817,7 @@ */ private void recordSuperSubInfo(JClassType type) { Set<JClassType> superSet = new IdentityHashSet<JClassType>(); - for (JClassType t = type.extnds; t != null; t = t.extnds) { + for (JClassType t = type.getSuperClass(); t != null; t = t.getSuperClass()) { superSet.add(t); add(subClassMap, t, type); } @@ -832,7 +831,7 @@ * them). */ private void recordSuperSubInfo(JInterfaceType type) { - if (!type.implments.isEmpty()) { + if (!type.getImplements().isEmpty()) { Set<JInterfaceType> superSet = new IdentityHashSet<JInterfaceType>(); recordSuperSubInfo(type, superSet, type); superInterfaceMap.put(type, IdentitySets.normalize(superSet)); @@ -844,7 +843,7 @@ */ private void recordSuperSubInfo(JInterfaceType base, Set<JInterfaceType> superSet, JInterfaceType cur) { - for (JInterfaceType intf : cur.implments) { + for (JInterfaceType intf : cur.getImplements()) { superSet.add(intf); add(subInterfaceMap, intf, base); recordSuperSubInfo(base, superSet, intf);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java index cbc7643..a6b46b8 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java
@@ -17,10 +17,10 @@ import com.google.gwt.dev.jjs.SourceInfo; import com.google.gwt.dev.jjs.ast.Context; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JFieldRef; import com.google.gwt.dev.jjs.ast.JNullLiteral; -import com.google.gwt.dev.jjs.ast.JReferenceType; import com.google.gwt.dev.jjs.ast.JVisitor; /** @@ -32,7 +32,7 @@ private boolean isLvalue; public JsniFieldRef(SourceInfo info, String ident, JField field, - JReferenceType enclosingType, boolean isLvalue) { + JDeclaredType enclosingType, boolean isLvalue) { super(info, field.isStatic() ? null : JNullLiteral.INSTANCE, field, enclosingType); this.ident = ident;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/AutoboxUtils.java b/dev/core/src/com/google/gwt/dev/jjs/impl/AutoboxUtils.java index 45e1077..ed59b75 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/AutoboxUtils.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/AutoboxUtils.java
@@ -18,13 +18,13 @@ import com.google.gwt.dev.jjs.InternalCompilerException; import com.google.gwt.dev.jjs.ast.JCastOperation; import com.google.gwt.dev.jjs.ast.JClassType; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JMethod; import com.google.gwt.dev.jjs.ast.JMethodCall; import com.google.gwt.dev.jjs.ast.JParameter; import com.google.gwt.dev.jjs.ast.JPrimitiveType; import com.google.gwt.dev.jjs.ast.JProgram; -import com.google.gwt.dev.jjs.ast.JReferenceType; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -37,7 +37,7 @@ public class AutoboxUtils { private Set<JPrimitiveType> boxablePrimitiveTypes; private Map<JClassType, JPrimitiveType> boxClassToPrimitiveMap; - private Set<JReferenceType> boxTypes; + private Set<JDeclaredType> boxTypes; private final JProgram program; private Set<JMethod> unboxMethods; @@ -109,7 +109,7 @@ // Find the correct valueOf() method. JMethod valueOfMethod = null; - for (JMethod method : wrapperType.methods) { + for (JMethod method : wrapperType.getMethods()) { if ("valueOf".equals(method.getName())) { if (method.getParams().size() == 1) { JParameter param = method.getParams().get(0); @@ -157,7 +157,7 @@ } private void computeBoxTypes() { - boxTypes = new LinkedHashSet<JReferenceType>(); + boxTypes = new LinkedHashSet<JDeclaredType>(); for (JPrimitiveType prim : boxablePrimitiveTypes) { boxTypes.add(boxClassForPrimitive(prim)); } @@ -165,9 +165,9 @@ private void computeUnboxMethods() { unboxMethods = new LinkedHashSet<JMethod>(); - for (JReferenceType boxType : boxTypes) { + for (JDeclaredType boxType : boxTypes) { if (boxType != null) { - for (JMethod method : boxType.methods) { + for (JMethod method : boxType.getMethods()) { if (!method.isStatic() && method.getParams().isEmpty() && method.getName().endsWith("Value") && (method.getType() instanceof JPrimitiveType)) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java b/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java index 4cede89..a486507 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
@@ -19,6 +19,7 @@ import com.google.gwt.dev.jjs.InternalCompilerException; import com.google.gwt.dev.jjs.SourceInfo; import com.google.gwt.dev.jjs.ast.JClassType; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JEnumType; import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JInterfaceType; @@ -245,7 +246,7 @@ public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { try { FieldBinding b = fieldDeclaration.binding; - JReferenceType enclosingType = (JReferenceType) typeMap.get(scope.enclosingSourceType()); + JDeclaredType enclosingType = (JDeclaredType) typeMap.get(scope.enclosingSourceType()); SourceInfo info = makeSourceInfo(fieldDeclaration, enclosingType); Expression initialization = fieldDeclaration.initialization; if (initialization != null @@ -282,7 +283,7 @@ public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { try { MethodBinding b = methodDeclaration.binding; - JReferenceType enclosingType = (JReferenceType) typeMap.get(scope.enclosingSourceType()); + JDeclaredType enclosingType = (JDeclaredType) typeMap.get(scope.enclosingSourceType()); SourceInfo info = makeSourceInfo(methodDeclaration, enclosingType); JMethod newMethod = processMethodBinding(b, enclosingType, info); mapParameters(newMethod, methodDeclaration); @@ -380,7 +381,7 @@ } private JField createField(SourceInfo info, FieldBinding binding, - JReferenceType enclosingType) { + JDeclaredType enclosingType) { JType type = (JType) typeMap.get(binding.type); boolean isCompileTimeConstant = binding.isStatic() && (binding.isFinal()) @@ -408,7 +409,7 @@ } private JField createField(SyntheticArgumentBinding binding, - JReferenceType enclosingType) { + JDeclaredType enclosingType) { JType type = (JType) typeMap.get(binding.type); SourceInfo info = enclosingType.getSourceInfo().makeChild( BuildDeclMapVisitor.class, "Field " + String.valueOf(binding.name)); @@ -530,14 +531,14 @@ JMethod method; MethodScope methodScope = scope.methodScope(); if (methodScope.isInsideInitializer()) { - JReferenceType enclosingType = (JReferenceType) typeMap.get(scope.classScope().referenceContext.binding); + JDeclaredType enclosingType = (JDeclaredType) typeMap.get(scope.classScope().referenceContext.binding); if (methodScope.isStatic) { // clinit - method = enclosingType.methods.get(0); + method = enclosingType.getMethods().get(0); } else { // init assert (enclosingType instanceof JClassType); - method = enclosingType.methods.get(1); + method = enclosingType.getMethods().get(1); } } else { AbstractMethodDeclaration referenceMethod = methodScope.referenceMethod(); @@ -613,7 +614,7 @@ */ return false; } - JReferenceType type = (JReferenceType) typeMap.get(binding); + JDeclaredType type = (JDeclaredType) typeMap.get(binding); try { // Create an override for getClass(). if (type instanceof JClassType @@ -623,7 +624,7 @@ type.getSourceInfo().makeChild(BuildDeclMapVisitor.class, "Synthetic getClass()"), "getClass".toCharArray(), type, program.getTypeJavaLangClass(), false, false, false, false, false); - assert (type.methods.get(2) == getClassMethod); + assert (type.getMethods().get(2) == getClassMethod); getClassMethod.freezeParamTypes(); } @@ -653,7 +654,7 @@ // TODO: handle separately? assert (binding.superclass().isClass() || binding.superclass().isEnum()); JClassType superClass = (JClassType) typeMap.get(superClassBinding); - type.extnds = superClass; + type.setSuperClass(superClass); } ReferenceBinding[] superInterfaces = binding.superInterfaces(); @@ -661,7 +662,7 @@ ReferenceBinding superInterfaceBinding = superInterfaces[i]; assert (superInterfaceBinding.isInterface()); JInterfaceType superInterface = (JInterfaceType) typeMap.get(superInterfaceBinding); - type.implments.add(superInterface); + type.addImplements(superInterface); } if (type instanceof JEnumType) { @@ -706,7 +707,7 @@ } private JMethod processMethodBinding(MethodBinding b, - JReferenceType enclosingType, SourceInfo info) { + JDeclaredType enclosingType, SourceInfo info) { JType returnType = (JType) typeMap.get(b.returnType); JMethod newMethod = program.createMethod(info, b.selector, enclosingType, returnType, b.isAbstract(), b.isStatic(), b.isFinal(), b.isPrivate(), @@ -717,7 +718,7 @@ } private void processNativeMethod(MethodDeclaration methodDeclaration, - SourceInfo info, JReferenceType enclosingType, JMethod newMethod) { + SourceInfo info, JDeclaredType enclosingType, JMethod newMethod) { // Handle JSNI block char[] source = methodDeclaration.compilationResult().getCompilationUnit().getContents(); String jsniCode = String.valueOf(source, methodDeclaration.bodyStart, @@ -912,7 +913,7 @@ } SourceInfo info = makeSourceInfo(typeDeclaration); - JReferenceType newType; + JDeclaredType newType; if (binding.isClass()) { newType = program.createClass(info, name, binding.isAbstract(), binding.isFinal());
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java index c883ac7..1b7e41f 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java
@@ -75,8 +75,8 @@ private class AssignTypeIdsVisitor extends JVisitor { - Set<JClassType> alreadyRan = new HashSet<JClassType>(); - private List<JClassType> classes = new ArrayList<JClassType>(); + Set<JReferenceType> alreadyRan = new HashSet<JReferenceType>(); + private List<JReferenceType> instantiableTypes = new ArrayList<JReferenceType>(); private final List<JArrayType> instantiatedArrayTypes = new ArrayList<JArrayType>(); private List<JsonObject> jsonObjects = new ArrayList<JsonObject>(); private int nextQueryId = 0; @@ -103,9 +103,9 @@ public void computeTypeIds() { // the 0th entry is the "always false" entry - classes.add(null); - jsonObjects.add(new JsonObject(program.createSourceInfoSynthetic(AssignTypeIdsVisitor.class, - "always-false typeinfo entry"), + instantiableTypes.add(null); + jsonObjects.add(new JsonObject(program.createSourceInfoSynthetic( + AssignTypeIdsVisitor.class, "always-false typeinfo entry"), program.getJavaScriptObject())); /* @@ -113,8 +113,8 @@ * respectively. This ensures consistent modification of String's * prototype. */ - computeSourceClass(program.getTypeJavaLangString()); - assert (classes.size() == 3); + computeSourceType(program.getTypeJavaLangString()); + assert (instantiableTypes.size() == 3); /* * Compute the list of classes than can successfully satisfy cast @@ -123,16 +123,16 @@ */ for (JReferenceType type : program.getDeclaredTypes()) { if (type instanceof JClassType) { - computeSourceClass((JClassType) type); + computeSourceType(type); } } for (JArrayType type : program.getAllArrayTypes()) { - computeSourceClass(type); + computeSourceType(type); } // pass our info to JProgram - program.initTypeInfo(classes, jsonObjects); + program.initTypeInfo(instantiableTypes, jsonObjects); // JSO's maker queryId is -1 (used for array stores). JClassType jsoType = program.getJavaScriptObject(); @@ -211,20 +211,15 @@ * Create the data for JSON table to capture the mapping from a class to its * query types. */ - private void computeSourceClass(JClassType type) { + private void computeSourceType(JReferenceType type) { if (type == null || alreadyRan.contains(type)) { return; } alreadyRan.add(type); - /* - * IMPORTANT: Visit my supertype first. The implementation of - * com.google.gwt.lang.Cast.wrapJSO() depends on all superclasses having - * typeIds that are less than all their subclasses. This allows the same - * JSO to be wrapped stronger but not weaker. - */ - computeSourceClass(type.extnds); + // Visit super type. + computeSourceType(type.getSuperClass()); if (!program.typeOracle.isInstantiatedType(type) || program.isJavaScriptObject(type)) { @@ -265,7 +260,8 @@ // Create a sparse lookup object. SourceInfo sourceInfo = program.createSourceInfoSynthetic( AssignTypeIdsVisitor.class, "typeinfo lookup"); - JsonObject jsonObject = new JsonObject(sourceInfo, program.getJavaScriptObject()); + JsonObject jsonObject = new JsonObject(sourceInfo, + program.getJavaScriptObject()); // Start at 1; 0 is Object and always true. for (int i = 1; i < nextQueryId; ++i) { if (yesArray[i] != null) { @@ -287,7 +283,7 @@ } // add an entry for me - classes.add(type); + instantiableTypes.add(type); jsonObjects.add(jsonObject); } @@ -343,8 +339,8 @@ JExpression newRhs = convertString(x.getRhs()); if (newLhs != x.getLhs() || newRhs != x.getRhs()) { JBinaryOperation newExpr = new JBinaryOperation(x.getSourceInfo(), - program.getTypeJavaLangString(), JBinaryOperator.ADD, - newLhs, newRhs); + program.getTypeJavaLangString(), JBinaryOperator.ADD, newLhs, + newRhs); ctx.replaceMe(newExpr); } } else if (x.getOp() == JBinaryOperator.ASG_ADD) { @@ -374,7 +370,8 @@ } } else if (expr.getType() == program.getTypePrimitiveLong()) { // Replace with LongLib.toString(l) - JMethodCall call = new JMethodCall(expr.getSourceInfo(), null, program.getIndexedMethod("LongLib.toString")); + JMethodCall call = new JMethodCall(expr.getSourceInfo(), null, + program.getIndexedMethod("LongLib.toString")); call.addArg(expr); return call; } @@ -547,8 +544,8 @@ if (methodName != null) { JMethod castMethod = program.getIndexedMethod(methodName); - JMethodCall call = new JMethodCall(x.getSourceInfo(), null, castMethod, - toType); + JMethodCall call = new JMethodCall(x.getSourceInfo(), null, + castMethod, toType); call.addArg(expr); replaceExpr = call; } else { @@ -566,9 +563,9 @@ if (program.typeOracle.canTriviallyCast(argType, toType)) { // trivially true if non-null; replace with a null test JNullLiteral nullLit = program.getLiteralNull(); - JBinaryOperation eq = new JBinaryOperation(x.getSourceInfo(), program.getTypePrimitiveBoolean(), - JBinaryOperator.NEQ, x.getExpr(), - nullLit); + JBinaryOperation eq = new JBinaryOperation(x.getSourceInfo(), + program.getTypePrimitiveBoolean(), JBinaryOperator.NEQ, + x.getExpr(), nullLit); ctx.replaceMe(eq); } else { JMethod method;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CodeSplitter.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CodeSplitter.java index f618856..8db2341 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/CodeSplitter.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CodeSplitter.java
@@ -18,6 +18,7 @@ import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.dev.jjs.ast.Context; import com.google.gwt.dev.jjs.ast.JClassLiteral; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JMethod; @@ -561,7 +562,7 @@ private void fixUpLoadOrderDependenciesForMethods(FragmentMap fragmentMap) { int numFixups = 0; - for (JReferenceType type : jprogram.getDeclaredTypes()) { + for (JDeclaredType type : jprogram.getDeclaredTypes()) { int typeFrag = getOrZero(fragmentMap.types, type); if (typeFrag != 0) { @@ -569,7 +570,7 @@ * If the type is in an exclusive fragment, all its instance methods * must be in the same one. */ - for (JMethod method : type.methods) { + for (JMethod method : type.getMethods()) { if (!method.isStatic() && methodsInJavaScript.contains(method)) { int methodFrag = getOrZero(fragmentMap.methods, method); if (methodFrag != typeFrag) { @@ -596,13 +597,13 @@ while (!typesToCheck.isEmpty()) { JReferenceType type = typesToCheck.remove(); - if (type.extnds != null) { + if (type.getSuperClass() != null) { int typeFrag = getOrZero(fragmentMap.types, type); - int supertypeFrag = getOrZero(fragmentMap.types, type.extnds); + int supertypeFrag = getOrZero(fragmentMap.types, type.getSuperClass()); if (typeFrag != supertypeFrag && supertypeFrag != 0) { numFixups++; - fragmentMap.types.put(type.extnds, 0); - typesToCheck.add(type.extnds); + fragmentMap.types.put(type.getSuperClass(), 0); + typesToCheck.add(type.getSuperClass()); } } }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java index 33547fe..383835a 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
@@ -24,6 +24,7 @@ import com.google.gwt.dev.jjs.ast.JClassLiteral; import com.google.gwt.dev.jjs.ast.JClassType; import com.google.gwt.dev.jjs.ast.JDeclarationStatement; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JFieldRef; @@ -102,13 +103,16 @@ // Rescue my super array type if (leafType instanceof JReferenceType) { JReferenceType rLeafType = (JReferenceType) leafType; - if (rLeafType.extnds != null) { - JArrayType superArray = program.getTypeArray(rLeafType.extnds, dims); + if (rLeafType.getSuperClass() != null) { + JArrayType superArray = program.getTypeArray( + rLeafType.getSuperClass(), dims); rescue(superArray, true, isInstantiated); } + } - for (int i = 0; i < rLeafType.implments.size(); ++i) { - JInterfaceType intfType = rLeafType.implments.get(i); + if (leafType instanceof JDeclaredType) { + JDeclaredType dLeafType = (JDeclaredType) leafType; + for (JInterfaceType intfType : dLeafType.getImplements()) { JArrayType intfArray = program.getTypeArray(intfType, dims); rescue(intfArray, true, isInstantiated); } @@ -188,15 +192,14 @@ boolean isInstantiated = instantiatedTypes.contains(type); // Rescue my super type - rescue(type.extnds, true, isInstantiated); + rescue(type.getSuperClass(), true, isInstantiated); // Rescue my clinit (it won't ever be explicitly referenced) - rescue(type.methods.get(0)); + rescue(type.getMethods().get(0)); // JLS 12.4.1: don't rescue my super interfaces just because I'm rescued. // However, if I'm instantiated, let's mark them as instantiated. - for (int i = 0; i < type.implments.size(); ++i) { - JInterfaceType intfType = type.implments.get(i); + for (JInterfaceType intfType : type.getImplements()) { rescue(intfType, false, isInstantiated); } @@ -260,20 +263,18 @@ assert (isReferenced || isInstantiated); // Rescue my clinit (it won't ever be explicitly referenced - rescue(type.methods.get(0)); + rescue(type.getMethods().get(0)); // JLS 12.4.1: don't rescue my super interfaces just because I'm rescued. // However, if I'm instantiated, let's mark them as instantiated. if (isInstantiated) { - for (int i = 0; i < type.implments.size(); ++i) { - JInterfaceType intfType = type.implments.get(i); + for (JInterfaceType intfType : type.getImplements()) { rescue(intfType, false, true); } } // visit any field initializers - for (int i = 0; i < type.fields.size(); ++i) { - JField it = type.fields.get(i); + for (JField it : type.getFields()) { accept(it); } @@ -566,7 +567,8 @@ JField field = (JField) var; accept(field.getInitializer()); referencedTypes.add(field.getEnclosingType()); - liveFieldsAndMethods.add(field.getEnclosingType().methods.get(0)); + liveFieldsAndMethods.add(field.getEnclosingType().getMethods().get( + 0)); } } } @@ -594,8 +596,7 @@ * Characters must rescue String.valueOf(char) */ if (stringValueOfChar == null) { - for (int i = 0; i < stringType.methods.size(); ++i) { - JMethod meth = stringType.methods.get(i); + for (JMethod meth : stringType.getMethods()) { if (meth.getName().equals("valueOf")) { List<JType> params = meth.getOriginalParamTypes(); if (params.size() == 1) { @@ -616,9 +617,9 @@ * If the type is instantiable, rescue any of its virtual methods that a * previously seen method call could call. */ - private void rescueMethodsIfInstantiable(JReferenceType type) { + private void rescueMethodsIfInstantiable(JDeclaredType type) { if (instantiatedTypes.contains(type)) { - for (JMethod method : type.methods) { + for (JMethod method : type.getMethods()) { if (!method.isStatic()) { if (methodsLiveExceptForInstantiability.contains(method)) { rescue(method); @@ -798,8 +799,8 @@ private void buildMethodsOverriding() { methodsThatOverrideMe = new HashMap<JMethod, List<JMethod>>(); - for (JReferenceType type : program.getDeclaredTypes()) { - for (JMethod method : type.methods) { + for (JDeclaredType type : program.getDeclaredTypes()) { + for (JMethod method : type.getMethods()) { for (JMethod overridden : program.typeOracle.getAllOverrides(method)) { List<JMethod> overs = methodsThatOverrideMe.get(overridden); if (overs == null) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java index 32b7018..2c42138 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
@@ -28,6 +28,7 @@ import com.google.gwt.dev.jjs.ast.JConditional; import com.google.gwt.dev.jjs.ast.JContinueStatement; import com.google.gwt.dev.jjs.ast.JDeclarationStatement; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JDoStatement; import com.google.gwt.dev.jjs.ast.JDoubleLiteral; import com.google.gwt.dev.jjs.ast.JExpression; @@ -397,7 +398,7 @@ } // Normal optimizations. - JReferenceType targetType = target.getEnclosingType(); + JDeclaredType targetType = target.getEnclosingType(); if (targetType == program.getTypeJavaLangString()) { tryOptimizeStringCall(x, ctx, target); } else if (JProgram.isClinit(target)) { @@ -1176,7 +1177,7 @@ private JMethodCall maybeCreateClinitCall(JFieldRef x) { if (x.hasClinit()) { - JMethod clinit = x.getField().getEnclosingType().methods.get(0); + JMethod clinit = x.getField().getEnclosingType().getMethods().get(0); assert (JProgram.isClinit(clinit)); return new JMethodCall(x.getSourceInfo(), null, clinit); }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Finalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Finalizer.java index f0595be..85533ae 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/Finalizer.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Finalizer.java
@@ -129,8 +129,8 @@ @Override public void endVisit(JClassType x, Context ctx) { - if (x.extnds != null) { - isSubclassed.add(x.extnds); + if (x.getSuperClass() != null) { + isSubclassed.add(x.getSuperClass()); } }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java index db0d928..570103c 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
@@ -37,6 +37,7 @@ import com.google.gwt.dev.jjs.ast.JConditional; import com.google.gwt.dev.jjs.ast.JContinueStatement; import com.google.gwt.dev.jjs.ast.JDeclarationStatement; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JDoStatement; import com.google.gwt.dev.jjs.ast.JDoubleLiteral; import com.google.gwt.dev.jjs.ast.JEnumField; @@ -241,7 +242,7 @@ private final AutoboxUtils autoboxUtils; - private JReferenceType currentClass; + private JDeclaredType currentClass; private ClassScope currentClassScope; @@ -337,7 +338,7 @@ JField mapField = createEnumValueMap(type); // Generate the synthetic values() and valueOf() methods. - for (JMethod method : type.methods) { + for (JMethod method : type.getMethods()) { currentMethod = method; if ("values".equals(method.getName())) { if (method.getParams().size() != 0) { @@ -370,7 +371,7 @@ // Do not process. return; } - currentClass = (JReferenceType) typeMap.get(x.binding); + currentClass = (JDeclaredType) typeMap.get(x.binding); try { currentClassScope = x.scope; currentSeparatorPositions = x.compilationResult.lineSeparatorPositions; @@ -380,11 +381,11 @@ * Make clinits chain to super class (JDT doesn't write code to do * this). Call super class $clinit; $clinit is always in position 0. */ - if (currentClass.extnds != null) { - JMethod myClinit = currentClass.methods.get(0); - JMethod superClinit = currentClass.extnds.methods.get(0); - JMethodCall superClinitCall = new JMethodCall(myClinit.getSourceInfo(), - null, superClinit); + if (currentClass.getSuperClass() != null) { + JMethod myClinit = currentClass.getMethods().get(0); + JMethod superClinit = currentClass.getSuperClass().getMethods().get(0); + JMethodCall superClinitCall = new JMethodCall( + myClinit.getSourceInfo(), null, superClinit); JMethodBody body = (JMethodBody) myClinit.getBody(); body.getBlock().addStmt(0, superClinitCall.makeStatement()); } @@ -395,12 +396,12 @@ FieldDeclaration fieldDeclaration = x.fields[i]; if (fieldDeclaration.isStatic()) { // clinit - currentMethod = currentClass.methods.get(0); + currentMethod = currentClass.getMethods().get(0); currentMethodBody = (JMethodBody) currentMethod.getBody(); currentMethodScope = x.staticInitializerScope; } else { // init - currentMethod = currentClass.methods.get(1); + currentMethod = currentClass.getMethods().get(1); currentMethodBody = (JMethodBody) currentMethod.getBody(); currentMethodScope = x.initializerScope; } @@ -435,13 +436,13 @@ if (currentClass instanceof JClassType && currentClass != program.getTypeJavaLangObject() && currentClass != program.getIndexedType("Array")) { - JMethod method = currentClass.methods.get(2); + JMethod method = currentClass.getMethods().get(2); assert ("getClass".equals(method.getName())); if (program.isJavaScriptObject(currentClass) && currentClass != program.getJavaScriptObject()) { // Just use JavaScriptObject's implementation for all subclasses. - currentClass.methods.remove(2); + currentClass.getMethods().remove(2); } else { tryFindUpRefs(method); implementMethod(method, program.getLiteralClass(currentClass)); @@ -469,13 +470,14 @@ JMethod nameMethod = program.getIndexedMethod("Class.getName"); // this.hashCode() - JMethodCall hashCall = new JMethodCall(info, program.getExprThisRef(info, (JClassType) currentClass), + JMethodCall hashCall = new JMethodCall(info, + program.getExprThisRef(info, (JClassType) currentClass), program.getIndexedMethod("Object.hashCode")); // "Class$" + hashCode() - JBinaryOperation op = new JBinaryOperation(info, program.getTypeJavaLangString(), - JBinaryOperator.ADD, program.getLiteralString(info, "Class$"), - hashCall); + JBinaryOperation op = new JBinaryOperation(info, + program.getTypeJavaLangString(), JBinaryOperator.ADD, + program.getLiteralString(info, "Class$"), hashCall); implementMethod(nameMethod, op); @@ -674,7 +676,7 @@ JClassType enclosingType = (JClassType) ctor.getEnclosingType(); // Call clinit; $clinit is always in position 0. - JMethod clinitMethod = enclosingType.methods.get(0); + JMethod clinitMethod = enclosingType.getMethods().get(0); JMethodCall clinitCall = new JMethodCall(info, null, clinitMethod); JMethodBody body = (JMethodBody) ctor.getBody(); JBlock block = body.getBlock(); @@ -740,7 +742,7 @@ */ if (!hasExplicitThis) { // $init is always in position 1 (clinit is in 0) - JMethod initMethod = enclosingType.methods.get(1); + JMethod initMethod = enclosingType.getMethods().get(1); JMethodCall initCall = new JMethodCall(info, thisRef, initMethod); block.addStmt(initCall.makeStatement()); } @@ -790,8 +792,7 @@ */ int ctorArgc = ctor.getParams().size(); JMethod targetMethod = null; - outer : for (int j = 0; j < javaLangString.methods.size(); ++j) { - JMethod method = javaLangString.methods.get(j); + outer : for (JMethod method : javaLangString.getMethods()) { if (method.getName().equals("_String") && method.getParams().size() == ctorArgc) { for (int i = 0; i < ctorArgc; ++i) { @@ -898,8 +899,8 @@ JExpression processExpression(ArrayReference x) { SourceInfo info = makeSourceInfo(x); - JArrayRef arrayRef = new JArrayRef(info, dispProcessExpression(x.receiver), - dispProcessExpression(x.position)); + JArrayRef arrayRef = new JArrayRef(info, + dispProcessExpression(x.receiver), dispProcessExpression(x.position)); return arrayRef; } @@ -973,7 +974,8 @@ JExpression processExpression(CastExpression x) { SourceInfo info = makeSourceInfo(x); JType type = (JType) typeMap.get(x.resolvedType); - JCastOperation cast = new JCastOperation(info, type, dispProcessExpression(x.expression)); + JCastOperation cast = new JCastOperation(info, type, + dispProcessExpression(x.expression)); return cast; } @@ -1182,7 +1184,8 @@ throw new InternalCompilerException("Unexpected postfix operator"); } - JPostfixOperation postOp = new JPostfixOperation(info, op, dispProcessExpression(x.lhs)); + JPostfixOperation postOp = new JPostfixOperation(info, op, + dispProcessExpression(x.lhs)); return postOp; } @@ -1203,7 +1206,8 @@ throw new InternalCompilerException("Unexpected prefix operator"); } - JPrefixOperation preOp = new JPrefixOperation(info, op, dispProcessExpression(x.lhs)); + JPrefixOperation preOp = new JPrefixOperation(info, op, + dispProcessExpression(x.lhs)); return preOp; } @@ -1319,7 +1323,7 @@ JExpression processExpression(QualifiedSuperReference x) { JClassType refType = (JClassType) typeMap.get(x.resolvedType); JClassType qualType = (JClassType) typeMap.get(x.qualification.resolvedType); - assert (refType == qualType.extnds); + assert (refType == qualType.getSuperClass()); // Oddly enough, super refs can be modeled as this refs, because whatever // expression they qualify has already been resolved. return processQualifiedThisOrSuperRef(x, qualType); @@ -1367,7 +1371,7 @@ JExpression processExpression(SuperReference x) { JClassType type = (JClassType) typeMap.get(x.resolvedType); - assert (type == currentClass.extnds); + assert (type == currentClass.getSuperClass()); SourceInfo info = makeSourceInfo(x); // Oddly enough, super refs can be modeled as a this refs. JExpression superRef = createThisRef(info, currentClass); @@ -1409,7 +1413,8 @@ "Unexpected operator for unary expression"); } - JPrefixOperation preOp = new JPrefixOperation(info, op, dispProcessExpression(x.expression)); + JPrefixOperation preOp = new JPrefixOperation(info, op, + dispProcessExpression(x.expression)); return preOp; } @@ -1451,8 +1456,8 @@ if (initializer != null) { SourceInfo info = makeSourceInfo(declaration); // JDeclarationStatement's ctor sets up the field's initializer. - JStatement decl = new JDeclarationStatement(info, createVariableRef(info, field), - initializer); + JStatement decl = new JDeclarationStatement(info, createVariableRef( + info, field), initializer); // will either be init or clinit currentMethodBody.getBlock().addStmt(decl); } @@ -1538,8 +1543,8 @@ JStatement processStatement(BreakStatement x) { SourceInfo info = makeSourceInfo(x); - return new JBreakStatement(info, getOrCreateLabel(info, - currentMethod, x.label)); + return new JBreakStatement(info, getOrCreateLabel(info, currentMethod, + x.label)); } JStatement processStatement(CaseStatement x) { @@ -1558,8 +1563,8 @@ JStatement processStatement(ContinueStatement x) { SourceInfo info = makeSourceInfo(x); - return new JContinueStatement(info, getOrCreateLabel(info, - currentMethod, x.label)); + return new JContinueStatement(info, getOrCreateLabel(info, currentMethod, + x.label)); } JStatement processStatement(DoStatement x) { @@ -1620,22 +1625,23 @@ program.getLiteralInt(0))); // int i$max = i$array.length initializers.add(createDeclaration(info, maxVar, new JFieldRef(info, - createVariableRef(info, arrayVar), program.getIndexedField("Array.length"), - currentClass))); + createVariableRef(info, arrayVar), + program.getIndexedField("Array.length"), currentClass))); // i$index < i$max - JExpression condition = new JBinaryOperation(info, program.getTypePrimitiveBoolean(), - JBinaryOperator.LT, createVariableRef(info, indexVar), - createVariableRef(info, maxVar)); + JExpression condition = new JBinaryOperation(info, + program.getTypePrimitiveBoolean(), JBinaryOperator.LT, + createVariableRef(info, indexVar), createVariableRef(info, maxVar)); // ++i$index List<JExpressionStatement> increments = new ArrayList<JExpressionStatement>( 1); - increments.add(new JPrefixOperation(info, JUnaryOperator.INC, createVariableRef(info, indexVar)).makeStatement()); + increments.add(new JPrefixOperation(info, JUnaryOperator.INC, + createVariableRef(info, indexVar)).makeStatement()); // T elementVar = i$array[i$index]; - elementDecl.initializer = new JArrayRef(info, createVariableRef(info, arrayVar), - createVariableRef(info, indexVar)); + elementDecl.initializer = new JArrayRef(info, createVariableRef(info, + arrayVar), createVariableRef(info, indexVar)); body.addStmt(0, elementDecl); result = new JForStatement(info, initializers, condition, increments, @@ -1655,15 +1661,16 @@ List<JStatement> initializers = new ArrayList<JStatement>(1); // Iterator<T> i$iterator = collection.iterator() initializers.add(createDeclaration(info, iteratorVar, new JMethodCall( - info, dispProcessExpression(x.collection), program.getIndexedMethod("Iterable.iterator")))); + info, dispProcessExpression(x.collection), + program.getIndexedMethod("Iterable.iterator")))); // i$iterator.hasNext() - JExpression condition = new JMethodCall(info, createVariableRef(info, iteratorVar), - program.getIndexedMethod("Iterator.hasNext")); + JExpression condition = new JMethodCall(info, createVariableRef(info, + iteratorVar), program.getIndexedMethod("Iterator.hasNext")); // T elementVar = (T) i$iterator.next(); - elementDecl.initializer = new JMethodCall(info, createVariableRef(info, iteratorVar), - program.getIndexedMethod("Iterator.next")); + elementDecl.initializer = new JMethodCall(info, createVariableRef(info, + iteratorVar), program.getIndexedMethod("Iterator.next")); // Perform any implicit reference type casts (due to generics). // Note this occurs before potential unboxing. @@ -1685,8 +1692,8 @@ body.addStmt(0, elementDecl); - result = new JForStatement(info, initializers, condition, Collections.<JExpressionStatement> emptyList(), - body); + result = new JForStatement(info, initializers, condition, + Collections.<JExpressionStatement> emptyList(), body); } // May need to box or unbox the element assignment. @@ -1743,8 +1750,8 @@ return null; } SourceInfo info = makeSourceInfo(x); - return new JLabeledStatement(info, getOrCreateLabel(info, - currentMethod, x.label), body); + return new JLabeledStatement(info, getOrCreateLabel(info, currentMethod, + x.label), body); } JStatement processStatement(LocalDeclaration x) { @@ -1765,8 +1772,7 @@ */ JClassType enclosingType = (JClassType) currentMethod.getEnclosingType(); assert (x.expression == null); - return new JReturnStatement(info, createThisRef(info, - enclosingType)); + return new JReturnStatement(info, createThisRef(info, enclosingType)); } else { return new JReturnStatement(info, dispProcessExpression(x.expression)); } @@ -1777,7 +1783,8 @@ JExpression expression = dispProcessExpression(x.expression); if (expression.getType() instanceof JClassType) { // Must be an enum; synthesize a call to ordinal(). - expression = new JMethodCall(info, expression, program.getIndexedMethod("Enum.ordinal")); + expression = new JMethodCall(info, expression, + program.getIndexedMethod("Enum.ordinal")); } JBlock block = new JBlock(info); block.addStmts(processStatements(x.statements)); @@ -1812,7 +1819,8 @@ } } JBlock finallyBlock = (JBlock) dispProcessStatement(x.finallyBlock); - return new JTryStatement(info, tryBlock, catchArgs, catchBlocks, finallyBlock); + return new JTryStatement(info, tryBlock, catchArgs, catchBlocks, + finallyBlock); } @SuppressWarnings("unused") @@ -1945,17 +1953,18 @@ private void addAllOuterThisRefs(List<? super JFieldRef> list, JExpression expr, JClassType classType) { - if (classType.fields.size() > 0) { - JField field = classType.fields.get(0); + if (classType.getFields().size() > 0) { + JField field = classType.getFields().get(0); if (field.getName().startsWith("this$")) { - list.add(new JFieldRef(expr.getSourceInfo(), expr, field, currentClass)); + list.add(new JFieldRef(expr.getSourceInfo(), expr, field, + currentClass)); } } } private void addAllOuterThisRefsPlusSuperChain( List<? super JFieldRef> workList, JExpression expr, JClassType classType) { - for (; classType != null; classType = classType.extnds) { + for (; classType != null; classType = classType.getSuperClass()) { addAllOuterThisRefs(workList, expr, classType); } } @@ -2040,17 +2049,17 @@ bridgeMethod.freezeParamTypes(); // create a call - JMethodCall call = new JMethodCall(program.createSourceInfoSynthetic(GenerateJavaAST.class, - "call to inherited method"), - program.getExprThisRef( - program.createSourceInfoSynthetic(GenerateJavaAST.class, - "part of a bridge method"), clazz), implmeth); + JMethodCall call = new JMethodCall(program.createSourceInfoSynthetic( + GenerateJavaAST.class, "call to inherited method"), + program.getExprThisRef(program.createSourceInfoSynthetic( + GenerateJavaAST.class, "part of a bridge method"), clazz), + implmeth); for (int i = 0; i < bridgeMethod.getParams().size(); i++) { JParameter param = bridgeMethod.getParams().get(i); - JParameterRef paramRef = new JParameterRef(program.createSourceInfoSynthetic(GenerateJavaAST.class, - "part of a bridge method"), - param); + JParameterRef paramRef = new JParameterRef( + program.createSourceInfoSynthetic(GenerateJavaAST.class, + "part of a bridge method"), param); call.addArg(maybeCast(implmeth.getParams().get(i).getType(), paramRef)); } @@ -2059,9 +2068,8 @@ if (bridgeMethod.getType() == program.getTypeVoid()) { callOrReturn = call.makeStatement(); } else { - callOrReturn = new JReturnStatement(program.createSourceInfoSynthetic(GenerateJavaAST.class, - "part of a bridge method"), - call); + callOrReturn = new JReturnStatement(program.createSourceInfoSynthetic( + GenerateJavaAST.class, "part of a bridge method"), call); } // create a body that is just that call @@ -2087,15 +2095,14 @@ private JDeclarationStatement createDeclaration(SourceInfo info, JLocal local, JExpression value) { - return new JDeclarationStatement(info, new JLocalRef(info, - local), value); + return new JDeclarationStatement(info, new JLocalRef(info, local), value); } private JField createEnumValueMap(JEnumType type) { SourceInfo sourceInfo = type.getSourceInfo().makeChild( JavaASTGenerationVisitor.class, "enum value lookup map"); JsonObject map = new JsonObject(sourceInfo, program.getJavaScriptObject()); - for (JEnumField field : type.enumList) { + for (JEnumField field : type.getEnumList()) { // JSON maps require leading underscores to prevent collisions. JStringLiteral key = program.getLiteralString(field.getSourceInfo(), "_" + field.getName()); @@ -2107,7 +2114,7 @@ Disposition.FINAL); // Initialize in clinit. - JMethodBody clinitBody = (JMethodBody) type.methods.get(0).getBody(); + JMethodBody clinitBody = (JMethodBody) type.getMethods().get(0).getBody(); JExpressionStatement assignment = program.createAssignmentStmt( sourceInfo, createVariableRef(sourceInfo, mapField), map); clinitBody.getBlock().addStmt(assignment); @@ -2171,7 +2178,7 @@ while (!workList.isEmpty()) { JExpression expr = workList.removeFirst(); JClassType classType = (JClassType) expr.getType(); - for (; classType != null; classType = classType.extnds) { + for (; classType != null; classType = classType.getSuperClass()) { // prefer myself or myself-as-supertype over any of my this$ fields // that may have already been added to the work list if (program.typeOracle.canTriviallyCast(classType, qualType)) { @@ -2227,9 +2234,9 @@ "FieldRef referencing field in a different type."); } } - return new JFieldRef(info.makeChild( - JavaASTGenerationVisitor.class, "Reference", - variable.getSourceInfo()), instance, field, currentClass); + return new JFieldRef(info.makeChild(JavaASTGenerationVisitor.class, + "Reference", variable.getSourceInfo()), instance, field, + currentClass); } throw new InternalCompilerException("Unknown JVariable subclass."); } @@ -2340,8 +2347,8 @@ * expression. Beware that when autoboxing, the type of the expression is * not necessarily the same as the type of the box to be created. The JDT * figures out what the necessary conversion is, depending on the context - * the expression appears in, and stores it in - * <code>x.implicitConversion</code>, so extract it from there. + * the expression appears in, and stores it in <code>x.implicitConversion</code>, + * so extract it from there. */ private JPrimitiveType implicitConversionTargetType(Expression x) throws InternalCompilerException { @@ -2391,7 +2398,8 @@ if (expected != expression.getType()) { // Must be a generic; insert a cast operation. JReferenceType toType = (JReferenceType) expected; - return new JCastOperation(expression.getSourceInfo(), toType, expression); + return new JCastOperation(expression.getSourceInfo(), toType, + expression); } else { return expression; } @@ -2458,8 +2466,8 @@ JBinaryOperator op, JType type, Expression arg1, Expression arg2) { JExpression exprArg1 = dispProcessExpression(arg1); JExpression exprArg2 = dispProcessExpression(arg2); - JBinaryOperation binaryOperation = new JBinaryOperation(info, type, - op, exprArg1, exprArg2); + JBinaryOperation binaryOperation = new JBinaryOperation(info, type, op, + exprArg1, exprArg2); return binaryOperation; } @@ -2537,11 +2545,11 @@ * methods that it overrides/implements. */ private void tryFindUpRefsRecursive(JMethod method, - JReferenceType searchThisType, List<JMethod> overrides) { + JDeclaredType searchThisType, List<JMethod> overrides) { // See if this class has any uprefs, unless this class is myself if (method.getEnclosingType() != searchThisType) { - for (JMethod upRef : searchThisType.methods) { + for (JMethod upRef : searchThisType.getMethods()) { if (JTypeOracle.methodsDoMatch(method, upRef) && !overrides.contains(upRef)) { overrides.add(upRef); @@ -2551,12 +2559,12 @@ } // recurse super class - if (searchThisType.extnds != null) { - tryFindUpRefsRecursive(method, searchThisType.extnds, overrides); + if (searchThisType.getSuperClass() != null) { + tryFindUpRefsRecursive(method, searchThisType.getSuperClass(), overrides); } // recurse super interfaces - for (JInterfaceType intf : searchThisType.implments) { + for (JInterfaceType intf : searchThisType.getImplements()) { tryFindUpRefsRecursive(method, intf, overrides); } } @@ -2612,7 +2620,7 @@ String valueMethodName = primitiveType.getName() + "Value"; JMethod valueMethod = null; - for (Object element : wrapperType.methods) { + for (Object element : wrapperType.getMethods()) { JMethod method = (JMethod) element; if (method.getName().equals(valueMethodName)) { if (method.getParams().isEmpty()) { @@ -2654,7 +2662,7 @@ SourceInfo sourceInfo = type.getSourceInfo().makeChild( JavaASTGenerationVisitor.class, "enum values method"); List<JExpression> initializers = new ArrayList<JExpression>(); - for (JEnumField field : type.enumList) { + for (JEnumField field : type.getEnumList()) { JFieldRef fieldRef = new JFieldRef(sourceInfo, null, field, type); initializers.add(fieldRef); } @@ -2730,8 +2738,7 @@ return null; } else { - for (int i = 0; i < ((JReferenceType) type).fields.size(); ++i) { - JField field = ((JReferenceType) type).fields.get(i); + for (JField field : ((JDeclaredType) type).getFields()) { if (field.getName().equals(fieldName)) { return field; } @@ -2758,12 +2765,11 @@ return program.getNullMethod(); } } else { - Queue<JReferenceType> workList = new LinkedList<JReferenceType>(); - workList.add((JReferenceType) type); + Queue<JDeclaredType> workList = new LinkedList<JDeclaredType>(); + workList.add((JDeclaredType) type); while (!workList.isEmpty()) { - JReferenceType cur = workList.poll(); - for (int i = 0; i < cur.methods.size(); ++i) { - JMethod method = cur.methods.get(i); + JDeclaredType cur = workList.poll(); + for (JMethod method : cur.getMethods()) { if (method.getName().equals(methodName)) { String sig = JProgram.getJsniSig(method); if (sig.equals(jsniSig)) { @@ -2775,10 +2781,10 @@ } } } - if (cur.extnds != null) { - workList.add(cur.extnds); + if (cur.getSuperClass() != null) { + workList.add(cur.getSuperClass()); } - workList.addAll(cur.implments); + workList.addAll(cur.getImplements()); } } @@ -2915,7 +2921,7 @@ } } - private JReferenceType currentClass; + private JDeclaredType currentClass; private final Map<JsniMethodBody, AbstractMethodDeclaration> jsniMethodMap; @@ -2939,7 +2945,7 @@ public void endVisit(JsniMethodBody x, Context ctx) { new JsniRefResolver(jsniMethodMap.get(x), x).accept(x.getFunc()); } - + @Override public boolean visit(JClassType x, Context ctx) { currentClass = x;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java index 2ea57f3..914fcc0 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -39,6 +39,7 @@ import com.google.gwt.dev.jjs.ast.JConditional; import com.google.gwt.dev.jjs.ast.JContinueStatement; import com.google.gwt.dev.jjs.ast.JDeclarationStatement; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JDoStatement; import com.google.gwt.dev.jjs.ast.JExpressionStatement; import com.google.gwt.dev.jjs.ast.JField; @@ -249,15 +250,15 @@ recordSymbol(x, jsName); // My class scope - if (x.extnds == null) { + if (x.getSuperClass() == null) { myScope = objectScope; } else { - JsScope parentScope = classScopes.get(x.extnds); + JsScope parentScope = classScopes.get(x.getSuperClass()); // Run my superclass first! if (parentScope == null) { - accept(x.extnds); + accept(x.getSuperClass()); } - parentScope = classScopes.get(x.extnds); + parentScope = classScopes.get(x.getSuperClass()); assert (parentScope != null); /* * WEIRD: we wedge the global interface scope in between object and all @@ -564,11 +565,11 @@ alreadyRan.add(x); - List<JsFunction> jsFuncs = popList(x.methods.size()); // methods - List<JsNode> jsFields = popList(x.fields.size()); // fields + List<JsFunction> jsFuncs = popList(x.getMethods().size()); // methods + List<JsNode> jsFields = popList(x.getFields().size()); // fields if (x.hasClinit()) { - JsFunction superClinit = clinitMap.get(x.extnds); + JsFunction superClinit = clinitMap.get(x.getSuperClass()); JsFunction myClinit = jsFuncs.get(0); handleClinit(myClinit, superClinit); clinitMap.put(x, myClinit); @@ -816,8 +817,8 @@ @Override public void endVisit(JInterfaceType x, Context ctx) { - List<JsFunction> jsFuncs = popList(x.methods.size()); // methods - List<JsVar> jsFields = popList(x.fields.size()); // fields + List<JsFunction> jsFuncs = popList(x.getMethods().size()); // methods + List<JsVar> jsFields = popList(x.getFields().size()); // fields List<JsStatement> globalStmts = jsProgram.getGlobalBlock().getStatements(); if (x.hasClinit()) { @@ -1208,8 +1209,8 @@ // force super type to generate code first, this is required for prototype // chaining to work properly - if (x.extnds != null && !alreadyRan.contains(x)) { - accept(x.extnds); + if (x.getSuperClass() != null && !alreadyRan.contains(x)) { + accept(x.getSuperClass()); } return true; @@ -1358,7 +1359,7 @@ * Must execute in clinit statement order, NOT field order, so that back * refs to super classes are preserved. */ - JMethodBody clinitBody = (JMethodBody) program.getTypeClassLiteralHolder().methods.get( + JMethodBody clinitBody = (JMethodBody) program.getTypeClassLiteralHolder().getMethods().get( 0).getBody(); for (JStatement stmt : clinitBody.getStatements()) { if (stmt instanceof JDeclarationStatement) { @@ -1494,9 +1495,10 @@ JsNameRef lhs = prototype.makeRef(sourceInfo); lhs.setQualifier(seedFuncName.makeRef(sourceInfo)); JsExpression rhs; - if (x.extnds != null) { + if (x.getSuperClass() != null) { JsNew newExpr = new JsNew(sourceInfo); - JsNameRef superPrototypeRef = names.get(x.extnds).makeRef(sourceInfo); + JsNameRef superPrototypeRef = names.get(x.getSuperClass()).makeRef( + sourceInfo); newExpr.setConstructorExpression(superPrototypeRef); rhs = newExpr; } else { @@ -1527,7 +1529,7 @@ private void generateToStringAlias(JClassType x, List<JsStatement> globalStmts) { JMethod toStringMeth = program.getIndexedMethod("Object.toString"); - if (x.methods.contains(toStringMeth)) { + if (x.getMethods().contains(toStringMeth)) { SourceInfo sourceInfo = x.getSourceInfo().makeChild( GenerateJavaScriptVisitor.class, "_.toString"); // _.toString = function(){return this.java_lang_Object_toString();} @@ -1610,8 +1612,7 @@ } private void generateVTables(JClassType x, List<JsStatement> globalStmts) { - for (int i = 0; i < x.methods.size(); ++i) { - JMethod method = x.methods.get(i); + for (JMethod method : x.getMethods()) { SourceInfo sourceInfo = method.getSourceInfo().makeChild( GenerateJavaScriptVisitor.class, "vtable assignment"); if (!method.isStatic() && !method.isAbstract()) { @@ -1643,14 +1644,14 @@ return null; } - JReferenceType targetType = x.getEnclosingType(); + JDeclaredType targetType = x.getEnclosingType(); if (!currentMethod.getEnclosingType().checkClinitTo(targetType)) { return null; } else if (targetType.equals(program.getTypeClassLiteralHolder())) { return null; } - JMethod clinitMethod = targetType.methods.get(0); + JMethod clinitMethod = targetType.getMethods().get(0); SourceInfo sourceInfo = x.getSourceInfo().makeChild( GenerateJavaScriptVisitor.class, "clinit invocation"); JsInvocation jsInvocation = new JsInvocation(sourceInfo); @@ -1665,7 +1666,7 @@ if (!x.isStatic() || program.isStaticImpl(x)) { return null; } - JReferenceType enclosingType = x.getEnclosingType(); + JDeclaredType enclosingType = x.getEnclosingType(); if (enclosingType == null || !enclosingType.hasClinit()) { return null; } @@ -1674,7 +1675,7 @@ return null; } - JMethod clinitMethod = enclosingType.methods.get(0); + JMethod clinitMethod = enclosingType.getMethods().get(0); SourceInfo sourceInfo = x.getSourceInfo().makeChild( GenerateJavaScriptVisitor.class, "clinit call"); JsInvocation jsInvocation = new JsInvocation(sourceInfo); @@ -1749,8 +1750,8 @@ @Override public void endVisit(JMethodCall x, Context ctx) { - JReferenceType sourceType = currentMethod.getEnclosingType(); - JReferenceType targetType = x.getTarget().getEnclosingType(); + JDeclaredType sourceType = currentMethod.getEnclosingType(); + JDeclaredType targetType = x.getTarget().getEnclosingType(); if (sourceType.checkClinitTo(targetType)) { crossClassTargets.add(x.getTarget()); } @@ -1774,21 +1775,14 @@ @Override public void endVisit(JClassType x, Context ctx) { - Collections.sort(x.fields, hasNameSort); - - // Sort the methods manually to avoid sorting clinit out of place! - List<JMethod> methods = x.methods; - JMethod a[] = methods.toArray(new JMethod[methods.size()]); - Arrays.sort(a, 1, a.length, hasNameSort); - for (int i = 1; i < a.length; i++) { - methods.set(i, a[i]); - } + x.sortFields(hasNameSort); + x.sortMethods(hasNameSort); } @Override public void endVisit(JInterfaceType x, Context ctx) { - Collections.sort(x.fields, hasNameSort); - Collections.sort(x.methods, hasNameSort); + x.sortFields(hasNameSort); + x.sortMethods(hasNameSort); } @Override @@ -2036,12 +2030,12 @@ final Map<JsName, JMethod> nameToMethodMap = new HashMap<JsName, JMethod>(); final HashMap<JsName, JField> nameToFieldMap = new HashMap<JsName, JField>(); final HashMap<JsName, JReferenceType> constructorNameToTypeMap = new HashMap<JsName, JReferenceType>(); - for (JReferenceType type : program.getDeclaredTypes()) { + for (JDeclaredType type : program.getDeclaredTypes()) { JsName typeName = names.get(type); if (typeName != null) { constructorNameToTypeMap.put(typeName, type); } - for (JField field : type.fields) { + for (JField field : type.getFields()) { if (field.isStatic()) { JsName fieldName = names.get(field); if (fieldName != null) { @@ -2049,7 +2043,7 @@ } } } - for (JMethod method : type.methods) { + for (JMethod method : type.getMethods()) { JsName methodName = names.get(method); if (methodName != null) { nameToMethodMap.put(methodName, method);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/JsoDevirtualizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/JsoDevirtualizer.java index 01898e4..83929cd 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/JsoDevirtualizer.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/JsoDevirtualizer.java
@@ -177,7 +177,7 @@ return; } - for (JMethod method : jsoType.methods) { + for (JMethod method : jsoType.getMethods()) { if (!method.isStatic()) { virtualJsoMethods.add(method); }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java index ca976b4..7a7f6b8 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
@@ -140,7 +140,7 @@ JClassType enclosingType = (JClassType) x.getEnclosingType(); JType returnType = x.getType(); SourceInfo sourceInfo = x.getSourceInfo(); - int myIndexInClass = enclosingType.methods.indexOf(x); + int myIndexInClass = enclosingType.getMethods().indexOf(x); assert (myIndexInClass > 0); // Create the new static method @@ -221,7 +221,7 @@ // Add the new method as a static impl of the old method program.putStaticImpl(x, newMethod); - enclosingType.methods.add(myIndexInClass + 1, newMethod); + enclosingType.getMethods().add(myIndexInClass + 1, newMethod); return false; } } @@ -257,7 +257,7 @@ return; } - if (!method.getEnclosingType().methods.contains(method)) { + if (!method.getEnclosingType().getMethods().contains(method)) { // The target method was already pruned (TypeTightener will fix this). return; }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodCallTightener.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodCallTightener.java index c9d9b60..4e5cb42 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodCallTightener.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodCallTightener.java
@@ -83,9 +83,8 @@ JMethod foundMethod = null; JClassType type; outer : for (type = (JClassType) instanceType; type != null - && type != enclosingType; type = type.extnds) { - for (int i = 0; i < type.methods.size(); ++i) { - JMethod methodIt = type.methods.get(i); + && type != enclosingType; type = type.getSuperClass()) { + for (JMethod methodIt : type.getMethods()) { if (methodOverrides(methodIt, method)) { foundMethod = methodIt; break outer;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java index 4f96422..5023b1d 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
@@ -18,6 +18,7 @@ import com.google.gwt.dev.jjs.InternalCompilerException; import com.google.gwt.dev.jjs.ast.Context; import com.google.gwt.dev.jjs.ast.JCastOperation; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JExpressionStatement; import com.google.gwt.dev.jjs.ast.JLocalRef; @@ -28,7 +29,6 @@ import com.google.gwt.dev.jjs.ast.JParameter; import com.google.gwt.dev.jjs.ast.JParameterRef; import com.google.gwt.dev.jjs.ast.JProgram; -import com.google.gwt.dev.jjs.ast.JReferenceType; import com.google.gwt.dev.jjs.ast.JReturnStatement; import com.google.gwt.dev.jjs.ast.JStatement; import com.google.gwt.dev.jjs.ast.JThisRef; @@ -111,7 +111,7 @@ List<JStatement> stmts = body.getStatements(); if (method.getEnclosingType() != null - && method.getEnclosingType().methods.get(0) == method + && method.getEnclosingType().getMethods().get(0) == method && !stmts.isEmpty()) { // clinit() calls cannot be inlined unless they are empty possibleToInline = false; @@ -147,7 +147,7 @@ } private JMethodCall createClinitCall(JMethodCall x) { - JReferenceType targetEnclosingType = x.getTarget().getEnclosingType(); + JDeclaredType targetEnclosingType = x.getTarget().getEnclosingType(); if (!currentMethod.getEnclosingType().checkClinitTo(targetEnclosingType)) { // Access from this class to the target class won't trigger a clinit return null; @@ -156,12 +156,12 @@ // No clinit needed; target is really an instance method. return null; } - if (x.getTarget() == x.getTarget().getEnclosingType().methods.get(0)) { + if (x.getTarget() == x.getTarget().getEnclosingType().getMethods().get(0)) { // This is a clinit call, doesn't need another clinit return null; } - JMethod clinit = targetEnclosingType.methods.get(0); + JMethod clinit = targetEnclosingType.getMethods().get(0); // If the clinit is a non-native, empty body we can optimize it out here if (!clinit.isNative()
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java index 3948954..2caa635 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
@@ -23,6 +23,7 @@ import com.google.gwt.dev.jjs.ast.JBinaryOperator; import com.google.gwt.dev.jjs.ast.JClassType; import com.google.gwt.dev.jjs.ast.JDeclarationStatement; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JFieldRef; @@ -321,21 +322,23 @@ assert (referencedTypes.contains(type)); boolean isInstantiated = program.typeOracle.isInstantiatedType(type); - for (Iterator<JField> it = type.fields.iterator(); it.hasNext();) { - JField field = it.next(); + for (int i = 0; i < type.getFields().size(); ++i) { + JField field = type.getFields().get(i); if (!referencedNonTypes.contains(field) || pruneViaNoninstantiability(isInstantiated, field)) { - it.remove(); + type.removeField(i); didChange = true; + --i; } } - for (Iterator<JMethod> it = type.methods.iterator(); it.hasNext();) { - JMethod method = it.next(); + for (int i = 0; i < type.getMethods().size(); ++i) { + JMethod method = type.getMethods().get(i); if (!methodIsReferenced(method) || pruneViaNoninstantiability(isInstantiated, method)) { - it.remove(); + type.removeMethod(i); didChange = true; + --i; } else { accept(method); } @@ -349,26 +352,24 @@ boolean isReferenced = referencedTypes.contains(type); boolean isInstantiated = program.typeOracle.isInstantiatedType(type); - for (Iterator<JField> it = type.fields.iterator(); it.hasNext();) { - JField field = it.next(); + for (int i = 0; i < type.getFields().size(); ++i) { + JField field = type.getFields().get(i); // all interface fields are static and final if (!isReferenced || !referencedNonTypes.contains(field)) { - it.remove(); + type.removeField(i); didChange = true; + --i; } } - Iterator<JMethod> it = type.methods.iterator(); - if (it.hasNext()) { - // start at index 1; never prune clinit directly out of the interface - it.next(); - } - while (it.hasNext()) { - JMethod method = it.next(); + // Start at index 1; never prune clinit directly out of the interface. + for (int i = 1; i < type.getMethods().size(); ++i) { + JMethod method = type.getMethods().get(i); // all other interface methods are instance and abstract if (!isInstantiated || !methodIsReferenced(method)) { - it.remove(); + type.removeMethod(i); didChange = true; + --i; } } @@ -400,8 +401,10 @@ */ JMethod staticImplFor = program.staticImplFor(x); // Unless the instance method has already been pruned, of course. - if (saveCodeGenTypes && staticImplFor != null - && staticImplFor.getEnclosingType().methods.contains(staticImplFor)) { + if (saveCodeGenTypes + && staticImplFor != null + && staticImplFor.getEnclosingType().getMethods().contains( + staticImplFor)) { // instance method is still live return true; } @@ -446,8 +449,8 @@ for (JMethod method : program.getAllEntryMethods()) { accept(method); } - for (Iterator<JReferenceType> it = program.getDeclaredTypes().iterator(); it.hasNext();) { - JReferenceType type = it.next(); + for (Iterator<JDeclaredType> it = program.getDeclaredTypes().iterator(); it.hasNext();) { + JDeclaredType type = it.next(); if (referencedTypes.contains(type) || program.typeOracle.isInstantiatedType(type)) { accept(type); @@ -634,10 +637,9 @@ * {@link JProgram#CODEGEN_TYPES_SET}. */ private void traverseFromCodeGenTypes(ControlFlowAnalyzer livenessAnalyzer) { - for (JReferenceType type : program.codeGenTypes) { + for (JClassType type : program.codeGenTypes) { livenessAnalyzer.traverseFromReferenceTo(type); - for (int i = 0; i < type.methods.size(); ++i) { - JMethod method = type.methods.get(i); + for (JMethod method : type.getMethods()) { livenessAnalyzer.traverseFrom(method); } }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRunAsyncs.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRunAsyncs.java index 9a1cc8b..b6f6c65 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRunAsyncs.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRunAsyncs.java
@@ -123,8 +123,8 @@ private JMethod getOnLoadMethod(JClassType loaderType) { assert loaderType != null; - assert loaderType.methods != null; - for (JMethod method : loaderType.methods) { + assert loaderType.getMethods() != null; + for (JMethod method : loaderType.getMethods()) { if (method.getName().equals("onLoad")) { assert (method.isStatic()); assert (method.getParams().size() == 0); @@ -137,8 +137,8 @@ private JMethod getRunAsyncMethod(JClassType loaderType) { assert loaderType != null; - assert loaderType.methods != null; - for (JMethod method : loaderType.methods) { + assert loaderType.getMethods() != null; + for (JMethod method : loaderType.getMethods()) { if (method.getName().equals("runAsync")) { assert (method.isStatic()); assert (method.getParams().size() == 1);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/SourceGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/jjs/impl/SourceGenerationVisitor.java index 1f52bfd..abbef1d 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/SourceGenerationVisitor.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/SourceGenerationVisitor.java
@@ -53,16 +53,14 @@ openBlock(); - for (int i = 0; i < x.fields.size(); ++i) { - JField it = x.fields.get(i); + for (JField it : x.getFields()) { accept(it); newline(); newline(); } - for (int i = 0; i < x.methods.size(); ++i) { - JMethod it = x.methods.get(i); - // Suppress empty clinit. - if (i == 0) { + for (JMethod it : x.getMethods()) { + if (JProgram.isClinit(it)) { + // Suppress empty clinit. JMethodBody body = (JMethodBody) it.getBody(); if (body.getBlock().getStatements().isEmpty()) { continue; @@ -83,14 +81,12 @@ openBlock(); - for (int i = 0; i < x.fields.size(); ++i) { - JField field = x.fields.get(i); + for (JField field : x.getFields()) { accept(field); newline(); newline(); } - for (int i = 0; i < x.methods.size(); ++i) { - JMethod method = x.methods.get(i); + for (JMethod method : x.getMethods()) { accept(method); newline(); newline();
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java index 9ad064c..c42a230 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java
@@ -289,19 +289,19 @@ print(CHARS_CLASS); printTypeName(x); space(); - if (x.extnds != null) { + if (x.getSuperClass() != null) { print(CHARS_EXTENDS); - printTypeName(x.extnds); + printTypeName(x.getSuperClass()); space(); } - if (x.implments.size() > 0) { + if (x.getImplements().size() > 0) { print(CHARS_IMPLEMENTS); - for (int i = 0, c = x.implments.size(); i < c; ++i) { + for (int i = 0, c = x.getImplements().size(); i < c; ++i) { if (i > 0) { print(CHARS_COMMA); } - printTypeName(x.implments.get(i)); + printTypeName(x.getImplements().get(i)); } space(); } @@ -523,13 +523,13 @@ printTypeName(x); space(); - if (x.implments.size() > 0) { + if (x.getImplements().size() > 0) { print(CHARS_EXTENDS); - for (int i = 0, c = x.implments.size(); i < c; ++i) { + for (int i = 0, c = x.getImplements().size(); i < c; ++i) { if (i > 0) { print(CHARS_COMMA); } - printTypeName(x.implments.get(i)); + printTypeName(x.getImplements().get(i)); } space(); }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java index 465d05d..2ac4be3 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
@@ -25,6 +25,7 @@ import com.google.gwt.dev.jjs.ast.JClassType; import com.google.gwt.dev.jjs.ast.JConditional; import com.google.gwt.dev.jjs.ast.JDeclarationStatement; +import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JFieldRef; @@ -180,7 +181,7 @@ @Override public void endVisit(JClassType x, Context ctx) { if (program.typeOracle.isInstantiatedType(x)) { - for (JClassType cur = x; cur != null; cur = cur.extnds) { + for (JClassType cur = x; cur != null; cur = cur.getSuperClass()) { addImplementor(cur, x); addInterfacesImplementorRecursive(cur, x); } @@ -308,7 +309,7 @@ */ JMethod staticImplFor = program.staticImplFor(x); if (staticImplFor == null - || !staticImplFor.getEnclosingType().methods.contains(staticImplFor)) { + || !staticImplFor.getEnclosingType().getMethods().contains(staticImplFor)) { // The instance method has already been pruned. return true; } @@ -343,9 +344,9 @@ add(target, implementor, implementors); } - private void addInterfacesImplementorRecursive(JReferenceType target, + private void addInterfacesImplementorRecursive(JDeclaredType target, JClassType implementor) { - for (JInterfaceType implment : target.implments) { + for (JInterfaceType implment : target.getImplements()) { addImplementor(implment, implementor); addInterfacesImplementorRecursive(implment, implementor); }