本文整理汇总了Java中org.apache.bcel.generic.MethodGen.getMethod方法的典型用法代码示例。如果您正苦于以下问题:Java MethodGen.getMethod方法的具体用法?Java MethodGen.getMethod怎么用?Java MethodGen.getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.generic.MethodGen
的用法示例。
在下文中一共展示了MethodGen.getMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateMain
import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
void generateMain(ClassGen clg, Method origMain) {
InstructionList il = new InstructionList();
MethodGen new_main = new MethodGen(Constants.ACC_STATIC
| Constants.ACC_PUBLIC, Type.VOID, new Type[] { new ArrayType(
Type.STRING, 1) }, new String[] { "argv" }, "main", clg
.getClassName(), il, clg.getConstantPool());
il.append(ins_f.createNew(cashmereType));
il.append(new DUP());
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "<init>",
Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "isMaster",
Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
BranchHandle ifcmp = il.append(new IFEQ(null));
InstructionHandle origMain_handle = il.append(new ALOAD(0));
InstructionHandle try_start = il.append(ins_f.createInvoke(clg
.getClassName(), origMain.getName(), Type.VOID,
new Type[] { new ArrayType(Type.STRING, 1) },
Constants.INVOKESTATIC));
BranchHandle try_end = il.append(new GOTO(null));
InstructionHandle e_handler = il.append(getCashmere(ins_f));
il.append(new SWAP());
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "exit",
Type.VOID, new Type[] { new ObjectType("java.lang.Throwable")},
Constants.INVOKEVIRTUAL));
BranchHandle gto2 = il.append(new GOTO(null));
InstructionHandle ifeq_target = il.append(getCashmere(ins_f));
ifcmp.setTarget(ifeq_target);
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "client",
Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(getCashmere(ins_f));
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "isMaster",
Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(new IFNE(origMain_handle));
InstructionHandle gto_target = il.append(getCashmere(ins_f));
try_end.setTarget(gto_target);
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "exit",
Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
InstructionHandle gto2_target = il.append(new RETURN());
gto2.setTarget(gto2_target);
new_main.addExceptionHandler(try_start, try_end, e_handler,
new ObjectType("java.lang.Throwable"));
new_main.setMaxStack();
new_main.setMaxLocals();
new_main.addLocalVariable("argv", new ArrayType(Type.STRING, 1), 0,
origMain_handle, null);
removeLocalTypeTables(new_main);
Method main = new_main.getMethod();
gen_c.addMethod(main);
}
示例2: instrument_reflection
import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
private static Method instrument_reflection(InstructionFactory inf, MethodGen mgen, ConstantPoolGen cpgen) {
Method ret = mgen.getMethod();
InstructionList ilist = mgen.getInstructionList();
if (ilist == null || ilist.size() == 0)
return ret;
InstructionHandle[] ihdls = ilist.getInstructionHandles();
for (InstructionHandle ihdl : ihdls) {
Instruction instr = ihdl.getInstruction();
// go through all instructions and look for invokes
if (instr instanceof InvokeInstruction) {
InvokeInstruction invoke = (InvokeInstruction) instr;
ReferenceType rtype = invoke.getReferenceType(cpgen);
if (rtype instanceof ObjectType) {
String cname = ((ObjectType) rtype).getClassName();
String mname = invoke.getName(cpgen);
// we look for exact match
if (cname.equals("java.lang.reflect.Method") && mname.equals("invoke")) {
// Util.log(rtype.toString());
Type[] arg_types = { new ObjectType(java.lang.reflect.Method.class.getCanonicalName()), Type.OBJECT, new ArrayType(Type.OBJECT, 1) };
ihdl.setInstruction(inf.createInvoke(SIFAStub.class.getCanonicalName(), "invoke", Type.OBJECT, arg_types, Constants.INVOKESTATIC));
}
} else {
// reference type can be ArrayType or UninitializedObjectType
}
}
}
ilist.setPositions();
mgen.setInstructionList(ilist);
mgen.removeLineNumbers();
mgen.setMaxStack();
mgen.setMaxLocals();
ret = mgen.getMethod();
return ret;
}