Revision: 8581
Author: [email protected]
Date: Thu Aug 19 13:25:39 2010
Log: 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

http://code.google.com/p/google-web-toolkit/source/detail?r=8581

Modified:
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclaredType.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JNonNullType.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java Wed Aug 11 09:22:23 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java Thu Aug 19 13:25:39 2010
@@ -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
@@ -77,6 +79,11 @@
   public JType getLeafType() {
     return leafType;
   }
+
+  @Override
+  public JClassType getSuperClass() {
+    return typeObject;
+  }

   public boolean isAbstract() {
     return false;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclaredType.java Mon Jun 14 14:39:55 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclaredType.java Thu Aug 19 13:25:39 2010
@@ -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;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JNonNullType.java Wed Dec 9 09:10:40 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JNonNullType.java Thu Aug 19 13:25:39 2010
@@ -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>.
@@ -58,11 +56,6 @@
   public boolean isFinal() {
     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);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java Wed Dec 9 09:10:40 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java Thu Aug 19 13:25:39 2010
@@ -45,6 +45,11 @@
   public String getJsniSignatureName() {
     return "N";
   }
+
+  @Override
+  public JClassType getSuperClass() {
+    return null;
+  }

   public boolean isAbstract() {
     return false;
@@ -53,11 +58,6 @@
   public boolean isFinal() {
     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)) {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java Mon Aug 16 17:56:17 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java Thu Aug 19 13:25:39 2010
@@ -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);

       /*
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java Wed Dec 9 09:10:40 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java Thu Aug 19 13:25:39 2010
@@ -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;
-  }
-}
+}

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to