/** * 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 isType(IMethod node) { return node.getName().toString().equals("type"); }
private static boolean isInvoke(IMethod node) { return node.getName().toString().startsWith("invoke"); }
private static boolean isType(IMethod node) { return node.getName().toString().equals("type"); }
public void addMethod(IMethod method) { if (this.methods.containsKey(method.getSelector())) { // TODO: Check this matches on signature not on contents! // TODO: What on different Context versions throw new IllegalStateException("The AndroidModelClass already contains a Method called" + method.getName()); } assert(this.methods != null); this.methods.put(method.getSelector(), method); }
public void addMethod(IMethod method) { if (this.methods.containsKey(method.getSelector())) { // TODO: Check this matches on signature not on contents! // TODO: What on different Context versions throw new IllegalStateException("The AndroidModelClass already contains a Method called" + method.getName()); } assert(this.methods != null); this.methods.put(method.getSelector(), method); }
@Override public String toString() { return "p" + param + ':' + getNode().getMethod().getName(); }
@Override public String toString() { return "p" + param + ':' + getNode().getMethod().getName(); }
public static boolean isRealFunction(IMethod method) { if(method instanceof AstMethod) { String methodName = method.getDeclaringClass().getName().toString(); // exclude synthetic DOM modelling functions if(methodName.contains("/make_node")) return false; if(IGNORE_HARNESS) { for(String bootstrapFile : JavaScriptLoader.bootstrapFileNames) if(methodName.startsWith('L' + bootstrapFile + '/')) return false; } return method.getName().equals(AstMethodReference.fnAtom); } return false; }
private static IMethod getCallTargetMethod(IMethod method) { if(method.getName().equals(JavaScriptMethods.ctorAtom)) { method = method.getDeclaringClass().getMethod(AstMethodReference.fnSelector); if(method != null) return method; } return method; }
private static IMethod getCallTargetMethod(IMethod method) { if(method.getName().equals(JavaScriptMethods.ctorAtom)) { method = method.getDeclaringClass().getMethod(AstMethodReference.fnSelector); if(method != null) return method; } return method; }
private Collection<IMethod> lookupMethods(IClass c) { Collection<IMethod> matching = new LinkedList<>(); Atom atom = Atom.findOrCreateUnicodeAtom(memberName); Descriptor desc = descriptor == null ? null : Descriptor.findOrCreateUTF8(descriptor); Collection<? extends IMethod> allMethods = c.getAllMethods(); for(IMethod m: allMethods) { if(m.getName().equals(atom) && (desc == null || m.getDescriptor().equals(desc))) { matching.add(m); } } return matching; }
private void checkThrownExceptions(CGNode node, IntraproceduralExceptionAnalysis analysis) { Set<TypeReference> exceptions = analysis.getExceptions(); String text = "Number of thrown exceptions did not match in " + node.getMethod().getName().toString() + ". The follwoing exceptions were thrown: " + exceptions.toString(); if (node.getMethod().getName().toString().matches("invokeSingle.*") && (!node.getMethod().getName().toString().equals("invokeSingleRecursive2Helper")) && (!node.getMethod().getName().toString().equals("invokeSinglePassThrough"))) { collector.checkThat(text, exceptions.size(), equalTo(1)); } else { collector.checkThat(text, exceptions.size(), equalTo(0)); } }
private final static CGNode findNode(CallGraph cg, String methodName) { for (CGNode n : cg) { if (n.getMethod().getName().toString().equals(methodName)) { return n; } } Assertions.UNREACHABLE("Unexpected: failed to find " + methodName + " node"); return null; }
private final static CGNode findDoNothingNode(CallGraph cg) { for (CGNode n : cg) { if (n.getMethod().getName().toString().equals("doNothing")) { return n; } } Assertions.UNREACHABLE("Unexpected: failed to find doNothing node"); return null; } }
public static CGNode findMethod(CallGraph cg, String name) { Atom a = Atom.findOrCreateUnicodeAtom(name); for (CGNode n : cg) { if (n.getMethod().getName().equals(a)) { return n; } } System.err.println("call graph " + cg); Assertions.UNREACHABLE("failed to find method " + name); return null; }
@Override public Set<CGNode> getNodes(MethodReference m) { if (m.getName().equals(JavaScriptMethods.ctorAtom)) { // TODO cache this? Set<CGNode> result = HashSetFactory.make(1); for (CGNode n : this) { IMethod method = n.getMethod(); if (method.getName().equals(JavaScriptMethods.ctorAtom) && method.getDeclaringClass().getReference().equals(m.getDeclaringClass())) { result.add(n); } } return result; } else { return super.getNodes(m); } }
public static CGNode findInstanceMethod(CallGraph cg, IClass declaringClass, Atom name, Descriptor args) { for (CGNode n : cg) { // System.err.println(n.getMethod().getDeclaringClass() + " " + // n.getMethod().getName() + " " + n.getMethod().getDescriptor()); if (n.getMethod().getDeclaringClass().equals(declaringClass) && n.getMethod().getName().equals(name) && n.getMethod().getDescriptor().equals(args)) { return n; } } Assertions.UNREACHABLE("failed to find method"); return null; }
public static CGNode findStaticMethod(CallGraph cg, Atom name, Descriptor args) { for (CGNode n : cg) { // System.err.println(n.getMethod().getName() + " " + // n.getMethod().getDescriptor()); if (n.getMethod().getName().equals(name) && n.getMethod().getDescriptor().equals(args)) { return n; } } Assertions.UNREACHABLE("failed to find method"); return null; }
public static CGNode findMainMethod(CallGraph cg) { Descriptor d = Descriptor.findOrCreateUTF8("([Ljava/lang/String;)V"); Atom name = Atom.findOrCreateUnicodeAtom("main"); for (CGNode n : Iterator2Iterable.make(cg.getSuccNodes(cg.getFakeRootNode()))) { if (n.getMethod().getName().equals(name) && n.getMethod().getDescriptor().equals(d)) { return n; } } Assertions.UNREACHABLE("failed to find method"); return null; }