/** * 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 + ")"; } /**
} else if (o instanceof IMethod) { IMethod m = (IMethod) o; return m.isInit() ? TypeReference.JavaLangReflectConstructor : TypeReference.JavaLangReflectMethod; } else if (o instanceof MethodHandle || o instanceof ReferenceToken) { return TypeReference.JavaLangInvokeMethodHandle;
} else if (o instanceof IMethod) { IMethod m = (IMethod) o; return m.isInit() ? TypeReference.JavaLangReflectConstructor : TypeReference.JavaLangReflectMethod; } else if (o instanceof MethodHandle || o instanceof ReferenceToken) { return TypeReference.JavaLangInvokeMethodHandle;
/** * Get all the constructors of a class */ private static Collection<IMethod> getConstructors(IClass cls) { Collection<IMethod> result = HashSetFactory.make(); for (IMethod m : cls.getDeclaredMethods()) { if (m.isInit()) { result.add(m); } } return result; }
/** * Get all the constructors of a class */ private static Collection<IMethod> getConstructors(IClass cls) { Collection<IMethod> result = HashSetFactory.make(); for (IMethod m : cls.getDeclaredMethods()) { if (m.isInit()) { result.add(m); } } return result; }
/** * Get all non-constructor, non-class-initializer methods declared by a class */ private static Collection<IMethod> getDeclaredNormalMethods(IClass cls) { Collection<IMethod> result = HashSetFactory.make(); for (IMethod m : cls.getDeclaredMethods()) { if (!m.isInit() && !m.isClinit()) { result.add(m); } } return result; }
/** * Get all the public constructors of a class */ private static Collection<IMethod> getPublicConstructors(IClass cls) { Collection<IMethod> result = HashSetFactory.make(); for (IMethod m : cls.getDeclaredMethods()) { if (m.isInit() && m.isPublic()) { result.add(m); } } return result; }
/** * Get all the public constructors of a class */ private static Collection<IMethod> getPublicConstructors(IClass cls) { Collection<IMethod> result = HashSetFactory.make(); for (IMethod m : cls.getDeclaredMethods()) { if (m.isInit() && m.isPublic()) { result.add(m); } } return result; }
/** * Get all non-constructor, non-class-initializer methods declared by a class */ private static Collection<IMethod> getDeclaredNormalMethods(IClass cls) { Collection<IMethod> result = HashSetFactory.make(); for (IMethod m : cls.getDeclaredMethods()) { if (!m.isInit() && !m.isClinit()) { result.add(m); } } return result; }
/** * Get all non-constructor, non-class-initializer methods declared by a class and all its superclasses */ private static Collection<IMethod> getAllNormalPublicMethods(IClass cls) { Collection<IMethod> result = HashSetFactory.make(); Collection<? extends IMethod> allMethods = null; allMethods = cls.getAllMethods(); for (IMethod m : allMethods) { if (!m.isInit() && !m.isClinit() && m.isPublic()) { result.add(m); } } return result; }
/** * Get all non-constructor, non-class-initializer methods declared by a class and all its superclasses */ private static Collection<IMethod> getAllNormalPublicMethods(IClass cls) { Collection<IMethod> result = HashSetFactory.make(); Collection<? extends IMethod> allMethods = null; allMethods = cls.getAllMethods(); for (IMethod m : allMethods) { if (!m.isInit() && !m.isClinit() && m.isPublic()) { result.add(m); } } return result; }
/** * Get all non-constructor, non-class-initializer methods declared by a class * if their name is equal to the specified name. * @param cls the class * @param name the name */ private static Collection<IMethod> getDeclaredNormalMethods(IClass cls,Atom name) { Collection<IMethod> result = HashSetFactory.make(); for (IMethod m : cls.getDeclaredMethods()) { if (!m.isInit() && !m.isClinit() && m.getSelector().getName().equals(name)) { result.add(m); } } return result; }
/** * Get all non-constructor, non-class-initializer methods declared by a class * if their name is equal to the specified name. * @param cls the class * @param name the name */ private static Collection<IMethod> getDeclaredNormalMethods(IClass cls,Atom name) { Collection<IMethod> result = HashSetFactory.make(); for (IMethod m : cls.getDeclaredMethods()) { if (!m.isInit() && !m.isClinit() && m.getSelector().getName().equals(name)) { result.add(m); } } return result; }
/** * Get all non-constructor, non-class-initializer methods declared by a class * and all its superclasses if their name is equal to the specified name. * @param cls the class * @param name the name */ private static Collection<IMethod> getAllNormalPublicMethods(IClass cls,Atom name) { Collection<IMethod> result = HashSetFactory.make(); Collection<? extends IMethod> allMethods = null; allMethods = cls.getAllMethods(); for (IMethod m : allMethods) { if (!m.isInit() && !m.isClinit() && m.isPublic() && m.getSelector().getName().equals(name)) { result.add(m); } } return result; }
/** * Get all non-constructor, non-class-initializer methods declared by a class * and all its superclasses if their name is equal to the specified name. * @param cls the class * @param name the name */ private static Collection<IMethod> getAllNormalPublicMethods(IClass cls,Atom name) { Collection<IMethod> result = HashSetFactory.make(); Collection<? extends IMethod> allMethods = null; allMethods = cls.getAllMethods(); for (IMethod m : allMethods) { if (!m.isInit() && !m.isClinit() && m.isPublic() && m.getSelector().getName().equals(name)) { result.add(m); } } return result; }
/** * Read the parameters from an IMethod. * * Using this Constructor influences the SSA-Values returned later. * * @param method The method to read the parameters from. */ public ParameterAccessor(final IMethod method) { if (method == null) { throw new IllegalArgumentException("Can't read the arguments from null."); } // Don't make a mRef but keep the IMethod! this.mRef = null; this.method = method; this.base = BasedOn.IMETHOD; this.numberOfParameters = method.getReference().getNumberOfParameters(); if (method.isStatic() && (! method.isInit())) { assert(method.getNumberOfParameters() == method.getReference().getNumberOfParameters()) : "WTF!" + method; this.implicitThis = -1; this.descriptorOffset = 0; } else { assert(method.getNumberOfParameters() == 1 + method.getReference().getNumberOfParameters()) : "WTF!" + method; this.implicitThis = 1; this.descriptorOffset = -1; } }
/** * Read the parameters from an IMethod. * * Using this Constructor influences the SSA-Values returned later. * * @param method The method to read the parameters from. */ public ParameterAccessor(final IMethod method) { if (method == null) { throw new IllegalArgumentException("Can't read the arguments from null."); } // Don't make a mRef but keep the IMethod! this.mRef = null; this.method = method; this.base = BasedOn.IMETHOD; this.numberOfParameters = method.getReference().getNumberOfParameters(); if (method.isStatic() && (! method.isInit())) { assert(method.getNumberOfParameters() == method.getReference().getNumberOfParameters()) : "WTF!" + method; this.implicitThis = -1; this.descriptorOffset = 0; } else { assert(method.getNumberOfParameters() == 1 + method.getReference().getNumberOfParameters()) : "WTF!" + method; this.implicitThis = 1; this.descriptorOffset = -1; } }
public static Set<IMethod> assertUserCodeReachable(CallGraph cg, Set<MethodReference> uncalled) { Set<IMethod> result = HashSetFactory.make(); for(IClass cls : Iterator2Iterable.make(cg.getClassHierarchy().getLoader(ClassLoaderReference.Application).iterateAllClasses())) { if (cls.isInterface()) { continue; } if (! cls.getName().toString().startsWith("Landroid") && ! cls.getName().toString().equals("Lde/ecspride/R$styleable")) { for(IMethod m : cls.getDeclaredMethods()) { if (!m.isInit() && !m.isAbstract() && !uncalled.contains(m.getReference())) { if (! cg.getNodes(m.getReference()).isEmpty()) { System.err.println("found " + m); } else { result.add(m); } } } } } return result; }
/** * Get the "setUp" and "tearDown" methods in the given class */ public static Set<IMethod> getSetUpTearDownMethods(IClass testClass) { final Atom junitPackage = Atom.findOrCreateAsciiAtom("junit/framework"); final Atom junitClass = Atom.findOrCreateAsciiAtom("TestCase"); final Atom junitSuite = Atom.findOrCreateAsciiAtom("TestSuite"); final TypeName junitTestCaseType = TypeName.findOrCreateClass(junitPackage, junitClass); final TypeName junitTestSuiteType = TypeName.findOrCreateClass(junitPackage, junitSuite); final Atom setUpMethodAtom = Atom.findOrCreateAsciiAtom("setUp"); final Atom tearDownMethodAtom = Atom.findOrCreateAsciiAtom("tearDown"); Set<IMethod> result = HashSetFactory.make(); IClass currClass = testClass; while (currClass != null && !currClass.getName().equals(junitTestCaseType) && !currClass.getName().equals(junitTestSuiteType)) { for (IMethod method : currClass.getDeclaredMethods()) { final Atom methodAtom = method.getName(); if (methodAtom.equals(setUpMethodAtom) || methodAtom.equals(tearDownMethodAtom) || method.isClinit() || method.isInit()) { result.add(method); } } currClass = currClass.getSuperclass(); } return result; } }
/** * Get the "setUp" and "tearDown" methods in the given class */ public static Set<IMethod> getSetUpTearDownMethods(IClass testClass) { final Atom junitPackage = Atom.findOrCreateAsciiAtom("junit/framework"); final Atom junitClass = Atom.findOrCreateAsciiAtom("TestCase"); final Atom junitSuite = Atom.findOrCreateAsciiAtom("TestSuite"); final TypeName junitTestCaseType = TypeName.findOrCreateClass(junitPackage, junitClass); final TypeName junitTestSuiteType = TypeName.findOrCreateClass(junitPackage, junitSuite); final Atom setUpMethodAtom = Atom.findOrCreateAsciiAtom("setUp"); final Atom tearDownMethodAtom = Atom.findOrCreateAsciiAtom("tearDown"); Set<IMethod> result = HashSetFactory.make(); IClass currClass = testClass; while (currClass != null && !currClass.getName().equals(junitTestCaseType) && !currClass.getName().equals(junitTestSuiteType)) { for (IMethod method : currClass.getDeclaredMethods()) { final Atom methodAtom = method.getName(); if (methodAtom.equals(setUpMethodAtom) || methodAtom.equals(tearDownMethodAtom) || method.isClinit() || method.isInit()) { result.add(method); } } currClass = currClass.getSuperclass(); } return result; } }