Refine search
private static boolean isVoidConstructor(JavaClass clazz, Method m) { String outerClassSignature = getSignatureOfOuterClass(clazz); if (outerClassSignature == null) { outerClassSignature = ""; } return Const.CONSTRUCTOR_NAME.equals(m.getName()) && m.getSignature().equals("(" + outerClassSignature + ")V"); }
Method findMethod(JavaClass clazz, String name, String sig) { Method[] m = clazz.getMethods(); for (Method aM : m) { if (aM.getName().equals(name) && aM.getSignature().equals(sig)) { return aM; } } return null; }
public static boolean isMainMethod(Method method) { return method.isStatic() && "main".equals(method.getName()) && "([Ljava/lang/String;)V".equals(method.getSignature()); }
/** is there a JUnit3TestSuite */ private boolean hasSuite(Method[] methods) { for (Method m : methods) { if (m.getName().equals("suite") && m.isPublic() && m.isStatic() // && m.getReturnType().equals(junit.framework.Test.class) // && m.getArgumentTypes().length == 0 && m.getSignature().equals("()Ljunit/framework/Test;")) { return true; } } return false; }
Set<String> definedInClass(JavaClass clazz) { HashSet<String> result = new HashSet<>(); for (Method m : clazz.getMethods()) { if (!skip(m)) { result.add(m.getName() + m.getSignature()); } } return result; }
/** * @param obj * the method to parse * @return a descriptor for the method */ protected MethodDescriptor parseMethod(Method obj) { return new MethodDescriptor(slashedClassName, obj.getName(), obj.getSignature(), obj.isStatic()); }
/** * Convenience method for generating a method signature in human readable * form. * * @param javaClass * the class * @param method * the method */ public static String convertMethodSignature(JavaClass javaClass, Method method) { return convertMethodSignature(javaClass.getClassName(), method.getName(), method.getSignature()); }
@Override public String toString() { return this.getClass().getSimpleName() + "(" + methodGen.getClassName() + "." + methodGen.getMethod().getName() + methodGen.getMethod().getSignature() + ")"; }
public static Method findImplementation(JavaClass clazz, String name, String signature) { Method[] m = clazz.getMethods(); for (Method aM : m) { if (aM.getName().equals(name) && aM.getSignature().equals(signature) && !aM.isPrivate() && !aM.isStatic()) { return aM; } } return null; } }
public String getFullyQualifiedMethodName(Method method) { return getClassDescriptor().getDottedClassName() + "." + method.getName() + method.getSignature(); }
@Override public void visit(Method obj) { if (isAdapter) { String methodName = obj.getName(); String signature = methodMap.get(methodName); if (!Const.CONSTRUCTOR_NAME.equals(methodName) && signature != null) { if (!signature.equals(obj.getSignature())) { if (!badOverrideMap.keySet().contains(methodName)) { badOverrideMap.put(methodName, new BugInstance(this, "BOA_BADLY_OVERRIDDEN_ADAPTER", NORMAL_PRIORITY) .addClassAndMethod(this).addSourceLine(this)); } } else { badOverrideMap.put(methodName, null); } } } } }
public static void dumpTypeDataflow(Method method, CFG cfg, TypeDataflow typeDataflow) throws DataflowAnalysisException { System.out.println("\n\n{ Type analysis for " + cfg.getMethodGen().getClassName() + "." + method.getName() + method.getSignature()); TreeSet<Location> tree = new TreeSet<>(); for (Iterator<Location> locs = cfg.locationIterator(); locs.hasNext();) { Location loc = locs.next(); tree.add(loc); } for (Location loc : tree) { System.out.println("\n Pre: " + typeDataflow.getFactAtLocation(loc)); System.out.println("Location: " + loc); System.out.println("Post: " + typeDataflow.getFactAfterLocation(loc)); } System.out.println("}\n\n"); }
/** * Create an XMethod object from a BCEL Method. * * @param className * the class to which the Method belongs * @param method * the Method * @return an XMethod representing the Method */ public static XMethod createXMethod(String className, Method method) { String methodName = method.getName(); String methodSig = method.getSignature(); int accessFlags = method.getAccessFlags(); return createXMethod(className, methodName, methodSig, accessFlags); }
boolean definedInThisClassOrSuper(JavaClass clazz, String method) throws ClassNotFoundException { if (clazz == null) { return false; } // System.out.println("Checking to see if " + method + " is defined in " // + clazz.getClassName()); for (Method m : clazz.getMethods()) { String key = m.getName() + ":" + m.getSignature(); if (!m.isStatic() && method.equals(key)) { return true; } } return definedInSuperClassOrInterface(clazz, method); }
public @Nonnull List<Method> getMethodsInCallOrder() { Map<XMethod, Method> map = new HashMap<>(); for (Method m : getJavaClass().getMethods()) { XMethod xMethod = classInfo.findMethod(m.getName(), m.getSignature(), m.isStatic()); map.put(xMethod, m); } List<? extends XMethod> xmethodsInCallOrder = classInfo.getXMethodsInCallOrder(); List<Method> methodsInCallOrder = new ArrayList<>(xmethodsInCallOrder.size()); for (XMethod x : xmethodsInCallOrder) { Method m = map.get(x); if (m != null) { methodsInCallOrder.add(m); } } return methodsInCallOrder; }
public static @CheckForNull JavaClassAndMethod findMethod(JavaClass javaClass, String methodName, String methodSig, JavaClassAndMethodChooser chooser) { if (DEBUG_METHOD_LOOKUP) { System.out.println("Check " + javaClass.getClassName()); } Method[] methodList = javaClass.getMethods(); for (Method method : methodList) { if (method.getName().equals(methodName) && method.getSignature().equals(methodSig)) { JavaClassAndMethod m = new JavaClassAndMethod(javaClass, method); if (chooser.choose(m)) { if (DEBUG_METHOD_LOOKUP) { System.out.println("\t==> FOUND: " + method); } return m; } } } if (DEBUG_METHOD_LOOKUP) { System.out.println("\t==> NOT FOUND"); } return null; }
private boolean classDefinesMethod(JavaClass c, XMethod m) { for (Method definedMethod : c.getMethods()) { if (definedMethod.getName().equals(m.getName()) && definedMethod.getSignature().equals(m.getSignature()) && definedMethod.isStatic() == m.isStatic()) { return true; } } return false; }
@Override public void visit(JavaClass obj) { try { methodMap.clear(); badOverrideMap.clear(); JavaClass superClass = obj.getSuperClass(); if (superClass == null) { return; } String packageName = superClass.getPackageName(); String className = superClass.getClassName(); // A more generic way to add Adapters would be nice here isAdapter = ((className.endsWith("Adapter")) && ("java.awt.event".equals(packageName) || "javax.swing.event".equals(packageName))) || (("DefaultHandler".equals(className) && ("org.xml.sax.helpers".equals(packageName)))); if (isAdapter) { Method[] methods = superClass.getMethods(); for (Method method1 : methods) { methodMap.put(method1.getName(), method1.getSignature()); } } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } }
public static @CheckForNull XMethod definedIn(JavaClass clazz, XMethod m) { for (Method m2 : clazz.getMethods()) { if (m.getName().equals(m2.getName()) && m.getSignature().equals(m2.getSignature()) && m.isStatic() == m2.isStatic()) { return XFactory.createXMethod(clazz, m2); } } return null; }
/** * Construct a MethodDescriptor from JavaClass and method. * * @param jclass * a JavaClass * @param method * a Method belonging to the JavaClass * @return a MethodDescriptor identifying the method */ public static MethodDescriptor getMethodDescriptor(JavaClass jclass, Method method) { return DescriptorFactory.instance().getMethodDescriptor(jclass.getClassName().replace('.', '/'), method.getName(), method.getSignature(), method.isStatic()); }