use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class AcceptanceTest method testDemo.
@Test
public void testDemo() {
parseCode(TEST_DEMO);
// System.out.println(TEST_DEMO);
ASTMethodDeclaration node = acu.findDescendantsOfType(ASTMethodDeclaration.class).get(0);
Scope s = node.getScope();
Map<NameDeclaration, List<NameOccurrence>> m = s.getDeclarations();
for (Map.Entry<NameDeclaration, List<NameOccurrence>> entry : m.entrySet()) {
assertEquals("buz", entry.getKey().getImage());
assertEquals("ArrayList", ((TypedNameDeclaration) entry.getKey()).getTypeImage());
List<NameOccurrence> u = entry.getValue();
assertEquals(1, u.size());
NameOccurrence o = u.get(0);
int beginLine = o.getLocation().getBeginLine();
assertEquals(3, beginLine);
// System.out.println("Variable: " + d.getImage());
// System.out.println("Type: " + d.getTypeImage());
// System.out.println("Usages: " + u.size());
// System.out.println("Used in line " + beginLine);
}
}
use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class AcceptanceTest method testCatchBlocks.
@Test
public void testCatchBlocks() {
parseCode(TEST_CATCH_BLOCKS);
ASTCatchStatement c = acu.findDescendantsOfType(ASTCatchStatement.class).get(0);
ASTBlock a = c.findDescendantsOfType(ASTBlock.class).get(0);
Scope s = a.getScope();
Map<NameDeclaration, List<NameOccurrence>> vars = s.getParent().getDeclarations();
assertEquals(1, vars.size());
NameDeclaration v = vars.keySet().iterator().next();
assertEquals("e", v.getImage());
assertEquals(1, (vars.get(v)).size());
}
use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class AcceptanceTest method testEq.
@Test
public void testEq() {
parseCode(TEST_EQ);
ASTEqualityExpression e = acu.findDescendantsOfType(ASTEqualityExpression.class).get(0);
ASTMethodDeclaration method = e.getFirstParentOfType(ASTMethodDeclaration.class);
Scope s = method.getScope();
Map<NameDeclaration, List<NameOccurrence>> m = s.getDeclarations();
assertEquals(2, m.size());
for (Map.Entry<NameDeclaration, List<NameOccurrence>> entry : m.entrySet()) {
NameDeclaration vnd = entry.getKey();
List<NameOccurrence> usages = entry.getValue();
if (vnd.getImage().equals("a") || vnd.getImage().equals("b")) {
assertEquals(1, usages.size());
assertEquals(3, usages.get(0).getLocation().getBeginLine());
} else {
fail("Unkown variable " + vnd);
}
}
}
use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class NodeInfoPanelController method initialize.
@Override
public void initialize(URL location, ResourceBundle resources) {
EventStreams.valuesOf(scopeHierarchyTreeView.getSelectionModel().selectedItemProperty()).filter(Objects::nonNull).map(TreeItem::getValue).filterMap(o -> o instanceof NameDeclaration, o -> (NameDeclaration) o).subscribe(parent::onNameDeclarationSelected);
scopeHierarchyTreeView.setCellFactory(view -> new ScopeHierarchyTreeCell(parent));
}
use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class VariableAccessVisitor method collectDeclarations.
private Set<Map<NameDeclaration, List<NameOccurrence>>> collectDeclarations(DataFlowNode inode) {
Set<Map<NameDeclaration, List<NameOccurrence>>> decls = new HashSet<>();
Map<NameDeclaration, List<NameOccurrence>> varDecls;
for (int i = 0; i < inode.getFlow().size(); i++) {
DataFlowNode n = inode.getFlow().get(i);
if (n instanceof StartOrEndDataFlowNode) {
continue;
}
varDecls = ((PLSQLNode) n.getNode()).getScope().getDeclarations();
if (!decls.contains(varDecls)) {
decls.add(varDecls);
}
}
return decls;
}
Aggregations