replace Filter with Predicate
This commit is contained in:
parent
b461107837
commit
853b5fc37a
|
@ -35,7 +35,7 @@ import com.ibm.wala.ssa.SSAInstruction;
|
|||
import com.ibm.wala.ssa.SSAMonitorInstruction;
|
||||
import com.ibm.wala.ssa.SSAPutInstruction;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.graph.traverse.DFS;
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class AstJavaSlicer extends Slicer {
|
|||
return new AstJavaSlicer().slice(sdg, ss, backward);
|
||||
}
|
||||
|
||||
public static Set<Statement> gatherStatements(CallGraph CG, Collection<CGNode> partialRoots, Filter<SSAInstruction> filter) {
|
||||
public static Set<Statement> gatherStatements(CallGraph CG, Collection<CGNode> partialRoots, Predicate<SSAInstruction> filter) {
|
||||
Set<Statement> result = new HashSet<Statement>();
|
||||
for (Iterator<CGNode> ns = DFS.getReachableNodes(CG, partialRoots).iterator(); ns.hasNext();) {
|
||||
CGNode n = ns.next();
|
||||
|
@ -66,7 +66,7 @@ public class AstJavaSlicer extends Slicer {
|
|||
if (nir != null) {
|
||||
SSAInstruction insts[] = nir.getInstructions();
|
||||
for (int i = 0; i < insts.length; i++) {
|
||||
if (filter.accepts(insts[i])) {
|
||||
if (filter.test(insts[i])) {
|
||||
result.add(new NormalStatement(n, i));
|
||||
}
|
||||
}
|
||||
|
@ -77,36 +77,32 @@ public class AstJavaSlicer extends Slicer {
|
|||
}
|
||||
|
||||
public static Set<Statement> gatherAssertions(CallGraph CG, Collection<CGNode> partialRoots) {
|
||||
return gatherStatements(CG, partialRoots, new Filter<SSAInstruction>() {
|
||||
@Override
|
||||
public boolean accepts(SSAInstruction o) {
|
||||
return gatherStatements(CG, partialRoots, new Predicate<SSAInstruction>() {
|
||||
@Override public boolean test(SSAInstruction o) {
|
||||
return o instanceof AstAssertInstruction;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Set<Statement> gatherMonitors(CallGraph CG, Collection<CGNode> partialRoots) {
|
||||
return gatherStatements(CG, partialRoots, new Filter<SSAInstruction>() {
|
||||
@Override
|
||||
public boolean accepts(SSAInstruction o) {
|
||||
return gatherStatements(CG, partialRoots, new Predicate<SSAInstruction>() {
|
||||
@Override public boolean test(SSAInstruction o) {
|
||||
return o instanceof SSAMonitorInstruction;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Set<Statement> gatherWrites(CallGraph CG, Collection<CGNode> partialRoots) {
|
||||
return gatherStatements(CG, partialRoots, new Filter<SSAInstruction>() {
|
||||
@Override
|
||||
public boolean accepts(SSAInstruction o) {
|
||||
return gatherStatements(CG, partialRoots, new Predicate<SSAInstruction>() {
|
||||
@Override public boolean test(SSAInstruction o) {
|
||||
return (o instanceof SSAPutInstruction) || (o instanceof SSAArrayStoreInstruction);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Set<Statement> gatherReads(CallGraph CG, Collection<CGNode> partialRoots) {
|
||||
return gatherStatements(CG, partialRoots, new Filter<SSAInstruction>() {
|
||||
@Override
|
||||
public boolean accepts(SSAInstruction o) {
|
||||
return gatherStatements(CG, partialRoots, new Predicate<SSAInstruction>() {
|
||||
@Override public boolean test(SSAInstruction o) {
|
||||
return (o instanceof SSAGetInstruction) || (o instanceof SSAArrayLoadInstruction);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -126,9 +126,8 @@ public class FlowGraph implements Iterable<Vertex> {
|
|||
GraphReachability<Vertex, T> optimistic_closure =
|
||||
new GraphReachability<Vertex,T>(
|
||||
new InvertedGraph<Vertex>(pruned_flowgraph),
|
||||
new Filter<Vertex>() {
|
||||
@Override
|
||||
public boolean accepts(Vertex o) {
|
||||
new Predicate<Vertex>() {
|
||||
@Override public boolean test(Vertex o) {
|
||||
return type.isInstance(o);
|
||||
}
|
||||
}
|
||||
|
@ -515,9 +514,8 @@ public class FlowGraph implements Iterable<Vertex> {
|
|||
|
||||
@Override
|
||||
public Collection<Object> getReachableInstances(Set<Object> roots) {
|
||||
return DFS.getReachableNodes(this, roots, new Filter<Object>() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
return DFS.getReachableNodes(this, roots, new Predicate<Object>() {
|
||||
@Override public boolean test(Object o) {
|
||||
return o instanceof ObjectVertex;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -25,7 +25,7 @@ import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
|||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.collections.CompoundIterator;
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.NonNullSingletonIterator;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
|
@ -140,9 +140,8 @@ abstract public class ScopeMappingInstanceKeys implements InstanceKeyFactory {
|
|||
public Iterator<Pair<CGNode, NewSiteReference>> getCreationSites(CallGraph CG) {
|
||||
return new FilterIterator<Pair<CGNode, NewSiteReference>>(
|
||||
base.getCreationSites(CG),
|
||||
new Filter<Pair<CGNode, NewSiteReference>>() {
|
||||
@Override
|
||||
public boolean accepts(Pair<CGNode, NewSiteReference> o) {
|
||||
new Predicate<Pair<CGNode, NewSiteReference>>() {
|
||||
@Override public boolean test(Pair<CGNode, NewSiteReference> o) {
|
||||
return o.fst.equals(creator);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -27,7 +27,7 @@ import com.ibm.wala.classLoader.IMethod;
|
|||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
|
@ -82,9 +82,8 @@ public abstract class CAstAbstractLoader implements IClassLoader {
|
|||
}
|
||||
|
||||
private Iterator<ModuleEntry> getMessages(final byte severity) {
|
||||
return new MapIterator<Map.Entry<ModuleEntry,Set<Warning>>, ModuleEntry>(new FilterIterator<Map.Entry<ModuleEntry,Set<Warning>>>(errors.entrySet().iterator(), new Filter<Map.Entry<ModuleEntry,Set<Warning>>>() {
|
||||
@Override
|
||||
public boolean accepts(Entry<ModuleEntry, Set<Warning>> o) {
|
||||
return new MapIterator<Map.Entry<ModuleEntry,Set<Warning>>, ModuleEntry>(new FilterIterator<Map.Entry<ModuleEntry,Set<Warning>>>(errors.entrySet().iterator(), new Predicate<Map.Entry<ModuleEntry,Set<Warning>>>() {
|
||||
@Override public boolean test(Entry<ModuleEntry, Set<Warning>> o) {
|
||||
for(Warning w : o.getValue()) {
|
||||
if (w.getLevel() == severity) {
|
||||
return true;
|
||||
|
|
|
@ -14,15 +14,15 @@ import java.util.Iterator;
|
|||
import java.util.Map;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.graph.traverse.DFSDiscoverTimeIterator;
|
||||
|
||||
public class CAstFunctions {
|
||||
|
||||
public static CAstNode findIf(CAstNode tree, Filter<CAstNode> f) {
|
||||
if (f.accepts(tree)) {
|
||||
public static CAstNode findIf(CAstNode tree, Predicate<CAstNode> f) {
|
||||
if (f.test(tree)) {
|
||||
return tree;
|
||||
} else {
|
||||
for (int i = 0; i < tree.getChildCount(); i++) {
|
||||
|
@ -79,7 +79,7 @@ public class CAstFunctions {
|
|||
};
|
||||
}
|
||||
|
||||
public static Iterator<CAstNode> findAll(CAstNode tree, Filter<?> f) {
|
||||
public static Iterator<CAstNode> findAll(CAstNode tree, Predicate<?> f) {
|
||||
return new FilterIterator<CAstNode>(iterateNodes(tree), f);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import junit.framework.Assert;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.impl.SlowSparseNumberedGraph;
|
||||
import com.ibm.wala.util.graph.traverse.DFSAllPathsFinder;
|
||||
|
@ -42,9 +42,8 @@ public class PathFinderTest {
|
|||
}
|
||||
|
||||
private static DFSAllPathsFinder<String> makeFinder(Graph<String> g, String start, final String end) {
|
||||
return new DFSAllPathsFinder<String>(g, start, new Filter<String>() {
|
||||
@Override
|
||||
public boolean accepts(String o) {
|
||||
return new DFSAllPathsFinder<String>(g, start, new Predicate<String>() {
|
||||
@Override public boolean test(String o) {
|
||||
return end.equals(o);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ import com.ibm.wala.properties.WalaProperties;
|
|||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
@ -194,16 +194,15 @@ public class PDFCallGraph {
|
|||
* <li> {@link LocalPointerKey}
|
||||
* </ul>
|
||||
*/
|
||||
private static class ApplicationLoaderFilter implements Filter<CGNode> {
|
||||
private static class ApplicationLoaderFilter extends Predicate<CGNode> {
|
||||
|
||||
@Override
|
||||
public boolean accepts(CGNode o) {
|
||||
@Override public boolean test(CGNode o) {
|
||||
if (o instanceof CGNode) {
|
||||
CGNode n = (CGNode) o;
|
||||
return n.getMethod().getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Application);
|
||||
} else if (o instanceof LocalPointerKey) {
|
||||
LocalPointerKey l = (LocalPointerKey) o;
|
||||
return accepts(l.getNode());
|
||||
return test(l.getNode());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import com.ibm.wala.ipa.slicer.Statement;
|
|||
import com.ibm.wala.properties.WalaProperties;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
|
@ -161,9 +161,8 @@ public class PDFSDG {
|
|||
}
|
||||
|
||||
private static Graph<Statement> pruneSDG(final SDG sdg) {
|
||||
Filter<Statement> f = new Filter<Statement>() {
|
||||
@Override
|
||||
public boolean accepts(Statement s) {
|
||||
Predicate<Statement> f = new Predicate<Statement>() {
|
||||
@Override public boolean test(Statement s) {
|
||||
if (s.getNode().equals(sdg.getCallGraph().getFakeRootNode())) {
|
||||
return false;
|
||||
} else if (s instanceof MethodExitStatement || s instanceof MethodEntryStatement) {
|
||||
|
|
|
@ -45,7 +45,7 @@ import com.ibm.wala.ssa.SSAInvokeInstruction;
|
|||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
|
@ -244,9 +244,8 @@ public class PDFSlice {
|
|||
* return a view of the sdg restricted to the statements in the slice
|
||||
*/
|
||||
public static Graph<Statement> pruneSDG(SDG sdg, final Collection<Statement> slice) {
|
||||
Filter<Statement> f = new Filter<Statement>() {
|
||||
@Override
|
||||
public boolean accepts(Statement o) {
|
||||
Predicate<Statement> f = new Predicate<Statement>() {
|
||||
@Override public boolean test(Statement o) {
|
||||
return slice.contains(o);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ import com.ibm.wala.properties.WalaProperties;
|
|||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
import com.ibm.wala.util.collections.CollectionFilter;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
|
@ -93,7 +93,7 @@ public class PDFTypeHierarchy {
|
|||
}
|
||||
}
|
||||
|
||||
public static <T> Graph<T> pruneGraph(Graph<T> g, Filter<T> f) throws WalaException {
|
||||
public static <T> Graph<T> pruneGraph(Graph<T> g, Predicate<T> f) throws WalaException {
|
||||
Collection<T> slice = GraphSlicer.slice(g, f);
|
||||
return GraphSlicer.prune(g, new CollectionFilter<T>(slice));
|
||||
}
|
||||
|
@ -102,9 +102,8 @@ public class PDFTypeHierarchy {
|
|||
* Restrict g to nodes from the Application loader
|
||||
*/
|
||||
public static Graph<IClass> pruneForAppLoader(Graph<IClass> g) throws WalaException {
|
||||
Filter<IClass> f = new Filter<IClass>() {
|
||||
@Override
|
||||
public boolean accepts(IClass c) {
|
||||
Predicate<IClass> f = new Predicate<IClass>() {
|
||||
@Override public boolean test(IClass c) {
|
||||
return (c.getClassLoader().getReference().equals(ClassLoaderReference.Application));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ import com.ibm.wala.ipa.callgraph.propagation.HeapModel;
|
|||
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.NumberedGraph;
|
||||
import com.ibm.wala.util.graph.impl.NumberedNodeIterator;
|
||||
|
@ -52,9 +52,8 @@ public abstract class HeapGraphImpl<T extends InstanceKey> implements HeapGraph<
|
|||
}
|
||||
|
||||
public Collection<Object> getReachableInstances(Set<Object> roots) {
|
||||
Filter f = new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
Predicate f = new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
return (o instanceof InstanceKey);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -43,7 +43,7 @@ import com.ibm.wala.ssa.SSAPutInstruction;
|
|||
import com.ibm.wala.types.FieldReference;
|
||||
import com.ibm.wala.types.MethodReference;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.MapIterator;
|
||||
|
@ -208,7 +208,7 @@ public class MethodHandles {
|
|||
return getIR(node).iterateNewSites();
|
||||
}
|
||||
|
||||
public Iterator<FieldReference> iterateFields(CGNode node, Filter<SSAInstruction> filter) {
|
||||
public Iterator<FieldReference> iterateFields(CGNode node, Predicate<SSAInstruction> filter) {
|
||||
return
|
||||
new MapIterator<SSAInstruction,FieldReference>(
|
||||
new FilterIterator<SSAInstruction>(getIR(node).iterateNormalInstructions(), filter),
|
||||
|
@ -222,9 +222,8 @@ public class MethodHandles {
|
|||
|
||||
@Override
|
||||
public Iterator<FieldReference> iterateFieldsRead(CGNode node) {
|
||||
return iterateFields(node, new Filter<SSAInstruction>() {
|
||||
@Override
|
||||
public boolean accepts(SSAInstruction o) {
|
||||
return iterateFields(node, new Predicate<SSAInstruction>() {
|
||||
@Override public boolean test(SSAInstruction o) {
|
||||
return o instanceof SSAGetInstruction;
|
||||
}
|
||||
});
|
||||
|
@ -232,9 +231,8 @@ public class MethodHandles {
|
|||
|
||||
@Override
|
||||
public Iterator<FieldReference> iterateFieldsWritten(CGNode node) {
|
||||
return iterateFields(node, new Filter<SSAInstruction>() {
|
||||
@Override
|
||||
public boolean accepts(SSAInstruction o) {
|
||||
return iterateFields(node, new Predicate<SSAInstruction>() {
|
||||
@Override public boolean test(SSAInstruction o) {
|
||||
return o instanceof SSAPutInstruction;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@ package com.ibm.wala.dataflow.IFDS;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.Iterator2Collection;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
@ -76,13 +76,13 @@ public class BackwardsSupergraph<T, P> implements ISupergraph<T, P> {
|
|||
/**
|
||||
* a filter that accepts only exit nodes from the original graph.
|
||||
*/
|
||||
private class ExitFilter implements Filter {
|
||||
private class ExitFilter extends Predicate {
|
||||
/*
|
||||
* @see com.ibm.wala.util.Filter#accepts(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean accepts(Object o) {
|
||||
public boolean test(Object o) {
|
||||
return delegate.isExit((T) o);
|
||||
}
|
||||
}
|
||||
|
@ -110,17 +110,15 @@ public class BackwardsSupergraph<T, P> implements ISupergraph<T, P> {
|
|||
@Override
|
||||
public Iterator<T> getNormalSuccessors(final T ret) {
|
||||
Iterator<? extends Object> allPreds = delegate.getPredNodes(ret);
|
||||
Filter sameProc = new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
Predicate sameProc = new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
// throw out the exit node, which can be a predecessor due to tail recursion.
|
||||
return getProcOf(ret).equals(getProcOf(o)) && !delegate.isExit(o);
|
||||
}
|
||||
};
|
||||
Iterator<Object> sameProcPreds = new FilterIterator<Object>(allPreds, sameProc);
|
||||
Filter notCall = new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
Predicate notCall = new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return !delegate.isCall(o);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -38,7 +38,7 @@ import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
|
|||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.analysis.IExplodedBasicBlock;
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
|
@ -117,9 +117,8 @@ public class ICFGSupergraph implements ISupergraph<BasicBlockInContext<IExploded
|
|||
|
||||
@Override
|
||||
public Iterator<? extends BasicBlockInContext<IExplodedBasicBlock>> getCalledNodes(BasicBlockInContext<IExplodedBasicBlock> call) {
|
||||
final Filter<BasicBlockInContext<IExplodedBasicBlock>> isEntryFilter = new Filter<BasicBlockInContext<IExplodedBasicBlock>>() {
|
||||
@Override
|
||||
public boolean accepts(BasicBlockInContext<IExplodedBasicBlock> o) {
|
||||
final Predicate<BasicBlockInContext<IExplodedBasicBlock>> isEntryFilter = new Predicate<BasicBlockInContext<IExplodedBasicBlock>>() {
|
||||
@Override public boolean test(BasicBlockInContext<IExplodedBasicBlock> o) {
|
||||
return o.isEntryBlock();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.ibm.wala.ssa.SSACFG;
|
|||
import com.ibm.wala.ssa.SSACFG.BasicBlock;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.SSAReturnInstruction;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.Iterator2Collection;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
@ -57,9 +57,8 @@ public class LocalLiveRangeAnalysis {
|
|||
final Collection<BasicBlock> uses = findBlocks(ir, du.getUses(v));
|
||||
|
||||
// a filter which accepts everything but the block which defs v
|
||||
Filter notDef = new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
Predicate notDef = new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
return (defBlock == null || !defBlock.equals(o));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ import com.ibm.wala.ssa.IR;
|
|||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.collections.ComposedIterator;
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
|
@ -144,9 +144,8 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
|
|||
new MapIterator<IMethod,CGNode>(
|
||||
new FilterIterator<IMethod>(
|
||||
getPossibleTargets(site),
|
||||
new Filter<IMethod>() {
|
||||
@Override
|
||||
public boolean accepts(IMethod o) {
|
||||
new Predicate<IMethod>() {
|
||||
@Override public boolean test(IMethod o) {
|
||||
return !o.isAbstract();
|
||||
}
|
||||
}
|
||||
|
@ -173,9 +172,8 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
|
|||
public Iterator<CallSiteReference> getPossibleSites(final CGNode src, final CGNode target) {
|
||||
return
|
||||
new FilterIterator<CallSiteReference>(getInterpreter(src).iterateCallSites(src),
|
||||
new Filter<CallSiteReference>() {
|
||||
@Override
|
||||
public boolean accepts(CallSiteReference o) {
|
||||
new Predicate<CallSiteReference>() {
|
||||
@Override public boolean test(CallSiteReference o) {
|
||||
return getPossibleTargets(src, o).contains(target);
|
||||
}
|
||||
});
|
||||
|
@ -296,10 +294,9 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
|
|||
return getPossibleTargets(n, outer).iterator();
|
||||
}
|
||||
},
|
||||
new Filter<CGNode>() {
|
||||
new Predicate<CGNode>() {
|
||||
private final MutableIntSet nodes = IntSetUtil.make();
|
||||
@Override
|
||||
public boolean accepts(CGNode o) {
|
||||
@Override public boolean test(CGNode o) {
|
||||
if (nodes.contains(o.getGraphNodeId())) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
@ -33,7 +33,7 @@ import com.ibm.wala.ssa.ISSABasicBlock;
|
|||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.IntMapIterator;
|
||||
|
@ -187,9 +187,8 @@ public class ExplicitCallGraph extends BasicCallGraph<SSAContextInterpreter> imp
|
|||
*/
|
||||
protected Iterator<CallSiteReference> getPossibleSites(final CGNode to) {
|
||||
final int n = getCallGraph().getNumber(to);
|
||||
return new FilterIterator<CallSiteReference>(iterateCallSites(), new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
return new FilterIterator<CallSiteReference>(iterateCallSites(), new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
IntSet s = getPossibleTargetNumbers((CallSiteReference) o);
|
||||
return s == null ? false : s.contains(n);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.ibm.wala.ipa.callgraph.CallGraph;
|
|||
import com.ibm.wala.ipa.callgraph.Context;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.types.MethodReference;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
|
@ -53,9 +53,8 @@ public class PartialCallGraph extends DelegatingGraph<CGNode> implements CallGra
|
|||
* @param nodes set of nodes that will be included in the new, partial call graph
|
||||
*/
|
||||
public static PartialCallGraph make(final CallGraph cg, final Collection<CGNode> partialRoots, final Collection<CGNode> nodes) {
|
||||
Graph<CGNode> partialGraph = GraphSlicer.prune(cg, new Filter<CGNode>() {
|
||||
@Override
|
||||
public boolean accepts(CGNode o) {
|
||||
Graph<CGNode> partialGraph = GraphSlicer.prune(cg, new Predicate<CGNode>() {
|
||||
@Override public boolean test(CGNode o) {
|
||||
return nodes.contains(o);
|
||||
}
|
||||
});
|
||||
|
@ -70,9 +69,8 @@ public class PartialCallGraph extends DelegatingGraph<CGNode> implements CallGra
|
|||
*/
|
||||
public static PartialCallGraph make(CallGraph cg, Collection<CGNode> partialRoots) {
|
||||
final Set<CGNode> nodes = DFS.getReachableNodes(cg, partialRoots);
|
||||
Graph<CGNode> partialGraph = GraphSlicer.prune(cg, new Filter<CGNode>() {
|
||||
@Override
|
||||
public boolean accepts(CGNode o) {
|
||||
Graph<CGNode> partialGraph = GraphSlicer.prune(cg, new Predicate<CGNode>() {
|
||||
@Override public boolean test(CGNode o) {
|
||||
return nodes.contains(o);
|
||||
}
|
||||
});
|
||||
|
@ -119,9 +117,8 @@ public class PartialCallGraph extends DelegatingGraph<CGNode> implements CallGra
|
|||
|
||||
@Override
|
||||
public Iterator<CGNode> iterateNodes(IntSet nodes) {
|
||||
return new FilterIterator<CGNode>(cg.iterateNodes(nodes), new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
return new FilterIterator<CGNode>(cg.iterateNodes(nodes), new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
return containsNode((CGNode) o);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ import com.ibm.wala.classLoader.NewSiteReference;
|
|||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
import com.ibm.wala.ipa.callgraph.Context;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.MapIterator;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
|
@ -96,9 +96,8 @@ public class AllocationSite implements InstanceKey {
|
|||
return new MapIterator<CGNode, Pair<CGNode, NewSiteReference>>(
|
||||
new FilterIterator<CGNode>(
|
||||
CG.getNodes(method.getReference()).iterator(),
|
||||
new Filter<CGNode>() {
|
||||
@Override
|
||||
public boolean accepts(CGNode o) {
|
||||
new Predicate<CGNode>() {
|
||||
@Override public boolean test(CGNode o) {
|
||||
return o.getMethod().equals(method);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import com.ibm.wala.ssa.IR;
|
|||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.collections.ComposedIterator;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.MapIterator;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
|
@ -111,9 +111,8 @@ public final class ConcreteTypeKey implements InstanceKey {
|
|||
return new MapIterator<NewSiteReference, Pair<CGNode, NewSiteReference>>(
|
||||
new FilterIterator<NewSiteReference>(
|
||||
outer.iterateNewSites(),
|
||||
new Filter<NewSiteReference>() {
|
||||
@Override
|
||||
public boolean accepts(NewSiteReference o) {
|
||||
new Predicate<NewSiteReference>() {
|
||||
@Override public boolean test(NewSiteReference o) {
|
||||
return o.getDeclaredType().equals(type.getReference());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ package com.ibm.wala.ipa.callgraph.propagation;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.IVector;
|
||||
import com.ibm.wala.util.collections.SimpleVector;
|
||||
|
@ -201,9 +201,8 @@ public class PointsToMap {
|
|||
* @return Iterator<PointerKey>
|
||||
*/
|
||||
public Iterator<PointerKey> getTransitiveRoots() {
|
||||
return new FilterIterator<PointerKey>(iterateKeys(), new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
return new FilterIterator<PointerKey>(iterateKeys(), new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
return isTransitiveRoot((PointerKey) o);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -27,7 +27,7 @@ import com.ibm.wala.fixpoint.UnaryOperator;
|
|||
import com.ibm.wala.fixpoint.UnaryStatement;
|
||||
import com.ibm.wala.util.collections.CompoundIterator;
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.SmallMap;
|
||||
|
@ -276,9 +276,8 @@ public class PropagationGraph implements IFixedPointSystem<PointsToSetVariable>
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator<AbstractStatement> getStatements() {
|
||||
Iterator<AbstractStatement> it = new FilterIterator(delegateGraph.iterator(), new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object x) {
|
||||
Iterator<AbstractStatement> it = new FilterIterator(delegateGraph.iterator(), new Predicate() {
|
||||
@Override public boolean test(Object x) {
|
||||
return x instanceof AbstractStatement;
|
||||
}
|
||||
});
|
||||
|
@ -769,9 +768,8 @@ public class PropagationGraph implements IFixedPointSystem<PointsToSetVariable>
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator<PointsToSetVariable> getVariables() {
|
||||
Iterator<PointsToSetVariable> it = new FilterIterator(delegateGraph.iterator(), new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object x) {
|
||||
Iterator<PointsToSetVariable> it = new FilterIterator(delegateGraph.iterator(), new Predicate() {
|
||||
@Override public boolean test(Object x) {
|
||||
return x instanceof IVariable;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.ibm.wala.classLoader.IClass;
|
|||
import com.ibm.wala.classLoader.NewSiteReference;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.MapIterator;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
|
@ -59,9 +59,8 @@ public class SmushedAllocationSiteInNode extends AbstractTypeInNode {
|
|||
return new MapIterator<NewSiteReference,Pair<CGNode, NewSiteReference>>(
|
||||
new FilterIterator<NewSiteReference>(
|
||||
getNode().iterateNewSites(),
|
||||
new Filter<NewSiteReference>() {
|
||||
@Override
|
||||
public boolean accepts(NewSiteReference o) {
|
||||
new Predicate<NewSiteReference>() {
|
||||
@Override public boolean test(NewSiteReference o) {
|
||||
return o.getDeclaredType().equals(getConcreteType().getReference());
|
||||
}
|
||||
}),
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.ibm.wala.ipa.callgraph.CallGraph;
|
|||
import com.ibm.wala.ssa.ISSABasicBlock;
|
||||
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.IndiscriminateFilter;
|
||||
import com.ibm.wala.util.collections.MapIterator;
|
||||
|
@ -65,7 +65,7 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
|
|||
/**
|
||||
* Filter that determines relevant call graph nodes
|
||||
*/
|
||||
private final Filter<CGNode> relevant;
|
||||
private final Predicate<CGNode> relevant;
|
||||
|
||||
/**
|
||||
* a cache: for each node (Basic Block), does that block end in a call?
|
||||
|
@ -133,7 +133,7 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
|
|||
* @param CG the call graph
|
||||
* @param relevant a filter which accepts those call graph nodes which should be included in the I-CFG. Other nodes are ignored.
|
||||
*/
|
||||
public AbstractInterproceduralCFG(CallGraph CG, Filter<CGNode> relevant) {
|
||||
public AbstractInterproceduralCFG(CallGraph CG, Predicate<CGNode> relevant) {
|
||||
|
||||
this.cg = CG;
|
||||
this.relevant = relevant;
|
||||
|
@ -146,7 +146,7 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
|
|||
* @param n
|
||||
*/
|
||||
private void addIntraproceduralNodesAndEdgesForCGNodeIfNeeded(CGNode n) {
|
||||
if (!cgNodesVisited.contains(cg.getNumber(n)) && relevant.accepts(n)) {
|
||||
if (!cgNodesVisited.contains(cg.getNumber(n)) && relevant.test(n)) {
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
System.err.println("Adding nodes and edges for cg node: " + n);
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
|
|||
if (DEBUG_LEVEL > 1) {
|
||||
System.err.println("got caller " + caller);
|
||||
}
|
||||
if (relevant.accepts(caller)) {
|
||||
if (relevant.test(caller)) {
|
||||
addEntryAndExitEdgesToCaller(n, entryBlock, exitBlock, caller);
|
||||
}
|
||||
}
|
||||
|
@ -493,7 +493,7 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
|
|||
boolean irrelevantTargets = false;
|
||||
for (Iterator ts = cg.getPossibleTargets(n, site).iterator(); ts.hasNext();) {
|
||||
CGNode tn = (CGNode) ts.next();
|
||||
if (!relevant.accepts(tn)) {
|
||||
if (!relevant.test(tn)) {
|
||||
if (DEBUG_LEVEL > 1) {
|
||||
System.err.println("Irrelevant target: " + tn);
|
||||
}
|
||||
|
@ -834,9 +834,8 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
|
|||
|
||||
// a successor node is a return site if it is in the same
|
||||
// procedure, and is not the entry() node.
|
||||
Filter isReturn = new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
Predicate isReturn = new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
BasicBlockInContext other = (BasicBlockInContext) o;
|
||||
return !other.isEntryBlock() && node.equals(other.getNode());
|
||||
}
|
||||
|
@ -856,9 +855,8 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
|
|||
Iterator<? extends T> it = cfg.getPredNodes(returnBlock.getDelegate());
|
||||
final CGNode node = returnBlock.getNode();
|
||||
|
||||
Filter<? extends T> dispatchFilter = new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T callBlock) {
|
||||
Predicate<? extends T> dispatchFilter = new Predicate<T>() {
|
||||
@Override public boolean test(T callBlock) {
|
||||
BasicBlockInContext<T> bb = new BasicBlockInContext<T>(node, callBlock);
|
||||
if (!hasCall(bb, cfg)) {
|
||||
return false;
|
||||
|
@ -883,9 +881,8 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
|
|||
return new FilterIterator<BasicBlockInContext<T>>(m, isCall);
|
||||
}
|
||||
|
||||
private final Filter<BasicBlockInContext<T>> isCall = new Filter<BasicBlockInContext<T>>() {
|
||||
@Override
|
||||
public boolean accepts(BasicBlockInContext<T> o) {
|
||||
private final Predicate<BasicBlockInContext<T>> isCall = new Predicate<BasicBlockInContext<T>>() {
|
||||
@Override public boolean test(BasicBlockInContext<T> o) {
|
||||
return hasCall(o);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@ import com.ibm.wala.ssa.IR;
|
|||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.analysis.ExplodedControlFlowGraph;
|
||||
import com.ibm.wala.ssa.analysis.IExplodedBasicBlock;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ public class ExplodedInterproceduralCFG extends AbstractInterproceduralCFG<IExpl
|
|||
super(cg);
|
||||
}
|
||||
|
||||
public ExplodedInterproceduralCFG(CallGraph cg, Filter<CGNode> filter) {
|
||||
public ExplodedInterproceduralCFG(CallGraph cg, Predicate<CGNode> filter) {
|
||||
super(cg, filter);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.util.Set;
|
|||
import com.ibm.wala.cfg.ControlFlowGraph;
|
||||
import com.ibm.wala.cfg.IBasicBlock;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.Iterator2Collection;
|
||||
import com.ibm.wala.util.graph.AbstractNumberedGraph;
|
||||
|
@ -69,36 +69,32 @@ public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGrap
|
|||
}
|
||||
|
||||
public Iterator<T> getExceptionalSuccessors(final T N) {
|
||||
return new FilterIterator<T>(cfg.getExceptionalSuccessors(N).iterator(), new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return new FilterIterator<T>(cfg.getExceptionalSuccessors(N).iterator(), new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return currentCFGNodes.containsNode(o) && filter.hasExceptionalEdge(N, o);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Iterator<T> getNormalSuccessors(final T N) {
|
||||
return new FilterIterator<T>(cfg.getNormalSuccessors(N).iterator(), new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return new FilterIterator<T>(cfg.getNormalSuccessors(N).iterator(), new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return currentCFGNodes.containsNode(o) && filter.hasNormalEdge(N, o);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Iterator<T> getExceptionalPredecessors(final T N) {
|
||||
return new FilterIterator<T>(cfg.getExceptionalPredecessors(N).iterator(), new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return new FilterIterator<T>(cfg.getExceptionalPredecessors(N).iterator(), new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return currentCFGNodes.containsNode(o) && filter.hasExceptionalEdge(o, N);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Iterator<T> getNormalPredecessors(final T N) {
|
||||
return new FilterIterator<T>(cfg.getNormalPredecessors(N).iterator(), new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return new FilterIterator<T>(cfg.getNormalPredecessors(N).iterator(), new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return currentCFGNodes.containsNode(o) && filter.hasNormalEdge(o, N);
|
||||
}
|
||||
});
|
||||
|
@ -106,9 +102,8 @@ public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGrap
|
|||
|
||||
@Override
|
||||
public Iterator<T> getSuccNodes(final T N) {
|
||||
return new FilterIterator<T>(cfg.getSuccNodes(N), new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return new FilterIterator<T>(cfg.getSuccNodes(N), new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return currentCFGNodes.containsNode(o) && (filter.hasNormalEdge(N, o) || filter.hasExceptionalEdge(N, o));
|
||||
}
|
||||
});
|
||||
|
@ -131,9 +126,8 @@ public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGrap
|
|||
|
||||
@Override
|
||||
public Iterator<T> getPredNodes(final T N) {
|
||||
return new FilterIterator<T>(cfg.getPredNodes(N), new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return new FilterIterator<T>(cfg.getPredNodes(N), new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return currentCFGNodes.containsNode(o) && (filter.hasNormalEdge(o, N) || filter.hasExceptionalEdge(o, N));
|
||||
}
|
||||
});
|
||||
|
@ -232,9 +226,8 @@ public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGrap
|
|||
}
|
||||
|
||||
private Iterator<T> filterNodes(Iterator nodeIterator) {
|
||||
return new FilterIterator<T>(nodeIterator, new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
return new FilterIterator<T>(nodeIterator, new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
return subset.contains(o);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -45,7 +45,7 @@ import com.ibm.wala.ssa.analysis.ExplodedControlFlowGraph;
|
|||
import com.ibm.wala.ssa.analysis.IExplodedBasicBlock;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.CancelRuntimeException;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.Iterator2Collection;
|
||||
|
@ -645,9 +645,8 @@ public class HeapReachingDefs {
|
|||
return null;
|
||||
} else {
|
||||
// only static fields are actually killed
|
||||
Filter staticFilter = new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
Predicate staticFilter = new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
return o instanceof StaticFieldKey;
|
||||
}
|
||||
};
|
||||
|
@ -656,10 +655,9 @@ public class HeapReachingDefs {
|
|||
if (kill.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
Filter f = new Filter() {
|
||||
Predicate f = new Predicate() {
|
||||
// accept any statement which writes a killed location.
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
@Override public boolean test(Object o) {
|
||||
Statement s = (Statement) o;
|
||||
Collection m = getMod(s, node, heapModel, pa, exclusions);
|
||||
for (PointerKey k : kill) {
|
||||
|
|
|
@ -52,7 +52,7 @@ import com.ibm.wala.ssa.SSAPhiInstruction;
|
|||
import com.ibm.wala.ssa.SSAPiInstruction;
|
||||
import com.ibm.wala.ssa.SSAReturnInstruction;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
|
@ -674,9 +674,8 @@ public class PDG implements NumberedGraph<Statement> {
|
|||
|
||||
// in reaching defs calculation, exclude heap statements that are
|
||||
// irrelevant.
|
||||
Filter f = new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
Predicate f = new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
if (o instanceof HeapStatement) {
|
||||
HeapStatement h = (HeapStatement) o;
|
||||
return h.getLocation().equals(pk);
|
||||
|
@ -767,9 +766,8 @@ public class PDG implements NumberedGraph<Statement> {
|
|||
* @return Statements representing each return instruction in the ir
|
||||
*/
|
||||
private Collection<NormalStatement> computeReturnStatements(final IR ir) {
|
||||
Filter filter = new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
Predicate filter = new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
if (o instanceof NormalStatement) {
|
||||
NormalStatement s = (NormalStatement) o;
|
||||
SSAInstruction st = ir.getInstructions()[s.getInstructionIndex()];
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.ibm.wala.ipa.callgraph.CGNode;
|
|||
import com.ibm.wala.ipa.slicer.Slicer.ControlDependenceOptions;
|
||||
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
|
@ -97,9 +97,8 @@ class SDGSupergraph implements ISupergraph<Statement, PDG> {
|
|||
public Iterator<? extends Statement> getCalledNodes(Statement call) {
|
||||
switch (call.getKind()) {
|
||||
case NORMAL:
|
||||
Filter f = new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
Predicate f = new Predicate() {
|
||||
@Override public boolean test(Object o) {
|
||||
Statement s = (Statement) o;
|
||||
return isEntry(s);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
|
|||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
import com.ibm.wala.util.collections.CollectionFilter;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.GraphSlicer;
|
||||
|
@ -106,9 +106,8 @@ public class SWTTypeHierarchy {
|
|||
* Restrict g to nodes from the Application loader
|
||||
*/
|
||||
static Graph<IClass> pruneForAppLoader(Graph<IClass> g) throws WalaException {
|
||||
Filter<IClass> f = new Filter<IClass>() {
|
||||
@Override
|
||||
public boolean accepts(IClass c) {
|
||||
Predicate<IClass> f = new Predicate<IClass>() {
|
||||
@Override public boolean test(IClass c) {
|
||||
return (c.getClassLoader().getReference().equals(ClassLoaderReference.Application));
|
||||
}
|
||||
};
|
||||
|
@ -116,9 +115,9 @@ public class SWTTypeHierarchy {
|
|||
}
|
||||
|
||||
/**
|
||||
* Remove from a graph g any nodes that are not accepted by a {@link Filter}
|
||||
* Remove from a graph g any nodes that are not accepted by a {@link Predicate}
|
||||
*/
|
||||
public static <T> Graph<T> pruneGraph(Graph<T> g, Filter<T> f) throws WalaException {
|
||||
public static <T> Graph<T> pruneGraph(Graph<T> g, Predicate<T> f) throws WalaException {
|
||||
Collection<T> slice = GraphSlicer.slice(g, f);
|
||||
return GraphSlicer.prune(g, new CollectionFilter<T>(slice));
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import com.ibm.wala.ssa.SSAInstruction;
|
|||
import com.ibm.wala.ssa.SSAPhiInstruction;
|
||||
import com.ibm.wala.ssa.analysis.IExplodedBasicBlock;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.GraphSlicer;
|
||||
|
@ -176,9 +176,8 @@ public class ViewIFDSLocalAction<T, P, F> extends Action {
|
|||
|
||||
try {
|
||||
final P proc = getProcedureForSelection();
|
||||
Filter<T> filter = new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
Predicate<T> filter = new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return supergraph.getProcOf(o).equals(proc);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@ import com.ibm.wala.fixpoint.IFixedPointSystem;
|
|||
import com.ibm.wala.fixpoint.IVariable;
|
||||
import com.ibm.wala.fixpoint.UnaryStatement;
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
@ -95,9 +95,8 @@ public class DefaultFixedPointSystem<T extends IVariable<?>> implements IFixedPo
|
|||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public Iterator<AbstractStatement> getStatements() {
|
||||
return new FilterIterator(graph.iterator(), new Filter() {
|
||||
@Override
|
||||
public boolean accepts(Object x) {
|
||||
return new FilterIterator(graph.iterator(), new Predicate() {
|
||||
@Override public boolean test(Object x) {
|
||||
return x instanceof AbstractStatement;
|
||||
}
|
||||
});
|
||||
|
@ -258,9 +257,8 @@ public class DefaultFixedPointSystem<T extends IVariable<?>> implements IFixedPo
|
|||
|
||||
@Override
|
||||
public Iterator<T> getVariables() {
|
||||
return new FilterIterator<T>(graph.iterator(), new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T x) {
|
||||
return new FilterIterator<T>(graph.iterator(), new Predicate<T>() {
|
||||
@Override public boolean test(T x) {
|
||||
return x instanceof IVariable;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
package com.ibm.wala.util.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.ibm.wala.util.Predicate;
|
||||
|
||||
/**
|
||||
* A filter defined by set membership
|
||||
*/
|
||||
public class CollectionFilter<T> implements Filter<T> {
|
||||
public class CollectionFilter<T> extends Predicate<T> {
|
||||
|
||||
private final Collection<? extends T> S;
|
||||
|
||||
|
@ -31,8 +31,7 @@ public class CollectionFilter<T> implements Filter<T> {
|
|||
/*
|
||||
* @see com.ibm.wala.util.Filter#accepts(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
@Override public boolean test(T o) {
|
||||
return S.contains(o);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.util.collections;
|
||||
|
||||
/**
|
||||
* Simple interface for an intensional set definition.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Filter<T> {
|
||||
/**
|
||||
* @return true iff o is in the set defined by this filter
|
||||
*/
|
||||
public boolean accepts(T o);
|
||||
}
|
|
@ -13,6 +13,8 @@ package com.ibm.wala.util.collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.ibm.wala.util.Predicate;
|
||||
|
||||
/**
|
||||
* A <code>FilterIterator</code> filters an <code>Iterator</code> to generate a new one.
|
||||
*/
|
||||
|
@ -20,7 +22,7 @@ public class FilterIterator<T> implements java.util.Iterator<T> {
|
|||
final Iterator<?> i;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
final Filter f;
|
||||
final Predicate f;
|
||||
|
||||
private T next = null;
|
||||
|
||||
|
@ -31,7 +33,7 @@ public class FilterIterator<T> implements java.util.Iterator<T> {
|
|||
* @param f a filter which defines which elements belong to the generated iterator
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public FilterIterator(Iterator<?> i, Filter f) {
|
||||
public FilterIterator(Iterator<?> i, Predicate f) {
|
||||
if (i == null) {
|
||||
throw new IllegalArgumentException("null i");
|
||||
}
|
||||
|
@ -50,7 +52,7 @@ public class FilterIterator<T> implements java.util.Iterator<T> {
|
|||
private void advance() {
|
||||
while (i.hasNext()) {
|
||||
Object o = i.next();
|
||||
if (f.accepts(o)) {
|
||||
if (f.test(o)) {
|
||||
next = (T) o;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -18,19 +18,19 @@ import com.ibm.wala.util.Predicate;
|
|||
@Deprecated
|
||||
public class FilterPredicate<T> extends Predicate<T> {
|
||||
|
||||
public static <T> FilterPredicate<T> toPredicate(Filter<T> f) {
|
||||
public static <T> FilterPredicate<T> toPredicate(Predicate<T> f) {
|
||||
return new FilterPredicate<T>(f);
|
||||
}
|
||||
|
||||
private final Filter<T> f;
|
||||
private final Predicate<T> f;
|
||||
|
||||
private FilterPredicate(Filter<T> f) {
|
||||
private FilterPredicate(Predicate<T> f) {
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return f.accepts(t);
|
||||
return f.test(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,16 +10,17 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.util.collections;
|
||||
|
||||
import com.ibm.wala.util.Predicate;
|
||||
|
||||
/**
|
||||
* intersection of two filters
|
||||
*/
|
||||
public class Filtersection<T> implements Filter<T> {
|
||||
|
||||
final private Filter<T> a;
|
||||
final private Filter<T> b;
|
||||
|
||||
public Filtersection(Filter<T> a, Filter<T> b) {
|
||||
public class Filtersection<T> extends Predicate<T> {
|
||||
|
||||
final private Predicate<T> a;
|
||||
final private Predicate<T> b;
|
||||
|
||||
public Filtersection(Predicate<T> a, Predicate<T> b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
if (a == null) {
|
||||
|
@ -31,8 +32,8 @@ public class Filtersection<T> implements Filter<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return a.accepts(o) && b.accepts(o);
|
||||
public boolean test(T o) {
|
||||
return a.test(o) && b.test(o);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
*******************************************************************************/
|
||||
|
||||
package com.ibm.wala.util.collections;
|
||||
|
||||
import com.ibm.wala.util.Predicate;
|
||||
|
||||
/**
|
||||
* A filter that accepts everything.
|
||||
*/
|
||||
public class IndiscriminateFilter<T> implements Filter<T> {
|
||||
public class IndiscriminateFilter<T> extends Predicate<T> {
|
||||
|
||||
public static <T> IndiscriminateFilter<T> singleton() {
|
||||
return new IndiscriminateFilter<T>();
|
||||
|
@ -24,8 +24,7 @@ public class IndiscriminateFilter<T> implements Filter<T> {
|
|||
/*
|
||||
* @see com.ibm.wala.util.Filter#accepts(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean accepts(Object o) {
|
||||
@Override public boolean test(Object o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ package com.ibm.wala.util.collections;
|
|||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.util.functions.Function;
|
||||
|
||||
import com.ibm.wala.util.Predicate;
|
||||
/**
|
||||
* utilities dealing with Iterators
|
||||
*/
|
||||
|
@ -49,9 +49,8 @@ public class IteratorUtil {
|
|||
@SuppressWarnings("deprecation")
|
||||
public static <T, S extends T> Iterator<S> filter(Iterator<T> iterator, final Class<S> cls) {
|
||||
return new MapIterator<T,S>(
|
||||
new FilterIterator<T>(iterator, new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
new FilterIterator<T>(iterator, new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return cls.isInstance(o);
|
||||
}
|
||||
}),
|
||||
|
|
|
@ -10,29 +10,30 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.util.collections;
|
||||
|
||||
import com.ibm.wala.util.Predicate;
|
||||
|
||||
/**
|
||||
* A filter "A or B"
|
||||
*/
|
||||
public class OrFilter<T> implements Filter<T> {
|
||||
public class OrFilter<T> extends Predicate<T> {
|
||||
|
||||
public static <T> OrFilter<T> createOrFilter(Filter<T> a, Filter<T> b) {
|
||||
public static <T> OrFilter<T> createOrFilter(Predicate<T> a, Predicate<T> b) {
|
||||
if (a == null || b == null) {
|
||||
throw new IllegalArgumentException("cannot compose null filter");
|
||||
}
|
||||
return new OrFilter<T>(a, b);
|
||||
}
|
||||
|
||||
private final Filter<T> a;
|
||||
private final Filter<T> b;
|
||||
private final Predicate<T> a;
|
||||
private final Predicate<T> b;
|
||||
|
||||
private OrFilter(Filter<T> a, Filter<T> b) {
|
||||
private OrFilter(Predicate<T> a, Predicate<T> b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return a.accepts(o) || b.accepts(o);
|
||||
@Override public boolean test(T o) {
|
||||
return a.test(o) || b.test(o);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import com.ibm.wala.fixpoint.BitVectorVariable;
|
|||
import com.ibm.wala.fixpoint.UnaryOperator;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.Iterator2Collection;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
@ -58,7 +58,7 @@ public class GraphReachability<T, S> {
|
|||
* @param filter "interesting" node definition
|
||||
* @throws IllegalArgumentException if g is null
|
||||
*/
|
||||
public GraphReachability(Graph<T> g, Filter<?> filter) {
|
||||
public GraphReachability(Graph<T> g, Predicate<?> filter) {
|
||||
if (g == null) {
|
||||
throw new IllegalArgumentException("g is null");
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Set;
|
|||
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.FilterPredicate;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
|
@ -61,16 +61,6 @@ public class GraphSlicer {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static <T> Set<T> slice(Graph<T> g, Filter<T> f){
|
||||
return slice(g, FilterPredicate.toPredicate(f));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static <T> Graph<T> prune(final Graph<T> g, final Filter<T> f) {
|
||||
return prune(g, FilterPredicate.toPredicate(f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prune a graph to only the nodes accepted by the {@link Predicate} p
|
||||
|
@ -181,7 +171,7 @@ public class GraphSlicer {
|
|||
return output;
|
||||
}
|
||||
|
||||
public static <E> AbstractGraph<E> project(final Graph<E> G, final Filter<E> fmember) {
|
||||
public static <E> AbstractGraph<E> project(final Graph<E> G, final Predicate<E> fmember) {
|
||||
final NodeManager<E> nodeManager = new NodeManager<E>() {
|
||||
private int count = -1;
|
||||
|
||||
|
@ -192,7 +182,7 @@ public class GraphSlicer {
|
|||
|
||||
@Override
|
||||
public boolean containsNode(E N) {
|
||||
return G.containsNode(N) && fmember.accepts(N);
|
||||
return G.containsNode(N) && fmember.test(N);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.NonNullSingletonIterator;
|
||||
|
@ -44,7 +44,7 @@ public class BFSPathFinder<T> {
|
|||
/**
|
||||
* The Filter which defines the target set of nodes to find
|
||||
*/
|
||||
final private Filter<T> filter;
|
||||
final private Predicate<T> filter;
|
||||
|
||||
/**
|
||||
* an enumeration of all nodes to search from
|
||||
|
@ -56,7 +56,7 @@ public class BFSPathFinder<T> {
|
|||
*
|
||||
* @param G the graph whose nodes to enumerate
|
||||
*/
|
||||
public BFSPathFinder(Graph<T> G, T N, Filter<T> f) {
|
||||
public BFSPathFinder(Graph<T> G, T N, Predicate<T> f) {
|
||||
if (G == null) {
|
||||
throw new IllegalArgumentException("G is null");
|
||||
}
|
||||
|
@ -83,9 +83,8 @@ public class BFSPathFinder<T> {
|
|||
if (!G.containsNode(src)) {
|
||||
throw new IllegalArgumentException("src is not in graph " + src);
|
||||
}
|
||||
this.filter = new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
this.filter = new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return target.equals(o);
|
||||
}
|
||||
};
|
||||
|
@ -108,9 +107,8 @@ public class BFSPathFinder<T> {
|
|||
this.G = G;
|
||||
this.roots = new NonNullSingletonIterator<T>(src);
|
||||
|
||||
this.filter = new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
this.filter = new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return ts.contains(o);
|
||||
}
|
||||
};
|
||||
|
@ -130,9 +128,8 @@ public class BFSPathFinder<T> {
|
|||
}
|
||||
this.G = G;
|
||||
this.roots = sources;
|
||||
this.filter = new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
this.filter = new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return target.equals(o);
|
||||
}
|
||||
};
|
||||
|
@ -144,7 +141,7 @@ public class BFSPathFinder<T> {
|
|||
*
|
||||
* @param nodes the set of nodes from which to start searching
|
||||
*/
|
||||
public BFSPathFinder(Graph<T> G, Iterator<T> nodes, Filter<T> f) {
|
||||
public BFSPathFinder(Graph<T> G, Iterator<T> nodes, Predicate<T> f) {
|
||||
this.G = G;
|
||||
this.roots = nodes;
|
||||
this.filter = f;
|
||||
|
@ -174,7 +171,7 @@ public class BFSPathFinder<T> {
|
|||
if (DEBUG) {
|
||||
System.err.println(("visit " + N));
|
||||
}
|
||||
if (filter.accepts(N)) {
|
||||
if (filter.test(N)) {
|
||||
return makePath(N, history);
|
||||
}
|
||||
Iterator<? extends T> children = getConnected(N);
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.Set;
|
|||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
|
@ -41,7 +41,7 @@ public class DFS {
|
|||
* @throws IllegalArgumentException if C is null
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static <T> Collection<T> getReachableNodes(final Graph<T> G, Collection<? extends T> C, @SuppressWarnings("rawtypes") final Filter filter) {
|
||||
public static <T> Collection<T> getReachableNodes(final Graph<T> G, Collection<? extends T> C, @SuppressWarnings("rawtypes") final Predicate filter) {
|
||||
if (C == null) {
|
||||
throw new IllegalArgumentException("C is null");
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ package com.ibm.wala.util.graph.traverse;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
|
||||
/**
|
||||
* Extends {@link DFSPathFinder} to discover all paths from a set of root nodes
|
||||
* to nodes passing some {@link Filter}.
|
||||
* to nodes passing some {@link Predicate}.
|
||||
*
|
||||
* Note that this code performs work that is potentially exponential in the size
|
||||
* of the underlying graph, using exponential space. It most likely won't work
|
||||
|
@ -28,20 +28,19 @@ import com.ibm.wala.util.graph.Graph;
|
|||
*/
|
||||
public class DFSAllPathsFinder<T> extends DFSPathFinder<T> {
|
||||
|
||||
public DFSAllPathsFinder(Graph<T> G, Iterator<T> nodes, Filter<T> f) {
|
||||
public DFSAllPathsFinder(Graph<T> G, Iterator<T> nodes, Predicate<T> f) {
|
||||
super(G, nodes, f);
|
||||
}
|
||||
|
||||
public DFSAllPathsFinder(Graph<T> G, T N, Filter<T> f) throws IllegalArgumentException {
|
||||
public DFSAllPathsFinder(Graph<T> G, T N, Predicate<T> f) throws IllegalArgumentException {
|
||||
super(G, N, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterator<? extends T> getConnected(T n) {
|
||||
final List<T> cp = currentPath();
|
||||
return new FilterIterator<T>(G.getSuccNodes(n), new Filter<T>() {
|
||||
@Override
|
||||
public boolean accepts(T o) {
|
||||
return new FilterIterator<T>(G.getSuccNodes(n), new Predicate<T>() {
|
||||
@Override public boolean test(T o) {
|
||||
return ! cp.contains(o);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.Predicate;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.NonNullSingletonIterator;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
|
@ -39,7 +39,7 @@ public class DFSPathFinder<T> extends Stack<T> {
|
|||
/**
|
||||
* The Filter which defines the target set of nodes to find
|
||||
*/
|
||||
final private Filter<T> filter;
|
||||
final private Predicate<T> filter;
|
||||
|
||||
/**
|
||||
* an enumeration of all nodes to search from
|
||||
|
@ -62,7 +62,7 @@ public class DFSPathFinder<T> extends Stack<T> {
|
|||
* @param G the graph whose nodes to enumerate
|
||||
* @throws IllegalArgumentException if G is null
|
||||
*/
|
||||
public DFSPathFinder(Graph<T> G, T N, Filter<T> f) throws IllegalArgumentException {
|
||||
public DFSPathFinder(Graph<T> G, T N, Predicate<T> f) throws IllegalArgumentException {
|
||||
if (G == null) {
|
||||
throw new IllegalArgumentException("G is null");
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class DFSPathFinder<T> extends Stack<T> {
|
|||
*
|
||||
* @param nodes the set of nodes from which to start searching
|
||||
*/
|
||||
public DFSPathFinder(Graph<T> G, Iterator<T> nodes, Filter<T> f) {
|
||||
public DFSPathFinder(Graph<T> G, Iterator<T> nodes, Predicate<T> f) {
|
||||
this.G = G;
|
||||
this.roots = nodes;
|
||||
this.filter = f;
|
||||
|
@ -114,7 +114,7 @@ public class DFSPathFinder<T> extends Stack<T> {
|
|||
}
|
||||
while (hasNext()) {
|
||||
T n = peek();
|
||||
if (filter.accepts(n)) {
|
||||
if (filter.test(n)) {
|
||||
List<T> path = currentPath();
|
||||
advance();
|
||||
return path;
|
||||
|
|
Loading…
Reference in New Issue