Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java55
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java5
2 files changed, 56 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
index 06e2f88eb3..95b826c859 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
@@ -2299,4 +2299,57 @@ public class SwitchPatternTest extends AbstractRegressionTest9 {
},
"Hello World!");
}
-}
+ public void testBug574614_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Long.valueOf(10));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " String s1 = \" Hello \";\n"+
+ " String s2 = \"World!\";\n"+
+ " switch (o) {\n"+
+ " case Integer I && I > 10: break;\n"+
+ " case X J: break;\n"+
+ " case String s : break;\n"+
+ " default:\n"+
+ " s1 = new StringBuilder(String.valueOf(s1)).append(String.valueOf(s2)).toString();\n"+
+ " System.out.println(s1);\n"+
+ " break; \n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello World!");
+ }
+ public void testBug574614_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Long.valueOf(0));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I:\n"+
+ " break;\n"+
+ " case String s :\n"+
+ " break;\n"+
+ " case X J:\n"+
+ " break;\n"+
+ " default:\n"+
+ " String s1 = \"Hello \";\n"+
+ " String s2 = \"World!\";\n"+
+ " s1 = s1 +s2; \n"+
+ " System.out.println(s1);\n"+
+ " break;\n"+
+ " }\n"+
+ " } \n"+
+ "}",
+ },
+ "Hello World!");
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
index c404d45188..690deb3ba9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
@@ -657,10 +657,9 @@ public class SwitchStatement extends Expression {
codeStream.load(this.dispatchPatternCopy);
codeStream.load(this.restartIndexLocal);
int invokeDynamicNumber = codeStream.classFile.recordBootstrapMethod(this);
- //TODO: replace this POC code with properly defined constants
codeStream.invokeDynamic(invokeDynamicNumber,
- this.caseLabelElements.size(),
- 1,
+ 2, // Object, restartIndex
+ 1, // int
"typeSwitch".toCharArray(), //$NON-NLS-1$
"(Ljava/lang/Object;I)I".toCharArray(), //$NON-NLS-1$
TypeIds.T_int,

Back to the top