本文整理汇总了Java中org.apache.bcel.generic.InstructionList.size方法的典型用法代码示例。如果您正苦于以下问题:Java InstructionList.size方法的具体用法?Java InstructionList.size怎么用?Java InstructionList.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.generic.InstructionList
的用法示例。
在下文中一共展示了InstructionList.size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check_reflection
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
private int check_reflection(MethodGen mgen, ConstantPoolGen cpgen) {
int cnt = 0;
InstructionList ilist = mgen.getInstructionList();
if (ilist == null || ilist.size() == 0)
return cnt;
for (Instruction instr : ilist.getInstructions()) {
// 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());
cnt++;
}
} else {
// reference type can be ArrayType or UninitializedObjectType
}
}
}
return cnt;
}
示例2: instrument_reflection
import org.apache.bcel.generic.InstructionList; //导入方法依赖的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;
}