@Override public IClass getAllocatedTarget(CGNode caller, NewSiteReference site) { if (site == null) { throw new IllegalArgumentException("site is null"); } IClass klass = cha.lookupClass(site.getDeclaredType()); if (klass == null) { return null; } else if (klass.isAbstract()) { return null; } else { return klass; } } }
@Override public IClass getAllocatedTarget(CGNode caller, NewSiteReference site) { if (site == null) { throw new IllegalArgumentException("site is null"); } IClass klass = cha.lookupClass(site.getDeclaredType()); if (klass == null) { return null; } else if (klass.isAbstract()) { return null; } else { return klass; } } }
/** * Are we allowed to allocate (for analysis purposes) an instance of a given type? By default, the answer is yes iff T is not * abstract. However, subclasses and summaries can override this to allow "special" abstract classes to be allocatable as well. * * @throws IllegalArgumentException if klass is null * */ public boolean isAllocatable(IClass klass) { if (klass == null) { throw new IllegalArgumentException("klass is null"); } if (!klass.isAbstract() && !klass.isInterface()) { return true; } else { return allocatable.contains(klass.getReference()); } } }
/** * Are we allowed to allocate (for analysis purposes) an instance of a given type? By default, the answer is yes iff T is not * abstract. However, subclasses and summaries can override this to allow "special" abstract classes to be allocatable as well. * * @throws IllegalArgumentException if klass is null * */ public boolean isAllocatable(IClass klass) { if (klass == null) { throw new IllegalArgumentException("klass is null"); } if (!klass.isAbstract() && !klass.isInterface()) { return true; } else { return allocatable.contains(klass.getReference()); } } }
/** * Returns all concrete classes implementing the given interface or any subinterfaces */ public Collection<IClass> concreteClassesForInterface(IClass iRoot) { Set<IClass> clazzes = HashSetFactory.make(); Set<IClass> done = HashSetFactory.make(); Deque<IClass> todo = Queues.newArrayDeque(); todo.push(iRoot); while (!todo.isEmpty()) { IClass i = todo.pop(); for (IClass clazz : cha.getImplementors(i.getReference())) { if (clazz.isInterface() && !done.contains(clazz)) { done.add(i); todo.push(clazz); } else if (!clazz.isAbstract()) { clazzes.add(clazz); } } } return clazzes; }
private TypeReference chooseAConcreteSubClass(IClass klass) { Collection<IClass> subclasses = cha.computeSubClasses(klass.getReference()); for (IClass c : subclasses) { if (!c.isAbstract()) { return c.getReference(); } } return null; }
private TypeReference chooseAConcreteSubClass(IClass klass) { Collection<IClass> subclasses = cha.computeSubClasses(klass.getReference()); for (IClass c : subclasses) { if (!c.isAbstract()) { return c.getReference(); } } return null; }
/** * @param c {@code Collection<IClass>} */ private static MutableMapping<InstanceKey> makeInstanceKeys(Collection<IClass> c) { if (c == null) { throw new IllegalArgumentException("null c"); } MutableMapping<InstanceKey> result = MutableMapping.make(); for (IClass klass : c) { if (!klass.isAbstract() && !klass.isInterface()) { result.add(new ConcreteTypeKey(klass)); } } return result; }
/** * @param c {@code Collection<IClass>} */ private static MutableMapping<InstanceKey> makeInstanceKeys(Collection<IClass> c) { if (c == null) { throw new IllegalArgumentException("null c"); } MutableMapping<InstanceKey> result = MutableMapping.make(); for (IClass klass : c) { if (!klass.isAbstract() && !klass.isInterface()) { result.add(new ConcreteTypeKey(klass)); } } return result; }
@Override public Iterator<Entrypoint> iterator() { Set<Entrypoint> ES = HashSetFactory.make(); Iterator<IClass> classes = scriptType.getClassLoader().iterateAllClasses(); while (classes.hasNext()) { IClass cls = classes.next(); if (cha.isSubclassOf(cls, scriptType) && !cls.isAbstract()) { for (IMethod method : cls.getDeclaredMethods()) { if (keep()) { ES.add(new ScriptEntryPoint(method)); } } } } return ES.iterator(); }
@Override public Iterator<Entrypoint> iterator() { Set<Entrypoint> ES = HashSetFactory.make(); Iterator<IClass> classes = scriptType.getClassLoader().iterateAllClasses(); while (classes.hasNext()) { IClass cls = classes.next(); if (cha.isSubclassOf(cls, scriptType) && !cls.isAbstract()) { for (IMethod method : cls.getDeclaredMethods()) { if (keep()) { ES.add(new ScriptEntryPoint(method)); } } } } return ES.iterator(); }
if (klass.isAbstract() || klass.isInterface() || typesAllocated.contains(T)) { continue;
if (!klass.isInterface() && !klass.isAbstract()) { result.addAll(computeTargetsNotInterface(ref, klass));
public Entrypoint make(String scriptName) { IClass cls = cha.lookupClass(TypeReference.findOrCreate(scriptType.getClassLoader().getReference(), scriptName)); assert cls != null && cha.isSubclassOf(cls, scriptType) && !cls.isAbstract() : String.valueOf(cls) + " for " + scriptName; for (IMethod method : cls.getDeclaredMethods()) { if (keep()) { return new ScriptEntryPoint(method); } } assert false; return null; } }
public Entrypoint make(String scriptName) { IClass cls = cha.lookupClass(TypeReference.findOrCreate(scriptType.getClassLoader().getReference(), scriptName)); assert cls != null && cha.isSubclassOf(cls, scriptType) && !cls.isAbstract() : String.valueOf(cls) + " for " + scriptName; for (IMethod method : cls.getDeclaredMethods()) { if (keep()) { return new ScriptEntryPoint(method); } } assert false; return null; } }
@Override protected TypeReference[] makeParameterTypes(IMethod method, int i) { TypeReference nominal = method.getParameterType(i); if (nominal.isPrimitiveType() || nominal.isArrayType()) return new TypeReference[] { nominal }; else { IClass nc = getCha().lookupClass(nominal); if (nc == null) { throw new IllegalStateException("Could not resolve in cha: " + nominal); } Collection<IClass> subcs = nc.isInterface() ? getCha().getImplementors(nominal) : getCha().computeSubClasses(nominal); Set<TypeReference> subs = HashSetFactory.make(); for (IClass cs : subcs) { if (!cs.isAbstract() && !cs.isInterface()) { subs.add(cs.getReference()); } } return subs.toArray(new TypeReference[0]); } } }
@Override protected TypeReference[] makeParameterTypes(IMethod method, int i) { TypeReference nominal = method.getParameterType(i); if (nominal.isPrimitiveType() || nominal.isArrayType()) return new TypeReference[] { nominal }; else { IClass nc = getCha().lookupClass(nominal); if (nc == null) { throw new IllegalStateException("Could not resolve in cha: " + nominal); } Collection<IClass> subcs = nc.isInterface() ? getCha().getImplementors(nominal) : getCha().computeSubClasses(nominal); Set<TypeReference> subs = HashSetFactory.make(); for (IClass cs : subcs) { if (!cs.isAbstract() && !cs.isInterface()) { subs.add(cs.getReference()); } } return subs.toArray(new TypeReference[0]); } } }
/** * If receiver is a {@link ConstantKey} whose value is an {@link IClass}, return a {@link JavaTypeContext} * representing the type of the IClass. (This corresponds to the case where we know the exact type that will be * allocated by the {@code Class.newInstance()} call.) Otherwise, return {@code null}. */ @Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) { if (callee.getReference().equals(ClassNewInstanceContextInterpreter.CLASS_NEW_INSTANCE_REF) && isTypeConstant(receiver[0])) { IClass c = (IClass) ((ConstantKey) receiver[0]).getValue(); if (!c.isAbstract() && !c.isInterface()) { return new JavaTypeContext(new PointType(c)); } } return null; }
/** * If receiver is a {@link ConstantKey} whose value is an {@link IClass}, return a {@link JavaTypeContext} * representing the type of the IClass. (This corresponds to the case where we know the exact type that will be * allocated by the {@code Class.newInstance()} call.) Otherwise, return {@code null}. */ @Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) { if (callee.getReference().equals(ClassNewInstanceContextInterpreter.CLASS_NEW_INSTANCE_REF) && isTypeConstant(receiver[0])) { IClass c = (IClass) ((ConstantKey) receiver[0]).getValue(); if (!c.isAbstract() && !c.isInterface()) { return new JavaTypeContext(new PointType(c)); } } return null; }
public static Iterable<Entrypoint> makePrimordialPublicEntrypoints(ClassHierarchy cha, String pkg) { final HashSet<Entrypoint> result = HashSetFactory.make(); for (IClass clazz : cha) { if (clazz.getName().toString().indexOf(pkg) != -1 && !clazz.isInterface() && !clazz.isAbstract()) { for (IMethod method : clazz.getDeclaredMethods()) { if (method.isPublic() && !method.isAbstract()) { System.out.println("Entry:" + method.getReference()); result.add(new DefaultEntrypoint(method, cha)); } } } } return result::iterator; }