use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testMethodUsageSeenWithThis.
@Test
public void testMethodUsageSeenWithThis() {
parseCode(METHOD_USAGE_SEEN_WITH_THIS);
ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
Map<NameDeclaration, List<NameOccurrence>> m = ((ClassScope) n.getScope()).getDeclarations();
Iterator<Map.Entry<NameDeclaration, List<NameOccurrence>>> i = m.entrySet().iterator();
MethodNameDeclaration mnd;
Map.Entry<NameDeclaration, List<NameOccurrence>> entry;
do {
entry = i.next();
mnd = (MethodNameDeclaration) entry.getKey();
} while (!mnd.getImage().equals("bar"));
List<NameOccurrence> usages = entry.getValue();
assertEquals(1, usages.size());
assertEquals("bar", ((JavaNameOccurrence) usages.get(0)).getImage());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testNoParams.
@Test
public final void testNoParams() {
parseCode(NO_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("()", mnd.getParameterDisplaySignature());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testNestedClassDeclFound.
@Test
public final void testNestedClassDeclFound() {
parseCode(NESTED_CLASS_FOUND);
ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
ClassScope c = (ClassScope) n.getScope();
Map<NameDeclaration, List<NameOccurrence>> m = c.getDeclarations();
ClassNameDeclaration cnd = (ClassNameDeclaration) m.keySet().iterator().next();
assertEquals("Buz", cnd.getImage());
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testImportNestedClassesResolution.
@Test
public void testImportNestedClassesResolution() {
parseCode(IMPORT_NESTED_CLASSES);
final ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
final ClassScope c = (ClassScope) n.getScope();
assertEquals(EnumTest.class, c.resolveType("EnumTest"));
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration in project pmd by pmd.
the class ClassScopeTest method testMethodUsageSeen.
@Test
public void testMethodUsageSeen() {
parseCode(METHOD_USAGE_SEEN);
ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
Map<NameDeclaration, List<NameOccurrence>> m = ((ClassScope) n.getScope()).getDeclarations();
Iterator<Map.Entry<NameDeclaration, List<NameOccurrence>>> i = m.entrySet().iterator();
MethodNameDeclaration mnd;
Map.Entry<NameDeclaration, List<NameOccurrence>> entry;
do {
entry = i.next();
mnd = (MethodNameDeclaration) entry.getKey();
} while (!mnd.getImage().equals("bar"));
List<NameOccurrence> usages = entry.getValue();
assertEquals(1, usages.size());
assertEquals("bar", ((JavaNameOccurrence) usages.get(0)).getImage());
}
Aggregations