Remove import to reduce diff

This commit is contained in:
Clément Fournier
2020-03-28 11:35:39 +01:00
parent b01d4dc0d7
commit 7c433f8820

View File

@ -6,13 +6,11 @@
package net.sourceforge.pmd.lang.java.ast;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import net.sourceforge.pmd.lang.ast.ParseException;
@ -52,36 +50,36 @@ public class Java14Test {
private void parseAndCheckSwitchExpression(JavaParsingHelper parser) {
ASTCompilationUnit compilationUnit = parser.parseResource("SwitchExpressions.java");
List<ASTSwitchStatement> switchStatements = compilationUnit.findDescendantsOfType(ASTSwitchStatement.class);
assertEquals(2, switchStatements.size());
Assert.assertEquals(2, switchStatements.size());
assertTrue(switchStatements.get(0).getChild(0) instanceof ASTExpression);
assertTrue(switchStatements.get(0).getChild(1) instanceof ASTSwitchLabeledExpression);
assertTrue(switchStatements.get(0).getChild(1).getChild(0) instanceof ASTSwitchLabel);
assertEquals(3, switchStatements.get(0).getChild(1).getChild(0).getNumChildren());
assertTrue(switchStatements.get(0).getChild(2).getChild(0) instanceof ASTSwitchLabel);
assertFalse(((ASTSwitchLabel) switchStatements.get(0).getChild(2).getChild(0)).isDefault());
assertEquals(1, switchStatements.get(0).getChild(2).getChild(0).getNumChildren());
Assert.assertTrue(switchStatements.get(0).getChild(0) instanceof ASTExpression);
Assert.assertTrue(switchStatements.get(0).getChild(1) instanceof ASTSwitchLabeledExpression);
Assert.assertTrue(switchStatements.get(0).getChild(1).getChild(0) instanceof ASTSwitchLabel);
Assert.assertEquals(3, switchStatements.get(0).getChild(1).getChild(0).getNumChildren());
Assert.assertTrue(switchStatements.get(0).getChild(2).getChild(0) instanceof ASTSwitchLabel);
Assert.assertFalse(((ASTSwitchLabel) switchStatements.get(0).getChild(2).getChild(0)).isDefault());
Assert.assertEquals(1, switchStatements.get(0).getChild(2).getChild(0).getNumChildren());
assertTrue(switchStatements.get(1).getChild(3) instanceof ASTSwitchLabeledExpression);
assertTrue(switchStatements.get(1).getChild(3).getChild(0) instanceof ASTSwitchLabel);
assertTrue(((ASTSwitchLabel) switchStatements.get(1).getChild(3).getChild(0)).isDefault());
Assert.assertTrue(switchStatements.get(1).getChild(3) instanceof ASTSwitchLabeledExpression);
Assert.assertTrue(switchStatements.get(1).getChild(3).getChild(0) instanceof ASTSwitchLabel);
Assert.assertTrue(((ASTSwitchLabel) switchStatements.get(1).getChild(3).getChild(0)).isDefault());
List<ASTSwitchExpression> switchExpressions = compilationUnit.findDescendantsOfType(ASTSwitchExpression.class);
assertEquals(4, switchExpressions.size());
Assert.assertEquals(4, switchExpressions.size());
assertEquals(Integer.TYPE, switchExpressions.get(0).getType());
assertEquals(4, switchExpressions.get(0).findChildrenOfType(ASTSwitchLabeledExpression.class).size());
assertEquals(Integer.TYPE, switchExpressions.get(0).getFirstChildOfType(ASTSwitchLabeledExpression.class)
Assert.assertEquals(Integer.TYPE, switchExpressions.get(0).getType());
Assert.assertEquals(4, switchExpressions.get(0).findChildrenOfType(ASTSwitchLabeledExpression.class).size());
Assert.assertEquals(Integer.TYPE, switchExpressions.get(0).getFirstChildOfType(ASTSwitchLabeledExpression.class)
.getFirstChildOfType(ASTExpression.class).getType());
assertTrue(switchExpressions.get(1).getChild(3) instanceof ASTSwitchLabeledBlock);
Assert.assertTrue(switchExpressions.get(1).getChild(3) instanceof ASTSwitchLabeledBlock);
assertEquals(Integer.TYPE, switchExpressions.get(2).getType());
Assert.assertEquals(Integer.TYPE, switchExpressions.get(2).getType());
List<ASTYieldStatement> yields = switchExpressions.get(2).findDescendantsOfType(ASTYieldStatement.class);
assertEquals(4, yields.size());
assertEquals("SwitchExpressions.BAZ", yields.get(2).getImage());
Assert.assertEquals(4, yields.size());
Assert.assertEquals("SwitchExpressions.BAZ", yields.get(2).getImage());
assertEquals(String.class, switchExpressions.get(3).getType());
Assert.assertEquals(String.class, switchExpressions.get(3).getType());
}
@Test
@ -108,7 +106,7 @@ public class Java14Test {
}
}
assertEquals(18, stmts.size());
Assert.assertEquals(18, stmts.size());
int i = 0;
assertThat(stmts.get(i++), instanceOf(ASTLocalVariableDeclaration.class));
@ -135,7 +133,7 @@ public class Java14Test {
assertThat(stmts.get(i++), instanceOf(ASTStatementExpression.class));
assertThat(stmts.get(i++), instanceOf(ASTYieldStatement.class));
assertEquals(i, stmts.size());
Assert.assertEquals(i, stmts.size());
}
@Test
@ -148,10 +146,10 @@ public class Java14Test {
private void multipleCaseLabels(JavaParsingHelper parser) {
ASTCompilationUnit compilationUnit = parser.parseResource("MultipleCaseLabels.java");
ASTSwitchStatement switchStatement = compilationUnit.getFirstDescendantOfType(ASTSwitchStatement.class);
assertTrue(switchStatement.getChild(0) instanceof ASTExpression);
assertTrue(switchStatement.getChild(1) instanceof ASTSwitchLabel);
Assert.assertTrue(switchStatement.getChild(0) instanceof ASTExpression);
Assert.assertTrue(switchStatement.getChild(1) instanceof ASTSwitchLabel);
ASTSwitchLabel switchLabel = switchStatement.getFirstChildOfType(ASTSwitchLabel.class);
assertEquals(3, switchLabel.findChildrenOfType(ASTExpression.class).size());
Assert.assertEquals(3, switchLabel.findChildrenOfType(ASTExpression.class).size());
}
@Test
@ -164,22 +162,22 @@ public class Java14Test {
private void switchRules(JavaParsingHelper parser) {
ASTCompilationUnit compilationUnit = parser.parseResource("SwitchRules.java");
ASTSwitchStatement switchStatement = compilationUnit.getFirstDescendantOfType(ASTSwitchStatement.class);
assertTrue(switchStatement.getChild(0) instanceof ASTExpression);
assertTrue(switchStatement.getChild(1) instanceof ASTSwitchLabeledExpression);
Assert.assertTrue(switchStatement.getChild(0) instanceof ASTExpression);
Assert.assertTrue(switchStatement.getChild(1) instanceof ASTSwitchLabeledExpression);
ASTSwitchLabeledExpression switchLabeledExpression = (ASTSwitchLabeledExpression) switchStatement.getChild(1);
assertEquals(2, switchLabeledExpression.getNumChildren());
assertTrue(switchLabeledExpression.getChild(0) instanceof ASTSwitchLabel);
assertTrue(switchLabeledExpression.getChild(1) instanceof ASTExpression);
Assert.assertEquals(2, switchLabeledExpression.getNumChildren());
Assert.assertTrue(switchLabeledExpression.getChild(0) instanceof ASTSwitchLabel);
Assert.assertTrue(switchLabeledExpression.getChild(1) instanceof ASTExpression);
ASTSwitchLabeledBlock switchLabeledBlock = (ASTSwitchLabeledBlock) switchStatement.getChild(4);
assertEquals(2, switchLabeledBlock.getNumChildren());
assertTrue(switchLabeledBlock.getChild(0) instanceof ASTSwitchLabel);
assertTrue(switchLabeledBlock.getChild(1) instanceof ASTBlock);
Assert.assertEquals(2, switchLabeledBlock.getNumChildren());
Assert.assertTrue(switchLabeledBlock.getChild(0) instanceof ASTSwitchLabel);
Assert.assertTrue(switchLabeledBlock.getChild(1) instanceof ASTBlock);
ASTSwitchLabeledThrowStatement switchLabeledThrowStatement = (ASTSwitchLabeledThrowStatement) switchStatement.getChild(5);
assertEquals(2, switchLabeledThrowStatement.getNumChildren());
assertTrue(switchLabeledThrowStatement.getChild(0) instanceof ASTSwitchLabel);
assertTrue(switchLabeledThrowStatement.getChild(1) instanceof ASTThrowStatement);
Assert.assertEquals(2, switchLabeledThrowStatement.getNumChildren());
Assert.assertTrue(switchLabeledThrowStatement.getChild(0) instanceof ASTSwitchLabel);
Assert.assertTrue(switchLabeledThrowStatement.getChild(1) instanceof ASTThrowStatement);
}
@Test
@ -192,13 +190,13 @@ public class Java14Test {
private void simpleSwitchExpressions(JavaParsingHelper parser) {
ASTCompilationUnit compilationUnit = parser.parseResource("SimpleSwitchExpressions.java");
ASTSwitchExpression switchExpression = compilationUnit.getFirstDescendantOfType(ASTSwitchExpression.class);
assertEquals(6, switchExpression.getNumChildren());
assertTrue(switchExpression.getChild(0) instanceof ASTExpression);
assertEquals(5, switchExpression.findChildrenOfType(ASTSwitchLabeledRule.class).size());
Assert.assertEquals(6, switchExpression.getNumChildren());
Assert.assertTrue(switchExpression.getChild(0) instanceof ASTExpression);
Assert.assertEquals(5, switchExpression.findChildrenOfType(ASTSwitchLabeledRule.class).size());
ASTLocalVariableDeclaration localVar = compilationUnit.findDescendantsOfType(ASTLocalVariableDeclaration.class).get(1);
ASTVariableDeclarator localVarDecl = localVar.getFirstChildOfType(ASTVariableDeclarator.class);
assertEquals(Integer.TYPE, localVarDecl.getType());
assertEquals(Integer.TYPE, switchExpression.getType());
Assert.assertEquals(Integer.TYPE, localVarDecl.getType());
Assert.assertEquals(Integer.TYPE, switchExpression.getType());
}
}