use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassTypeResolverTest method testAnonymousInnerClass.
@Test
public void testAnonymousInnerClass() throws ClassNotFoundException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(AnonymousInnerClass.class);
Class<?> theAnonymousInnerClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.AnonymousInnerClass$1");
// Outer class
ASTTypeDeclaration typeDeclaration = acu.getFirstDescendantOfType(ASTTypeDeclaration.class);
assertEquals(AnonymousInnerClass.class, typeDeclaration.getType());
ASTClassOrInterfaceDeclaration outerClassDeclaration = typeDeclaration.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class);
assertEquals(AnonymousInnerClass.class, outerClassDeclaration.getType());
// Anonymous Inner class
assertEquals(theAnonymousInnerClass, outerClassDeclaration.getFirstDescendantOfType(ASTAllocationExpression.class).getType());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testMethodDeclarationRecorded.
@Test
public void testMethodDeclarationRecorded() {
parseCode(METHOD_DECLARATIONS_RECORDED);
ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
ClassScope s = (ClassScope) n.getScope();
Map<NameDeclaration, List<NameOccurrence>> m = s.getDeclarations();
assertEquals(1, m.size());
MethodNameDeclaration mnd = (MethodNameDeclaration) m.keySet().iterator().next();
assertEquals("bar", mnd.getImage());
ASTMethodDeclaration node = (ASTMethodDeclaration) mnd.getNode().jjtGetParent();
assertTrue(node.isPrivate());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testNestedClassesOfImportResolution.
@Test
public void testNestedClassesOfImportResolution() {
parseCode(NESTED_CLASSES_OF_IMPORT);
final ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
final ClassScope c = (ClassScope) n.getScope();
assertEquals(EnumTest.class, c.resolveType("TheInnerClass.EnumTest"));
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testOneParam.
@Test
public final void testOneParam() {
parseCode(ONE_PARAM);
ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
Map<NameDeclaration, List<NameOccurrence>> m = ((ClassScope) n.getScope()).getDeclarations();
MethodNameDeclaration mnd = (MethodNameDeclaration) m.keySet().iterator().next();
assertEquals("(String)", mnd.getParameterDisplaySignature());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testMethodUsageSeen2.
@Test
public void testMethodUsageSeen2() {
parseCode(METHOD_USAGE_SEEN2);
ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
Map<NameDeclaration, List<NameOccurrence>> m = ((ClassScope) n.getScope()).getDeclarations();
assertEquals(2, m.size());
for (Map.Entry<NameDeclaration, List<NameOccurrence>> entry : m.entrySet()) {
assertEquals("baz", entry.getKey().getImage());
if (entry.getKey().getNode().getBeginLine() == 2) {
// this is the public method declaration - it is not used
// anywhere
assertEquals(0, entry.getValue().size());
} else if (entry.getKey().getNode().getBeginLine() == 5) {
// this is the private (overloaded) method
assertEquals(1, entry.getValue().size());
// it's used once in line 3
assertEquals(3, entry.getValue().get(0).getLocation().getBeginLine());
} else {
fail("unexpected name declaration");
}
}
}
Aggregations