use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassTypeResolverTest method testInnerClass.
@Test
public void testInnerClass() throws ClassNotFoundException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(InnerClass.class);
Class<?> theInnerClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.InnerClass$TheInnerClass");
// Outer class
ASTTypeDeclaration typeDeclaration = acu.getFirstDescendantOfType(ASTTypeDeclaration.class);
assertEquals(InnerClass.class, typeDeclaration.getType());
ASTClassOrInterfaceDeclaration outerClassDeclaration = typeDeclaration.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class);
assertEquals(InnerClass.class, outerClassDeclaration.getType());
// Inner class
assertEquals(theInnerClass, outerClassDeclaration.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getType());
// Method parameter as inner class
ASTFormalParameter formalParameter = typeDeclaration.getFirstDescendantOfType(ASTFormalParameter.class);
assertEquals(theInnerClass, formalParameter.getType());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testOneParamVararg.
@Test
public final void testOneParamVararg() {
parseCode15(ONE_PARAM_VARARG);
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 testClassName.
@Test
public void testClassName() {
parseCode(CLASS_NAME);
ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
assertEquals("Foo", n.getScope().getEnclosingScope(ClassScope.class).getClassName());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testTwoMethodsSameNameDiffArgs.
@Test
public void testTwoMethodsSameNameDiffArgs() {
// TODO this won't work with String and java.lang.String
parseCode(METHODS_WITH_DIFF_ARG);
ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
Map<NameDeclaration, List<NameOccurrence>> m = ((ClassScope) n.getScope()).getDeclarations();
assertEquals(2, m.size());
Iterator<NameDeclaration> i = m.keySet().iterator();
MethodNameDeclaration mnd = (MethodNameDeclaration) i.next();
assertEquals("bar", mnd.getImage());
assertEquals("bar", ((MethodNameDeclaration) i.next()).getImage());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testTwoParams.
@Test
public final void testTwoParams() {
parseCode(TWO_PARAMS);
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,int)", mnd.getParameterDisplaySignature());
}
Aggregations