当前位置: 首页>>代码示例>>Java>>正文


Java MethodGen.getMethod方法代码示例

本文整理汇总了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);
    }
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:66,代码来源:Cashmerec.java

示例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;
}
 
开发者ID:USC-NSL,项目名称:SIF,代码行数:45,代码来源:ReflectionHandler.java


注:本文中的org.apache.bcel.generic.MethodGen.getMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。