introduce factory for Iterator2Collection
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1308 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
c6cda8b431
commit
6421783e52
|
@ -145,7 +145,7 @@ public abstract class AbstractCFG implements ControlFlowGraph, Constants {
|
|||
boolean exceptionalIn = getNumberOfExceptionalIn(N) > 0;
|
||||
if (normalIn) {
|
||||
if (exceptionalIn) {
|
||||
return new Iterator2Collection<IBasicBlock>(getPredNodes(N)).size();
|
||||
return Iterator2Collection.toCollection(getPredNodes(N)).size();
|
||||
} else {
|
||||
return getNumberOfNormalIn(N);
|
||||
}
|
||||
|
@ -243,8 +243,8 @@ public abstract class AbstractCFG implements ControlFlowGraph, Constants {
|
|||
if (normalIn) {
|
||||
if (exceptionalIn) {
|
||||
HashSet<IBasicBlock> result = new HashSet<IBasicBlock>(getNumberOfNormalIn(N) + getNumberOfExceptionalIn(N));
|
||||
result.addAll(new Iterator2Collection<IBasicBlock>(normalEdgeManager.getPredNodes(N)));
|
||||
result.addAll(new Iterator2Collection<IBasicBlock>(exceptionalEdgeManager.getPredNodes(N)));
|
||||
result.addAll(Iterator2Collection.toCollection(normalEdgeManager.getPredNodes(N)));
|
||||
result.addAll(Iterator2Collection.toCollection(exceptionalEdgeManager.getPredNodes(N)));
|
||||
if (fallThru.get(number - 1)) {
|
||||
result.add(getNode(number - 1));
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ public abstract class AbstractCFG implements ControlFlowGraph, Constants {
|
|||
}
|
||||
|
||||
private int slowCountSuccNodes(IBasicBlock N) {
|
||||
return new Iterator2Collection<IBasicBlock>(getSuccNodes(N)).size();
|
||||
return Iterator2Collection.toCollection(getSuccNodes(N)).size();
|
||||
}
|
||||
|
||||
public Iterator<IBasicBlock> getSuccNodes(IBasicBlock N) {
|
||||
|
@ -580,7 +580,7 @@ public abstract class AbstractCFG implements ControlFlowGraph, Constants {
|
|||
if (b == null) {
|
||||
throw new IllegalArgumentException("b is null");
|
||||
}
|
||||
return new Iterator2Collection<IBasicBlock>(iterateExceptionalSuccessors(b.getNumber()));
|
||||
return Iterator2Collection.toCollection(iterateExceptionalSuccessors(b.getNumber()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -590,7 +590,7 @@ public abstract class AbstractCFG implements ControlFlowGraph, Constants {
|
|||
if (b == null) {
|
||||
throw new IllegalArgumentException("b is null");
|
||||
}
|
||||
return new Iterator2Collection<IBasicBlock>(iterateNormalSuccessors(b.getNumber()));
|
||||
return Iterator2Collection.toCollection(iterateNormalSuccessors(b.getNumber()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -625,7 +625,7 @@ public abstract class AbstractCFG implements ControlFlowGraph, Constants {
|
|||
if (b == null) {
|
||||
throw new IllegalArgumentException("b is null");
|
||||
}
|
||||
return new Iterator2Collection<IBasicBlock>(iterateExceptionalPredecessors(b));
|
||||
return Iterator2Collection.toCollection(iterateExceptionalPredecessors(b));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -635,7 +635,7 @@ public abstract class AbstractCFG implements ControlFlowGraph, Constants {
|
|||
if (b == null) {
|
||||
throw new IllegalArgumentException("b is null");
|
||||
}
|
||||
return new Iterator2Collection<IBasicBlock>(iterateNormalPredecessors(b));
|
||||
return Iterator2Collection.toCollection(iterateNormalPredecessors(b));
|
||||
}
|
||||
|
||||
public IntSet getPredNodeNumbers(IBasicBlock node) {
|
||||
|
|
|
@ -121,7 +121,7 @@ public class ClassLoaderImpl implements IClassLoader {
|
|||
Trace.println("Get source files for " + M);
|
||||
}
|
||||
TreeSet<ModuleEntry> sortedEntries = new TreeSet<ModuleEntry>(HashCodeComparator.instance());
|
||||
sortedEntries.addAll(new Iterator2Collection<ModuleEntry>(M.getEntries()));
|
||||
sortedEntries.addAll(Iterator2Collection.toCollection(M.getEntries()));
|
||||
|
||||
HashSet<ModuleEntry> result = HashSetFactory.make();
|
||||
for (Iterator it = sortedEntries.iterator(); it.hasNext();) {
|
||||
|
@ -154,7 +154,7 @@ public class ClassLoaderImpl implements IClassLoader {
|
|||
Trace.println("Get class files for " + M);
|
||||
}
|
||||
TreeSet<ModuleEntry> sortedEntries = new TreeSet<ModuleEntry>(HashCodeComparator.instance());
|
||||
sortedEntries.addAll(new Iterator2Collection<ModuleEntry>(M.getEntries()));
|
||||
sortedEntries.addAll(Iterator2Collection.toCollection(M.getEntries()));
|
||||
|
||||
HashSet<ModuleEntry> result = HashSetFactory.make();
|
||||
for (Iterator it = sortedEntries.iterator(); it.hasNext();) {
|
||||
|
|
|
@ -88,7 +88,7 @@ public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
|||
public Iterator<T> getCalledNodes(T ret) {
|
||||
if (DEBUG_LEVEL > 1) {
|
||||
Trace.println(getClass() + " getCalledNodes " + ret);
|
||||
Trace.printCollection("called nodes ", new Iterator2Collection<Object>(new FilterIterator<Object>(getSuccNodes(ret), exitFilter)));
|
||||
Trace.printCollection("called nodes ", Iterator2Collection.toCollection(new FilterIterator<Object>(getSuccNodes(ret), exitFilter)));
|
||||
}
|
||||
return new FilterIterator<T>(getSuccNodes(ret), exitFilter);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class ExplodedSupergraphWithSummaryEdges<T> extends ExplodedSupergraph<T>
|
|||
throw new IllegalArgumentException("src is null");
|
||||
}
|
||||
HashSet<ExplodedSupergraphNode<T>> result = HashSetFactory.make(5);
|
||||
result.addAll(new Iterator2Collection<ExplodedSupergraphNode<T>>(super.getSuccNodes(src)));
|
||||
result.addAll(Iterator2Collection.toCollection(super.getSuccNodes(src)));
|
||||
|
||||
// add facts from summary edges
|
||||
if (getSupergraph().isCall(src.getSupergraphNode())) {
|
||||
|
@ -76,7 +76,7 @@ public class ExplodedSupergraphWithSummaryEdges<T> extends ExplodedSupergraph<T>
|
|||
throw new IllegalArgumentException("dest is null");
|
||||
}
|
||||
HashSet<ExplodedSupergraphNode<T>> result = HashSetFactory.make(5);
|
||||
result.addAll(new Iterator2Collection<ExplodedSupergraphNode<T>>(super.getPredNodes(dest)));
|
||||
result.addAll(Iterator2Collection.toCollection(super.getPredNodes(dest)));
|
||||
|
||||
// add facts from summary edges
|
||||
if (getSupergraph().isReturn(dest.getSupergraphNode())) {
|
||||
|
@ -99,7 +99,7 @@ public class ExplodedSupergraphWithSummaryEdges<T> extends ExplodedSupergraph<T>
|
|||
*/
|
||||
@Override
|
||||
public int getPredNodeCount(ExplodedSupergraphNode<T> N) {
|
||||
return new Iterator2Collection<ExplodedSupergraphNode<T>>(getPredNodes(N)).size();
|
||||
return Iterator2Collection.toCollection(getPredNodes(N)).size();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -107,6 +107,6 @@ public class ExplodedSupergraphWithSummaryEdges<T> extends ExplodedSupergraph<T>
|
|||
*/
|
||||
@Override
|
||||
public int getSuccNodeCount(ExplodedSupergraphNode<T> N) {
|
||||
return new Iterator2Collection<ExplodedSupergraphNode<T>>(getSuccNodes(N)).size();
|
||||
return Iterator2Collection.toCollection(getSuccNodes(N)).size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -524,7 +524,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public int getPredNodeCount(Object N) {
|
||||
Collection c = new Iterator2Collection<Object>(getPredNodes(N));
|
||||
Collection c = Iterator2Collection.toCollection(getPredNodes(N));
|
||||
return c.size();
|
||||
}
|
||||
|
||||
|
@ -645,7 +645,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public int getSuccNodeCount(Object N) {
|
||||
Collection c = new Iterator2Collection<Object>(getSuccNodes(N));
|
||||
Collection c = Iterator2Collection.toCollection(getSuccNodes(N));
|
||||
return c.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -570,7 +570,7 @@ public class TabulationSolver<T, P> {
|
|||
// c:= number of the call node
|
||||
final int c = supergraph.getNumber(edge.n);
|
||||
|
||||
final Collection<T> returnSites = new Iterator2Collection<T>(supergraph.getReturnSites(edge.n));
|
||||
final Collection<T> returnSites = Iterator2Collection.toCollection(supergraph.getReturnSites(edge.n));
|
||||
|
||||
// [14 - 16]
|
||||
for (Iterator<? extends T> it = supergraph.getCalledNodes(edge.n); it.hasNext();) {
|
||||
|
|
|
@ -324,9 +324,7 @@ public class JdtUtil {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JavaModelException
|
||||
*/
|
||||
|
||||
public static Collection<String> getTypeParameterNames(IType type) throws JavaModelException {
|
||||
ITypeParameter[] tp = type.getTypeParameters();
|
||||
Collection<String> typeParameterNames = HashSetFactory.make(tp.length);
|
||||
|
|
|
@ -105,7 +105,7 @@ public class LocalLiveRangeAnalysis {
|
|||
* Iterator<SSAInstruction>
|
||||
*/
|
||||
private static Collection<BasicBlock> findBlocks(IR ir, Iterator<SSAInstruction> statements) {
|
||||
Collection<SSAInstruction> s = new Iterator2Collection<SSAInstruction>(statements);
|
||||
Collection<SSAInstruction> s = Iterator2Collection.toCollection(statements);
|
||||
Collection<BasicBlock> result = HashSetFactory.make();
|
||||
outer: for (Iterator it = ir.getControlFlowGraph().iterator(); it.hasNext();) {
|
||||
SSACFG.BasicBlock b = (SSACFG.BasicBlock) it.next();
|
||||
|
|
|
@ -542,7 +542,7 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
|
|||
* @see com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis#iteratePointerKeys()
|
||||
*/
|
||||
public Collection<PointerKey> getPointerKeys() {
|
||||
return new Iterator2Collection<PointerKey>(pointsToMap.iterateKeys());
|
||||
return Iterator2Collection.toCollection(pointsToMap.iterateKeys());
|
||||
}
|
||||
|
||||
public IClassHierarchy getClassHierarchy() {
|
||||
|
|
|
@ -150,7 +150,7 @@ public class PreTransitiveSolver extends AbstractPointsToSolver {
|
|||
}
|
||||
|
||||
// cache the predecessors before unification might screw things up.
|
||||
Iterator2Collection<IVariable> origPred = new Iterator2Collection<IVariable>(ag.getPredNodes(v));
|
||||
Iterator2Collection<? extends IVariable> origPred = Iterator2Collection.toCollection(ag.getPredNodes(v));
|
||||
for (Iterator it = origPred.iterator(); it.hasNext();) {
|
||||
PointsToSetVariable n = (PointsToSetVariable) it.next();
|
||||
|
||||
|
|
|
@ -824,7 +824,7 @@ public class PropagationSystem extends DefaultFixedPointSolver {
|
|||
if (p != pRef) {
|
||||
// pRef is the representative for p.
|
||||
// be careful: cache the defs before mucking with the underlying system
|
||||
for (Iterator d = new Iterator2Collection<AbstractStatement>(getStatementsThatDef(p)).iterator(); d.hasNext();) {
|
||||
for (Iterator d = Iterator2Collection.toCollection(getStatementsThatDef(p)).iterator(); d.hasNext();) {
|
||||
AbstractStatement as = (AbstractStatement) d.next();
|
||||
|
||||
if (as instanceof AssignEquation) {
|
||||
|
@ -841,7 +841,7 @@ public class PropagationSystem extends DefaultFixedPointSolver {
|
|||
}
|
||||
}
|
||||
// be careful: cache the defs before mucking with the underlying system
|
||||
for (Iterator u = new Iterator2Collection<AbstractStatement>(getStatementsThatUse(p)).iterator(); u.hasNext();) {
|
||||
for (Iterator u = Iterator2Collection.toCollection(getStatementsThatUse(p)).iterator(); u.hasNext();) {
|
||||
AbstractStatement as = (AbstractStatement) u.next();
|
||||
if (as instanceof AssignEquation) {
|
||||
AssignEquation assign = (AssignEquation) as;
|
||||
|
|
|
@ -91,7 +91,7 @@ public class ReflectionHandler {
|
|||
}
|
||||
}
|
||||
};
|
||||
Collection<Statement> casts = new Iterator2Collection<Statement>(new FilterIterator<Statement>(slice.iterator(), f));
|
||||
Collection<Statement> casts = Iterator2Collection.toCollection(new FilterIterator<Statement>(slice.iterator(), f));
|
||||
changedNodes.addAll(modifyFactoryInterpreter(st, casts, builder.getContextInterpreter(), builder.getClassHierarchy()));
|
||||
}
|
||||
for (Iterator<CGNode> it = changedNodes.iterator(); it.hasNext();) {
|
||||
|
|
|
@ -152,7 +152,7 @@ public class TypeBasedPointerAnalysis extends AbstractPointerAnalysis {
|
|||
}
|
||||
|
||||
public Collection<PointerKey> getPointerKeys() {
|
||||
return new Iterator2Collection<PointerKey>(heapModel.iteratePointerKeys());
|
||||
return Iterator2Collection.toCollection(heapModel.iteratePointerKeys());
|
||||
}
|
||||
|
||||
public boolean isFiltered(PointerKey pk) {
|
||||
|
|
|
@ -38,12 +38,20 @@ import com.ibm.wala.util.intset.IntSetUtil;
|
|||
import com.ibm.wala.util.intset.MutableIntSet;
|
||||
|
||||
/**
|
||||
* A pruned view of a control flow graph
|
||||
*
|
||||
* A pruned view of a {@link ControlFlowGraph}. Use this class along with
|
||||
* an {@link EdgeFilter} to produce a custom view of a CFG.
|
||||
*
|
||||
* For example, you can use this class to produce a CFG view that ignores certain
|
||||
* types of exceptional edges.
|
||||
*/
|
||||
public class PrunedCFG extends AbstractNumberedGraph<IBasicBlock> implements ControlFlowGraph {
|
||||
|
||||
/**
|
||||
* @param cfg the original CFG that you want a view of
|
||||
* @param filter an object that selectively filters edges in the original CFG
|
||||
* @return a view of cfg that includes only edges accepted by the filter.
|
||||
* @throws IllegalArgumentException if cfg is null
|
||||
*/
|
||||
public static PrunedCFG make(final ControlFlowGraph cfg, final EdgeFilter filter) {
|
||||
if (cfg == null) {
|
||||
throw new IllegalArgumentException("cfg is null");
|
||||
|
@ -101,7 +109,7 @@ public class PrunedCFG extends AbstractNumberedGraph<IBasicBlock> implements Con
|
|||
}
|
||||
|
||||
public int getSuccNodeCount(IBasicBlock N) {
|
||||
return new Iterator2Collection<IBasicBlock>(getSuccNodes(N)).size();
|
||||
return Iterator2Collection.toCollection(getSuccNodes(N)).size();
|
||||
}
|
||||
|
||||
public IntSet getSuccNodeNumbers(IBasicBlock N) {
|
||||
|
@ -118,7 +126,7 @@ public class PrunedCFG extends AbstractNumberedGraph<IBasicBlock> implements Con
|
|||
}
|
||||
|
||||
public int getPredNodeCount(IBasicBlock N) {
|
||||
return new Iterator2Collection<IBasicBlock>(getPredNodes(N)).size();
|
||||
return Iterator2Collection.toCollection(getPredNodes(N)).size();
|
||||
}
|
||||
|
||||
public IntSet getPredNodeNumbers(IBasicBlock N) {
|
||||
|
@ -272,19 +280,19 @@ public class PrunedCFG extends AbstractNumberedGraph<IBasicBlock> implements Con
|
|||
}
|
||||
|
||||
public Collection<IBasicBlock> getExceptionalSuccessors(final IBasicBlock N) {
|
||||
return new Iterator2Collection<IBasicBlock>(edges.getExceptionalSuccessors(N));
|
||||
return Iterator2Collection.toCollection(edges.getExceptionalSuccessors(N));
|
||||
}
|
||||
|
||||
public Collection<IBasicBlock> getNormalSuccessors(final IBasicBlock N) {
|
||||
return new Iterator2Collection<IBasicBlock>(edges.getNormalSuccessors(N));
|
||||
return Iterator2Collection.toCollection(edges.getNormalSuccessors(N));
|
||||
}
|
||||
|
||||
public Collection<IBasicBlock> getExceptionalPredecessors(final IBasicBlock N) {
|
||||
return new Iterator2Collection<IBasicBlock>(edges.getExceptionalPredecessors(N));
|
||||
return Iterator2Collection.toCollection(edges.getExceptionalPredecessors(N));
|
||||
}
|
||||
|
||||
public Collection<IBasicBlock> getNormalPredecessors(final IBasicBlock N) {
|
||||
return new Iterator2Collection<IBasicBlock>(edges.getNormalPredecessors(N));
|
||||
return Iterator2Collection.toCollection(edges.getNormalPredecessors(N));
|
||||
}
|
||||
|
||||
public IBasicBlock entry() {
|
||||
|
|
|
@ -60,7 +60,6 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
*/
|
||||
private final Language language;
|
||||
|
||||
|
||||
final private HashMap<IClass, Node> map = HashMapFactory.make();
|
||||
|
||||
/**
|
||||
|
@ -165,38 +164,46 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
try {
|
||||
int numLoaders = 0;
|
||||
for (ClassLoaderReference ref : scope.getLoaders()) {
|
||||
if (ref.getLanguage().equals(language.getName())) {
|
||||
numLoaders++;
|
||||
}
|
||||
if (ref.getLanguage().equals(language.getName())) {
|
||||
numLoaders++;
|
||||
}
|
||||
}
|
||||
|
||||
loaders = new IClassLoader[numLoaders];
|
||||
int idx = 0;
|
||||
|
||||
progressMonitor.beginTask("Build Class Hierarchy", numLoaders);
|
||||
if (progressMonitor != null) {
|
||||
progressMonitor.beginTask("Build Class Hierarchy", numLoaders);
|
||||
}
|
||||
for (ClassLoaderReference ref : scope.getLoaders()) {
|
||||
if (progressMonitor.isCanceled()) {
|
||||
throw new CancelCHAConstructionException();
|
||||
if (progressMonitor != null) {
|
||||
if (progressMonitor.isCanceled()) {
|
||||
throw new CancelCHAConstructionException();
|
||||
}
|
||||
}
|
||||
|
||||
if (ref.getLanguage().equals(language.getName())) {
|
||||
IClassLoader icl = factory.getLoader(ref, this, scope);
|
||||
loaders[idx++] = icl;
|
||||
addAllClasses(icl, progressMonitor);
|
||||
if (ref.getLanguage().equals(language.getName())) {
|
||||
IClassLoader icl = factory.getLoader(ref, this, scope);
|
||||
loaders[idx++] = icl;
|
||||
addAllClasses(icl, progressMonitor);
|
||||
|
||||
progressMonitor.worked(1);
|
||||
}
|
||||
if (progressMonitor != null) {
|
||||
progressMonitor.worked(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ClassHierarchyException("factory.getLoader failed " + e);
|
||||
} finally {
|
||||
progressMonitor.done(); // In case an exception is thrown.
|
||||
if (progressMonitor != null) {
|
||||
progressMonitor.done(); // In case an exception is thrown.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (root == null) {
|
||||
throw new ClassHierarchyException("failed to load root " + language.getRootType() + " of class hierarchy");
|
||||
}
|
||||
|
||||
|
||||
// perform numbering for subclass tests.
|
||||
numberTree();
|
||||
ReferenceCleanser.registerClassHierarchy(this);
|
||||
|
@ -211,8 +218,10 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
}
|
||||
Collection<IClass> toRemove = HashSetFactory.make();
|
||||
for (Iterator<IClass> it = loader.iterateAllClasses(); it.hasNext();) {
|
||||
if (progressMonitor.isCanceled()) {
|
||||
throw new CancelCHAConstructionException();
|
||||
if (progressMonitor != null) {
|
||||
if (progressMonitor.isCanceled()) {
|
||||
throw new CancelCHAConstructionException();
|
||||
}
|
||||
}
|
||||
IClass klass = it.next();
|
||||
boolean added = addClass(klass);
|
||||
|
@ -221,13 +230,14 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
}
|
||||
}
|
||||
loader.removeAll(toRemove);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param klass
|
||||
* @return true if the add succeeded; false if it failed for some reason
|
||||
* @throws IllegalArgumentException if klass is null
|
||||
* @throws IllegalArgumentException
|
||||
* if klass is null
|
||||
*/
|
||||
public boolean addClass(IClass klass) {
|
||||
if (klass == null) {
|
||||
|
@ -326,7 +336,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
* @param ref
|
||||
* method reference
|
||||
* @return the set of IMethods that this call can resolve to.
|
||||
* @throws IllegalArgumentException if ref is null
|
||||
* @throws IllegalArgumentException
|
||||
* if ref is null
|
||||
*/
|
||||
public Collection<IMethod> getPossibleTargets(MethodReference ref) {
|
||||
if (ref == null) {
|
||||
|
@ -357,7 +368,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Set<IMethod> findOrCreateTargetSet(IClass declaredClass, MethodReference ref) {
|
||||
Map<MethodReference, Set<IMethod>> classCache = (Map<MethodReference, Set<IMethod>>) CacheReference.get(targetCache.get(declaredClass));
|
||||
Map<MethodReference, Set<IMethod>> classCache = (Map<MethodReference, Set<IMethod>>) CacheReference.get(targetCache
|
||||
.get(declaredClass));
|
||||
if (classCache == null) {
|
||||
classCache = HashMapFactory.make(3);
|
||||
targetCache.put(declaredClass, CacheReference.make(classCache));
|
||||
|
@ -441,7 +453,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
*
|
||||
* @param m
|
||||
* @return IMethod, or null if no appropriate receiver is found.
|
||||
* @throws IllegalArgumentException if m is null
|
||||
* @throws IllegalArgumentException
|
||||
* if m is null
|
||||
*/
|
||||
public IMethod resolveMethod(MethodReference m) {
|
||||
if (m == null) {
|
||||
|
@ -458,7 +471,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
/**
|
||||
* @return the canonical FieldReference that represents a given field , or
|
||||
* null if none found
|
||||
* @throws IllegalArgumentException if f is null
|
||||
* @throws IllegalArgumentException
|
||||
* if f is null
|
||||
*/
|
||||
public IField resolveField(FieldReference f) {
|
||||
if (f == null) {
|
||||
|
@ -474,8 +488,10 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
/**
|
||||
* @return the canonical FieldReference that represents a given field , or
|
||||
* null if none found
|
||||
* @throws IllegalArgumentException if f is null
|
||||
* @throws IllegalArgumentException if klass is null
|
||||
* @throws IllegalArgumentException
|
||||
* if f is null
|
||||
* @throws IllegalArgumentException
|
||||
* if klass is null
|
||||
*/
|
||||
public IField resolveField(IClass klass, FieldReference f) {
|
||||
if (klass == null) {
|
||||
|
@ -496,7 +512,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
* @param selector
|
||||
* method signature
|
||||
* @return Method resolved method abstraction
|
||||
* @throws IllegalArgumentException if receiverClass is null
|
||||
* @throws IllegalArgumentException
|
||||
* if receiverClass is null
|
||||
*/
|
||||
public IMethod resolveMethod(IClass receiverClass, Selector selector) {
|
||||
if (receiverClass == null) {
|
||||
|
@ -688,7 +705,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException if A is null
|
||||
* @throws IllegalArgumentException
|
||||
* if A is null
|
||||
*/
|
||||
public IClass getLeastCommonSuperclass(IClass A, IClass B) {
|
||||
|
||||
|
@ -761,7 +779,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
* Load a class using one of the loaders specified for this class hierarchy
|
||||
*
|
||||
* @return null if can't find the class.
|
||||
* @throws IllegalArgumentException if A is null
|
||||
* @throws IllegalArgumentException
|
||||
* if A is null
|
||||
*/
|
||||
public IClass lookupClass(TypeReference A) {
|
||||
if (A == null) {
|
||||
|
@ -829,7 +848,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
|
||||
private final static Atom syntheticLoaderName = Atom.findOrCreateUnicodeAtom("Synthetic");
|
||||
|
||||
private final static ClassLoaderReference syntheticLoaderRef = new ClassLoaderReference(syntheticLoaderName, Language.JAVA.getName());
|
||||
private final static ClassLoaderReference syntheticLoaderRef = new ClassLoaderReference(syntheticLoaderName, Language.JAVA
|
||||
.getName());
|
||||
|
||||
public boolean isSyntheticClass(IClass c) {
|
||||
if (c == null) {
|
||||
|
@ -840,7 +860,9 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
|
||||
/**
|
||||
* Is c a subclass of T?
|
||||
* @throws IllegalArgumentException if c is null
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if c is null
|
||||
*/
|
||||
public boolean isSubclassOf(IClass c, IClass T) {
|
||||
if (c == null) {
|
||||
|
@ -1075,7 +1097,7 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
return n.klass;
|
||||
}
|
||||
};
|
||||
return new Iterator2Collection<IClass>(new MapIterator<Node, IClass>(findNode(klass).children.iterator(), node2Class));
|
||||
return Iterator2Collection.toCollection(new MapIterator<Node, IClass>(findNode(klass).children.iterator(), node2Class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1083,16 +1105,16 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
* @param warnings
|
||||
* @return a ClassHierarchy object representing the analysis scope
|
||||
* @throws ClassHierarchyException
|
||||
* @throws NullPointerException if scope is null
|
||||
* @throws NullPointerException
|
||||
* if scope is null
|
||||
*/
|
||||
public static ClassHierarchy make(AnalysisScope scope, WarningSet warnings) throws NullPointerException, ClassHierarchyException {
|
||||
return make(scope, new ClassLoaderFactoryImpl(scope.getExclusions(), warnings), warnings);
|
||||
}
|
||||
|
||||
/**
|
||||
* temporarily marking this internal to avoid infinite sleep with
|
||||
* randomly chosen IProgressMonitor.
|
||||
* TODO: nanny for testgen
|
||||
* temporarily marking this internal to avoid infinite sleep with randomly
|
||||
* chosen IProgressMonitor. TODO: nanny for testgen
|
||||
*/
|
||||
@Internal
|
||||
public static ClassHierarchy make(AnalysisScope scope, WarningSet warnings, IProgressMonitor monitor)
|
||||
|
@ -1106,9 +1128,8 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
}
|
||||
|
||||
/**
|
||||
* temporarily marking this internal to avoid infinite sleep with
|
||||
* randomly chosen IProgressMonitor.
|
||||
* TODO: nanny for testgen
|
||||
* temporarily marking this internal to avoid infinite sleep with randomly
|
||||
* chosen IProgressMonitor. TODO: nanny for testgen
|
||||
*/
|
||||
@Internal
|
||||
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings, IProgressMonitor monitor)
|
||||
|
@ -1116,19 +1137,18 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
return new ClassHierarchy(scope, factory, warnings, monitor);
|
||||
}
|
||||
|
||||
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings,
|
||||
Language language) throws ClassHierarchyException {
|
||||
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings, Language language)
|
||||
throws ClassHierarchyException {
|
||||
return new ClassHierarchy(scope, factory, warnings, language, new NullProgressMonitor());
|
||||
}
|
||||
|
||||
/**
|
||||
* temporarily marking this internal to avoid infinite sleep with
|
||||
* randomly chosen IProgressMonitor.
|
||||
* TODO: nanny for testgen
|
||||
* temporarily marking this internal to avoid infinite sleep with randomly
|
||||
* chosen IProgressMonitor. TODO: nanny for testgen
|
||||
*/
|
||||
@Internal
|
||||
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings,
|
||||
Language language, IProgressMonitor monitor) throws ClassHierarchyException {
|
||||
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings, Language language,
|
||||
IProgressMonitor monitor) throws ClassHierarchyException {
|
||||
return new ClassHierarchy(scope, factory, warnings, language, monitor);
|
||||
}
|
||||
|
||||
|
@ -1175,8 +1195,11 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
* Does an expression c1 x := c2 y typecheck?
|
||||
*
|
||||
* i.e. is c2 a subtype of c1?
|
||||
* @throws IllegalArgumentException if c1 is null
|
||||
* @throws IllegalArgumentException if c2 is null
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if c1 is null
|
||||
* @throws IllegalArgumentException
|
||||
* if c2 is null
|
||||
*/
|
||||
public boolean isAssignableFrom(IClass c1, IClass c2) {
|
||||
if (c2 == null) {
|
||||
|
|
|
@ -584,7 +584,7 @@ public class HeapReachingDefs {
|
|||
return o instanceof StaticFieldKey;
|
||||
}
|
||||
};
|
||||
final Collection<PointerKey> kill = new Iterator2Collection<PointerKey>(new FilterIterator<PointerKey>(mod.iterator(),
|
||||
final Collection<PointerKey> kill = Iterator2Collection.toCollection(new FilterIterator<PointerKey>(mod.iterator(),
|
||||
staticFilter));
|
||||
if (kill.isEmpty()) {
|
||||
return null;
|
||||
|
@ -602,7 +602,7 @@ public class HeapReachingDefs {
|
|||
return false;
|
||||
}
|
||||
};
|
||||
Collection<Statement> killedStatements = new Iterator2Collection<Statement>(new FilterIterator<Statement>(domain
|
||||
Collection<Statement> killedStatements = Iterator2Collection.toCollection(new FilterIterator<Statement>(domain
|
||||
.iterator(), f));
|
||||
BitVector result = new BitVector();
|
||||
for (Statement k : killedStatements) {
|
||||
|
|
|
@ -489,7 +489,7 @@ public class PDG extends SlowSparseNumberedGraph<Statement> {
|
|||
}
|
||||
}
|
||||
};
|
||||
Collection<Statement> relevantStatements = new Iterator2Collection<Statement>(new FilterIterator<Statement>(iterator(), f));
|
||||
Collection<Statement> relevantStatements = Iterator2Collection.toCollection(new FilterIterator<Statement>(iterator(), f));
|
||||
|
||||
Map<Statement, OrdinalSet<Statement>> heapReachingDefs = dOptions.isIgnoreHeap() ? null : HeapReachingDefs.computeReachingDefs(
|
||||
node, ir, pa, mod, relevantStatements, new HeapExclusions(SetComplement.complement(new SingletonSet(t))));
|
||||
|
@ -581,7 +581,7 @@ public class PDG extends SlowSparseNumberedGraph<Statement> {
|
|||
}
|
||||
}
|
||||
};
|
||||
return new Iterator2Collection<NormalStatement>(new FilterIterator<NormalStatement>(iterator(), filter));
|
||||
return Iterator2Collection.toCollection(new FilterIterator<NormalStatement>(iterator(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -599,7 +599,7 @@ public class PDG extends SlowSparseNumberedGraph<Statement> {
|
|||
}
|
||||
}
|
||||
};
|
||||
return new Iterator2Collection<NormalStatement>(new FilterIterator<NormalStatement>(iterator(), filter));
|
||||
return Iterator2Collection.toCollection(new FilterIterator<NormalStatement>(iterator(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -210,7 +210,7 @@ public class SDG extends AbstractNumberedGraph<Statement> implements ISDG {
|
|||
case EXC_RET_CALLER: {
|
||||
ParamStatement.ExceptionalReturnCaller nrc = (ParamStatement.ExceptionalReturnCaller) N;
|
||||
SSAAbstractInvokeInstruction call = nrc.getCall();
|
||||
Collection<Statement> result = new Iterator2Collection<Statement>(getPDG(N.getNode()).getPredNodes(N));
|
||||
Collection<Statement> result = Iterator2Collection.toCollection(getPDG(N.getNode()).getPredNodes(N));
|
||||
if (!dOptions.equals(DataDependenceOptions.NONE)) {
|
||||
// data dependence predecessors
|
||||
for (CGNode t : N.getNode().getPossibleTargets(call.getCallSite())) {
|
||||
|
@ -224,7 +224,7 @@ public class SDG extends AbstractNumberedGraph<Statement> implements ISDG {
|
|||
case NORMAL_RET_CALLER: {
|
||||
ParamStatement.NormalReturnCaller nrc = (ParamStatement.NormalReturnCaller) N;
|
||||
SSAAbstractInvokeInstruction call = nrc.getCall();
|
||||
Collection<Statement> result = new Iterator2Collection<Statement>(getPDG(N.getNode()).getPredNodes(N));
|
||||
Collection<Statement> result = Iterator2Collection.toCollection(getPDG(N.getNode()).getPredNodes(N));
|
||||
if (!dOptions.equals(DataDependenceOptions.NONE)) {
|
||||
// data dependence predecessors
|
||||
for (CGNode t : N.getNode().getPossibleTargets(call.getCallSite())) {
|
||||
|
@ -238,7 +238,7 @@ public class SDG extends AbstractNumberedGraph<Statement> implements ISDG {
|
|||
case HEAP_RET_CALLER: {
|
||||
HeapStatement.ReturnCaller r = (HeapStatement.ReturnCaller) N;
|
||||
SSAAbstractInvokeInstruction call = r.getCall();
|
||||
Collection<Statement> result = new Iterator2Collection<Statement>(getPDG(N.getNode()).getPredNodes(N));
|
||||
Collection<Statement> result = Iterator2Collection.toCollection(getPDG(N.getNode()).getPredNodes(N));
|
||||
if (!dOptions.equals(DataDependenceOptions.NONE)) {
|
||||
// data dependence predecessors
|
||||
for (CGNode t : N.getNode().getPossibleTargets(call.getCallSite())) {
|
||||
|
|
|
@ -275,7 +275,7 @@ public class Slicer {
|
|||
Assertions._assert(!st.getKind().equals(Kind.EXC_RET_CALLEE));
|
||||
}
|
||||
|
||||
Collection<Statement> succs = new Iterator2Collection<Statement>(sdg.getSuccNodes(st));
|
||||
Collection<Statement> succs = Iterator2Collection.toCollection(sdg.getSuccNodes(st));
|
||||
succs.removeAll(slice);
|
||||
for (Statement s : succs) {
|
||||
// s is a statement that is a successor of a return statement to the
|
||||
|
@ -314,7 +314,7 @@ public class Slicer {
|
|||
case HEAP_PARAM_CALLEE:
|
||||
case PARAM_CALLEE:
|
||||
case METHOD_ENTRY:
|
||||
Collection<Statement> preds = new Iterator2Collection<Statement>(sdg.getPredNodes(st));
|
||||
Collection<Statement> preds = Iterator2Collection.toCollection(sdg.getPredNodes(st));
|
||||
preds.removeAll(slice);
|
||||
for (Statement p : preds) {
|
||||
// p is a statement that is a predecessor of an incoming parameter
|
||||
|
|
|
@ -938,7 +938,7 @@ public class SSACFG implements ControlFlowGraph{
|
|||
return basicBlocks[cfg.getNumber(object)];
|
||||
}
|
||||
};
|
||||
return new Iterator2Collection<IBasicBlock>(new MapIterator<IBasicBlock,IBasicBlock>(cfg.getExceptionalPredecessors(n).iterator(), f));
|
||||
return Iterator2Collection.toCollection(new MapIterator<IBasicBlock,IBasicBlock>(cfg.getExceptionalPredecessors(n).iterator(), f));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
package com.ibm.wala.util.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* Converts an iterator to a collection
|
||||
*
|
||||
* @author sfink
|
||||
|
@ -24,15 +23,17 @@ public class Iterator2Collection<T> implements Collection<T> {
|
|||
|
||||
private final Collection<T> delegate;
|
||||
|
||||
/**
|
||||
* @param i
|
||||
*/
|
||||
public Iterator2Collection(Iterator<? extends T> i) {
|
||||
|
||||
private Iterator2Collection(Iterator<? extends T> i) {
|
||||
delegate = new LinkedHashSet<T>(5);
|
||||
while (i.hasNext()) {
|
||||
delegate.add(i.next());
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Iterator2Collection<T> toCollection(Iterator<? extends T> i) {
|
||||
return new Iterator2Collection<T>(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -137,5 +138,4 @@ public class Iterator2Collection<T> implements Collection<T> {
|
|||
public int hashCode() {
|
||||
return delegate.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class GraphReachability<T> {
|
|||
}
|
||||
this.g = g;
|
||||
Iterator<T> i = new FilterIterator<T>(g.iterator(), filter);
|
||||
domain = new MutableMapping<T>((new Iterator2Collection<T>(i)).toArray());
|
||||
domain = new MutableMapping<T>((Iterator2Collection.toCollection(i)).toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,7 @@ public class DFS {
|
|||
return new FilterIterator<T>(G.getSuccNodes(n), filter);
|
||||
}
|
||||
};
|
||||
return new Iterator2Collection<T>(dfs);
|
||||
return Iterator2Collection.toCollection(dfs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -110,7 +110,7 @@ public class OrdinalSet<T> implements Iterable<T> {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new Iterator2Collection<T>(iterator()).toString();
|
||||
return Iterator2Collection.toCollection(iterator()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,7 +148,7 @@ public class OrdinalSet<T> implements Iterable<T> {
|
|||
* @throws NullPointerException if instances is null
|
||||
*/
|
||||
public static <T> Collection<T> toCollection(OrdinalSet<T> instances) throws NullPointerException {
|
||||
return new Iterator2Collection<T>(instances.iterator());
|
||||
return Iterator2Collection.toCollection(instances.iterator());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -213,7 +213,7 @@ public class EngineTimings {
|
|||
}
|
||||
|
||||
private static void addUnaccountedFor(EObjectGraphImpl g) {
|
||||
Collection nodes = new Iterator2Collection<EObject>(g.iterator());
|
||||
Collection nodes = Iterator2Collection.toCollection(g.iterator());
|
||||
for (Iterator it = nodes.iterator(); it.hasNext();) {
|
||||
EPhaseTiming node = (EPhaseTiming) it.next();
|
||||
|
||||
|
|
|
@ -202,7 +202,7 @@ public class DotUtil {
|
|||
*
|
||||
*/
|
||||
private static <T> Collection<T> computeDotNodes(Graph<T> g) throws WalaException {
|
||||
return new Iterator2Collection<T>(g.iterator());
|
||||
return Iterator2Collection.toCollection(g.iterator());
|
||||
// if (!usingClusters()) {
|
||||
// return new Iterator2Collection(getGraphInput().iterateNodes());
|
||||
// } else {
|
||||
|
|
Loading…
Reference in New Issue