/** * For an interface parent (MUST be an interface), returns set of all subinterfaces including <code>parent</code>. * * This method can be used concurrently (is thread safe). * * @param parent * the parent interface. * @return an set, possibly empty */ public Set<SootClass> getAllSubinterfaces(SootClass parent) { parent.checkLevel(SootClass.HIERARCHY); if (!parent.isInterface()) { return Collections.emptySet(); } Set<SootClass> result = interfaceToAllSubinterfaces.get(parent); if (result.size() > 0) { return result; } result = new HashSet<>(); result.add(parent); for (SootClass si : interfaceToSubinterfaces.get(parent)) { result.addAll(getAllSubinterfaces(si)); } interfaceToAllSubinterfaces.putAll(parent, result); return result; }
/** * 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; }
return parent == rtObject.getSootClass(); } else { return getAllSubinterfaces(parent).contains(child);
/** For an interface parent (MUST be an interface), returns set of all * subinterfaces. */ protected Set getAllSubinterfaces( SootClass parent ) { parent.checkLevel(SootClass.HIERARCHY); if( !interfaceToAllSubinterfaces.containsKey( parent ) ) { interfaceToAllSubinterfaces.put( parent, parent ); for( Iterator it = interfaceToSubinterfaces.get( parent ).iterator(); it.hasNext(); ) { interfaceToAllSubinterfaces.putAll(parent, getAllSubinterfaces( (SootClass) it.next() ) ); } } return interfaceToAllSubinterfaces.get( parent ); }
/** For an interface parent (MUST be an interface), returns set of all * subinterfaces. */ protected Set getAllSubinterfaces( SootClass parent ) { parent.checkLevel(SootClass.HIERARCHY); if( !interfaceToAllSubinterfaces.containsKey( parent ) ) { interfaceToAllSubinterfaces.put( parent, parent ); for( Iterator it = interfaceToSubinterfaces.get( parent ).iterator(); it.hasNext(); ) { interfaceToAllSubinterfaces.putAll(parent, getAllSubinterfaces( (SootClass) it.next() ) ); } } return interfaceToAllSubinterfaces.get( parent ); }
/** 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; } }
/** 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 ); }