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:
Juan Martín Sotuyo Dodero
2016-12-12 16:32:26 -03:00
committed by Andreas Dangel
parent b6bc06d3d2
commit b950929b7c
22 changed files with 132 additions and 215 deletions

View File

@ -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());
}
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;