Revision: 9115
Author: [email protected]
Date: Mon Oct 18 12:52:42 2010
Log: Fix for resolving overloaded enum valueOf method
Review at http://gwt-code-reviews.appspot.com/1024801
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9115
Modified:
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
/trunk/user/test/com/google/gwt/dev/jjs/test/EnumsTest.java
/trunk/user/test/com/google/gwt/dev/jjs/test/EnumsWithNameObfuscationTest.java
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java Mon
Jun 14 14:39:55 2010
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java Mon
Oct 18 12:52:42 2010
@@ -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;
=======================================
--- /trunk/user/test/com/google/gwt/dev/jjs/test/EnumsTest.java Fri May 28
09:34:24 2010
+++ /trunk/user/test/com/google/gwt/dev/jjs/test/EnumsTest.java Mon Oct 18
12:52:42 2010
@@ -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();
=======================================
---
/trunk/user/test/com/google/gwt/dev/jjs/test/EnumsWithNameObfuscationTest.java
Tue Oct 5 11:03:13 2010
+++
/trunk/user/test/com/google/gwt/dev/jjs/test/EnumsWithNameObfuscationTest.java
Mon Oct 18 12:52:42 2010
@@ -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;
@@ -181,6 +182,14 @@
} catch (NullPointerException expected) {
}
}
+
+ @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();
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors