Add additional tests
* Parse problem with switch fallthrough * Verify type of switch expression
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
public class ASTSwitchExpression extends AbstractJavaNode {
|
||||
public class ASTSwitchExpression extends AbstractJavaTypeNode {
|
||||
ASTSwitchExpression(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
@ -85,6 +85,8 @@ public class Java12Test {
|
||||
Assert.assertEquals(6, switchExpression.jjtGetNumChildren());
|
||||
Assert.assertTrue(switchExpression.jjtGetChild(0) instanceof ASTExpression);
|
||||
Assert.assertEquals(5, switchExpression.findChildrenOfType(ASTSwitchLabeledRule.class).size());
|
||||
|
||||
Assert.assertEquals(Integer.TYPE, switchExpression.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -274,6 +274,14 @@ public class ParserCornersTest {
|
||||
Assert.assertTrue("Test setup wrong - variable 'someVarNameSameAsMethodReference' not found anymore!", foundVariable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchWithFallthrough() throws Exception {
|
||||
ASTCompilationUnit compilationUnit = ParserTstUtil.parseAndTypeResolveJava("11", readAsString("SwitchWithFallthrough.java"));
|
||||
Assert.assertNotNull(compilationUnit);
|
||||
ASTSwitchStatement switchStatement = compilationUnit.getFirstDescendantOfType(ASTSwitchStatement.class);
|
||||
Assert.assertEquals(2, switchStatement.findChildrenOfType(ASTSwitchLabel.class).size());
|
||||
}
|
||||
|
||||
private String readAsString(String resource) {
|
||||
try (InputStream in = ParserCornersTest.class.getResourceAsStream(resource)) {
|
||||
return IOUtils.toString(in, StandardCharsets.UTF_8);
|
||||
|
@ -0,0 +1,11 @@
|
||||
public class SwitchWithFallthrough {
|
||||
|
||||
// only fall through, no block statements.
|
||||
public void myMethod() {
|
||||
int a = 1;
|
||||
switch (a) {
|
||||
case 1:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user