Deprecate Iterator2Collection.toCollection(); use toSet() or toList() instead.
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3421 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
4d40fa5d34
commit
e08ed2663f
|
@ -677,31 +677,31 @@ public class PrimitivesTest extends WalaTestCase {
|
|||
NumberedGraph<Integer> G = makeBFSTestGraph();
|
||||
|
||||
BoundedBFSIterator<Integer> bfs = new BoundedBFSIterator<Integer>(G, G.getNode(0), 0);
|
||||
Collection<Integer> c = Iterator2Collection.toCollection(bfs);
|
||||
Collection<Integer> c = Iterator2Collection.toSet(bfs);
|
||||
assertTrue(c.size() == 1);
|
||||
|
||||
bfs = new BoundedBFSIterator<Integer>(G, G.getNode(0), 1);
|
||||
c = Iterator2Collection.toCollection(bfs);
|
||||
c = Iterator2Collection.toSet(bfs);
|
||||
assertTrue(c.size() == 3);
|
||||
|
||||
bfs = new BoundedBFSIterator<Integer>(G, G.getNode(0), 2);
|
||||
c = Iterator2Collection.toCollection(bfs);
|
||||
c = Iterator2Collection.toSet(bfs);
|
||||
assertTrue(c.size() == 5);
|
||||
|
||||
bfs = new BoundedBFSIterator<Integer>(G, G.getNode(0), 3);
|
||||
c = Iterator2Collection.toCollection(bfs);
|
||||
c = Iterator2Collection.toSet(bfs);
|
||||
assertTrue(c.size() == 7);
|
||||
|
||||
bfs = new BoundedBFSIterator<Integer>(G, G.getNode(0), 4);
|
||||
c = Iterator2Collection.toCollection(bfs);
|
||||
c = Iterator2Collection.toSet(bfs);
|
||||
assertTrue(c.size() == 9);
|
||||
|
||||
bfs = new BoundedBFSIterator<Integer>(G, G.getNode(0), 5);
|
||||
c = Iterator2Collection.toCollection(bfs);
|
||||
c = Iterator2Collection.toSet(bfs);
|
||||
assertTrue(c.size() == 10);
|
||||
|
||||
bfs = new BoundedBFSIterator<Integer>(G, G.getNode(0), 500);
|
||||
c = Iterator2Collection.toCollection(bfs);
|
||||
c = Iterator2Collection.toSet(bfs);
|
||||
assertTrue(c.size() == 10);
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ public abstract class AbstractCFG<I, T extends IBasicBlock<I>> implements Contro
|
|||
boolean exceptionalIn = getNumberOfExceptionalIn(N) > 0;
|
||||
if (normalIn) {
|
||||
if (exceptionalIn) {
|
||||
return Iterator2Collection.toCollection(getPredNodes(N)).size();
|
||||
return Iterator2Collection.toSet(getPredNodes(N)).size();
|
||||
} else {
|
||||
return getNumberOfNormalIn(N);
|
||||
}
|
||||
|
@ -241,8 +241,8 @@ public abstract class AbstractCFG<I, T extends IBasicBlock<I>> implements Contro
|
|||
if (normalIn) {
|
||||
if (exceptionalIn) {
|
||||
HashSet<T> result = HashSetFactory.make(getNumberOfNormalIn(N) + getNumberOfExceptionalIn(N));
|
||||
result.addAll(Iterator2Collection.toCollection(normalEdgeManager.getPredNodes(N)));
|
||||
result.addAll(Iterator2Collection.toCollection(exceptionalEdgeManager.getPredNodes(N)));
|
||||
result.addAll(Iterator2Collection.toSet(normalEdgeManager.getPredNodes(N)));
|
||||
result.addAll(Iterator2Collection.toSet(exceptionalEdgeManager.getPredNodes(N)));
|
||||
if (fallThru.get(number - 1)) {
|
||||
result.add(getNode(number - 1));
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ public abstract class AbstractCFG<I, T extends IBasicBlock<I>> implements Contro
|
|||
}
|
||||
|
||||
private int slowCountSuccNodes(T N) {
|
||||
return Iterator2Collection.toCollection(getSuccNodes(N)).size();
|
||||
return Iterator2Collection.toSet(getSuccNodes(N)).size();
|
||||
}
|
||||
|
||||
public Iterator<T> getSuccNodes(T N) {
|
||||
|
@ -595,7 +595,7 @@ public abstract class AbstractCFG<I, T extends IBasicBlock<I>> implements Contro
|
|||
if (b == null) {
|
||||
throw new IllegalArgumentException("b is null");
|
||||
}
|
||||
return Iterator2Collection.toCollection(iterateNormalSuccessors(b.getNumber()));
|
||||
return Iterator2Collection.toSet(iterateNormalSuccessors(b.getNumber()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -628,7 +628,7 @@ public abstract class AbstractCFG<I, T extends IBasicBlock<I>> implements Contro
|
|||
if (b == null) {
|
||||
throw new IllegalArgumentException("b is null");
|
||||
}
|
||||
return Iterator2Collection.toCollection(iterateExceptionalPredecessors(b));
|
||||
return Iterator2Collection.toSet(iterateExceptionalPredecessors(b));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -638,7 +638,7 @@ public abstract class AbstractCFG<I, T extends IBasicBlock<I>> implements Contro
|
|||
if (b == null) {
|
||||
throw new IllegalArgumentException("b is null");
|
||||
}
|
||||
return Iterator2Collection.toCollection(iterateNormalPredecessors(b));
|
||||
return Iterator2Collection.toSet(iterateNormalPredecessors(b));
|
||||
}
|
||||
|
||||
public IntSet getPredNodeNumbers(T node) throws UnimplementedError {
|
||||
|
|
|
@ -112,7 +112,7 @@ public class ClassLoaderImpl implements IClassLoader {
|
|||
System.err.println("Get source files for " + M);
|
||||
}
|
||||
TreeSet<ModuleEntry> sortedEntries = new TreeSet<ModuleEntry>(HashCodeComparator.instance());
|
||||
sortedEntries.addAll(Iterator2Collection.toCollection(M.getEntries()));
|
||||
sortedEntries.addAll(Iterator2Collection.toSet(M.getEntries()));
|
||||
|
||||
HashSet<ModuleEntry> result = HashSetFactory.make();
|
||||
for (Iterator it = sortedEntries.iterator(); it.hasNext();) {
|
||||
|
@ -144,7 +144,7 @@ public class ClassLoaderImpl implements IClassLoader {
|
|||
System.err.println("Get class files for " + M);
|
||||
}
|
||||
TreeSet<ModuleEntry> sortedEntries = new TreeSet<ModuleEntry>(HashCodeComparator.instance());
|
||||
sortedEntries.addAll(Iterator2Collection.toCollection(M.getEntries()));
|
||||
sortedEntries.addAll(Iterator2Collection.toSet(M.getEntries()));
|
||||
|
||||
HashSet<ModuleEntry> result = HashSetFactory.make();
|
||||
for (Iterator it = sortedEntries.iterator(); it.hasNext();) {
|
||||
|
|
|
@ -93,7 +93,7 @@ public class BackwardsSupergraph<T, P> implements ISupergraph<T, P> {
|
|||
if (DEBUG_LEVEL > 1) {
|
||||
System.err.println(getClass() + " getCalledNodes " + ret);
|
||||
System.err.println("called nodes: "
|
||||
+ Iterator2Collection.toCollection(new FilterIterator<Object>(getSuccNodes(ret), exitFilter)));
|
||||
+ Iterator2Collection.toSet(new FilterIterator<Object>(getSuccNodes(ret), exitFilter)));
|
||||
}
|
||||
return new FilterIterator<T>(getSuccNodes(ret), exitFilter);
|
||||
}
|
||||
|
|
|
@ -555,7 +555,7 @@ public class TabulationSolver<T, P, F> {
|
|||
System.err.println(" process callee: " + callee);
|
||||
}
|
||||
MutableSparseIntSet reached = MutableSparseIntSet.makeEmpty();
|
||||
final Collection<T> returnSitesForCallee = Iterator2Collection.toCollection(supergraph.getReturnSites(edge.target, supergraph
|
||||
final Collection<T> returnSitesForCallee = Iterator2Collection.toSet(supergraph.getReturnSites(edge.target, supergraph
|
||||
.getProcOf(callee)));
|
||||
allReturnSites.addAll(returnSitesForCallee);
|
||||
// we modify this to handle each return site individually. Some types of problems
|
||||
|
|
|
@ -677,7 +677,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
}
|
||||
|
||||
public Collection<InstanceKey> getP2Set(LocalPointerKey lpk) {
|
||||
return Iterator2Collection.toCollection(new MapIterator<InstanceKeyAndState, InstanceKey>(makeOrdinalSet(
|
||||
return Iterator2Collection.toSet(new MapIterator<InstanceKeyAndState, InstanceKey>(makeOrdinalSet(
|
||||
find(pkToP2Set, new PointerKeyAndState(lpk, stateMachine.getStartState()))).iterator(),
|
||||
new Function<InstanceKeyAndState, InstanceKey>() {
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ public class SimpleDemandPointsTo extends AbstractDemandPointsTo {
|
|||
SlowDFSDiscoverTimeIterator<Object> dfs = new SlowDFSDiscoverTimeIterator<Object>(g, pk);
|
||||
// Collection reached =
|
||||
// DFS.getReachableNodes(g,Collections.singleton(pk));
|
||||
return Iterator2Collection.toCollection((Iterator<? extends InstanceKey>)(Iterator)new FilterIterator<Object>(dfs, iKeyFilter));
|
||||
return Iterator2Collection.toSet((Iterator<? extends InstanceKey>)(Iterator)new FilterIterator<Object>(dfs, iKeyFilter));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class LocalLiveRangeAnalysis {
|
|||
* Iterator<SSAInstruction>
|
||||
*/
|
||||
private static Collection<BasicBlock> findBlocks(IR ir, Iterator<SSAInstruction> statements) {
|
||||
Collection<SSAInstruction> s = Iterator2Collection.toCollection(statements);
|
||||
Collection<SSAInstruction> s = Iterator2Collection.toSet(statements);
|
||||
Collection<BasicBlock> result = HashSetFactory.make();
|
||||
outer: for (Iterator it = ir.getControlFlowGraph().iterator(); it.hasNext();) {
|
||||
SSACFG.BasicBlock b = (SSACFG.BasicBlock) it.next();
|
||||
|
|
|
@ -548,7 +548,7 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
|
|||
* @see com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis#iteratePointerKeys()
|
||||
*/
|
||||
public Collection<PointerKey> getPointerKeys() {
|
||||
return Iterator2Collection.toCollection(pointsToMap.iterateKeys());
|
||||
return Iterator2Collection.toSet(pointsToMap.iterateKeys());
|
||||
}
|
||||
|
||||
public IClassHierarchy getClassHierarchy() {
|
||||
|
|
|
@ -144,7 +144,7 @@ public class PreTransitiveSolver extends AbstractPointsToSolver {
|
|||
}
|
||||
|
||||
// cache the predecessors before unification might screw things up.
|
||||
Iterator2Collection<? extends IVariable> origPred = Iterator2Collection.toCollection(ag.getPredNodes(v));
|
||||
Iterator2Collection<? extends IVariable> origPred = Iterator2Collection.toSet(ag.getPredNodes(v));
|
||||
for (Iterator it = origPred.iterator(); it.hasNext();) {
|
||||
PointsToSetVariable n = (PointsToSetVariable) it.next();
|
||||
|
||||
|
|
|
@ -838,7 +838,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
|
|||
if (p != pRef) {
|
||||
// pRef is the representative for p.
|
||||
// be careful: cache the defs before mucking with the underlying system
|
||||
for (Iterator d = Iterator2Collection.toCollection(getStatementsThatDef(p)).iterator(); d.hasNext();) {
|
||||
for (Iterator d = Iterator2Collection.toSet(getStatementsThatDef(p)).iterator(); d.hasNext();) {
|
||||
AbstractStatement as = (AbstractStatement) d.next();
|
||||
|
||||
if (as instanceof AssignEquation) {
|
||||
|
@ -855,7 +855,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
|
|||
}
|
||||
}
|
||||
// be careful: cache the defs before mucking with the underlying system
|
||||
for (Iterator u = Iterator2Collection.toCollection(getStatementsThatUse(p)).iterator(); u.hasNext();) {
|
||||
for (Iterator u = Iterator2Collection.toSet(getStatementsThatUse(p)).iterator(); u.hasNext();) {
|
||||
AbstractStatement as = (AbstractStatement) u.next();
|
||||
if (as instanceof AssignEquation) {
|
||||
AssignEquation assign = (AssignEquation) as;
|
||||
|
|
|
@ -81,7 +81,7 @@ public class ReflectionHandler {
|
|||
}
|
||||
}
|
||||
};
|
||||
Collection<Statement> casts = Iterator2Collection.toCollection(new FilterIterator<Statement>(slice.iterator(), f));
|
||||
Collection<Statement> casts = Iterator2Collection.toSet(new FilterIterator<Statement>(slice.iterator(), f));
|
||||
changedNodes.addAll(modifyFactoryInterpreter(st, casts, builder.getContextInterpreter(), builder.getClassHierarchy()));
|
||||
}
|
||||
for (Iterator<CGNode> it = changedNodes.iterator(); it.hasNext();) {
|
||||
|
|
|
@ -177,7 +177,7 @@ public class TypeBasedPointerAnalysis extends AbstractPointerAnalysis {
|
|||
}
|
||||
|
||||
public Collection<PointerKey> getPointerKeys() {
|
||||
return Iterator2Collection.toCollection(heapModel.iteratePointerKeys());
|
||||
return Iterator2Collection.toSet(heapModel.iteratePointerKeys());
|
||||
}
|
||||
|
||||
public boolean isFiltered(PointerKey pk) {
|
||||
|
|
|
@ -117,7 +117,7 @@ public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGrap
|
|||
}
|
||||
|
||||
public int getSuccNodeCount(T N) {
|
||||
return Iterator2Collection.toCollection(getSuccNodes(N)).size();
|
||||
return Iterator2Collection.toSet(getSuccNodes(N)).size();
|
||||
}
|
||||
|
||||
public IntSet getSuccNodeNumbers(T N) {
|
||||
|
@ -139,7 +139,7 @@ public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGrap
|
|||
}
|
||||
|
||||
public int getPredNodeCount(T N) {
|
||||
return Iterator2Collection.toCollection(getPredNodes(N)).size();
|
||||
return Iterator2Collection.toSet(getPredNodes(N)).size();
|
||||
}
|
||||
|
||||
public IntSet getPredNodeNumbers(T N) {
|
||||
|
@ -301,15 +301,15 @@ public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGrap
|
|||
}
|
||||
|
||||
public Collection<T> getNormalSuccessors(final T N) {
|
||||
return Iterator2Collection.toCollection(edges.getNormalSuccessors(N));
|
||||
return Iterator2Collection.toSet(edges.getNormalSuccessors(N));
|
||||
}
|
||||
|
||||
public Collection<T> getExceptionalPredecessors(final T N) {
|
||||
return Iterator2Collection.toCollection(edges.getExceptionalPredecessors(N));
|
||||
return Iterator2Collection.toSet(edges.getExceptionalPredecessors(N));
|
||||
}
|
||||
|
||||
public Collection<T> getNormalPredecessors(final T N) {
|
||||
return Iterator2Collection.toCollection(edges.getNormalPredecessors(N));
|
||||
return Iterator2Collection.toSet(edges.getNormalPredecessors(N));
|
||||
}
|
||||
|
||||
public T entry() {
|
||||
|
|
|
@ -1109,7 +1109,7 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
return n.klass;
|
||||
}
|
||||
};
|
||||
return Iterator2Collection.toCollection(new MapIterator<Node, IClass>(findNode(klass).children.iterator(), node2Class));
|
||||
return Iterator2Collection.toSet(new MapIterator<Node, IClass>(findNode(klass).children.iterator(), node2Class));
|
||||
}
|
||||
|
||||
private Collection<IClass> getImmediateArraySubclasses(IClass klass) {
|
||||
|
|
|
@ -48,6 +48,7 @@ import com.ibm.wala.util.collections.Filter;
|
|||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.Iterator2Collection;
|
||||
import com.ibm.wala.util.collections.Iterator2Iterable;
|
||||
import com.ibm.wala.util.collections.ObjectArrayMapping;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.intset.BasicNaturalRelation;
|
||||
|
@ -81,24 +82,16 @@ public class HeapReachingDefs {
|
|||
/**
|
||||
* For each statement s, return the set of statements that may def the heap value read by s.
|
||||
*
|
||||
* @param node
|
||||
* the node we are computing heap reaching defs for
|
||||
* @param ir
|
||||
* IR for the node
|
||||
* @param pa
|
||||
* governing pointer analysis
|
||||
* @param mod
|
||||
* the set of heap locations which may be written (transitively) by this node. These are logically return
|
||||
* values in the SDG.
|
||||
* @param statements
|
||||
* the statements whose def-use are considered interesting
|
||||
* @param exclusions
|
||||
* heap locations that should be excluded from data dependence tracking
|
||||
* @param node the node we are computing heap reaching defs for
|
||||
* @param ir IR for the node
|
||||
* @param pa governing pointer analysis
|
||||
* @param mod the set of heap locations which may be written (transitively) by this node. These are logically return values in the
|
||||
* SDG.
|
||||
* @param statements the statements whose def-use are considered interesting
|
||||
* @param exclusions heap locations that should be excluded from data dependence tracking
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if pa is null
|
||||
* @throws IllegalArgumentException
|
||||
* if statements is null
|
||||
* @throws IllegalArgumentException if pa is null
|
||||
* @throws IllegalArgumentException if statements is null
|
||||
*/
|
||||
public Map<Statement, OrdinalSet<Statement>> computeReachingDefs(CGNode node, IR ir, PointerAnalysis pa,
|
||||
Map<CGNode, OrdinalSet<PointerKey>> mod, Collection<Statement> statements, HeapExclusions exclusions, CallGraph cg) {
|
||||
|
@ -482,8 +475,8 @@ public class HeapReachingDefs {
|
|||
private final HeapExclusions exclusions;
|
||||
|
||||
/**
|
||||
* if (i,j) \in heapReturnCaller, then statement j is a HeapStatement.ReturnCaller for statement i, a
|
||||
* NormalStatement representing an invoke
|
||||
* if (i,j) \in heapReturnCaller, then statement j is a HeapStatement.ReturnCaller for statement i, a NormalStatement
|
||||
* representing an invoke
|
||||
*/
|
||||
private final IBinaryNaturalRelation heapReturnCaller = new BasicNaturalRelation();
|
||||
|
||||
|
@ -640,8 +633,8 @@ public class HeapReachingDefs {
|
|||
return o instanceof StaticFieldKey;
|
||||
}
|
||||
};
|
||||
final Collection<PointerKey> kill = Iterator2Collection.toCollection(new FilterIterator<PointerKey>(mod.iterator(),
|
||||
staticFilter));
|
||||
final Collection<PointerKey> kill = Iterator2Collection
|
||||
.toSet(new FilterIterator<PointerKey>(mod.iterator(), staticFilter));
|
||||
if (kill.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
|
@ -658,10 +651,8 @@ public class HeapReachingDefs {
|
|||
return false;
|
||||
}
|
||||
};
|
||||
Collection<Statement> killedStatements = Iterator2Collection.toCollection(new FilterIterator<Statement>(domain
|
||||
.iterator(), f));
|
||||
BitVector result = new BitVector();
|
||||
for (Statement k : killedStatements) {
|
||||
for (Statement k : Iterator2Iterable.make(new FilterIterator<Statement>(domain.iterator(), f))) {
|
||||
result.set(domain.getMappedIndex(k));
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -648,7 +648,7 @@ public class PDG implements NumberedGraph<Statement> {
|
|||
}
|
||||
}
|
||||
};
|
||||
Collection<Statement> relevantStatements = Iterator2Collection.toCollection(new FilterIterator<Statement>(iterator(), f));
|
||||
Collection<Statement> relevantStatements = Iterator2Collection.toSet(new FilterIterator<Statement>(iterator(), f));
|
||||
|
||||
Map<Statement, OrdinalSet<Statement>> heapReachingDefs = new HeapReachingDefs(modRef).computeReachingDefs(node, ir, pa, mod,
|
||||
relevantStatements, new HeapExclusions(SetComplement.complement(new SingletonSet(t))), cg);
|
||||
|
@ -741,7 +741,7 @@ public class PDG implements NumberedGraph<Statement> {
|
|||
}
|
||||
}
|
||||
};
|
||||
return Iterator2Collection.toCollection(new FilterIterator<NormalStatement>(iterator(), filter));
|
||||
return Iterator2Collection.toSet(new FilterIterator<NormalStatement>(iterator(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -312,7 +312,7 @@ public class SDG extends AbstractNumberedGraph<Statement> implements ISDG {
|
|||
case EXC_RET_CALLER: {
|
||||
ExceptionalReturnCaller nrc = (ExceptionalReturnCaller) N;
|
||||
SSAAbstractInvokeInstruction call = nrc.getInstruction();
|
||||
Collection<Statement> result = Iterator2Collection.toCollection(getPDG(N.getNode()).getPredNodes(N));
|
||||
Collection<Statement> result = Iterator2Collection.toSet(getPDG(N.getNode()).getPredNodes(N));
|
||||
if (!dOptions.equals(DataDependenceOptions.NONE)) {
|
||||
// data dependence predecessors
|
||||
for (CGNode t : cg.getPossibleTargets(N.getNode(), call.getCallSite())) {
|
||||
|
@ -326,7 +326,7 @@ public class SDG extends AbstractNumberedGraph<Statement> implements ISDG {
|
|||
case NORMAL_RET_CALLER: {
|
||||
NormalReturnCaller nrc = (NormalReturnCaller) N;
|
||||
SSAAbstractInvokeInstruction call = nrc.getInstruction();
|
||||
Collection<Statement> result = Iterator2Collection.toCollection(getPDG(N.getNode()).getPredNodes(N));
|
||||
Collection<Statement> result = Iterator2Collection.toSet(getPDG(N.getNode()).getPredNodes(N));
|
||||
if (!dOptions.equals(DataDependenceOptions.NONE)) {
|
||||
// data dependence predecessors
|
||||
for (CGNode t : cg.getPossibleTargets(N.getNode(), call.getCallSite())) {
|
||||
|
@ -340,7 +340,7 @@ public class SDG extends AbstractNumberedGraph<Statement> implements ISDG {
|
|||
case HEAP_RET_CALLER: {
|
||||
HeapStatement.HeapReturnCaller r = (HeapStatement.HeapReturnCaller) N;
|
||||
SSAAbstractInvokeInstruction call = r.getCall();
|
||||
Collection<Statement> result = Iterator2Collection.toCollection(getPDG(N.getNode()).getPredNodes(N));
|
||||
Collection<Statement> result = Iterator2Collection.toSet(getPDG(N.getNode()).getPredNodes(N));
|
||||
if (!dOptions.equals(DataDependenceOptions.NONE)) {
|
||||
// data dependence predecessors
|
||||
for (CGNode t : cg.getPossibleTargets(N.getNode(), call.getCallSite())) {
|
||||
|
|
|
@ -141,7 +141,7 @@ public class CISDG implements ISDG {
|
|||
pred.addAll(invMod.get(p));
|
||||
}
|
||||
}
|
||||
pred.addAll(Iterator2Collection.toCollection(noHeap.getPredNodes(N)));
|
||||
pred.addAll(Iterator2Collection.toSet(noHeap.getPredNodes(N)));
|
||||
return pred.iterator();
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ public class CISDG implements ISDG {
|
|||
succ.addAll(invRef.get(p));
|
||||
}
|
||||
}
|
||||
succ.addAll(Iterator2Collection.toCollection(noHeap.getSuccNodes(N)));
|
||||
succ.addAll(Iterator2Collection.toSet(noHeap.getSuccNodes(N)));
|
||||
return succ.iterator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -984,7 +984,7 @@ public class SSACFG implements ControlFlowGraph<SSAInstruction, ISSABasicBlock>
|
|||
return basicBlocks[cfg.getNumber(object)];
|
||||
}
|
||||
};
|
||||
return Iterator2Collection.toCollection(new MapIterator<IBasicBlock<IInstruction>, ISSABasicBlock>(cfg.getExceptionalPredecessors(n)
|
||||
return Iterator2Collection.toSet(new MapIterator<IBasicBlock<IInstruction>, ISSABasicBlock>(cfg.getExceptionalPredecessors(n)
|
||||
.iterator(), f));
|
||||
}
|
||||
|
||||
|
|
|
@ -10,32 +10,58 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.util.collections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Converts an iterator to a collection
|
||||
* Converts an {@link Iterator} to a {@link Collection}. Note that if you just want to use Java 5's for-each loop with an
|
||||
* {@link Iterator}, use {@link Iterator2Iterable}.
|
||||
*
|
||||
* @author sfink
|
||||
* @see Iterator2Iterable
|
||||
*/
|
||||
public class Iterator2Collection<T> implements Collection<T> {
|
||||
|
||||
private final Collection<T> delegate;
|
||||
|
||||
|
||||
private Iterator2Collection(Iterator<? extends T> i) {
|
||||
delegate = new LinkedHashSet<T>(5);
|
||||
private Iterator2Collection(Iterator<? extends T> i, Collection<T> delegate) {
|
||||
this.delegate = delegate;
|
||||
while (i.hasNext()) {
|
||||
delegate.add(i.next());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just calls {@link #toSet(Iterator)}
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T> Iterator2Collection<T> toCollection(Iterator<? extends T> i) throws IllegalArgumentException {
|
||||
return toSet(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Set} containing all elements in i. Note that duplicates will be removed.
|
||||
*/
|
||||
public static <T> Iterator2Collection<T> toSet(Iterator<? extends T> i) throws IllegalArgumentException {
|
||||
if (i == null) {
|
||||
throw new IllegalArgumentException("i == null");
|
||||
}
|
||||
return new Iterator2Collection<T>(i);
|
||||
return new Iterator2Collection<T>(i, new LinkedHashSet<T>(5));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link List} containing all elements in i, preserving duplicates.
|
||||
*/
|
||||
public static <T> Iterator2Collection<T> toList(Iterator<? extends T> i) throws IllegalArgumentException {
|
||||
if (i == null) {
|
||||
throw new IllegalArgumentException("i == null");
|
||||
}
|
||||
return new Iterator2Collection<T>(i, new ArrayList<T>(5));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -72,7 +72,7 @@ public class GraphReachability<T> {
|
|||
}
|
||||
this.g = g;
|
||||
Iterator<T> i = new FilterIterator<T>(g.iterator(), filter);
|
||||
domain = new MutableMapping<T>((Iterator2Collection.toCollection(i)).toArray());
|
||||
domain = new MutableMapping<T>((Iterator2Collection.toSet(i)).toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -230,7 +230,7 @@ public class SparseNumberedLabeledEdgeManager<T, U> implements NumberedLabeledEd
|
|||
public Iterator<? extends T> getPredNodes(T N) {
|
||||
Collection<T> preds = HashSetFactory.make();
|
||||
for (U label : nodeToPredLabels.get(N)) {
|
||||
preds.addAll(Iterator2Collection.toCollection(getPredNodes(N, label)));
|
||||
preds.addAll(Iterator2Collection.toSet(getPredNodes(N, label)));
|
||||
}
|
||||
return preds.iterator();
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ public class SparseNumberedLabeledEdgeManager<T, U> implements NumberedLabeledEd
|
|||
public Iterator<? extends T> getSuccNodes(T N) {
|
||||
Collection<T> succs = HashSetFactory.make();
|
||||
for (U label : nodeToSuccLabels.get(N)) {
|
||||
succs.addAll(Iterator2Collection.toCollection(getSuccNodes(N, label)));
|
||||
succs.addAll(Iterator2Collection.toSet(getSuccNodes(N, label)));
|
||||
}
|
||||
return succs.iterator();
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class DFS {
|
|||
return new FilterIterator<T>(G.getSuccNodes(n), filter);
|
||||
}
|
||||
};
|
||||
return Iterator2Collection.toCollection(dfs);
|
||||
return Iterator2Collection.toSet(dfs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -133,7 +133,7 @@ public class OrdinalSet<T> implements Iterable<T> {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Iterator2Collection.toCollection(iterator()).toString();
|
||||
return Iterator2Collection.toSet(iterator()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,7 +169,7 @@ public class OrdinalSet<T> implements Iterable<T> {
|
|||
* @throws NullPointerException if instances is null
|
||||
*/
|
||||
public static <T> Collection<T> toCollection(OrdinalSet<T> instances) {
|
||||
return Iterator2Collection.toCollection(instances.iterator());
|
||||
return Iterator2Collection.toSet(instances.iterator());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -241,7 +241,7 @@ public class DotUtil {
|
|||
* Compute the nodes to visualize
|
||||
*/
|
||||
private static <T> Collection<T> computeDotNodes(Graph<T> g) throws WalaException {
|
||||
return Iterator2Collection.toCollection(g.iterator());
|
||||
return Iterator2Collection.toSet(g.iterator());
|
||||
}
|
||||
|
||||
private static String getRankDir() throws WalaException {
|
||||
|
|
|
@ -214,7 +214,7 @@ class J2EEContainerModel extends SyntheticClass implements BytecodeConstants, EJ
|
|||
}
|
||||
}
|
||||
};
|
||||
staticFieldRefs = Iterator2Collection.toCollection(it);
|
||||
staticFieldRefs = Iterator2Collection.toSet(it);
|
||||
initializeStaticFieldMap();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue