@Override public Collection<? extends IMethod> getAllMethods() { return realType.getAllMethods(); }
@Override public Collection<? extends IMethod> getAllMethods() { return realType.getAllMethods(); }
/** * Looks up a method by name in a class object. If the method is overloaded, * the first one found is returned. * @param clazz IClass object * @param methodName name of the method to be looked up * @return IMethod if method is declared in clazz, null otherwise */ public static IMethod getMethodByName(IClass clazz, String methodName) { for (IMethod m: clazz.getAllMethods()) { // DeclaredMethods()) -> only impl./overriden methods if (m.getSelector().toString().startsWith(methodName)) { return m; } } return null; }
@Override public Collection<? extends IMethod> getAllMethods() { Collection<IMethod> result = HashSetFactory.make(); result.addAll(getDeclaredMethods()); if (getSuperclass() != null) { result.addAll(getSuperclass().getAllMethods()); } return result; }
public static IMethod getIMethod(IClassHierarchy cha, String signature) { // TODO: throw exceptions String clazzName = Utils.getFullClassName(signature); String selector = signature.substring(clazzName.length()+1); try { IClass clazz = WalaUtils.lookupClass(cha, clazzName); for (IMethod m: clazz.getAllMethods()) { // DeclaredMethods()) -> only impl./overriden methods if (m.getSelector().toString().equals(selector)) { return m; } } } catch (ClassNotFoundException e) { logger.debug("Classname " + clazzName + " could not be looked up!"); } return null; // TODO: throw exception }
@Override public Collection<? extends IMethod> getAllMethods() { Collection<IMethod> result = HashSetFactory.make(); result.addAll(getDeclaredMethods()); if (getSuperclass() != null) { result.addAll(getSuperclass().getAllMethods()); } return result; }
protected LexicalParent[] getParents(InstanceKey base) { IClass cls = base.getConcreteType(); if (isPossiblyLexicalClass(cls)) { Set<LexicalParent> result = HashSetFactory.make(); for (IMethod m : cls.getAllMethods()) { if ((m instanceof AstMethod) && !m.isStatic()) { AstMethod M = (AstMethod) m; LexicalParent[] parents = M.getParents(); result.addAll(Arrays.asList(parents)); } } if (!result.isEmpty()) { if (AstTranslator.DEBUG_LEXICAL) System.err.println((base + " has parents: " + result)); return result.toArray(new LexicalParent[0]); } } if (AstTranslator.DEBUG_LEXICAL) System.err.println((base + " has no parents")); return new LexicalParent[0]; }
protected LexicalParent[] getParents(InstanceKey base) { IClass cls = base.getConcreteType(); if (isPossiblyLexicalClass(cls)) { Set<LexicalParent> result = HashSetFactory.make(); for (IMethod m : cls.getAllMethods()) { if ((m instanceof AstMethod) && !m.isStatic()) { AstMethod M = (AstMethod) m; LexicalParent[] parents = M.getParents(); result.addAll(Arrays.asList(parents)); } } if (!result.isEmpty()) { if (AstTranslator.DEBUG_LEXICAL) System.err.println((base + " has parents: " + result)); return result.toArray(new LexicalParent[0]); } } if (AstTranslator.DEBUG_LEXICAL) System.err.println((base + " has no parents")); return new LexicalParent[0]; }
/** * 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; }
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; }
@Override public Collection<IMethod> getAllMethods() { Collection<IMethod> result = new LinkedList<>(getDeclaredMethods()); if (isInterface()) { for (IClass i : getDirectInterfaces()) { result.addAll(i.getAllMethods()); } } else { // for non-interfaces, add default methods inherited from interfaces #219. for (IClass i : this.getAllImplementedInterfaces()) for (IMethod m : i.getDeclaredMethods()) if (!m.isAbstract()) result.add(m); } IClass s = getSuperclass(); while (s != null) { result.addAll(s.getDeclaredMethods()); s = s.getSuperclass(); } return result; }
/** * Hierarchy lookup of a method selector. If the method is not declared in the class * the lookup is continued at the superclass. This is continued until the method is found or * the Object class is reached * @param clazz the IClass to start with * @param selector the method selector * @return a IMethod object of the method in question * @throws MethodNotFoundException */ public static IMethod lookupMethod(IClass clazz, String selector) throws MethodNotFoundException { for (IMethod im: clazz.getAllMethods()) { if (im.getSelector().toString().equals(selector)) { return im; } } throw new MethodNotFoundException("[lookupMethod] Method " + selector + " not found in class: " + clazz.getName().toString() + " and its superclasses"); }
@Override public Collection<IMethod> getAllMethods() { Collection<IMethod> result = new LinkedList<>(getDeclaredMethods()); if (isInterface()) { for (IClass i : getDirectInterfaces()) { result.addAll(i.getAllMethods()); } } else { // for non-interfaces, add default methods inherited from interfaces #219. for (IClass i : this.getAllImplementedInterfaces()) for (IMethod m : i.getDeclaredMethods()) if (!m.isAbstract()) result.add(m); } IClass s = getSuperclass(); while (s != null) { result.addAll(s.getDeclaredMethods()); s = s.getSuperclass(); } return result; }
@Override public Collection<? extends IMethod> getAllMethods() { return loader.lookupClass(getClassLoader().getLanguage().getRootType().getName()).getAllMethods(); }
@Override public Collection<? extends IMethod> getAllMethods() { return loader.lookupClass(getClassLoader().getLanguage().getRootType().getName()).getAllMethods(); }
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(SourceModule[] scripts_array) throws ClassHierarchyException { JSCallGraphUtil.setTranslatorFactory(translatorFactory); JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(null); CAstAnalysisScope scope = new CAstAnalysisScope(scripts_array, loaders, Collections.singleton(JavaScriptLoader.JS)); IClassHierarchy cha = ClassHierarchyFactory.make(scope, loaders, JavaScriptLoader.JS); try { com.ibm.wala.cast.util.Util.checkForFrontEndErrors(cha); } catch (WalaException e) { return Collections.emptyMap(); } IRFactory<IMethod> factory = AstIRFactory.makeDefaultFactory(); Map<IMethod, CorrelationSummary> correlations = HashMapFactory.make(); for(IClass klass : cha) { for(IMethod method : klass.getAllMethods()) { IR ir = factory.makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions()); CorrelationSummary summary = findCorrelatedAccesses(method, ir); if(!summary.getCorrelations().isEmpty()) correlations.put(method, summary); } } return correlations; }
/** * 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; }
@Override public IR getIR(CGNode node) { if (!irs.containsKey(node) || irs.get(node).get() == null) { MethodSummary code = new MethodSummary(node.getMethod().getReference()); SummarizedMethod m = new SummarizedMethod(node.getMethod().getReference(), code, node.getMethod().getDeclaringClass()); SSAInstructionFactory insts = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().instructionFactory(); assert node.getContext().isA(FindContext.class); @SuppressWarnings("unchecked") IClass cls = node.getClassHierarchy().lookupClass(((HandlesItem<TypeReference>)node.getContext().get(CLASS_KEY)).item); @SuppressWarnings("unchecked") String selector = ((HandlesItem<String>)node.getContext().get(NAME_KEY)).item; int vn = 10; for(IMethod handleMethod : cls.getAllMethods()) { if (handleMethod.getName().toString().contains(selector)) { code.addStatement(insts.LoadMetadataInstruction(code.getNextProgramCounter(), vn, TypeReference.JavaLangInvokeMethodHandle, handleMethod.getReference())); code.addStatement(insts.ReturnInstruction(code.getNextProgramCounter(), vn , false)); vn++; } } irs.put(node, new SoftReference<>(m.makeIR(node.getContext(), SSAOptions.defaultOptions()))); } return irs.get(node).get(); } }