use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class ClassScope method addNameOccurrence.
@Override
public Set<NameDeclaration> addNameOccurrence(NameOccurrence occ) {
PLSQLNameOccurrence occurrence = (PLSQLNameOccurrence) occ;
Set<NameDeclaration> declarations = findVariableHere(occurrence);
Map<MethodNameDeclaration, List<NameOccurrence>> methodNames = getMethodDeclarations();
if (!declarations.isEmpty() && occurrence.isMethodOrConstructorInvocation()) {
for (NameDeclaration decl : declarations) {
List<NameOccurrence> nameOccurrences = methodNames.get(decl);
if (nameOccurrences == null) {
// TODO may be a class name: Foo.this.super();
} else {
nameOccurrences.add(occurrence);
Node n = occurrence.getLocation();
if (n instanceof ASTName) {
((ASTName) n).setNameDeclaration(decl);
}
// TODO what to do with PrimarySuffix case?
}
}
} else if (!declarations.isEmpty() && !occurrence.isThisOrSuper()) {
Map<VariableNameDeclaration, List<NameOccurrence>> variableNames = getVariableDeclarations();
for (NameDeclaration decl : declarations) {
List<NameOccurrence> nameOccurrences = variableNames.get(decl);
if (nameOccurrences == null) {
// TODO may be a class name
} else {
nameOccurrences.add(occurrence);
Node n = occurrence.getLocation();
if (n instanceof ASTName) {
((ASTName) n).setNameDeclaration(decl);
}
// TODO what to do with PrimarySuffix case?
}
}
}
return declarations;
}
use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class MethodScope method addNameOccurrence.
@Override
public Set<NameDeclaration> addNameOccurrence(NameOccurrence occ) {
PLSQLNameOccurrence occurrence = (PLSQLNameOccurrence) occ;
Set<NameDeclaration> declarations = findVariableHere(occurrence);
if (!declarations.isEmpty() && !occurrence.isThisOrSuper()) {
for (NameDeclaration decl : declarations) {
getVariableDeclarations().get(decl).add(occurrence);
Node n = occurrence.getLocation();
if (n instanceof ASTName) {
((ASTName) n).setNameDeclaration(decl);
}
// TODO what to do with PrimarySuffix case?
}
}
return declarations;
}
use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class MethodScope method findVariableHere.
public Set<NameDeclaration> findVariableHere(PLSQLNameOccurrence occurrence) {
Set<NameDeclaration> result = new HashSet<>();
if (occurrence.isThisOrSuper() || occurrence.isMethodOrConstructorInvocation()) {
return result;
}
ImageFinderFunction finder = new ImageFinderFunction(occurrence.getImage());
Applier.apply(finder, getVariableDeclarations().keySet().iterator());
if (finder.getDecl() != null) {
result.add(finder.getDecl());
}
return result;
}
use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.
the class OccurrenceFinder method visit.
@Override
public Object visit(ASTPrimaryExpression node, Object data) {
NameFinder nameFinder = new NameFinder(node);
// Maybe do some sort of State pattern thingy for when NameDeclaration
// is empty/not empty
Set<NameDeclaration> declarations = new HashSet<>();
List<PLSQLNameOccurrence> names = nameFinder.getNames();
for (PLSQLNameOccurrence occ : names) {
Search search = new Search(occ);
if (declarations.isEmpty()) {
// doing the first name lookup
search.execute();
declarations.addAll(search.getResult());
if (declarations.isEmpty()) {
// SymbolNotFoundException
break;
}
} else {
Set<NameDeclaration> additionalDeclarations = new HashSet<>();
for (NameDeclaration decl : declarations) {
// now we've got a scope we're starting with, so work from
// there
Scope scope = decl.getScope();
if (null == scope) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("NameOccurrence has no Scope:" + decl.getClass().getCanonicalName() + "=>" + decl.getImage());
}
break;
}
search.execute(scope);
Set<NameDeclaration> found = search.getResult();
additionalDeclarations.addAll(found);
if (found.isEmpty()) {
// SymbolNotFoundException
break;
}
}
declarations.addAll(additionalDeclarations);
}
}
return super.visit(node, data);
}
Aggregations