Improve symboltable codebase
- Move shared code to pmd-core - Allow search methods to stop searching when they want to - If we are looking for a variable declaration, just search among those and not all name declarations - This is roughtly another 10% improvement on symbol table performance
This commit is contained in:

committed by
Andreas Dangel

parent
b6bc06d3d2
commit
b950929b7c
@ -1,21 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.plsql.symboltable;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sourceforge.pmd.util.UnaryFunction;
|
||||
|
||||
public final class Applier {
|
||||
|
||||
private Applier() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
public static <E> void apply(UnaryFunction<E> f, Iterator<? extends E> i) {
|
||||
while (i.hasNext()) {
|
||||
f.applyTo(i.next());
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.plsql.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode;
|
||||
import net.sourceforge.pmd.lang.symboltable.AbstractScope;
|
||||
import net.sourceforge.pmd.lang.symboltable.Applier;
|
||||
import net.sourceforge.pmd.lang.symboltable.ImageFinderFunction;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.plsql.symboltable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
import net.sourceforge.pmd.util.UnaryFunction;
|
||||
|
||||
public class ImageFinderFunction implements UnaryFunction<NameDeclaration> {
|
||||
|
||||
private Set<String> images = new HashSet<>();
|
||||
private NameDeclaration decl;
|
||||
|
||||
public ImageFinderFunction(String img) {
|
||||
images.add(img);
|
||||
}
|
||||
|
||||
public ImageFinderFunction(List<String> imageList) {
|
||||
images.addAll(imageList);
|
||||
}
|
||||
|
||||
public void applyTo(NameDeclaration nameDeclaration) {
|
||||
if (images.contains(nameDeclaration.getImage())) {
|
||||
decl = nameDeclaration;
|
||||
}
|
||||
}
|
||||
|
||||
public NameDeclaration getDecl() {
|
||||
return this.decl;
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ import java.util.Set;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.plsql.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.symboltable.AbstractScope;
|
||||
import net.sourceforge.pmd.lang.symboltable.Applier;
|
||||
import net.sourceforge.pmd.lang.symboltable.ImageFinderFunction;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
|
||||
|
||||
|
@ -12,6 +12,8 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.plsql.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode;
|
||||
import net.sourceforge.pmd.lang.symboltable.AbstractScope;
|
||||
import net.sourceforge.pmd.lang.symboltable.Applier;
|
||||
import net.sourceforge.pmd.lang.symboltable.ImageFinderFunction;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
package net.sourceforge.pmd.lang.plsql.symboltable;
|
||||
|
||||
import net.sourceforge.pmd.lang.symboltable.AbstractScope;
|
||||
import net.sourceforge.pmd.lang.symboltable.Applier;
|
||||
import net.sourceforge.pmd.lang.symboltable.ImageFinderFunction;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
|
||||
|
||||
|
Reference in New Issue
Block a user