/** * Find a method in given list of classes, searching the classes in order. * * @param classList * list of classes in which to search * @param methodName * the name of the method * @param methodSig * the signature of the method * @param chooser * JavaClassAndMethodChooser to select which methods are * considered; it must return true for a method to be returned * @return the JavaClassAndMethod, or null if no such method exists in the * class */ public static JavaClassAndMethod findMethod(JavaClass[] classList, String methodName, String methodSig, JavaClassAndMethodChooser chooser) { JavaClassAndMethod m = null; for (JavaClass cls : classList) { if ((m = findMethod(cls, methodName, methodSig, chooser)) != null) { break; } } return m; }
/** * Find a method in given list of classes, searching the classes in order. * * @param classList * list of classes in which to search * @param methodName * the name of the method * @param methodSig * the signature of the method * @return the JavaClassAndMethod, or null if no such method exists in the * class */ @Deprecated public static JavaClassAndMethod findMethod(JavaClass[] classList, String methodName, String methodSig) { return findMethod(classList, methodName, methodSig, ANY_METHOD); }
/** * Find a method in given class. * * @param javaClass * the class * @param methodName * the name of the method * @param methodSig * the signature of the method * @return the JavaClassAndMethod, or null if no such method exists in the * class */ public static @CheckForNull JavaClassAndMethod findMethod(JavaClass javaClass, String methodName, String methodSig) { return findMethod(javaClass, methodName, methodSig, ANY_METHOD); }
/** * Find a method in given class. * * @param javaClass * the class * @param methodName * the name of the method * @param methodSig * the signature of the method * @param chooser * the JavaClassAndMethodChooser to use to screen possible * candidates * @return the XMethod, or null if no such method exists in the class */ @Deprecated public static @CheckForNull XMethod findXMethod(JavaClass javaClass, String methodName, String methodSig, JavaClassAndMethodChooser chooser) { JavaClassAndMethod result = findMethod(javaClass, methodName, methodSig, chooser); return result == null ? null : XFactory.createXMethod(result.getJavaClass(), result.getMethod()); }
/** * Find XMethod for method in given list of classes, searching the classes * in order. * * @param classList * list of classes in which to search * @param methodName * the name of the method * @param methodSig * the signature of the method * @param chooser * JavaClassAndMethodChooser to select which methods are * considered; it must return true for a method to be returned * @return the XMethod, or null if no such method exists in the class */ @Deprecated public static XMethod findXMethod(JavaClass[] classList, String methodName, String methodSig, JavaClassAndMethodChooser chooser) { for (JavaClass cls : classList) { JavaClassAndMethod m; if ((m = findMethod(cls, methodName, methodSig)) != null && chooser.choose(m)) { return XFactory.createXMethod(cls, m.getMethod()); } } return null; }
public static @CheckForNull JavaClassAndMethod findInvocationLeastUpperBound(JavaClass jClass, String methodName, String methodSig, JavaClassAndMethodChooser methodChooser, boolean invokeInterface) throws ClassNotFoundException { JavaClassAndMethod result = findMethod(jClass, methodName, methodSig, methodChooser); if (result != null) { return result; } if (invokeInterface) { for (JavaClass i : jClass.getInterfaces()) { result = findInvocationLeastUpperBound(i, methodName, methodSig, methodChooser, invokeInterface); if (result != null) { return null; } } } else { JavaClass sClass = jClass.getSuperClass(); if (sClass != null) { return findInvocationLeastUpperBound(sClass, methodName, methodSig, methodChooser, invokeInterface); } } return null; }
/** * Look up the method referenced by given InvokeInstruction. This method * does <em>not</em> look for implementations in super or subclasses * according to the virtual dispatch rules. * * @param inv * the InvokeInstruction * @param cpg * the ConstantPoolGen used by the class the InvokeInstruction * belongs to * @param chooser * JavaClassAndMethodChooser to use to pick the method from among * the candidates * @return the JavaClassAndMethod, or null if no such method is defined in * the class */ public static JavaClassAndMethod findExactMethod(InvokeInstruction inv, ConstantPoolGen cpg, JavaClassAndMethodChooser chooser) throws ClassNotFoundException { String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); JavaClass jclass = Repository.lookupClass(className); return findMethod(jclass, methodName, methodSig, chooser); }
JavaClass[] superclassList = javaClass.getSuperClasses(); if (superclassList != null) { JavaClassAndMethod match = Hierarchy.findMethod(superclassList, method.getName(), method.getSignature(), Hierarchy.INSTANCE_METHOD); if (match != null) { JavaClassAndMethod match = Hierarchy.findMethod(interfaceList, method.getName(), method.getSignature(), Hierarchy.INSTANCE_METHOD); if (match != 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); }
/** * Visit all superclass methods which the given method overrides. * * @param method * the method * @param chooser * chooser which visits each superclass method * @return the chosen method, or null if no method is chosen * @throws ClassNotFoundException */ public static JavaClassAndMethod visitSuperClassMethods(JavaClassAndMethod method, JavaClassAndMethodChooser chooser) throws ClassNotFoundException { return findMethod(method.getJavaClass().getSuperClasses(), method.getMethod().getName(), method.getMethod() .getSignature(), chooser); }
JavaClassAndMethod classAndMethod = findMethod(javaLangObject, methodName, methodSig, INSTANCE_METHOD); if (classAndMethod != null) { result.add(classAndMethod); JavaClassAndMethod upperBound = findMethod(receiverClass, methodName, methodSig, CONCRETE_METHOD); if (upperBound == null) { upperBound = findInvocationLeastUpperBound(receiverClass, methodName, methodSig, CONCRETE_METHOD, false); XMethod concreteSubtypeMethod = findMethod(subtype, methodName, methodSig, false); if (concreteSubtypeMethod != null && (concreteSubtypeMethod.getAccessFlags() & Const.ACC_ABSTRACT) == 0) { result.add(new JavaClassAndMethod(concreteSubtypeMethod));
/** * Create a SourceLineAnnotation covering an entire method. * * @param javaClass * JavaClass containing the method * @param xmethod * the method * @return a SourceLineAnnotation for the entire method */ public static SourceLineAnnotation forEntireMethod(JavaClass javaClass, XMethod xmethod) { JavaClassAndMethod m = Hierarchy.findMethod(javaClass, xmethod.getName(), xmethod.getSignature()); if (m == null) { return createUnknown(javaClass.getClassName(), javaClass.getSourceFileName()); } else { return forEntireMethod(javaClass, m.getMethod()); } }
static SourceLineAnnotation getSourceAnnotationForMethod(String className, String methodName, String methodSig) { JavaClassAndMethod targetMethod = null; Code code = null; try { JavaClass targetClass = AnalysisContext.currentAnalysisContext().lookupClass(className); targetMethod = Hierarchy.findMethod(targetClass, methodName, methodSig); if (targetMethod != null) { Method method = targetMethod.getMethod(); if (method != null) { code = method.getCode(); } } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } SourceInfoMap sourceInfoMap = AnalysisContext.currentAnalysisContext().getSourceInfoMap(); SourceInfoMap.SourceLineRange range = sourceInfoMap.getMethodLine(className, methodName, methodSig); if (range != null) { return new SourceLineAnnotation(className, AnalysisContext.currentAnalysisContext().lookupSourceFile(className), range.getStart(), range.getEnd(), 0, code == null ? -1 : code.getLength()); } if (sourceInfoMap.fallBackToClassfile() && targetMethod != null) { return forEntireMethod(targetMethod.getJavaClass(), targetMethod.getMethod()); } // If we couldn't find the source lines, // create an unknown source line annotation referencing // the class and source file. return createUnknown(className); }
/** * Find a method in given class. * * @param javaClass * the class * @param methodName * the name of the method * @param methodSig * the signature of the method * @return the JavaClassAndMethod, or null if no such method exists in the * class */ public static @CheckForNull JavaClassAndMethod findMethod(JavaClass javaClass, String methodName, String methodSig) { return findMethod(javaClass, methodName, methodSig, ANY_METHOD); }
/** * Find a method in given list of classes, searching the classes in order. * * @param classList * list of classes in which to search * @param methodName * the name of the method * @param methodSig * the signature of the method * @return the JavaClassAndMethod, or null if no such method exists in the * class */ @Deprecated public static JavaClassAndMethod findMethod(JavaClass[] classList, String methodName, String methodSig) { return findMethod(classList, methodName, methodSig, ANY_METHOD); }
/** * Find a method in given class. * * @param javaClass * the class * @param methodName * the name of the method * @param methodSig * the signature of the method * @param chooser * the JavaClassAndMethodChooser to use to screen possible * candidates * @return the XMethod, or null if no such method exists in the class */ @Deprecated public static @CheckForNull XMethod findXMethod(JavaClass javaClass, String methodName, String methodSig, JavaClassAndMethodChooser chooser) { JavaClassAndMethod result = findMethod(javaClass, methodName, methodSig, chooser); return result == null ? null : XFactory.createXMethod(result.getJavaClass(), result.getMethod()); }
public static @CheckForNull JavaClassAndMethod findInvocationLeastUpperBound(JavaClass jClass, String methodName, String methodSig, JavaClassAndMethodChooser methodChooser, boolean invokeInterface) throws ClassNotFoundException { JavaClassAndMethod result = findMethod(jClass, methodName, methodSig, methodChooser); if (result != null) { return result; } if (invokeInterface) { for (JavaClass i : jClass.getInterfaces()) { result = findInvocationLeastUpperBound(i, methodName, methodSig, methodChooser, invokeInterface); if (result != null) { return null; } } } else { JavaClass sClass = jClass.getSuperClass(); if (sClass != null) { return findInvocationLeastUpperBound(sClass, methodName, methodSig, methodChooser, invokeInterface); } } return null; }
/** * Visit all superclass methods which the given method overrides. * * @param method * the method * @param chooser * chooser which visits each superclass method * @return the chosen method, or null if no method is chosen * @throws ClassNotFoundException */ public static JavaClassAndMethod visitSuperClassMethods(JavaClassAndMethod method, JavaClassAndMethodChooser chooser) throws ClassNotFoundException { return findMethod(method.getJavaClass().getSuperClasses(), method.getMethod().getName(), method.getMethod() .getSignature(), chooser); }
/** * 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); }
/** * Create a SourceLineAnnotation covering an entire method. * * @param javaClass * JavaClass containing the method * @param xmethod * the method * @return a SourceLineAnnotation for the entire method */ public static SourceLineAnnotation forEntireMethod(JavaClass javaClass, XMethod xmethod) { JavaClassAndMethod m = Hierarchy.findMethod(javaClass, xmethod.getName(), xmethod.getSignature()); if (m == null) { return createUnknown(javaClass.getClassName(), javaClass.getSourceFileName()); } else { return forEntireMethod(javaClass, m.getMethod()); } }