Java Code Examples for org.apache.bcel.Const#RETURN
The following examples show how to use
org.apache.bcel.Const#RETURN .
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: FinalizerNullsFields.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void sawOpcode(int seen) { if (state == 0 && seen == Const.ALOAD_0) { state++; } else if (state == 1 && seen == Const.ACONST_NULL) { state++; } else if (state == 2 && seen == Const.PUTFIELD) { bugAccumulator.accumulateBug( new BugInstance(this, "FI_FINALIZER_NULLS_FIELDS", NORMAL_PRIORITY).addClassAndMethod(this) .addReferencedField(this), this); sawFieldNulling = true; state = 0; } else if (seen == Const.RETURN) { state = 0; } else { state = 0; sawAnythingElse = true; } }
Example 2
Source File: Naming.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
private boolean markedAsNotUsable(Method obj) { for (Attribute a : obj.getAttributes()) { if (a instanceof Deprecated) { return true; } } Code code = obj.getCode(); if (code == null) { return false; } byte[] codeBytes = code.getCode(); if (codeBytes.length > 1 && codeBytes.length < 10) { int lastOpcode = codeBytes[codeBytes.length - 1] & 0xff; if (lastOpcode != Const.ATHROW) { return false; } for (int b : codeBytes) { if ((b & 0xff) == Const.RETURN) { return false; } } return true; } return false; }
Example 3
Source File: ReturnInstruction.java From commons-bcel with Apache License 2.0 | 6 votes |
public Type getType() { final short _opcode = super.getOpcode(); switch (_opcode) { case Const.IRETURN: return Type.INT; case Const.LRETURN: return Type.LONG; case Const.FRETURN: return Type.FLOAT; case Const.DRETURN: return Type.DOUBLE; case Const.ARETURN: return Type.OBJECT; case Const.RETURN: return Type.VOID; default: // Never reached throw new ClassGenException("Unknown type " + _opcode); } }
Example 4
Source File: DismantleBytecode.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
public boolean isReturn(int opcode) { switch (opcode) { case Const.IRETURN: case Const.ARETURN: case Const.LRETURN: case Const.DRETURN: case Const.FRETURN: case Const.RETURN: return true; default: return false; } }
Example 5
Source File: Noise.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { int priority; switch (seen) { case Const.INVOKEINTERFACE: case Const.INVOKEVIRTUAL: case Const.INVOKESPECIAL: case Const.INVOKESTATIC: hq.pushHash(getClassConstantOperand()); if (getNameConstantOperand().indexOf('$') == -1) { hq.pushHash(getNameConstantOperand()); } hq.pushHash(getSigConstantOperand()); priority = hq.getPriority(); if (priority <= Priorities.LOW_PRIORITY) { accumulator.accumulateBug(new BugInstance(this, "NOISE_METHOD_CALL", priority).addClassAndMethod(this) .addCalledMethod(this), this); } break; case Const.GETFIELD: case Const.PUTFIELD: case Const.GETSTATIC: case Const.PUTSTATIC: hq.pushHash(getClassConstantOperand()); if (getNameConstantOperand().indexOf('$') == -1) { hq.pushHash(getNameConstantOperand()); } hq.pushHash(getSigConstantOperand()); priority = hq.getPriority(); if (priority <= Priorities.LOW_PRIORITY) { accumulator.accumulateBug(new BugInstance(this, "NOISE_FIELD_REFERENCE", priority).addClassAndMethod(this) .addReferencedField(this), this); } break; case Const.CHECKCAST: case Const.INSTANCEOF: case Const.NEW: hq.pushHash(getClassConstantOperand()); break; case Const.IFEQ: case Const.IFNE: case Const.IFNONNULL: case Const.IFNULL: case Const.IF_ICMPEQ: case Const.IF_ICMPNE: case Const.IF_ICMPLE: case Const.IF_ICMPGE: case Const.IF_ICMPGT: case Const.IF_ICMPLT: case Const.IF_ACMPEQ: case Const.IF_ACMPNE: case Const.RETURN: case Const.ARETURN: case Const.IRETURN: case Const.MONITORENTER: case Const.MONITOREXIT: case Const.IINC: case Const.NEWARRAY: case Const.TABLESWITCH: case Const.LOOKUPSWITCH: case Const.LCMP: case Const.INEG: case Const.IADD: case Const.IMUL: case Const.ISUB: case Const.IDIV: case Const.IREM: case Const.IXOR: case Const.ISHL: case Const.ISHR: case Const.IUSHR: case Const.IAND: case Const.IOR: case Const.LAND: case Const.LOR: case Const.LADD: case Const.LMUL: case Const.LSUB: case Const.LDIV: case Const.LSHL: case Const.LSHR: case Const.LUSHR: case Const.AALOAD: case Const.AASTORE: case Const.IALOAD: case Const.IASTORE: case Const.BALOAD: case Const.BASTORE: hq.push(seen); priority = hq.getPriority(); if (priority <= Priorities.LOW_PRIORITY) { accumulator.accumulateBug( new BugInstance(this, "NOISE_OPERATION", priority).addClassAndMethod(this).addString(Const.getOpcodeName(seen)), this); } break; default: break; } }
Example 6
Source File: UselessSubclassMethod.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { switch (state) { case SEEN_NOTHING: if (seen == Const.ALOAD_0) { argTypes = Type.getArgumentTypes(this.getMethodSig()); curParm = 0; curParmOffset = 1; if (argTypes.length > 0) { state = State.SEEN_PARM; } else { state = State.SEEN_LAST_PARM; } } else { state = State.SEEN_INVALID; } break; case SEEN_PARM: if (curParm >= argTypes.length) { state = State.SEEN_INVALID; } else { String signature = argTypes[curParm++].getSignature(); char typeChar0 = signature.charAt(0); if ((typeChar0 == 'L') || (typeChar0 == '[')) { checkParm(seen, Const.ALOAD_0, Const.ALOAD, 1); } else if (typeChar0 == 'D') { checkParm(seen, Const.DLOAD_0, Const.DLOAD, 2); } else if (typeChar0 == 'F') { checkParm(seen, Const.FLOAD_0, Const.FLOAD, 1); } else if (typeChar0 == 'I' || typeChar0 == 'Z' || typeChar0 == 'S' || typeChar0 == 'C') { checkParm(seen, Const.ILOAD_0, Const.ILOAD, 1); } else if (typeChar0 == 'J') { checkParm(seen, Const.LLOAD_0, Const.LLOAD, 2); } else { state = State.SEEN_INVALID; } if ((state != State.SEEN_INVALID) && (curParm >= argTypes.length)) { state = State.SEEN_LAST_PARM; } } break; case SEEN_LAST_PARM: if ((seen == Const.INVOKENONVIRTUAL) && getMethodName().equals(getNameConstantOperand()) && getMethodSig().equals(getSigConstantOperand())) { invokePC = getPC(); state = State.SEEN_INVOKE; } else { state = State.SEEN_INVALID; } break; case SEEN_INVOKE: Type returnType = getMethod().getReturnType(); char retSigChar0 = returnType.getSignature().charAt(0); if ((retSigChar0 == 'V') && (seen == Const.RETURN)) { state = State.SEEN_RETURN; } else if (((retSigChar0 == 'L') || (retSigChar0 == '[')) && (seen == Const.ARETURN)) { state = State.SEEN_RETURN; } else if ((retSigChar0 == 'D') && (seen == Const.DRETURN)) { state = State.SEEN_RETURN; } else if ((retSigChar0 == 'F') && (seen == Const.FRETURN)) { state = State.SEEN_RETURN; } else if ((retSigChar0 == 'I' || retSigChar0 == 'S' || retSigChar0 == 'C' || retSigChar0 == 'B' || retSigChar0 == 'Z') && (seen == Const.IRETURN)) { state = State.SEEN_RETURN; } else if ((retSigChar0 == 'J') && (seen == Const.LRETURN)) { state = State.SEEN_RETURN; } else { state = State.SEEN_INVALID; } break; case SEEN_RETURN: state = State.SEEN_INVALID; break; default: break; } }
Example 7
Source File: MethodGen.java From commons-bcel with Apache License 2.0 | 4 votes |
/** * Computes stack usage of an instruction list by performing control flow analysis. * * @return maximum stack depth used by method */ public static int getMaxStack( final ConstantPoolGen cp, final InstructionList il, final CodeExceptionGen[] et ) { final BranchStack branchTargets = new BranchStack(); /* Initially, populate the branch stack with the exception * handlers, because these aren't (necessarily) branched to * explicitly. in each case, the stack will have depth 1, * containing the exception object. */ for (final CodeExceptionGen element : et) { final InstructionHandle handler_pc = element.getHandlerPC(); if (handler_pc != null) { branchTargets.push(handler_pc, 1); } } int stackDepth = 0; int maxStackDepth = 0; InstructionHandle ih = il.getStart(); while (ih != null) { final Instruction instruction = ih.getInstruction(); final short opcode = instruction.getOpcode(); final int delta = instruction.produceStack(cp) - instruction.consumeStack(cp); stackDepth += delta; if (stackDepth > maxStackDepth) { maxStackDepth = stackDepth; } // choose the next instruction based on whether current is a branch. if (instruction instanceof BranchInstruction) { final BranchInstruction branch = (BranchInstruction) instruction; if (instruction instanceof Select) { // explore all of the select's targets. the default target is handled below. final Select select = (Select) branch; final InstructionHandle[] targets = select.getTargets(); for (final InstructionHandle target : targets) { branchTargets.push(target, stackDepth); } // nothing to fall through to. ih = null; } else if (!(branch instanceof IfInstruction)) { // if an instruction that comes back to following PC, // push next instruction, with stack depth reduced by 1. if (opcode == Const.JSR || opcode == Const.JSR_W) { branchTargets.push(ih.getNext(), stackDepth - 1); } ih = null; } // for all branches, the target of the branch is pushed on the branch stack. // conditional branches have a fall through case, selects don't, and // jsr/jsr_w return to the next instruction. branchTargets.push(branch.getTarget(), stackDepth); } else { // check for instructions that terminate the method. if (opcode == Const.ATHROW || opcode == Const.RET || (opcode >= Const.IRETURN && opcode <= Const.RETURN)) { ih = null; } } // normal case, go to the next instruction. if (ih != null) { ih = ih.getNext(); } // if we have no more instructions, see if there are any deferred branches to explore. if (ih == null) { final BranchTarget bt = branchTargets.pop(); if (bt != null) { ih = bt.target; stackDepth = bt.stackDepth; } } } return maxStackDepth; }