use of net.sourceforge.pmd.lang.symboltable.ImageFinderFunction in project pmd by pmd.
the class ImageFinderFunctionTest method testSeveralImages.
@Test
public void testSeveralImages() {
List<String> imgs = new ArrayList<>();
imgs.add("Foo.foo");
imgs.add("foo");
ImageFinderFunction f = new ImageFinderFunction(imgs);
ASTVariableDeclaratorId node = new ASTVariableDeclaratorId(1);
node.setImage("foo");
NameDeclaration decl = new VariableNameDeclaration(node);
f.applyTo(decl);
assertEquals(decl, f.getDecl());
}
use of net.sourceforge.pmd.lang.symboltable.ImageFinderFunction in project pmd by pmd.
the class ImageFinderFunctionTest method testSingleImage.
@Test
public void testSingleImage() {
ImageFinderFunction f = new ImageFinderFunction("foo");
ASTVariableDeclaratorId node = new ASTVariableDeclaratorId(1);
node.setImage("foo");
NameDeclaration decl = new VariableNameDeclaration(node);
f.applyTo(decl);
assertEquals(decl, f.getDecl());
}
use of net.sourceforge.pmd.lang.symboltable.ImageFinderFunction in project pmd by pmd.
the class ClassScope method findVariableHere.
protected Set<NameDeclaration> findVariableHere(PLSQLNameOccurrence occurrence) {
Set<NameDeclaration> result = new HashSet<>();
Map<VariableNameDeclaration, List<NameOccurrence>> variableDeclarations = getVariableDeclarations();
Map<MethodNameDeclaration, List<NameOccurrence>> methodDeclarations = getMethodDeclarations();
if (occurrence.isThisOrSuper() || occurrence.getImage().equals(className)) {
if (variableDeclarations.isEmpty() && methodDeclarations.isEmpty()) {
// }
return result;
}
// and then we'll look up X.
if (!variableDeclarations.isEmpty()) {
result.add(variableDeclarations.keySet().iterator().next());
return result;
}
result.add(methodDeclarations.keySet().iterator().next());
return result;
}
if (occurrence.isMethodOrConstructorInvocation()) {
for (MethodNameDeclaration mnd : methodDeclarations.keySet()) {
if (mnd.getImage().equals(occurrence.getImage())) {
int args = occurrence.getArgumentCount();
if (args == mnd.getParameterCount() || mnd.isVarargs() && args >= mnd.getParameterCount() - 1) {
// FIXME if several methods have the same name
// and parameter count, only one will get caught here
// we need to make some attempt at type lookup and
// discrimination
// or, failing that, mark this as a usage of all those
// methods
result.add(mnd);
}
}
}
return result;
}
List<String> images = new ArrayList<>();
images.add(occurrence.getImage());
if (null == occurrence.getImage()) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("occurrence==" + occurrence.toString() + "with Argumanet Count == " + occurrence.getArgumentCount() + " for className=" + className);
}
}
if (occurrence.getImage().startsWith(className)) {
images.add(clipClassName(occurrence.getImage()));
}
ImageFinderFunction finder = new ImageFinderFunction(images);
Applier.apply(finder, getVariableDeclarations().keySet().iterator());
if (finder.getDecl() != null) {
result.add(finder.getDecl());
}
return result;
}
use of net.sourceforge.pmd.lang.symboltable.ImageFinderFunction in project pmd by pmd.
the class LocalScope 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.ImageFinderFunction in project pmd by pmd.
the class ClassScope method findVariableHere.
protected Set<NameDeclaration> findVariableHere(JavaNameOccurrence occurrence) {
if (occurrence.isThisOrSuper() || className.equals(occurrence.getImage())) {
// Reference to ourselves!
return Collections.<NameDeclaration>singleton(classDeclaration);
}
Map<MethodNameDeclaration, List<NameOccurrence>> methodDeclarations = getMethodDeclarations();
Set<NameDeclaration> result = new HashSet<>();
if (occurrence.isMethodOrConstructorInvocation()) {
final boolean hasAuxclasspath = getEnclosingScope(SourceFileScope.class).hasAuxclasspath();
matchMethodDeclaration(occurrence, methodDeclarations.keySet(), hasAuxclasspath, result);
if (isEnum && "valueOf".equals(occurrence.getImage())) {
result.add(createBuiltInMethodDeclaration("valueOf", "String"));
}
if (result.isEmpty()) {
for (ClassNameDeclaration innerClass : getClassDeclarations().keySet()) {
matchMethodDeclaration(occurrence, innerClass.getScope().getDeclarations(MethodNameDeclaration.class).keySet(), hasAuxclasspath, result);
}
}
return result;
}
if (occurrence.isMethodReference()) {
for (MethodNameDeclaration mnd : methodDeclarations.keySet()) {
if (mnd.getImage().equals(occurrence.getImage())) {
result.add(mnd);
}
}
return result;
}
List<String> images = new ArrayList<>();
if (occurrence.getImage() != null) {
images.add(occurrence.getImage());
if (occurrence.getImage().startsWith(className)) {
images.add(clipClassName(occurrence.getImage()));
}
}
Map<VariableNameDeclaration, List<NameOccurrence>> variableDeclarations = getVariableDeclarations();
ImageFinderFunction finder = new ImageFinderFunction(images);
Applier.apply(finder, variableDeclarations.keySet().iterator());
if (finder.getDecl() != null) {
result.add(finder.getDecl());
}
// search inner classes
Map<ClassNameDeclaration, List<NameOccurrence>> classDeclarations = getClassDeclarations();
if (result.isEmpty() && !classDeclarations.isEmpty()) {
for (ClassNameDeclaration innerClass : getClassDeclarations().keySet()) {
Applier.apply(finder, innerClass.getScope().getDeclarations(VariableNameDeclaration.class).keySet().iterator());
if (finder.getDecl() != null) {
result.add(finder.getDecl());
}
}
}
return result;
}
Aggregations