private void addGetEnhancementContractVersionMethod() { // public int getEnhancementContractVersion() BCMethod method = _pc.declareMethod(PRE + "GetEnhancementContractVersion", int.class, null); method.makePublic(); Code code = method.getCode(true); code.constant().setValue(ENHANCER_VERSION); code.ireturn(); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Set the type of class being loaded. * * @return the first Instruction of the block added by setting the type * @throws IllegalStateException if type has already been set */ public Instruction setClass(String name) { name = _class.getProject().getNameCache().getExternalForm(name, false); setClassName(name, getWrapperClass(name)); return _ins; }
/** * When adding class entries, make sure the bytecode spec supports them. */ private void ensureBytecodeVersion() { BCClass bc = getCode().getMethod().getDeclarer(); if (bc.getMajorVersion() < Constants.MAJOR_VERSION_JAVA5) { bc.setMajorVersion(Constants.MAJOR_VERSION_JAVA5); bc.setMinorVersion(Constants.MINOR_VERSION_JAVA5); } } }
private void addGetData(BCClass bc) { // return getObjectField(i); BCMethod method = bc.declareMethod("getData", Object.class, new Class[]{ int.class }); Code code = method.getCode(true); code.aload().setThis(); code.iload().setParam(0); code.invokevirtual().setMethod("getObject", Object.class, new Class[]{ int.class }); code.areturn(); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Set the method this instruction operates on. * * @return this instruction, for method chaining */ public MethodInstruction setMethod(BCMethod method) { if (method == null) return setMethodIndex(0); return setMethod(method.getDeclarer().getName(), method.getName(), method.getReturnName(), method.getParamNames(), false); }
/** * Set the field this instruction operates on. * * @return this instruction, for method chaining */ public FieldInstruction setField(BCField field) { if (field == null) return setFieldIndex(0); return setField(field.getDeclarer().getName(), field.getName(), field.getTypeName()); }
/** * Set the return type of this method. */ public void setReturn(String name) { setDescriptor(getProject().getNameCache().getDescriptor(name, getParamNames())); }
/** * Return the local variable object this instruction * operates on, or null if none. * * @see LocalVariableTable#getLocalVariable(int) */ public LocalVariable getLocalVariable() { LocalVariableTable table = getCode().getLocalVariableTable(false); if (table == null) return null; return table.getLocalVariable(getLocal()); }
/** * Adds a copy of the given instruction. * * @return the newly added instruction */ public Instruction add(Instruction ins) { Instruction newIns = createInstruction(ins.getOpcode()); newIns.read(ins); _ci.add(newIns); return newIns; }
/** * Set the type of instruction this wide instruction modifies. */ public WideInstruction setInstruction(Instruction ins) { if (ins == null) return setInstruction(Constants.NOP); setInstruction(ins.getOpcode()); if (_ins == Constants.IINC) _inc = ((IIncInstruction) ins).getIncrement(); return this; }
/** * Set the method parameter that this local corresponds to. */ public void setParam(int param) { setLocal(_owner.getCode().getLocalsIndex(param)); }
private void addGetEnhancementContractVersionMethod() { // public int getEnhancementContractVersion() BCMethod method = _pc.declareMethod(PRE + "GetEnhancementContractVersion", int.class, null); method.makePublic(); Code code = method.getCode(true); code.constant().setValue(ENHANCER_VERSION); code.ireturn(); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Helper method to add the code necessary to throw the given * exception type, sans message. */ private Instruction throwException(Code code, Class type) { Instruction ins = code.anew().setType(type); code.dup(); code.invokespecial().setMethod(type, "<init>", void.class, null); code.athrow(); return ins; }
/** * Set the method this instruction operates on. * * @return this instruction, for method chaining */ public MethodInstruction setMethod(BCMethod method) { if (method == null) return setMethodIndex(0); return setMethod(method.getDeclarer().getName(), method.getName(), method.getReturnName(), method.getParamNames(), false); }
/** * Return the local variable object this instruction * operates on, or null if none. * * @see LocalVariableTable#getLocalVariable(int) */ public LocalVariable getLocalVariable() { LocalVariableTable table = getCode().getLocalVariableTable(false); if (table == null) return null; return table.getLocalVariable(getLocal()); }
/** * Set the type of instruction this wide instruction modifies. */ public WideInstruction setInstruction(Instruction ins) { if (ins == null) return setInstruction(Constants.NOP); setInstruction(ins.getOpcode()); if (_ins == Constants.IINC) _inc = ((IIncInstruction) ins).getIncrement(); return this; }
private void addGetEnhancementContractVersionMethod() { // public int getEnhancementContractVersion() BCMethod method = _pc.declareMethod(PRE + "GetEnhancementContractVersion", int.class, null); method.makePublic(); Code code = method.getCode(true); code.constant().setValue(ENHANCER_VERSION); code.ireturn(); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Helper method to add the code necessary to throw the given * exception type, sans message. */ private Instruction throwException(Code code, Class type) { Instruction ins = code.anew().setType(type); code.dup(); code.invokespecial().setMethod(type, "<init>", void.class, null); code.athrow(); return ins; }