Reviewers: scottb,

Description:
Fix for resolving overloaded enum valueOf method


Please review this at http://gwt-code-reviews.appspot.com/1024801/show

Affected files:
  M dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
  M user/test/com/google/gwt/dev/jjs/test/EnumsTest.java


Index: dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
===================================================================
--- dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java (revision 9091) +++ dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java (working copy)
@@ -101,9 +101,9 @@
               continue;
             }
             valuesMethod = methodIt;
-          }
-          if ("valueOf".equals(methodIt.getName())) {
-            if (methodIt.getParams().size() != 1) {
+          } else if ("valueOf".equals(methodIt.getName())) {
+            if (methodIt.getParams().size() != 1 ||
+ methodIt.getParams().get(0).getType() != program.getTypeJavaLangString()) {
               continue;
             }
             valueOfMethod = methodIt;
Index: user/test/com/google/gwt/dev/jjs/test/EnumsTest.java
===================================================================
--- user/test/com/google/gwt/dev/jjs/test/EnumsTest.java        (revision 9091)
+++ user/test/com/google/gwt/dev/jjs/test/EnumsTest.java        (working copy)
@@ -63,6 +63,25 @@

     public abstract String value();
   }
+
+  enum BasicWithOverloadedValueOf {
+    A(1), B(2), C(3);
+
+    private final int id;
+
+    private BasicWithOverloadedValueOf(int id) {
+      this.id = id;
+    }
+
+    public static BasicWithOverloadedValueOf valueOf(Integer id) {
+ for (BasicWithOverloadedValueOf val : BasicWithOverloadedValueOf.values()) {
+        if (val.id == id) {
+          return val;
+        }
+      }
+      throw new IllegalArgumentException();
+    }
+  }

   public String getModuleName() {
     return "com.google.gwt.dev.jjs.CompilerSuite";
@@ -234,6 +253,15 @@
     } catch (NullPointerException e) {
     }
   }
+
+  public void testValueOfOverload() {
+ BasicWithOverloadedValueOf val1 = Enum.valueOf(BasicWithOverloadedValueOf.class,"A"); + BasicWithOverloadedValueOf val2 = BasicWithOverloadedValueOf.valueOf("B"); + BasicWithOverloadedValueOf valById1 = BasicWithOverloadedValueOf.valueOf(1); + BasicWithOverloadedValueOf valById2 = BasicWithOverloadedValueOf.valueOf(2);
+    assertEquals(val1, valById1);
+    assertEquals(val2, valById2);
+  }

   public void testValues() {
     Basic[] simples = Basic.values();


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

Reply via email to