use of net.sourceforge.pmd.lang.symboltable.NameDeclaration 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.symboltable.NameDeclaration 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");
}
}
}
use of net.sourceforge.pmd.lang.symboltable.NameDeclaration 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.symboltable.NameDeclaration 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.symboltable.NameDeclaration 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());
}
Aggregations