Skip to content

Commit f4d1cc8

Browse files
committed
Partial fix for testIssue708_1 - better dom tree support for switch / yield
Signed-off-by: Rob Stryker <[email protected]> Fix regressions Signed-off-by: Rob Stryker <[email protected]>
1 parent a91c176 commit f4d1cc8

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5513,4 +5513,63 @@ public void acceptBinding(String bindingKey, IBinding binding) {
55135513
parser.createASTs(new ICompilationUnit[] {this.workingCopy}, new String[0], requestor, null);
55145514
}
55155515

5516+
// j19
5517+
public void testIssue708_1() throws JavaModelException {
5518+
String contents = "public class Test1 {\n"
5519+
+ " public void test(Type type, String string) {\n"
5520+
+ " switch (type) {\n"
5521+
+ " case openDeclarationFails -> {\n"
5522+
+ " switch (string) {\n"
5523+
+ " case \"Test\" -> method(Type.openDeclarationFails);\n"
5524+
+ " }\n"
5525+
+ " method(Type.openDeclarationFails);\n"
5526+
+ " }\n"
5527+
+ " case anotherValue -> {\n"
5528+
+ " switch (string) {\n"
5529+
+ " case \"Test\" -> method(Type.anotherValue);\n"
5530+
+ " }\n"
5531+
+ " }\n"
5532+
+ " }\n"
5533+
+ " }\n"
5534+
+ " private void method(Type relay) {}\n"
5535+
+ " static public enum Type {\n"
5536+
+ " openDeclarationFails, anotherValue;\n"
5537+
+ " }\n"
5538+
+ "}";
5539+
5540+
this.workingCopy = getWorkingCopy("/Converter22/src/xyz/X.java", true/*resolve*/);
5541+
CompilationUnit cu = (CompilationUnit) buildAST(AST_INTERNAL_JLS20,
5542+
contents, this.workingCopy, false, false, false);
5543+
5544+
TypeDeclaration td = (TypeDeclaration)cu.types().get(0);
5545+
MethodDeclaration testMethod = td.getMethods()[0];
5546+
Block blok = testMethod.getBody();
5547+
SwitchStatement ss = (SwitchStatement)blok.statements().get(0);
5548+
assertEquals("type", ss.getExpression().toString());
5549+
assertEquals(4, ss.statements().size());
5550+
assertTrue(ss.statements().get(0) instanceof SwitchCase);
5551+
assertTrue(ss.statements().get(1) instanceof Block);
5552+
assertTrue(ss.statements().get(2) instanceof SwitchCase);
5553+
assertTrue(ss.statements().get(3) instanceof Block);
5554+
5555+
Block b1 = (Block)ss.statements().get(1);
5556+
List b1State = b1.statements();
5557+
assertEquals(2, b1State.size());
5558+
assertTrue(b1State.get(0) instanceof SwitchStatement);
5559+
assertTrue(b1State.get(1) instanceof ExpressionStatement);
5560+
5561+
List b1State1Statements = ((SwitchStatement)b1State.get(0)).statements();
5562+
assertEquals(2, b1State1Statements.size());
5563+
assertTrue(b1State1Statements.get(0) instanceof SwitchCase);
5564+
assertTrue(b1State1Statements.get(1) instanceof YieldStatement);
5565+
5566+
Block b2 = (Block)ss.statements().get(3);
5567+
List b2State = b2.statements();
5568+
assertEquals(1, b2State.size());
5569+
assertTrue(b2State.get(0) instanceof SwitchStatement);
5570+
List b2State1Statements = ((SwitchStatement)b2State.get(0)).statements();
5571+
assertEquals(2, b2State1Statements.size());
5572+
assertTrue(b2State1Statements.get(0) instanceof SwitchCase);
5573+
assertTrue(b2State1Statements.get(1) instanceof YieldStatement);
5574+
}
55165575
}

0 commit comments

Comments
 (0)