Removes superClass field from JReferenceType in favor of pushing down to some subclasses.
This fixes duplication between JReferenceType and JDeclaredType.
Suggested by: grek
Review by: spoon
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8581 8db76d5a-ed1c-0410-87a9-c151d255dfc7
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 96af818..c618fea 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
@@ -31,16 +31,18 @@
private int dims;
private JType elementType;
private JType leafType;
+ private JClassType typeObject;
/**
* These are only supposed to be constructed by JProgram.
*/
- JArrayType(JType elementType, JType leafType, int dims) {
+ JArrayType(JType elementType, JType leafType, int dims, JClassType typeObject) {
super(leafType.getSourceInfo().makeChild(JArrayType.class, "Array type"),
calcName(leafType, dims));
this.elementType = elementType;
this.leafType = leafType;
this.dims = dims;
+ this.typeObject = typeObject;
}
@Override
@@ -78,6 +80,11 @@
return leafType;
}
+ @Override
+ public JClassType getSuperClass() {
+ return typeObject;
+ }
+
public boolean isAbstract() {
return false;
}
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
index 97964e7..8eb5517 100755
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclaredType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclaredType.java
@@ -218,12 +218,8 @@
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() {
+ public final JClassType getSuperClass() {
return superClass;
}
@@ -270,9 +266,12 @@
/**
* Sets this type's super class.
+ *
+ * TODO: to replace this setter with a final field, we'd have to refactor
+ * {@link com.google.gwt.dev.jjs.impl.BuildTypeMap} to use the builder pattern
+ * and resolve super types first.
*/
- @Override
- public void setSuperClass(JClassType superClass) {
+ public final void setSuperClass(JClassType superClass) {
this.superClass = superClass;
}
@@ -314,7 +313,7 @@
annotations = (List<JAnnotation>) stream.readObject();
}
- /**
+/**
* See {@link #writeMethodBodies(ObjectOutputStream).
*
* @see #writeMethodBodies(ObjectOutputStream)
@@ -336,12 +335,10 @@
if (newClinitTarget != null && getClass().desiredAssertionStatus()) {
// Make sure this is a pure upgrade to a superclass or null.
for (JDeclaredType current = clinitTarget; current != newClinitTarget; current = current.getSuperClass()) {
- Preconditions.checkNotNull(current.getSuperClass(),
+ Preconditions.checkNotNull(
+ current.getSuperClass(),
"Null super class for: %s (currentTarget: %s; newTarget: %s) in %s",
- current,
- clinitTarget,
- newClinitTarget,
- this);
+ current, clinitTarget, newClinitTarget, this);
}
}
clinitTarget = newClinitTarget;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JNonNullType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JNonNullType.java
index 1d19196..81e9770 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JNonNullType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JNonNullType.java
@@ -15,8 +15,6 @@
*/
package com.google.gwt.dev.jjs.ast;
-import com.google.gwt.dev.jjs.InternalCompilerException;
-
/**
* A type including all the values in some other type except for
* <code>null</code>.
@@ -59,11 +57,6 @@
return ref.isFinal();
}
- @Override
- public void setSuperClass(JClassType superClass) {
- throw new InternalCompilerException("should not be called");
- }
-
public void traverse(JVisitor visitor, Context ctx) {
visitor.accept(ref);
}
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 cac95fb..b10feda 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
@@ -46,6 +46,11 @@
return "N";
}
+ @Override
+ public JClassType getSuperClass() {
+ return null;
+ }
+
public boolean isAbstract() {
return false;
}
@@ -54,11 +59,6 @@
return true;
}
- @Override
- public void setSuperClass(JClassType superClass) {
- throw new InternalCompilerException("should not be called");
- }
-
public void traverse(JVisitor visitor, Context ctx) {
if (visitor.visit(this, ctx)) {
}
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 397f6f5..c3c51e4 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
@@ -1040,8 +1040,8 @@
} else {
elementType = getTypeArray(leafType, dimensions - 1);
}
- arrayType = new JArrayType(elementType, leafType, dimensions);
- arrayType.setSuperClass(typeJavaLangObject);
+ arrayType = new JArrayType(elementType, leafType, dimensions,
+ typeJavaLangObject);
allArrayTypes.add(arrayType);
/*
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 db07d97..4fc8dea 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
@@ -22,11 +22,6 @@
*/
public abstract class JReferenceType extends JType implements CanBeAbstract {
- /**
- * This type's super class.
- */
- private JClassType superClass;
-
public JReferenceType(SourceInfo info, String name) {
super(info, name, JNullLiteral.INSTANCE);
}
@@ -60,9 +55,7 @@
* Returns this type's super class, or <code>null</code> if this type is
* {@link Object} or the {@link JNullType}.
*/
- public JClassType getSuperClass() {
- return superClass;
- }
+ public abstract JClassType getSuperClass();
/**
* If this type is a non-null type, returns the underlying (original) type.
@@ -70,11 +63,4 @@
public JReferenceType getUnderlyingType() {
return this;
}
-
- /**
- * Sets this type's super class.
- */
- public void setSuperClass(JClassType superClass) {
- this.superClass = superClass;
- }
}