use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.
the class LocalScopeTest method testLocalVariableDeclarationFound.
@Test
public void testLocalVariableDeclarationFound() {
parseCode(TEST1);
List<ASTVariableDeclaratorId> nodes = acu.findDescendantsOfType(ASTVariableDeclaratorId.class);
ASTVariableDeclaratorId node = nodes.get(0);
Map<NameDeclaration, List<NameOccurrence>> vars = node.getScope().getDeclarations();
assertEquals(1, vars.size());
NameDeclaration decl = vars.keySet().iterator().next();
assertEquals("b", decl.getImage());
}
use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.
the class AcceptanceTest method testFieldFinder.
@Test
public void testFieldFinder() {
parseCode(TEST_FIELD);
// System.out.println(TEST_FIELD);
ASTVariableDeclaratorId declaration = acu.findDescendantsOfType(ASTVariableDeclaratorId.class).get(1);
assertEquals(3, declaration.getBeginLine());
assertEquals("bbbbbbbbbb", declaration.getImage());
assertEquals(1, declaration.getUsages().size());
NameOccurrence no = declaration.getUsages().get(0);
Node location = no.getLocation();
assertEquals(6, location.getBeginLine());
// System.out.println("variable " + declaration.getImage() + " is used
// here: " + location.getImage());
}
use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.
the class AcceptanceTest method testInnerOuterClass.
@Test
public void testInnerOuterClass() {
parseCode(TEST_INNER_CLASS);
ASTVariableDeclaratorId vdi = // get inner class
acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(1).getFirstDescendantOfType(// get first declaration
ASTVariableDeclaratorId.class);
List<NameOccurrence> usages = vdi.getUsages();
assertEquals(2, usages.size());
assertEquals(5, usages.get(0).getLocation().getBeginLine());
assertEquals(10, usages.get(1).getLocation().getBeginLine());
}
Aggregations