private Set<Type> resolveToClasses(Set<Type> rawTypes) { Set<Type> toReturn = new HashSet<Type>(); for (Type ty : rawTypes) { if (ty instanceof AnySubType) { AnySubType anySubType = (AnySubType) ty; RefType base = anySubType.getBase(); Set<SootClass> classRoots; if (base.getSootClass().isInterface()) { classRoots = fh.getAllImplementersOfInterface(base.getSootClass()); } else { classRoots = Collections.singleton(base.getSootClass()); } toReturn.addAll(getTransitiveSubClasses(classRoots)); } else if (ty instanceof ArrayType || ty instanceof RefType) { toReturn.add(ty); } } return toReturn; }
/** * For an interface parent (MUST be an interface), returns set of all implementers of it but NOT their subclasses. * * This method can be used concurrently (is thread safe). * * @param parent * the parent interface. * @return an set, possibly empty */ public Set<SootClass> getAllImplementersOfInterface(SootClass parent) { parent.checkLevel(SootClass.HIERARCHY); Set<SootClass> result = interfaceToAllImplementers.get(parent); if (result.size() > 0) { return result; } result = new HashSet<>(); for (SootClass subinterface : getAllSubinterfaces(parent)) { if (subinterface == parent) { continue; } result.addAll(getAllImplementersOfInterface(subinterface)); } result.addAll(interfaceToImplementers.get(parent)); interfaceToAllImplementers.putAll(parent, result); return result; }
cl = worklist.removeFirst(); if (cl.isInterface()) { for (Iterator<SootClass> cIt = fh.getAllImplementersOfInterface(cl).iterator(); cIt.hasNext();) { final SootClass c = cIt.next(); if (workset.add(c)) {
final Set<SootClass> impl = getAllImplementersOfInterface(parent); if (impl.size() > 1000) {
worklist.addAll(getAllImplementersOfInterface(concreteType)); continue;
Deque<SootClass> worklist = new ArrayDeque<SootClass>(); if (base.isInterface()) { worklist.addAll(getAllImplementersOfInterface(base)); } else { worklist.add(base);
final private BitVector makeMaskOfInterface(SootClass interf) { if (!(interf.isInterface())) { throw new RuntimeException(); } BitVector ret = new BitVector(pag.getAllocNodeNumberer().size()); typeMask.put(interf.getType(), ret); Collection<SootClass> implementers = getFastHierarchy().getAllImplementersOfInterface(interf); for (SootClass impl : implementers) { BitVector other = typeMask.get(impl.getType()); if (other == null) { other = makeClassTypeMask(impl); } ret.or(other); } // I think, the following can be eliminated. It is added to make // type-masks exactly the same as the original type-masks if (implementers.size() == 0) { for (AllocNode an : anySubtypeAllocs) { ret.set(an.getNumber()); } } return ret; }
/** Given an object of declared type child, returns true if the object * can be stored in a variable of type parent. If child is an interface * that is not a subinterface of parent, this method will return false * even though some objects implementing the child interface may also * implement the parent interface. */ protected boolean canStoreClass( SootClass child, SootClass parent ) { parent.checkLevel(SootClass.HIERARCHY); child.checkLevel(SootClass.HIERARCHY); Interval parentInterval = classToInterval.get( parent ); Interval childInterval = classToInterval.get( child ); if( parentInterval != null && childInterval != null ) { return parentInterval.isSubrange( childInterval ); } if( childInterval == null ) { // child is interface if( parentInterval != null ) { // parent is not interface return parent.equals( RefType.v("java.lang.Object").getSootClass() ); } else { return getAllSubinterfaces( parent ).contains( child ); } } else { Set impl = getAllImplementersOfInterface( parent ); for( Iterator it = impl.iterator(); it.hasNext(); ) { parentInterval = classToInterval.get( it.next() ); if( parentInterval != null && parentInterval.isSubrange( childInterval ) ) { return true; } } return false; } }
/** Given an object of declared type child, returns true if the object * can be stored in a variable of type parent. If child is an interface * that is not a subinterface of parent, this method will return false * even though some objects implementing the child interface may also * implement the parent interface. */ protected boolean canStoreClass( SootClass child, SootClass parent ) { parent.checkLevel(SootClass.HIERARCHY); child.checkLevel(SootClass.HIERARCHY); Interval parentInterval = classToInterval.get( parent ); Interval childInterval = classToInterval.get( child ); if( parentInterval != null && childInterval != null ) { return parentInterval.isSubrange( childInterval ); } if( childInterval == null ) { // child is interface if( parentInterval != null ) { // parent is not interface return parent.equals( RefType.v("java.lang.Object").getSootClass() ); } else { return getAllSubinterfaces( parent ).contains( child ); } } else { Set impl = getAllImplementersOfInterface( parent ); for( Iterator it = impl.iterator(); it.hasNext(); ) { parentInterval = classToInterval.get( it.next() ); if( parentInterval != null && parentInterval.isSubrange( childInterval ) ) { return true; } } return false; } }
SootClass savedConcreteType = concreteType; if( concreteType.isInterface() ) { worklist.addAll( getAllImplementersOfInterface( concreteType ) ); continue;
SootClass savedConcreteType = concreteType; if( concreteType.isInterface() ) { worklist.addAll( getAllImplementersOfInterface( concreteType ) ); continue;
/** For an interface parent (MUST be an interface), returns set of all * implementers of it but NOT their subclasses. */ public Set getAllImplementersOfInterface( SootClass parent ) { parent.checkLevel(SootClass.HIERARCHY); if( !interfaceToAllImplementers.containsKey( parent ) ) { for( Iterator subinterfaceIt = getAllSubinterfaces( parent ).iterator(); subinterfaceIt.hasNext(); ) { final SootClass subinterface = (SootClass) subinterfaceIt.next(); if( subinterface == parent ) continue; interfaceToAllImplementers.putAll(parent, getAllImplementersOfInterface( subinterface ) ); } interfaceToAllImplementers.putAll(parent, interfaceToImplementers.get( parent ) ); } return interfaceToAllImplementers.get( parent ); }
/** For an interface parent (MUST be an interface), returns set of all * implementers of it but NOT their subclasses. */ public Set getAllImplementersOfInterface( SootClass parent ) { parent.checkLevel(SootClass.HIERARCHY); if( !interfaceToAllImplementers.containsKey( parent ) ) { for( Iterator subinterfaceIt = getAllSubinterfaces( parent ).iterator(); subinterfaceIt.hasNext(); ) { final SootClass subinterface = (SootClass) subinterfaceIt.next(); if( subinterface == parent ) continue; interfaceToAllImplementers.putAll(parent, getAllImplementersOfInterface( subinterface ) ); } interfaceToAllImplementers.putAll(parent, interfaceToImplementers.get( parent ) ); } return interfaceToAllImplementers.get( parent ); }
cl = worklist.removeFirst(); if( cl.isInterface() ) { for( Iterator cIt = fh.getAllImplementersOfInterface(cl).iterator(); cIt.hasNext(); ) { final SootClass c = (SootClass) cIt.next(); if( workset.add( c ) ) worklist.add( c );
cl = worklist.removeFirst(); if( cl.isInterface() ) { for( Iterator cIt = fh.getAllImplementersOfInterface(cl).iterator(); cIt.hasNext(); ) { final SootClass c = (SootClass) cIt.next(); if( workset.add( c ) ) worklist.add( c );
SootClass parentClass = ((RefType) parent).getSootClass(); LinkedList worklist = new LinkedList(); if( base.isInterface() ) worklist.addAll(getAllImplementersOfInterface(base)); else worklist.add(base); Set<SootClass> workset = new HashSet<SootClass>();
SootClass parentClass = ((RefType) parent).getSootClass(); LinkedList worklist = new LinkedList(); if( base.isInterface() ) worklist.addAll(getAllImplementersOfInterface(base)); else worklist.add(base); Set<SootClass> workset = new HashSet<SootClass>();