Hi,
 
You do not mentioned the type of your problem. Is it a Runtime Exception or you 
just didn't get the expected results?. If the second option is the case, then 
you my inject your code at the end of the constructor which, as I can guess, 
fall after the RETURN instruction.
 
If the first option is the case, then AUCH!!, no way to see in dark man, 
because your code is corrct (the one with ifact.createThis(), but try 
InstructionFactory.createThis();)
). 

Best Regards,

===============================
A b d u l l a h   O.  A l - Z a g h a m e e m
Technical University of  Berlin
Germany

--- On Mon, 6/15/09, casertap <pierre.case...@loria.fr> wrote:


From: casertap <pierre.case...@loria.fr>
Subject: misunderstanding of InstructionFactory
To: bcel-user@jakarta.apache.org
Date: Monday, June 15, 2009, 7:22 PM



I have a very basic class:
---------------
public class MyClass{
    public static LinkedList<Class> 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.


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscr...@jakarta.apache.org
For additional commands, e-mail: bcel-user-h...@jakarta.apache.org




      

Reply via email to