misunderstanding of InstructionFactory

casertap <[email protected]> Mon, 15 Jun 2009 09:22:10 -0700 (PDT)
Newsgroups gmane.comp.jakarta.bcel.user
Message-ID <[email protected]>
------=_Part_36072_12229215.1245082930952
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


I have a very basic class:
---------------
public class MyClass{
	public static LinkedList classesLoaded;
	public static void addClass(Object o){
		Class c = o.getClass();
		classesLoaded.add(c);
	}
}
----------------
I have another class which adds statements to class constructor (when the
class is charged by the JVM).

My class implements ClassFileTransformer and I use the transform method to
do the modification on each class which is loaded.

I just want to add this java code to class constructor :
MyClass.addClass(this);
MyClass.addClass = a static invocation of the addClass method
(this) = the class which the JVM is loading.
This way I can save a list of class (of my application) which are loaded by
the JVM because every constructor add an object in the classesLoaded
LinkedList.

I suppose, I must use the class InstructionFactory to genetate the byte
code, but I have some problems.

This is what i made but it does not work:

InstructionList il = new InstructionList();
InstructionFactory ifact = new InstructionFactory(constantPoolGen);

il.append(ifact.createThis());
//I think i must push This on the stack but i do not know
il.append(ifact.createInvoke("MyClass","addClass",Type.VOID, new
Type[]{Type.OBJECT}, Constants.INVOKESTATIC));

it work when I write :

il.append(new PUSH(constantPoolGen,javaClass.getClassName()));
il.append(instructionFactory.createInvoke("MyClass", "addClass", Type.VOID,
new Type[] { Type.OBJECT }, Constants.INVOKESTATIC));

but in the latter version I send a String object to the addClass method. It
is not what I want.

-- 
View this message in context: http://www.nabble.com/misunderstanding-of-InstructionFactory-tp24037858p24037858.html
Sent from the BCEL - User mailing list archive at Nabble.com.

------=_Part_36072_12229215.1245082930952--