Removes JsMethod for boxed type factory methods.

Change-Id: Ida57c587efcecf5dde8993b3df75c020ec83a560
Review-Link: https://gwt-review.googlesource.com/#/c/15061/
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/RewriteConstructorCallsForUnboxedTypes.java b/dev/core/src/com/google/gwt/dev/jjs/impl/RewriteConstructorCallsForUnboxedTypes.java
index 4717a41..b9a9a72 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/RewriteConstructorCallsForUnboxedTypes.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/RewriteConstructorCallsForUnboxedTypes.java
@@ -40,14 +40,16 @@
 
   public static final String NATIVE_TYPE_CREATEMETHOD_PREFIX = "$create";
   private JProgram program;
-  private Map<String, JMethod> jsniSig2Method = new HashMap<>();
+  private Map<JDeclaredType, Map<String, JMethod>> createMethodsByType = new HashMap<>();
 
   public RewriteConstructorCallsForUnboxedTypes(JProgram program) {
     this.program = program;
     for (JDeclaredType unboxedType : program.getRepresentedAsNativeTypes()) {
+      HashMap<String, JMethod> createMethods = new HashMap<>();
+      createMethodsByType.put(unboxedType, createMethods);
       for (JMethod method : unboxedType.getMethods()) {
         if (method.getName().startsWith(NATIVE_TYPE_CREATEMETHOD_PREFIX)) {
-          jsniSig2Method.put(method.getJsniSignature(false, false), method);
+          createMethods.put(method.getOriginalParamTypes().toString(), method);
         }
       }
     }
@@ -55,16 +57,17 @@
 
   @Override
   public void endVisit(JNewInstance x, Context ctx) {
-    JMethod createMethod;
     JConstructor ctor = x.getTarget();
 
     if (!program.isRepresentedAsNativeJsPrimitive(ctor.getEnclosingType())) {
       return;
     }
 
-    // map BoxedType(args) -> BoxedType.$createBoxedType(args)
-    createMethod = jsniSig2Method.get(NATIVE_TYPE_CREATEMETHOD_PREFIX
-        + ctor.getJsniSignature(false, false));
+    // map BoxedType(args) -> BoxedType.$create(args)
+    JMethod createMethod =
+        createMethodsByType
+            .get(ctor.getEnclosingType())
+            .get(ctor.getOriginalParamTypes().toString());
     assert createMethod != null;
 
     JMethodCall createCall = new JMethodCall(x.getSourceInfo(), null, createMethod);
@@ -77,9 +80,11 @@
     if (x.getTarget().isConstructor()
         && program.isRepresentedAsNativeJsPrimitive(x.getTarget().getEnclosingType())) {
       JConstructor ctor = (JConstructor) x.getTarget();
-      // map BoxedType(args) -> BoxedType.$createBoxedType(args)
-      JMethod createMethod = jsniSig2Method.get(NATIVE_TYPE_CREATEMETHOD_PREFIX
-          + ctor.getJsniSignature(false, false));
+      // map BoxedType(args) -> BoxedType.$createType(args)
+      JMethod createMethod =
+          createMethodsByType
+              .get(ctor.getEnclosingType())
+              .get(ctor.getOriginalParamTypes().toString());
       assert createMethod != null;
 
       JsniMethodRef newJsniMethodRef = new JsniMethodRef(x.getSourceInfo(),
diff --git a/user/super/com/google/gwt/emul/java/lang/Boolean.java b/user/super/com/google/gwt/emul/java/lang/Boolean.java
index 2b72e54..ec3e351 100644
--- a/user/super/com/google/gwt/emul/java/lang/Boolean.java
+++ b/user/super/com/google/gwt/emul/java/lang/Boolean.java
@@ -63,7 +63,7 @@
   }
 
   public static Boolean valueOf(boolean b) {
-    return b ? $createBoolean(true) : $createBoolean(false);
+    return b ? $create(true) : $create(false);
   }
 
   public static Boolean valueOf(String s) {
@@ -72,20 +72,20 @@
 
   public Boolean(boolean value) {
     /*
-     * Call to $createBoolean(value) must be here so that the method is referenced and not pruned
-     * before new Boolean(value) is replaced by $createBoolean(value) by
+     * Call to $create(value) must be here so that the method is referenced and not pruned
+     * before new Boolean(value) is replaced by $create(value) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createBoolean(value);
+    $create(value);
   }
 
   public Boolean(String s) {
      /*
-     * Call to $createBoolean(value) must be here so that the method is referenced and not pruned
-     * before new Boolean(value) is replaced by $createBoolean(value) by
+     * Call to $create(value) must be here so that the method is referenced and not pruned
+     * before new Boolean(value) is replaced by $create(value) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createBoolean(s);
+    $create(s);
   }
 
   public boolean booleanValue() {
@@ -113,13 +113,11 @@
   }
 
   // CHECKSTYLE_OFF: Utility Methods for unboxed Boolean.
-  @JsMethod(name = "$create__boolean")
-  private static Boolean $createBoolean(boolean x) {
+  protected static Boolean $create(boolean x) {
     return createNative(x);
   }
 
-  @JsMethod(name = "$create__java_lang_String")
-  private static Boolean $createBoolean(String x) {
+  protected static Boolean $create(String x) {
     return createNative(Boolean.parseBoolean(x));
   }
 
@@ -128,7 +126,7 @@
   }-*/;
 
   @JsMethod
-  private static boolean $isInstance(Object instance) {
+  protected static boolean $isInstance(Object instance) {
     return "boolean".equals(JsUtils.typeOf(instance));
   }
   //CHECKSTYLE_ON: End utility methods
diff --git a/user/super/com/google/gwt/emul/java/lang/Double.java b/user/super/com/google/gwt/emul/java/lang/Double.java
index c2b05ca..173a63c 100644
--- a/user/super/com/google/gwt/emul/java/lang/Double.java
+++ b/user/super/com/google/gwt/emul/java/lang/Double.java
@@ -295,20 +295,20 @@
 
   public Double(double value) {
     /*
-     * Call to $createDouble(value) must be here so that the method is referenced and not
-     * pruned before new Double(value) is replaced by $createDouble(value) by
+     * Call to $create(value) must be here so that the method is referenced and not
+     * pruned before new Double(value) is replaced by $create(value) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createDouble(value);
+    $create(value);
   }
 
   public Double(String s) {
     /*
-     * Call to $createDouble(value) must be here so that the method is referenced and not
-     * pruned before new Double(value) is replaced by $createDouble(value) by
+     * Call to $create(value) must be here so that the method is referenced and not
+     * pruned before new Double(value) is replaced by $create(value) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createDouble(s);
+    $create(s);
   }
 
   @Override
@@ -379,13 +379,11 @@
   }
 
   // CHECKSTYLE_OFF: Utility Methods for unboxed Double.
-  @JsMethod(name = "$create__double")
-  private static Double $createDouble(double x) {
+  protected static Double $create(double x) {
     return createNative(x);
   }
 
-  @JsMethod(name = "$create__java_lang_String")
-  private static Double $createDouble(String s) {
+  protected static Double $create(String s) {
     return createNative(Double.parseDouble(s));
   }
 
@@ -394,7 +392,7 @@
   }-*/;
 
   @JsMethod
-  private static boolean $isInstance(Object instance) {
+  protected static boolean $isInstance(Object instance) {
     return "number".equals(JsUtils.typeOf(instance));
   }
   //CHECKSTYLE_ON: End utility methods
diff --git a/user/super/com/google/gwt/emul/java/lang/String.java b/user/super/com/google/gwt/emul/java/lang/String.java
index 6421e68..5a0cce1 100644
--- a/user/super/com/google/gwt/emul/java/lang/String.java
+++ b/user/super/com/google/gwt/emul/java/lang/String.java
@@ -238,122 +238,122 @@
 
   public String() {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString();
+    $create();
   }
 
   public String(byte[] bytes) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(bytes);
+    $create(bytes);
   }
 
   public String(byte[] bytes, int ofs, int len) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(bytes, ofs, len);
+    $create(bytes, ofs, len);
   }
 
   public String(byte[] bytes, int ofs, int len, String charsetName)
       throws UnsupportedEncodingException {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(bytes, ofs, len, charsetName);
+    $create(bytes, ofs, len, charsetName);
   }
 
   public String(byte[] bytes, int ofs, int len, Charset charset) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(bytes, ofs, len, charset);
+    $create(bytes, ofs, len, charset);
   }
 
   public String(byte[] bytes, String charsetName)
       throws UnsupportedEncodingException {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(bytes, charsetName);
+    $create(bytes, charsetName);
   }
 
   public String(byte[] bytes, Charset charset)
       throws UnsupportedEncodingException {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(bytes, charset);
+    $create(bytes, charset);
   }
 
   public String(char value[]) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(value);
+    $create(value);
   }
 
   public String(char value[], int offset, int count) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(value, offset, count);
+    $create(value, offset, count);
   }
 
   public String(int codePoints[], int offset, int count) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(codePoints, offset, count);
+    $create(codePoints, offset, count);
   }
 
   public String(String other) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(other);
+    $create(other);
   }
 
   public String(StringBuffer sb) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(sb);
+    $create(sb);
   }
 
   public String(StringBuilder sb) {
     /*
-     * Call to $createString(args) must be here so that the method is referenced and not
-     * pruned before new String(args) is replaced by $createString(args) by
+     * Call to $create(args) must be here so that the method is referenced and not
+     * pruned before new String(args) is replaced by $create(args) by
      * RewriteConstructorCallsForUnboxedTypes.
      */
-    $createString(sb);
+    $create(sb);
   }
 
   private NativeString asNativeString() {
@@ -786,56 +786,46 @@
 
   // CHECKSTYLE_OFF: Utility Methods for unboxed String.
 
-  @JsMethod(name = "$create")
-  private static String $createString() {
+  protected static String $create() {
     return "";
   }
 
-  @JsMethod(name = "$create__arrayOf_byte")
-  private static String $createString(byte[] bytes) {
-    return $createString(bytes, 0, bytes.length);
+  protected static String $create(byte[] bytes) {
+    return $create(bytes, 0, bytes.length);
   }
 
-  @JsMethod(name = "$create__arrayOf_byte__int__int")
-  private static String $createString(byte[] bytes, int ofs, int len) {
-    return $createString(bytes, ofs, len, EmulatedCharset.UTF_8);
+  protected static String $create(byte[] bytes, int ofs, int len) {
+    return $create(bytes, ofs, len, EmulatedCharset.UTF_8);
   }
 
-  @JsMethod(name = "$create__arrayOf_byte__int__int__java_lang_String")
-  private static String $createString(byte[] bytes, int ofs, int len, String charsetName)
+  protected static String $create(byte[] bytes, int ofs, int len, String charsetName)
       throws UnsupportedEncodingException {
-    return $createString(bytes, ofs, len, String.getCharset(charsetName));
+    return $create(bytes, ofs, len, String.getCharset(charsetName));
   }
 
-  @JsMethod(name = "$create__arrayOf_byte__int__int__java_nio_charset_Charset")
-  private static String $createString(byte[] bytes, int ofs, int len, Charset charset) {
+  protected static String $create(byte[] bytes, int ofs, int len, Charset charset) {
     return String.valueOf(((EmulatedCharset) charset).decodeString(bytes, ofs, len));
   }
 
-  @JsMethod(name = "$create__arrayOf_byte__java_lang_String")
-  private static String $createString(byte[] bytes, String charsetName)
+  protected static String $create(byte[] bytes, String charsetName)
       throws UnsupportedEncodingException {
-    return $createString(bytes, 0, bytes.length, charsetName);
+    return $create(bytes, 0, bytes.length, charsetName);
   }
 
-  @JsMethod(name = "$create__arrayOf_byte__java_nio_charset_Charset")
-  private static String $createString(byte[] bytes, Charset charset)
+  protected static String $create(byte[] bytes, Charset charset)
       throws UnsupportedEncodingException {
-    return $createString(bytes, 0, bytes.length, charset.name());
+    return $create(bytes, 0, bytes.length, charset.name());
   }
 
-  @JsMethod(name = "$create__arrayOf_char")
-  private static String $createString(char value[]) {
+  protected static String $create(char value[]) {
     return String.valueOf(value);
   }
 
-  @JsMethod(name = "$create__arrayOf_char__int__int")
-  private static String $createString(char value[], int offset, int count) {
+  protected static String $create(char value[], int offset, int count) {
     return String.valueOf(value, offset, count);
   }
 
-  @JsMethod(name = "$create__arrayOf_int__int__int")
-  private static String $createString(int[] codePoints, int offset, int count) {
+  protected static String $create(int[] codePoints, int offset, int count) {
     char[] chars = new char[count * 2];
     int charIdx = 0;
     while (count-- > 0) {
@@ -844,23 +834,20 @@
     return String.valueOf(chars, 0, charIdx);
   }
 
-  @JsMethod(name = "$create__java_lang_String")
-  private static String $createString(String other) {
+  protected static String $create(String other) {
     return other;
   }
 
-  @JsMethod(name = "$create__java_lang_StringBuffer")
-  private static String $createString(StringBuffer sb) {
+  protected static String $create(StringBuffer sb) {
     return String.valueOf(sb);
   }
 
-  @JsMethod(name = "$create__java_lang_StringBuilder")
-  private static String $createString(StringBuilder sb) {
+  protected static String $create(StringBuilder sb) {
     return String.valueOf(sb);
   }
 
   @JsMethod
-  private static boolean $isInstance(Object instance) {
+  protected static boolean $isInstance(Object instance) {
     return "string".equals(JsUtils.typeOf(instance));
   }
   // CHECKSTYLE_ON: end utility methods