if (!pkgName.isEmpty() && !cls.getName().toString().startsWith(pkgName)) continue; LOG(DEBUG, "DEBUG", "analyzing class: " + cls.getName().toString()); for (IMethod mtd : Iterator2Iterable.make(cls.getDeclaredMethods().iterator())) { && !isAllPrimitiveTypes(mtd) && !mtd.getDeclaringClass() .getClassLoader() .getName() .toString()
private TypeReference chooseAConcreteSubClass(IClass klass) { Collection<IClass> subclasses = cha.computeSubClasses(klass.getReference()); for (IClass c : subclasses) { if (!c.isAbstract()) { return c.getReference(); } } return null; }
/** * Does a particular class contain (implement) a particular method? * * @param clazz class in question * @param selector method selector * @return the method if found, else null */ private static IMethod findMethod(IClass clazz, Selector selector) { return clazz.getMethod(selector); }
@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(); }
public static boolean representsNullType(InstanceKey key) throws IllegalArgumentException { if (key == null) { throw new IllegalArgumentException("key == null"); } IClass cls = key.getConcreteType(); Language L = cls.getClassLoader().getLanguage(); return L.isNullType(cls.getReference()); }
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; }
/** * @return an Iterator of IClass that implement this interface */ public Iterator<IClass> iterateImplementors() { return type.getClassHierarchy().getImplementors(getType().getReference()).iterator(); }
/** * Get astubx style method signature. {FullyQualifiedEnclosingType}: {UnqualifiedMethodReturnType} * {methodName} ([{UnqualifiedArgumentType}*]) * * @param mtd Method reference. * @return String Method signature. */ // TODO: handle generics and inner classes private static String getSignature(IMethod mtd) { String classType = mtd.getDeclaringClass().getName().toString().replaceAll("/", "\\.").substring(1); classType = classType.replaceAll("\\$", "\\."); // handle inner class String returnType = mtd.isInit() ? null : getSimpleTypeName(mtd.getReturnType()); String strArgTypes = ""; int argi = mtd.isStatic() ? 0 : 1; // Skip 'this' parameter for (; argi < mtd.getNumberOfParameters(); argi++) { strArgTypes += getSimpleTypeName(mtd.getParameterType(argi)); if (argi < mtd.getNumberOfParameters() - 1) strArgTypes += ", "; } return classType + ":" + (returnType == null ? "void " : returnType + " ") + mtd.getName().toString() + "(" + strArgTypes + ")"; } /**
private static boolean isAPIComponent(final IClass cls) { ClassLoaderReference clr = cls.getClassLoader().getReference(); if (! (clr.equals(ClassLoaderReference.Primordial) || clr.equals(ClassLoaderReference.Extension))) { if (cls.getName().toString().startsWith("Landroid/")) { return true; } return false; } else { return true; } }
@Deprecated public static boolean isApplicationClass(IClass clazz) { // we need the additional check as framework classes from the support package are loaded via the Application classloader return clazz.getClassHierarchy().getScope().isApplicationLoader(clazz.getClassLoader()) && !clazz.getName().toString().startsWith("Landroid"); // strip android.v4 / android.v7 support packages as they are considered part of the framework // TODO necessary? support packages are loaded via Primordial! }
@Override public int getNumberOfMethods() { return types.values().stream() .mapToInt(cls -> cls.getDeclaredMethods().size()) .sum(); }
public static boolean fromLoader(IClass declClass, ClassLoaderReference clr) { ClassLoaderReference nodeClRef = declClass.getClassLoader().getReference(); return nodeClRef.equals(clr); } }
@Override public Collection<? extends IMethod> getAllMethods() { return realType.getAllMethods(); }
/** * @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 boolean isInterface(TypeReference type) { IClass T = lookupClass(type); assert T != null : "Null lookup for " + type; return T.isInterface(); }
private TypeReference chooseAnImplementor(IClass iface) { Set implementors = cha.getImplementors(iface.getReference()); if (!implementors.isEmpty()) { return ((IClass) implementors.iterator().next()).getReference(); } else { return null; } }
private void registerInstanceWithAllSuperclasses(int index, IClass T) { while (T != null && !T.getReference().equals(TypeReference.JavaLangObject)) { MutableIntSet set = findOrCreateSparseSetForClass(T); set.add(index); if (DEBUG) { System.err.println("dense filter for class " + T + ' ' + set); } T = T.getSuperclass(); } }
protected TypeInference(IR ir, boolean doPrimitives) { if (ir == null) { throw new IllegalArgumentException("ir is null"); } this.language = ir.getMethod().getDeclaringClass().getClassLoader().getLanguage(); this.cha = ir.getMethod().getDeclaringClass().getClassHierarchy(); this.ir = ir; this.doPrimitives = doPrimitives; this.BOTTOM = new ConeType(cha.getRootClass()); initialize(); solve(); }
@Override public Collection<IClass> getAllImplementedInterfaces() { Collection<IClass> realIfaces = realType.getAllImplementedInterfaces(); if (realType.isInterface()) { HashSet<IClass> result = HashSetFactory.make(realIfaces); result.add(realType); return result; } else { return realIfaces; } }
public static boolean isThrowable(IClass c) { if (c == null) { throw new IllegalArgumentException("null c"); } return c.getClassHierarchy().isSubclassOf(c, c.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable)); }