Fix for resolving overloaded enum valueOf method
Review at http://gwt-code-reviews.appspot.com/1024801
Review by: scottb@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9115 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
index a3ff614..8e3305a 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
@@ -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;
diff --git a/user/test/com/google/gwt/dev/jjs/test/EnumsTest.java b/user/test/com/google/gwt/dev/jjs/test/EnumsTest.java
index 13eb765..5eda6ce 100644
--- a/user/test/com/google/gwt/dev/jjs/test/EnumsTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/EnumsTest.java
@@ -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();
diff --git a/user/test/com/google/gwt/dev/jjs/test/EnumsWithNameObfuscationTest.java b/user/test/com/google/gwt/dev/jjs/test/EnumsWithNameObfuscationTest.java
index d669efc..936e0b5 100644
--- a/user/test/com/google/gwt/dev/jjs/test/EnumsWithNameObfuscationTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/EnumsWithNameObfuscationTest.java
@@ -16,6 +16,7 @@
package com.google.gwt.dev.jjs.test;
import com.google.gwt.core.client.JavaScriptException;
+import com.google.gwt.dev.jjs.test.EnumsTest.BasicWithOverloadedValueOf;
import com.google.gwt.junit.DoNotRunWith;
import com.google.gwt.junit.Platform;
@@ -182,6 +183,14 @@
}
}
+ @Override
+ public void testValueOfOverload() {
+ BasicWithOverloadedValueOf valById1 = BasicWithOverloadedValueOf.valueOf(1);
+ BasicWithOverloadedValueOf valById2 = BasicWithOverloadedValueOf.valueOf(2);
+ assertEquals(valById1.ordinal(),0);
+ assertEquals(valById2.ordinal(),1);
+ }
+
private <T extends Enum<T>> void enumValuesTest(Class<T> enumClass) {
T[] constants = enumClass.getEnumConstants();
for (T constant : constants) {