本文整理汇总了Java中org.apache.bcel.generic.ClassGen.getMethods方法的典型用法代码示例。如果您正苦于以下问题:Java ClassGen.getMethods方法的具体用法?Java ClassGen.getMethods怎么用?Java ClassGen.getMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.generic.ClassGen
的用法示例。
在下文中一共展示了ClassGen.getMethods方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nullAdaptClass
import org.apache.bcel.generic.ClassGen; //导入方法依赖的package包/类
byte[] nullAdaptClass(final InputStream is, final String name)
throws Exception
{
JavaClass jc = new ClassParser(is, name + ".class").parse();
ClassGen cg = new ClassGen(jc);
ConstantPoolGen cp = cg.getConstantPool();
Method[] ms = cg.getMethods();
for (int j = 0; j < ms.length; ++j) {
MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
boolean lv = ms[j].getLocalVariableTable() == null;
boolean ln = ms[j].getLineNumberTable() == null;
if (lv) {
mg.removeLocalVariables();
}
if (ln) {
mg.removeLineNumbers();
}
mg.stripAttributes(skipDebug);
InstructionList il = mg.getInstructionList();
if (il != null) {
InstructionHandle ih = il.getStart();
while (ih != null) {
ih = ih.getNext();
}
if (compute) {
mg.setMaxStack();
mg.setMaxLocals();
}
}
cg.replaceMethod(ms[j], mg.getMethod());
}
return cg.getJavaClass().getBytes();
}
示例2: counterAdaptClass
import org.apache.bcel.generic.ClassGen; //导入方法依赖的package包/类
byte[] counterAdaptClass(final InputStream is, final String name)
throws Exception
{
JavaClass jc = new ClassParser(is, name + ".class").parse();
ClassGen cg = new ClassGen(jc);
ConstantPoolGen cp = cg.getConstantPool();
if (!cg.isInterface()) {
FieldGen fg = new FieldGen(ACC_PUBLIC,
Type.getType("I"),
"_counter",
cp);
cg.addField(fg.getField());
}
Method[] ms = cg.getMethods();
for (int j = 0; j < ms.length; ++j) {
MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
if (!mg.getName().equals("<init>") && !mg.isStatic()
&& !mg.isAbstract() && !mg.isNative())
{
if (mg.getInstructionList() != null) {
InstructionList il = new InstructionList();
il.append(new ALOAD(0));
il.append(new ALOAD(0));
il.append(new GETFIELD(cp.addFieldref(name, "_counter", "I")));
il.append(new ICONST(1));
il.append(new IADD());
il.append(new PUTFIELD(cp.addFieldref(name, "_counter", "I")));
mg.getInstructionList().insert(il);
mg.setMaxStack(Math.max(mg.getMaxStack(), 2));
boolean lv = ms[j].getLocalVariableTable() == null;
boolean ln = ms[j].getLineNumberTable() == null;
if (lv) {
mg.removeLocalVariables();
}
if (ln) {
mg.removeLineNumbers();
}
cg.replaceMethod(ms[j], mg.getMethod());
}
}
}
return cg.getJavaClass().getBytes();
}