use of net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration in project pmd by pmd.
the class ClassTypeResolverTest method acceptanceTest.
@Test
public void acceptanceTest() {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(ArrayListFound.class);
assertEquals(ArrayListFound.class, acu.getFirstDescendantOfType(ASTTypeDeclaration.class).getType());
assertEquals(ArrayListFound.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getType());
ASTImportDeclaration id = acu.getFirstDescendantOfType(ASTImportDeclaration.class);
assertEquals("java.util", id.getPackage().getName());
assertEquals(ArrayList.class, id.getType());
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceType.class).getType());
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTReferenceType.class).getType());
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTType.class).getType());
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTVariableDeclaratorId.class).getType());
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTVariableDeclarator.class).getType());
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTFieldDeclaration.class).getType());
acu = parseAndTypeResolveForClass15(DefaultJavaLangImport.class);
assertEquals(String.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceType.class).getType());
assertEquals(Override.class, acu.findDescendantsOfType(ASTName.class).get(1).getType());
}
use of net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration in project pmd by pmd.
the class JavaRuleViolationTest method testPackageAndEnumName.
@Test
public void testPackageAndEnumName() {
ASTCompilationUnit ast = parse("package pkg; import java.util.List; public enum FooE { }");
ASTImportDeclaration importNode = ast.getFirstDescendantOfType(ASTImportDeclaration.class);
JavaRuleViolation violation = new JavaRuleViolation(null, new RuleContext(), importNode, null);
assertEquals("pkg", violation.getPackageName());
assertEquals("FooE", violation.getClassName());
}
use of net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration in project pmd by pmd.
the class JavaRuleViolationTest method testPackageAndMultipleClassesName.
@Test
public void testPackageAndMultipleClassesName() {
ASTCompilationUnit ast = parse("package pkg; import java.util.List; class Foo { } public class Bar { }");
ASTImportDeclaration importNode = ast.getFirstDescendantOfType(ASTImportDeclaration.class);
JavaRuleViolation violation = new JavaRuleViolation(null, new RuleContext(), importNode, null);
assertEquals("pkg", violation.getPackageName());
assertEquals("Bar", violation.getClassName());
}
use of net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration in project pmd by pmd.
the class JavaRuleViolationTest method testDefaultPackageAndClassName.
@Test
public void testDefaultPackageAndClassName() {
ASTCompilationUnit ast = parse("import java.util.List; public class Foo { }");
ASTImportDeclaration importNode = ast.getFirstDescendantOfType(ASTImportDeclaration.class);
JavaRuleViolation violation = new JavaRuleViolation(null, new RuleContext(), importNode, null);
assertEquals("", violation.getPackageName());
assertEquals("Foo", violation.getClassName());
}
use of net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration in project pmd-eclipse-plugin by pmd.
the class ASTContentProvider method withoutHiddenOnes.
private List<Node> withoutHiddenOnes(Object parent) {
List<Node> kids = new ArrayList<Node>();
if (includeComments && parent instanceof ASTCompilationUnit) {
// if (!hiddenNodeTypes.contains(Comment.class)) {
List<Comment> comments = ((ASTCompilationUnit) parent).getComments();
kids.addAll(comments);
// }
}
AbstractNode node = (AbstractNode) parent;
int kidCount = node.jjtGetNumChildren();
for (int i = 0; i < kidCount; i++) {
Node kid = node.jjtGetChild(i);
// if (hiddenNodeTypes.contains(kid.getClass())) continue;
if (!includeImports && kid instanceof ASTImportDeclaration) {
continue;
}
if (!includeComments && kid instanceof Comment) {
continue;
}
kids.add(kid);
}
Collections.sort(kids, BY_LINE_NUMBER);
return kids;
}
Aggregations