Search in sources :

Example 6 with Code

use of org.apache.bcel.classfile.Code in project fb-contrib by mebigfatguy.

the class NonRecycleableTaglibs method getAttributes.

/**
 * collect all possible attributes given the name of methods available.
 *
 * @param cls
 *            the class to look for setter methods to infer properties
 * @return the map of possible attributes/types
 */
private static Map<QMethod, String> getAttributes(JavaClass cls) {
    Map<QMethod, String> atts = new HashMap<>();
    Method[] methods = cls.getMethods();
    for (Method m : methods) {
        String name = m.getName();
        if (name.startsWith("set") && m.isPublic() && !m.isStatic()) {
            String sig = m.getSignature();
            List<String> args = SignatureUtils.getParameterSignatures(sig);
            if ((args.size() == 1) && Values.SIG_VOID.equals(SignatureUtils.getReturnSignature(sig))) {
                String parmSig = args.get(0);
                if (validAttrTypes.contains(parmSig)) {
                    Code code = m.getCode();
                    if ((code != null) && (code.getCode().length < MAX_ATTRIBUTE_CODE_LENGTH)) {
                        atts.put(new QMethod(name, sig), parmSig);
                    }
                }
            }
        }
    }
    return atts;
}
Also used : QMethod(com.mebigfatguy.fbcontrib.utils.QMethod) HashMap(java.util.HashMap) Method(org.apache.bcel.classfile.Method) QMethod(com.mebigfatguy.fbcontrib.utils.QMethod) Code(org.apache.bcel.classfile.Code)

Example 7 with Code

use of org.apache.bcel.classfile.Code in project fb-contrib by mebigfatguy.

the class AbstractOverriddenMethod method visitMethod.

/**
 * overrides the visitor to find abstract methods that override concrete ones
 *
 * @param obj
 *            the context object of the currently parsed method
 */
@Override
public void visitMethod(Method obj) {
    if (!obj.isAbstract())
        return;
    String methodName = obj.getName();
    String methodSig = obj.getSignature();
    outer: for (JavaClass cls : superClasses) {
        Method[] methods = cls.getMethods();
        for (Method m : methods) {
            if (m.isPrivate() || m.isAbstract())
                continue;
            if (methodName.equals(m.getName()) && methodSig.equals(m.getSignature())) {
                BugInstance bug = new BugInstance(this, BugType.AOM_ABSTRACT_OVERRIDDEN_METHOD.name(), NORMAL_PRIORITY).addClass(this).addMethod(this);
                Code code = obj.getCode();
                if (code != null)
                    bug.addSourceLineRange(clsContext, this, 0, code.getLength() - 1);
                bugReporter.reportBug(bug);
                break outer;
            }
        }
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) BugInstance(edu.umd.cs.findbugs.BugInstance) Method(org.apache.bcel.classfile.Method) Code(org.apache.bcel.classfile.Code)

Aggregations

Code (org.apache.bcel.classfile.Code)7 BugInstance (edu.umd.cs.findbugs.BugInstance)2 ArrayList (java.util.ArrayList)2 Attribute (org.apache.bcel.classfile.Attribute)2 Constant (org.apache.bcel.classfile.Constant)2 ConstantPool (org.apache.bcel.classfile.ConstantPool)2 ConstantString (org.apache.bcel.classfile.ConstantString)2 ExceptionTable (org.apache.bcel.classfile.ExceptionTable)2 LocalVariable (org.apache.bcel.classfile.LocalVariable)2 LocalVariableTable (org.apache.bcel.classfile.LocalVariableTable)2 Method (org.apache.bcel.classfile.Method)2 QMethod (com.mebigfatguy.fbcontrib.utils.QMethod)1 StopOpcodeParsingException (com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException)1 BasicBlock (edu.umd.cs.findbugs.ba.BasicBlock)1 CFG (edu.umd.cs.findbugs.ba.CFG)1 CFGBuilderException (edu.umd.cs.findbugs.ba.CFGBuilderException)1 Edge (edu.umd.cs.findbugs.ba.Edge)1 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 JavaClass (org.apache.bcel.classfile.JavaClass)1