JavaClass[] infs = newCls.getAllInterfaces(); for (JavaClass inf : infs) { if (xmlInterfaces.contains(inf.getClassName())) {
@Override public void visitClassContext(ClassContext classContext) { try { JavaClass cls = classContext.getJavaClass(); superclassName = cls.getSuperclassName(); JavaClass[] interfaces = null; if (cls.isClass() && ((cls.getAccessFlags() & Const.ACC_ABSTRACT) != 0)) { interfaces = cls.getAllInterfaces(); interfaceMethods = new HashSet<>(); for (JavaClass aInterface : interfaces) { Method[] infMethods = aInterface.getMethods(); for (Method meth : infMethods) { interfaceMethods.add(meth.getName() + meth.getSignature()); } } } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } super.visitClassContext(classContext); }
/** * Visit all superinterface methods which the given method implements. * * @param method * the method * @param chooser * chooser which visits each superinterface method * @return the chosen method, or null if no method is chosen * @throws ClassNotFoundException */ public static JavaClassAndMethod visitSuperInterfaceMethods(JavaClassAndMethod method, JavaClassAndMethodChooser chooser) throws ClassNotFoundException { return findMethod(method.getJavaClass().getAllInterfaces(), method.getMethod().getName(), method.getMethod() .getSignature(), chooser); }
JavaClass[] interfaceList = javaClass.getAllInterfaces(); if (interfaceList != null) { JavaClassAndMethod match = Hierarchy.findMethod(interfaceList, method.getName(), method.getSignature(),
/** * @return all interfaces implemented by class and its super * classes and the interfaces that those interfaces extend, and so on. * (Some people call this a transitive hull). * @throws ClassNotFoundException if any of the class's * superclasses or superinterfaces can't be found */ public static JavaClass[] getInterfaces( final JavaClass clazz ) throws ClassNotFoundException { return clazz.getAllInterfaces(); }
/** * @return all interfaces implemented by class and its super * classes and the interfaces that those interfaces extend, and so on. * (Some people call this a transitive hull). */ public static JavaClass[] getInterfaces(JavaClass clazz) { return clazz.getAllInterfaces(); }
/** * returns if the class implements Serializable or Externalizable * * @param cls * the class to check for interfaces * * @return if the class implements Serializable or Externalizable * * @throws ClassNotFoundException * if a super class or super interfaces can't be found */ private static boolean isSerializable(JavaClass cls) throws ClassNotFoundException { JavaClass[] infs = cls.getAllInterfaces(); for (JavaClass inf : infs) { String clsName = inf.getClassName(); if ("java.io.Serializable".equals(clsName) || "java.io.Externalizable".equals(clsName)) { return true; } } return false; }
/** * @return true, if clazz is an implementation of interface inter */ public boolean implementationOf(JavaClass inter) { if(!inter.isInterface()) { throw new IllegalArgumentException(inter.getClassName() + " is no interface"); } if(this.equals(inter)) { return true; } JavaClass[] super_interfaces = getAllInterfaces(); for(int i=0; i < super_interfaces.length; i++) { if(super_interfaces[i].equals(inter)) { return true; } } return false; }
private Set<MethodAndSink> getSuperSinks(JavaClass javaClass, String method) throws ClassNotFoundException { for (JavaClass superClass : javaClass.getSuperClasses()) { String fullMethodName = superClass.getClassName().replace('.', '/').concat(method); Set<InjectionSink> sinks = injectionSinks.get(fullMethodName); if (sinks != null) { return getMethodAndSinks(fullMethodName, sinks); } } for (JavaClass interfaceClass : javaClass.getAllInterfaces()) { String fullMethodName = interfaceClass.getClassName().replace('.', '/').concat(method); Set<InjectionSink> sinks = injectionSinks.get(fullMethodName); if (sinks != null) { return getMethodAndSinks(fullMethodName, sinks); } } return Collections.emptySet(); }
private Set<QMethod> collectInterfaceMethods(JavaClass cls) throws ClassNotFoundException { Set<QMethod> methods = new HashSet<>(); for (JavaClass inf : cls.getAllInterfaces()) { for (Method m : inf.getMethods()) { methods.add(new QMethod(m.getName(), m.getSignature())); } } return methods; } }
private Set<QMethod> collectInterfaceMethods(JavaClass cls) throws ClassNotFoundException { Set<QMethod> methods = new HashSet<>(); for (JavaClass inf : cls.getAllInterfaces()) { for (Method m : inf.getMethods()) { methods.add(new QMethod(m.getName(), m.getSignature())); } } return methods; } }
private Set<MethodAndSink> getSuperSinks(JavaClass javaClass, String method) throws ClassNotFoundException { for (JavaClass superClass : javaClass.getSuperClasses()) { String fullMethodName = superClass.getClassName().replace('.', '/').concat(method); Set<InjectionSink> sinks = injectionSinks.get(fullMethodName); if (sinks != null) { return getMethodAndSinks(fullMethodName, sinks); } } for (JavaClass interfaceClass : javaClass.getAllInterfaces()) { String fullMethodName = interfaceClass.getClassName().replace('.', '/').concat(method); Set<InjectionSink> sinks = injectionSinks.get(fullMethodName); if (sinks != null) { return getMethodAndSinks(fullMethodName, sinks); } } return Collections.emptySet(); }
/** * returns a map of method information for each public method for each interface * this class implements * * @param cls the class whose interfaces to record * * @return a map of (method name)(method sig) by interface * @throws ClassNotFoundException if unable to load the class */ private static Map<JavaClass, List<MethodInfo>> getClassDefiners(final JavaClass cls) throws ClassNotFoundException { Map<JavaClass, List<MethodInfo>> definers = new HashMap<>(); for (JavaClass ci : cls.getAllInterfaces()) { if (cls.equals(ci) || !cls.isPublic() || "java.lang.Comparable".equals(ci.getClassName())) { continue; } List<MethodInfo> methodInfos = getPublicMethodInfos(ci); if (!methodInfos.isEmpty()) { definers.put(ci, methodInfos); } } return definers; }
public static boolean isInheritedMethod(JavaClass cls, String methodName, String signature) throws ClassNotFoundException { JavaClass[] infs = cls.getAllInterfaces(); if (findInheritedMethod(infs, methodName, signature) != null) { return true; } JavaClass[] supers = cls.getSuperClasses(); for (int i = 0; i < supers.length; i++) { if (Values.DOTTED_JAVA_LANG_OBJECT.equals(supers[i].getClassName())) { supers[i] = null; } } return findInheritedMethod(supers, methodName, signature) != null; }
public static boolean isInheritedMethod(JavaClass cls, String methodName, String signature) throws ClassNotFoundException { JavaClass[] infs = cls.getAllInterfaces(); if (findInheritedMethod(infs, methodName, signature) != null) { return true; } JavaClass[] supers = cls.getSuperClasses(); for (int i = 0; i < supers.length; i++) { if (Values.DOTTED_JAVA_LANG_OBJECT.equals(supers[i].getClassName())) { supers[i] = null; } } return findInheritedMethod(supers, methodName, signature) != null; }
/** * @return true, if this class is an implementation of interface inter * @throws ClassNotFoundException if superclasses or superinterfaces * of this class can't be found */ public boolean implementationOf( final JavaClass inter ) throws ClassNotFoundException { if (!inter.isInterface()) { throw new IllegalArgumentException(inter.getClassName() + " is no interface"); } if (this.equals(inter)) { return true; } final JavaClass[] super_interfaces = getAllInterfaces(); for (final JavaClass super_interface : super_interfaces) { if (super_interface.equals(inter)) { return true; } } return false; }
public TaintMethodConfig getSuperMethodConfig(String className, String methodId) { try { if (className.endsWith("]")) { // not a real class return null; } JavaClass javaClass = Repository.lookupClass(className); assert javaClass != null; TaintMethodConfig methodConfig = getSuperMethodConfig(javaClass.getSuperClasses(), methodId); if (methodConfig != null) { return methodConfig; } return getSuperMethodConfig(javaClass.getAllInterfaces(), methodId); } catch (ClassNotFoundException ex) { AnalysisContext.reportMissingClass(ex); return null; } }
public TaintMethodConfig getSuperMethodConfig(String className, String methodId) { try { if (className.endsWith("]")) { // not a real class return null; } JavaClass javaClass = Repository.lookupClass(className); assert javaClass != null; TaintMethodConfig methodConfig = getSuperMethodConfig(javaClass.getSuperClasses(), methodId); if (methodConfig != null) { return methodConfig; } return getSuperMethodConfig(javaClass.getAllInterfaces(), methodId); } catch (ClassNotFoundException ex) { AnalysisContext.reportMissingClass(ex); return null; } }
/** * Visit all superinterface methods which the given method implements. * * @param method * the method * @param chooser * chooser which visits each superinterface method * @return the chosen method, or null if no method is chosen * @throws ClassNotFoundException */ public static JavaClassAndMethod visitSuperInterfaceMethods(JavaClassAndMethod method, JavaClassAndMethodChooser chooser) throws ClassNotFoundException { return findMethod(method.getJavaClass().getAllInterfaces(), method.getMethod().getName(), method.getMethod() .getSignature(), chooser); }
@Override public void visitClassContext(ClassContext classContext) { try { JavaClass cls = classContext.getJavaClass(); superclassName = cls.getSuperclassName(); JavaClass[] interfaces = null; if (cls.isClass() && ((cls.getAccessFlags() & Constants.ACC_ABSTRACT) != 0)) { interfaces = cls.getAllInterfaces(); interfaceMethods = new HashSet<String>(); for (JavaClass aInterface : interfaces) { Method[] infMethods = aInterface.getMethods(); for (Method meth : infMethods) { interfaceMethods.add(meth.getName() + meth.getSignature()); } } } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } super.visitClassContext(classContext); }