Revision: 7540
Author: [email protected]
Date: Tue Feb 9 18:20:49 2010
Log: Merged in Lex's fix for switch(enum) [not yet mirrored to trunk]
http://code.google.com/p/google-web-toolkit/source/detail?r=7540
Modified:
/branches/snapshot-2010.01.05-r7362/branch-info.txt
/branches/snapshot-2010.01.05-r7362/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
/branches/snapshot-2010.01.05-r7362/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
=======================================
--- /branches/snapshot-2010.01.05-r7362/branch-info.txt Tue Jan 12 14:33:11
2010
+++ /branches/snapshot-2010.01.05-r7362/branch-info.txt Tue Feb 9 18:20:49
2010
@@ -14,3 +14,5 @@
svn merge --ignore-ancestry -c7385 \
https://google-web-toolkit.googlecode.com/svn/trunk
+
+Merged Lex's fix for switch(enum) (not yet mirrored to trunk)
=======================================
---
/branches/snapshot-2010.01.05-r7362/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
Wed Dec 9 09:10:40 2009
+++
/branches/snapshot-2010.01.05-r7362/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
Tue Feb 9 18:20:49 2010
@@ -1756,7 +1756,7 @@
JStatement processStatement(SwitchStatement x) {
SourceInfo info = makeSourceInfo(x);
JExpression expression = dispProcessExpression(x.expression);
- if (expression.getType() instanceof JClassType) {
+ if (isEnumType(expression.getType())) {
// Must be an enum; synthesize a call to ordinal().
expression = new JMethodCall(info, expression,
program.getIndexedMethod("Enum.ordinal"));
@@ -2380,6 +2380,24 @@
"Could not determine the desired box type");
}
}
+
+ /**
+ * Check whether the specified type is definitely for an enum class.
+ *
+ * @param type The type being tested
+ * @return whether it is certainly an enum
+ */
+ private boolean isEnumType(JType type) {
+ if (type instanceof JClassType) {
+ return ((JClassType) type).isEnumOrSubclass() != null;
+ }
+
+ if (type instanceof JNonNullType) {
+ return isEnumType(((JNonNullType) type).getUnderlyingType());
+ }
+
+ return false;
+ }
private SourceInfo makeSourceInfo(Statement x) {
int startLine = Util.getLineNumber(x.sourceStart,
=======================================
---
/branches/snapshot-2010.01.05-r7362/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
Mon Jun 15 17:51:24 2009
+++
/branches/snapshot-2010.01.05-r7362/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
Tue Feb 9 18:20:49 2010
@@ -66,6 +66,25 @@
private interface Bm2Listener<E extends Bm2BaseEvent> extends
EventListener {
int handleEvent(E be);
}
+
+ /**
+ * Used in {...@link #testSwitchOnEnumTypedThis()}.
+ */
+ private static enum ChangeDirection {
+ NEGATIVE, POSITIVE;
+
+ public String getText() {
+ switch (this) {
+ case POSITIVE:
+ return "POSITIVE";
+ case NEGATIVE:
+ return "NEGATIVE";
+ default:
+ throw new IllegalArgumentException("Unhandled change direction: "
+ + this);
+ }
+ }
+ }
private static class ConcreteSub extends AbstractSuper {
public static String foo() {
@@ -1065,7 +1084,12 @@
public void testSubclassStaticInnerAndClinitOrdering() {
new CheckSubclassStaticInnerAndClinitOrdering();
}
-
+
+ public void testSwitchOnEnumTypedThis() {
+ assertEquals("POSITIVE", ChangeDirection.POSITIVE.getText());
+ assertEquals("NEGATIVE", ChangeDirection.NEGATIVE.getText());
+ }
+
public void testSwitchStatement() {
switch (0) {
case 0:
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors