List of usage examples for org.aspectj.apache.bcel.generic ClassGen ClassGen
public ClassGen(String classname, String superclassname, String filename, int modifiers, String[] interfacenames)
From source file:br.jabuti.instrumenter.bytecode.bcel.ASMInstrumenter.java
License:Open Source License
/** Inserts a peace of code before a given instruction * in the specified method./* www . j a v a 2 s . c om*/ * * @param ih The instruction before which the code will be inserted * @param x A sequence of JVM instructions to be inserted * * @throws ParseException If the string <code>x</code> is not a valid * sequence of instructions. To the complete definition of what is a * valid sequence see <a href="asm.txt"> the Javacc grammar</a> * */ public void insertBefore(InstructionHandle ih, String x) throws ParseException { // try once with fake method and class // if no exception, do it again ClassGen cg2 = new ClassGen("DUMMY", "java/lang/Object", "DUMMY.class", 0, null); MethodGen m2 = meth.copy(meth.getClassName(), new ConstantPoolGen()); ASMParse asmp = new ASMParse(new ByteArrayInputStream(x.getBytes()), m2, cg2); InstructionList inedir = asmp.ASMProg(); // do a second time with the real method and class asmp = new ASMParse(new ByteArrayInputStream(x.getBytes()), meth, classGen); inedir = asmp.ASMProg(); // System.out.println(meth.getConstantPool()); // System.out.println(meth.getConstantPool().getFinalConstantPool()); insertBefore(ih, inedir); meth.setMaxLocals(); meth.setMaxStack(); }
From source file:br.jabuti.instrumenter.bytecode.bcel.ASMInstrumenter.java
License:Open Source License
/** Adds a peace of code before a given instruction * in the specified method.// ww w .j a va2 s. co m * * @param ih The instruction before which the code will be inserted * @param x A sequence of JVM instructions to be added * * @throws ParseException If the string <code>x</code> is not a valid * sequence of instructions. To the complete definition of what is a * valid sequence see <a href="asm.txt"> the Javacc grammar</a> * */ public void addBefore(InstructionHandle ih, String x) throws ParseException { // try once with fake method and class // if no exception, do it again ClassGen cg2 = new ClassGen("DUMMY", "java/lang/Object", "DUMMY.class", 0, null); MethodGen m2 = meth.copy(meth.getClassName(), new ConstantPoolGen()); ASMParse asmp = new ASMParse(new ByteArrayInputStream(x.getBytes()), m2, cg2); InstructionList inedir = asmp.ASMProg(); // do a second time with the real method and class asmp = new ASMParse(new ByteArrayInputStream(x.getBytes()), meth, classGen); inedir = asmp.ASMProg(); // System.out.println(meth.getConstantPool()); // System.out.println(meth.getConstantPool().getFinalConstantPool()); addBefore(ih, inedir); meth.setMaxLocals(); meth.setMaxStack(); }
From source file:br.jabuti.instrumenter.bytecode.bcel.ASMInstrumenter.java
License:Open Source License
/** Inserts a peace of code after a given instruction * in the specified method./*from w ww . j ava2 s .co m*/ * * @param ih The instruction before which the code will be inserted * @param x A sequence of JVM instructions to be inserted * * @throws ParseException If the string <code>x</code> is not a valid * sequence of instructions. To the complete definition of what is a * valid sequence see <a href="asm.txt"> the Javacc grammar</a> * */ public void insertAfter(InstructionHandle ih, String x) throws ParseException { // try once with fake method and class // if no exception, do it again ClassGen cg2 = new ClassGen("DUMMY", "java/lang/Object", "DUMMY.class", 0, null); MethodGen m2 = meth.copy(meth.getClassName(), new ConstantPoolGen()); ASMParse asmp = new ASMParse(new ByteArrayInputStream(x.getBytes()), m2, cg2); InstructionList inedir = asmp.ASMProg(); // do a second time with the real method and class asmp = new ASMParse(new ByteArrayInputStream(x.getBytes()), meth, classGen); inedir = asmp.ASMProg(); // System.out.println(meth.getConstantPool()); // System.out.println(meth.getConstantPool().getFinalConstantPool()); insertAfter(ih, inedir); meth.setMaxLocals(); meth.setMaxStack(); }