Deprecated GWT.getTypeName() in favor of getClass().getName().  I've inlined the implementation of GWT.getTypeName() everywhere, and removed the null tests, since everywhere I saw, the test made no difference (either it was already guaranteed non-null, or it would throw an NPE further down if it was).

Review by: jat


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1497 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/core/client/GWT.java b/user/src/com/google/gwt/core/client/GWT.java
index a38907c..96b1265 100644
--- a/user/src/com/google/gwt/core/client/GWT.java
+++ b/user/src/com/google/gwt/core/client/GWT.java
@@ -100,13 +100,9 @@
   }
 
   /**
-   * Gets the class name of the specified object, as would be returned by
-   * <code>o.getClass().getName()</code>.
-   * 
-   * @param o the object whose class name is being sought, or <code>null</code>
-   * @return the class name of the specified object, or <code>null</code> if
-   *         <code>o</code> is <code>null</code>
+   * @deprecated Use {@link Object#getClass()}, {@link Class#getName()}.
    */
+  @Deprecated
   public static String getTypeName(Object o) {
     return (o == null) ? null : o.getClass().getName();
   }
diff --git a/user/src/com/google/gwt/junit/client/impl/ExceptionWrapper.java b/user/src/com/google/gwt/junit/client/impl/ExceptionWrapper.java
index 1c010b9..0226bab 100644
--- a/user/src/com/google/gwt/junit/client/impl/ExceptionWrapper.java
+++ b/user/src/com/google/gwt/junit/client/impl/ExceptionWrapper.java
@@ -15,7 +15,6 @@
  */
 package com.google.gwt.junit.client.impl;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.IsSerializable;
 
 /**
@@ -56,7 +55,7 @@
    * @param e the {@link Throwable} to wrap.
    */
   public ExceptionWrapper(Throwable e) {
-    typeName = GWT.getTypeName(e);
+    typeName = e.getClass().getName();
     message = e.getMessage();
     stackTrace = StackTraceWrapper.wrapStackTrace(e.getStackTrace());
     Throwable ecause = e.getCause();
diff --git a/user/src/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamWriter.java b/user/src/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamWriter.java
index 5db85a1..345d3fa 100644
--- a/user/src/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamWriter.java
+++ b/user/src/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamWriter.java
@@ -15,7 +15,6 @@
  */
 package com.google.gwt.user.client.rpc.impl;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.user.client.rpc.SerializationException;
 
@@ -81,7 +80,7 @@
    * @param serializer the {@link Serializer} to use
    * @param moduleBaseURL the location of the module
    * @param serializationPolicyStrongName the strong name of serialization
-   *            policy
+   *          policy
    */
   public ClientSerializationStreamWriter(Serializer serializer,
       String moduleBaseURL, String serializationPolicyStrongName) {
@@ -148,7 +147,7 @@
 
   @Override
   protected String getObjectTypeSignature(Object o) {
-    String typeName = GWT.getTypeName(o);
+    String typeName = o.getClass().getName();
     String serializationSignature = serializer.getSerializationSignature(typeName);
     if (serializationSignature != null) {
       typeName += "/" + serializationSignature;
diff --git a/user/src/com/google/gwt/user/client/ui/Composite.java b/user/src/com/google/gwt/user/client/ui/Composite.java
index 6f672a1..1a7b893 100644
--- a/user/src/com/google/gwt/user/client/ui/Composite.java
+++ b/user/src/com/google/gwt/user/client/ui/Composite.java
@@ -15,7 +15,6 @@
  */
 package com.google.gwt.user.client.ui;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Element;
 
 /**
@@ -44,7 +43,7 @@
   public Element getElement() {
     if (widget == null) {
       throw new IllegalStateException("initWidget() was never called in "
-          + GWT.getTypeName(this));
+          + this.getClass().getName());
     }
     return super.getElement();
   }
diff --git a/user/src/com/google/gwt/user/client/ui/FastStringMap.java b/user/src/com/google/gwt/user/client/ui/FastStringMap.java
index 6e397a7..b2ad53c 100644
--- a/user/src/com/google/gwt/user/client/ui/FastStringMap.java
+++ b/user/src/com/google/gwt/user/client/ui/FastStringMap.java
@@ -16,7 +16,6 @@
 
 package com.google.gwt.user.client.ui;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.JavaScriptObject;
 
 import java.util.AbstractMap;
@@ -277,7 +276,7 @@
     if (key instanceof String) {
       return (String) key;
     } else {
-      throw new IllegalArgumentException(GWT.getTypeName(this)
+      throw new IllegalArgumentException(this.getClass().getName()
           + " can only have Strings as keys, not" + key);
     }
   }
diff --git a/user/src/com/google/gwt/user/client/ui/Widget.java b/user/src/com/google/gwt/user/client/ui/Widget.java
index 79d5b47..f8809c7 100644
--- a/user/src/com/google/gwt/user/client/ui/Widget.java
+++ b/user/src/com/google/gwt/user/client/ui/Widget.java
@@ -15,11 +15,10 @@
  */
 package com.google.gwt.user.client.ui;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.EventListener;
-import com.google.gwt.user.client.Element;
 
 /**
  * The base class for the majority of user-interface objects. Widget adds
@@ -228,7 +227,7 @@
     if (parent == null) {
       if (oldParent != null && oldParent.isAttached()) {
         onDetach();
-        assert !isAttached() : "Failure of " + GWT.getTypeName(this)
+        assert !isAttached() : "Failure of " + this.getClass().getName()
             + " to call super.onDetach()";
       }
       this.parent = null;
@@ -240,7 +239,7 @@
       this.parent = parent;
       if (parent.isAttached()) {
         onAttach();
-        assert isAttached() : "Failure of " + GWT.getTypeName(this)
+        assert isAttached() : "Failure of " + this.getClass().getName()
             + " to call super.onAttach()";
       }
     }
diff --git a/user/super/com/google/gwt/emul/java/lang/System.java b/user/super/com/google/gwt/emul/java/lang/System.java
index b88ac54..cc6a2e8 100644
--- a/user/super/com/google/gwt/emul/java/lang/System.java
+++ b/user/super/com/google/gwt/emul/java/lang/System.java
@@ -15,8 +15,6 @@
  */
 package java.lang;
 
-import com.google.gwt.core.client.GWT;
-
 import java.io.PrintStream;
 
 /**
@@ -38,12 +36,15 @@
    */
   public static final PrintStream out = new PrintStream(null);
 
-  public static void arraycopy(Object src, int srcOfs, Object dest, int destOfs, int len) {
+  public static void arraycopy(Object src, int srcOfs, Object dest,
+      int destOfs, int len) {
     if (src == null || dest == null) {
       throw new NullPointerException();
     }
-    String srcTypeName = GWT.getTypeName(src); 
-    String destTypeName = GWT.getTypeName(dest);
+    
+    // TODO: use Class objects when Class.getComponentType() is supported.
+    String srcTypeName = src.getClass().getName();
+    String destTypeName = dest.getClass().getName();
     if (srcTypeName.charAt(0) != '[' || destTypeName.charAt(0) != '[') {
       throw new ArrayStoreException("Must be array types");
     }
@@ -52,16 +53,17 @@
     }
     int srclen = getArrayLength(src);
     int destlen = getArrayLength(dest);
-    if (srcOfs < 0 || destOfs < 0 || len < 0 || srcOfs + len > srclen || destOfs + len > destlen) {
+    if (srcOfs < 0 || destOfs < 0 || len < 0 || srcOfs + len > srclen
+        || destOfs + len > destlen) {
       throw new IndexOutOfBoundsException();
     }
     /*
-     * If the arrays are not references or if they are exactly the same type,
-     * we can copy them in native code for speed.  Otherwise, we have to copy
-     * them in Java so we get appropriate errors.
-     */ 
-    if ((srcTypeName.charAt(1) == 'L' || srcTypeName.charAt(1) == '[') &&
-        !srcTypeName.equals(destTypeName)) {
+     * If the arrays are not references or if they are exactly the same type, we
+     * can copy them in native code for speed. Otherwise, we have to copy them
+     * in Java so we get appropriate errors.
+     */
+    if ((srcTypeName.charAt(1) == 'L' || srcTypeName.charAt(1) == '[')
+        && !srcTypeName.equals(destTypeName)) {
       // copy in Java to make sure we get ArrayStoreExceptions if the values
       // aren't compatible
       Object[] srcArray = (Object[]) src;
@@ -70,11 +72,11 @@
         // TODO(jat): how does backward copies handle failures in the middle?
         // copy backwards to avoid destructive copies
         srcOfs += len;
-        for (int destEnd = destOfs + len; destEnd-- > destOfs; ) {
+        for (int destEnd = destOfs + len; destEnd-- > destOfs;) {
           destArray[destEnd] = srcArray[--srcOfs];
         }
       } else {
-        for (int destEnd = destOfs + len; destOfs < destEnd; ) {
+        for (int destEnd = destOfs + len; destOfs < destEnd;) {
           destArray[destOfs++] = srcArray[srcOfs++];
         }
       }
diff --git a/user/super/com/google/gwt/emul/java/lang/Throwable.java b/user/super/com/google/gwt/emul/java/lang/Throwable.java
index 23649d4..6cfd85b 100644
--- a/user/super/com/google/gwt/emul/java/lang/Throwable.java
+++ b/user/super/com/google/gwt/emul/java/lang/Throwable.java
@@ -15,8 +15,6 @@
  */
 package java.lang;
 
-import com.google.gwt.core.client.GWT;
-
 import java.io.PrintStream;
 
 /**
@@ -126,7 +124,7 @@
 
   @Override
   public String toString() {
-    String className = GWT.getTypeName(this);
+    String className = this.getClass().getName();
     String msg = getMessage();
     if (msg != null) {
       return className + ": " + msg;
diff --git a/user/super/com/google/gwt/emul/java/util/Arrays.java b/user/super/com/google/gwt/emul/java/util/Arrays.java
index a4a19ee..29dd10f 100644
--- a/user/super/com/google/gwt/emul/java/util/Arrays.java
+++ b/user/super/com/google/gwt/emul/java/util/Arrays.java
@@ -16,7 +16,6 @@
 
 package java.util;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.lang.Array;
 
@@ -338,11 +337,17 @@
 
       Object obj1 = a1[i];
       Object obj2 = a2[i];
-      if (obj1 == obj2 || obj1.equals(obj2)) {
+      if (obj1 == obj2) {
         continue;
       }
-      String class1 = GWT.getTypeName(obj1);
-      String class2 = GWT.getTypeName(obj2);
+      if (obj1 == null || obj2 == null) {
+        return false;
+      }
+      if (obj1.equals(obj2)) {
+        continue;
+      }
+      String class1 = obj1.getClass().getName();
+      String class2 = obj2.getClass().getName();
 
       // We have to test and see if these are two arrays of the same type,
       // then see what types of arrays they are and dispatch to the
@@ -1087,9 +1092,9 @@
         b.append(", ");
       }
       Object obj = a[i];
-
-      if (GWT.getTypeName(obj).startsWith("[")) {
-
+      if (obj == null) {
+        b.append("null");
+      } else if (obj.getClass().getName().startsWith("[")) {
         if (obj instanceof Object[]) {
           if (arraysIveSeen.contains(obj)) {
             b.append("[...]");
@@ -1116,7 +1121,7 @@
           b.append(toString((double[]) obj));
         }
 
-        assert false : "Unexpected array type: " + GWT.getTypeName(obj);
+        assert false : "Unexpected array type: " + obj.getClass().getName();
       } else {
         b.append(String.valueOf(obj));
       }
diff --git a/user/super/com/google/gwt/junit/translatable/junit/framework/TestCase.java b/user/super/com/google/gwt/junit/translatable/junit/framework/TestCase.java
index c834da0..a27dac7 100644
--- a/user/super/com/google/gwt/junit/translatable/junit/framework/TestCase.java
+++ b/user/super/com/google/gwt/junit/translatable/junit/framework/TestCase.java
@@ -15,8 +15,6 @@
  */
 package junit.framework;
 
-import com.google.gwt.core.client.GWT;
-
 /**
  * Translatable version of JUnit's <code>TestCase</code>.
  */
@@ -50,7 +48,7 @@
   }
 
   public String toString() {
-    return getName() + "(" + GWT.getTypeName(this) + ")";
+    return getName() + "(" + this.getClass().getName() + ")";
   }
 
   /**
diff --git a/user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java b/user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java
index 517e382..b2adab6 100644
--- a/user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java
@@ -15,7 +15,6 @@
  */
 package com.google.gwt.dev.jjs.test;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.JavaScriptException;
 import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.junit.client.GWTTestCase;
@@ -115,8 +114,8 @@
       // thwart optimizer
       Object f1 = noOptimizeFalse() ? (Object) new PolyA()
           : (Object) new IFoo[1];
-      assertTrue(GWT.getTypeName(f1).equals(
-          "[Lcom.google.gwt.dev.jjs.test.MiscellaneousTest$IFoo;"));
+      assertEquals("[Lcom.google.gwt.dev.jjs.test.MiscellaneousTest$IFoo;",
+          f1.getClass().getName());
       assertFalse(f1 instanceof PolyA[][]);
       assertFalse(f1 instanceof IFoo[][]);
       assertFalse(f1 instanceof PolyA[]);
@@ -137,7 +136,7 @@
       Object a1 = noOptimizeFalse() ? (Object) new PolyA()
           : (Object) new PolyA[1];
       assertEquals("[Lcom.google.gwt.dev.jjs.test.MiscellaneousTest$PolyA;",
-          GWT.getTypeName(a1));
+          a1.getClass().getName());
       assertFalse(a1 instanceof PolyA[][]);
       assertFalse(a1 instanceof IFoo[][]);
       assertTrue(a1 instanceof PolyA[]);
@@ -157,7 +156,7 @@
       Object f2 = noOptimizeFalse() ? (Object) new PolyA()
           : (Object) new IFoo[1][];
       assertEquals("[[Lcom.google.gwt.dev.jjs.test.MiscellaneousTest$IFoo;",
-          GWT.getTypeName(f2));
+          f2.getClass().getName());
       assertFalse(f2 instanceof PolyA[][]);
       assertTrue(f2 instanceof IFoo[][]);
       assertFalse(f2 instanceof PolyA[]);
@@ -177,7 +176,7 @@
       Object a2 = noOptimizeFalse() ? (Object) new PolyA()
           : (Object) new PolyA[1][];
       assertEquals("[[Lcom.google.gwt.dev.jjs.test.MiscellaneousTest$PolyA;",
-          GWT.getTypeName(a2));
+          a2.getClass().getName());
       assertTrue(a2 instanceof PolyA[][]);
       assertTrue(a2 instanceof IFoo[][]);
       assertFalse(a2 instanceof PolyA[]);
@@ -195,14 +194,14 @@
 
   public void testArrays() {
     int[] c = new int[] {1, 2};
-    assertEquals("[I", GWT.getTypeName(c));
+    assertEquals("[I", c.getClass().getName());
     int[][] d = new int[][] { {1, 2}, {3, 4}};
-    assertEquals("[[I", GWT.getTypeName(d));
-    assertEquals("[I", GWT.getTypeName(d[1]));
+    assertEquals("[[I", d.getClass().getName());
+    assertEquals("[I", d[1].getClass().getName());
     int[][][] e = new int[][][] { { {1, 2}, {3, 4}}, { {5, 6}, {7, 8}}};
-    assertEquals("[[[I", GWT.getTypeName(e));
-    assertEquals("[[I", GWT.getTypeName(e[1]));
-    assertEquals("[I", GWT.getTypeName(e[1][1]));
+    assertEquals("[[[I", e.getClass().getName());
+    assertEquals("[[I", e[1].getClass().getName());
+    assertEquals("[I", e[1][1].getClass().getName());
     assertEquals(2, c[1]);
     assertEquals(3, d[1][0]);
     assertEquals(8, e[1][1][1]);
diff --git a/user/test/com/google/gwt/user/client/rpc/CollectionsTest.java b/user/test/com/google/gwt/user/client/rpc/CollectionsTest.java
index 94d5518..441045d 100644
--- a/user/test/com/google/gwt/user/client/rpc/CollectionsTest.java
+++ b/user/test/com/google/gwt/user/client/rpc/CollectionsTest.java
@@ -196,7 +196,7 @@
 
     service.getArraysAsList(expected, new AsyncCallback() {
       public void onFailure(Throwable caught) {
-        assertTrue(GWT.getTypeName(caught)
+        assertTrue(caught.getClass().getName()
             + " should have been an InvocationException",
             caught instanceof InvocationException);
         finishTest();
diff --git a/user/test/org/apache/commons/collections/LocalTestNode.java b/user/test/org/apache/commons/collections/LocalTestNode.java
index 48df84f..64e22d8 100644
--- a/user/test/org/apache/commons/collections/LocalTestNode.java
+++ b/user/test/org/apache/commons/collections/LocalTestNode.java
@@ -15,10 +15,6 @@
  */
 package org.apache.commons.collections;
 
-import com.google.gwt.core.client.GWT;
-
-
-
 /**
 * Class LocalTestNode
 *
@@ -102,8 +98,8 @@
         }
 
          
-        if(!(GWT.getTypeName(o).equals(GWT.getTypeName(o)))){
-        	return false;
+        if(!(getClass().getName().equals(o.getClass().getName()))){
+            return false;
         }
         LocalTestNode node = (LocalTestNode) o;
 
diff --git a/user/test/org/apache/commons/collections/TestComparator.java b/user/test/org/apache/commons/collections/TestComparator.java
index 30068dc..488dd6a 100644
--- a/user/test/org/apache/commons/collections/TestComparator.java
+++ b/user/test/org/apache/commons/collections/TestComparator.java
@@ -15,8 +15,6 @@
  */
 package org.apache.commons.collections;
 
-import com.google.gwt.core.client.GWT;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -98,7 +96,7 @@
     public String getCanonicalComparatorName(Object object) {
         StringBuffer retval = new StringBuffer();
         retval.append("data/test/");
-        String colName = GWT.getTypeName(object);
+        String colName = object.getClass().getName();
         colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
         retval.append(colName);
         retval.append(".version");
diff --git a/user/test/org/apache/commons/collections/TestObject.java b/user/test/org/apache/commons/collections/TestObject.java
index b45c78a..a66cce2 100644
--- a/user/test/org/apache/commons/collections/TestObject.java
+++ b/user/test/org/apache/commons/collections/TestObject.java
@@ -15,7 +15,6 @@
  */
 package org.apache.commons.collections;
   
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.emultest.java.util.EmulTestBase;
 
 /**
@@ -85,7 +84,7 @@
     public String getCanonicalEmptyCollectionName(Object object) {
         StringBuffer retval = new StringBuffer();
         retval.append("data/test/");
-        String colName = GWT.getTypeName(object);
+        String colName = object.getClass().getName();
         
         colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
         retval.append(colName);
@@ -98,7 +97,7 @@
     public String getCanonicalFullCollectionName(Object object) {
         StringBuffer retval = new StringBuffer();
         retval.append("data/test/");
-        String colName = GWT.getTypeName(object);
+        String colName = object.getClass().getName();
         colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
         retval.append(colName);
         retval.append(".fullCollection.version");