Java Code Examples for org.apache.bcel.classfile.LocalVariable#getSignature()

The following examples show how to use org.apache.bcel.classfile.LocalVariable#getSignature() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpcodeStack.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void pushByLocalObjectLoad(DismantleBytecode dbc, int register) {
    Method m = dbc.getMethod();
    LocalVariableTable lvt = m.getLocalVariableTable();
    if (lvt != null) {
        LocalVariable lv = LVTHelper.getLocalVariableAtPC(lvt, register, dbc.getPC());
        if (lv != null) {
            String signature = lv.getSignature();
            pushByLocalLoad(signature, register);
            return;
        }
    }
    pushByLocalLoad("Ljava/lang/Object;", register);
}
 
Example 2
Source File: TypeFrameModelingVisitor.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@CheckForNull
GenericObjectType getLocalVariable(int index, int pos) {
    if (genericLocalVariables == null || !genericLocalVariables.get(index)) {
        return null;
    }
    for (LocalVariable local : localTypeTable.getLocalVariableTypeTable()) {
        if (local.getIndex() == index && local.getStartPC() <= pos
                && pos < +local.getStartPC() + local.getLength()) {
            String signature = local.getSignature();
            if (signature.indexOf('<') < 0) {
                continue;
            }
            Type t;
            try {
                t = GenericUtilities.getType(signature);
                if (t instanceof GenericObjectType) {
                    return (GenericObjectType) t;
                }
            } catch (RuntimeException e) {
                AnalysisContext.logError("Bad signature " + signature
                        + " for " + local.getName(), e);

            }
            return null;
        }
    }
    return null;
}
 
Example 3
Source File: SuperfluousInstanceOf.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    switch (state) {
    case SEEN_NOTHING:
        if (seen == Const.ALOAD) {
            register = getRegisterOperand();
        } else if ((seen >= Const.ALOAD_0) && (seen <= Const.ALOAD_3)) {
            register = seen - Const.ALOAD_0;
        } else {
            return;
        }
        state = SEEN_ALOAD;
        break;

    case SEEN_ALOAD:
        try {
            if (seen == Const.INSTANCEOF) {
                LocalVariable lv = LVTHelper.getLocalVariableAtPC(varTable, register, getPC());
                if (lv != null) {
                    String objSignature = lv.getSignature();
                    if (objSignature.charAt(0) == 'L') {
                        objSignature = objSignature.substring(1, objSignature.length() - 1).replace('/', '.');
                        String clsSignature = getDottedClassConstantOperand();

                        if (clsSignature.charAt(0) != '[') {
                            if (org.apache.bcel.Repository.instanceOf(objSignature, clsSignature)) {
                                bugReporter.reportBug(new BugInstance(this, "SIO_SUPERFLUOUS_INSTANCEOF", LOW_PRIORITY)
                                        .addClassAndMethod(this).addSourceLine(this));
                            }
                        }
                    }
                }
            }
        } catch (ClassNotFoundException cnfe) {
            bugReporter.reportMissingClass(cnfe);
        }

        state = SEEN_NOTHING;
        break;
    default:
        break;
    }

}