Java Code Examples for org.apache.bcel.Const#IFLE

The following examples show how to use org.apache.bcel.Const#IFLE . 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: DismantleBytecode.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void printOpCode(int seen) {
    System.out.print("  " + this.getClass().getSimpleName() + ": [" + formatter.format(getPC()) + "]  " + Const.getOpcodeName(seen));
    if ((seen == Const.INVOKEVIRTUAL) || (seen == Const.INVOKESPECIAL) || (seen == Const.INVOKEINTERFACE) || (seen == Const.INVOKESTATIC)) {
        System.out.print("   " + getClassConstantOperand() + "." + getNameConstantOperand() + " " + getSigConstantOperand());
    } else if (seen == Const.LDC || seen == Const.LDC_W || seen == Const.LDC2_W) {
        Constant c = getConstantRefOperand();
        if (c instanceof ConstantString) {
            System.out.print("   \"" + getStringConstantOperand() + "\"");
        } else if (c instanceof ConstantClass) {
            System.out.print("   " + getClassConstantOperand());
        } else {
            System.out.print("   " + c);
        }
    } else if ((seen == Const.ALOAD) || (seen == Const.ASTORE)) {
        System.out.print("   " + getRegisterOperand());
    } else if ((seen == Const.GOTO) || (seen == Const.GOTO_W) || (seen == Const.IF_ACMPEQ) || (seen == Const.IF_ACMPNE)
            || (seen == Const.IF_ICMPEQ)
            || (seen == Const.IF_ICMPGE) || (seen == Const.IF_ICMPGT) || (seen == Const.IF_ICMPLE) || (seen == Const.IF_ICMPLT)
            || (seen == Const.IF_ICMPNE) || (seen == Const.IFEQ) || (seen == Const.IFGE) || (seen == Const.IFGT) || (seen == Const.IFLE)
            || (seen == Const.IFLT)
            || (seen == Const.IFNE) || (seen == Const.IFNONNULL) || (seen == Const.IFNULL)) {
        System.out.print("   " + getBranchTarget());
    } else if ((seen == Const.NEW) || (seen == Const.INSTANCEOF)) {
        System.out.print("   " + getClassConstantOperand());
    } else if ((seen == Const.TABLESWITCH) || (seen == Const.LOOKUPSWITCH)) {
        System.out.print("    [");
        int switchPC = getPC();
        int[] offsets = getSwitchOffsets();
        for (int offset : offsets) {
            System.out.print((switchPC + offset) + ",");
        }
        System.out.print((switchPC + getDefaultSwitchOffset()) + "]");
    }

    System.out.println();
}
 
Example 2
Source File: DismantleBytecode.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean areOppositeBranches(int opcode1, int opcode2) {
    if (!isBranch(opcode1)) {
        throw new IllegalArgumentException(Const.getOpcodeName(opcode1) + " isn't a branch");
    }
    if (!isBranch(opcode2)) {
        throw new IllegalArgumentException(Const.getOpcodeName(opcode2) + " isn't a branch");
    }
    switch (opcode1) {
    case Const.IF_ACMPEQ:
    case Const.IF_ACMPNE:
    case Const.IF_ICMPEQ:
    case Const.IF_ICMPNE:
    case Const.IF_ICMPLT:
    case Const.IF_ICMPLE:
    case Const.IF_ICMPGT:
    case Const.IF_ICMPGE:
    case Const.IFNE:
    case Const.IFEQ:
    case Const.IFLT:
    case Const.IFLE:
    case Const.IFGT:
    case Const.IFGE:
        return ((opcode1 + 1) ^ 1) == opcode2 + 1;
    case Const.IFNONNULL:
        return opcode2 == Const.IFNULL;
    case Const.IFNULL:
        return opcode2 == Const.IFNONNULL;
    default:
        return false;

    }
}
 
Example 3
Source File: BadUseOfReturnValue.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (seen == Const.INVOKEVIRTUAL && "indexOf".equals(getNameConstantOperand())
            && "java/lang/String".equals(getClassConstantOperand())
            && "(Ljava/lang/String;)I".equals(getSigConstantOperand())) {
        stringIndexOfOnTOS = true;
    } else if (stringIndexOfOnTOS) {
        if (seen == Const.IFLE || seen == Const.IFGT) {
            bugAccumulator.accumulateBug(
                    new BugInstance(this, "RV_CHECK_FOR_POSITIVE_INDEXOF", LOW_PRIORITY).addClassAndMethod(this), this);
        }
        stringIndexOfOnTOS = false;
    }

    if (seen == Const.INVOKEVIRTUAL && "readLine".equals(getNameConstantOperand())
            && "()Ljava/lang/String;".equals(getSigConstantOperand()) && getClassConstantOperand().startsWith("java/io")
            && !"java/io/LineNumberReader".equals(getClassConstantOperand())) {
        readLineOnTOS = true;
    } else if (readLineOnTOS) {
        if (seen == Const.IFNULL || seen == Const.IFNONNULL) {
            bugAccumulator.accumulateBug(
                    new BugInstance(this, "RV_DONT_JUST_NULL_CHECK_READLINE", NORMAL_PRIORITY).addClassAndMethod(this), this);
        }

        readLineOnTOS = false;
    }
}
 
Example 4
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
/** Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH.
 * For those you should use the SWITCH compound instruction.
 */
public static BranchInstruction createBranchInstruction( final short opcode, final InstructionHandle target ) {
    switch (opcode) {
        case Const.IFEQ:
            return new IFEQ(target);
        case Const.IFNE:
            return new IFNE(target);
        case Const.IFLT:
            return new IFLT(target);
        case Const.IFGE:
            return new IFGE(target);
        case Const.IFGT:
            return new IFGT(target);
        case Const.IFLE:
            return new IFLE(target);
        case Const.IF_ICMPEQ:
            return new IF_ICMPEQ(target);
        case Const.IF_ICMPNE:
            return new IF_ICMPNE(target);
        case Const.IF_ICMPLT:
            return new IF_ICMPLT(target);
        case Const.IF_ICMPGE:
            return new IF_ICMPGE(target);
        case Const.IF_ICMPGT:
            return new IF_ICMPGT(target);
        case Const.IF_ICMPLE:
            return new IF_ICMPLE(target);
        case Const.IF_ACMPEQ:
            return new IF_ACMPEQ(target);
        case Const.IF_ACMPNE:
            return new IF_ACMPNE(target);
        case Const.GOTO:
            return new GOTO(target);
        case Const.JSR:
            return new JSR(target);
        case Const.IFNULL:
            return new IFNULL(target);
        case Const.IFNONNULL:
            return new IFNONNULL(target);
        case Const.GOTO_W:
            return new GOTO_W(target);
        case Const.JSR_W:
            return new JSR_W(target);
        default:
            throw new IllegalArgumentException("Invalid opcode: " + opcode);
    }
}