Mark's correction of the return statement generation is absolutely correct. \
Meanwhile I noticed a mistake in the code snipplet I've send: you have to
mg.setInstructionList(il)
at some point;
or, alternatively
instead of
InstructionList il = new InstructionList();
place
InstructionList il = mg.getInstructionList(); // will be null if the method is newly generated or abstract


Mark R. Diggory wrote:



Sapan Shah wrote:

Thanks for the inputs!..it;s done. I checked the code of classExtender and
it works for me.
However, just to clear my concepts, I wanted to know, what will the snippet
below do. I am putting in comments wherever i could understand. The code is
for the setter method.



//create the factory InstructionFactory fac = new InstructionFactory(classGen, cp); //load the This variable as it is at the index 0 InstructionHandle ih_0 = il.append(fac.createLoad(Type.OBJECT, 0));


//what will this do??. What variable is loaded?
il.append(fac.createLoad(Type.OBJECT, 1));


This loads "arg1" parameter handed in

public void method(Object arg1, Object arg2)

onto the stack


il.append(fac.createFieldAccess(classGen.getClassName(), field.getName(),
Type.getType(field.getSignature()), Constants.PUTFIELD));
//create the return instrauction. But how would it know, that it is to
create the return instrauction for a particular variable?
InstructionHandle ih_5 = il.append(fac.createReturn(Type.VOID));


In this case it just returns viod. ButI believe when you want to return something other than void it is what you last placed on the stack using fac.createFieldAccess...

ie
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
il.append(_factory.createFieldAccess(className, propertyName, type, Constants.GETFIELD));
InstructionHandle ih_4 = il.append(_factory.createReturn(type));



I'm not 100% sure. I'm rather a novice so far with the package. If I'm wrong could someone please correct me.


-Mark


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to