You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by "Nikhil C. Khedkar" <ni...@yahoo.com> on 2004/02/02 16:54:50 UTC

Statement v/s Line

Hi,
  I have posted the query few days back about putting
in a StringBuffer variable in a class. Here's the code
I could finally manage (though i am still not able to
initialize the static variable at the start only, but
instead I am doing it in every method).
I must say it was a pretty painful process. The APIs
are most of the times NOT documented, which makes the
use of this library totally based on the personal
intution (No kidding, I used to search the
functionality from their names). It doesn't have any
examples. This part should be improved a lot.

//StringBuffer initialization start
InstructionList instrumentedInitList = new
InstructionList();
InstructionFactory iFactory = new
InstructionFactory(cp);
instrumentedInitList.append(iFactory.createNew("java.lang.StringBuffer"));
instrumentedInitList.append(InstructionConstants.DUP);
instrumentedInitList.append(new PUSH(cp, ""));
instrumentedInitList.append(iFactory.createInvoke("java.lang.StringBuffer",
"<init>", Type.VOID,
			   new Type[] { Type.VOID },
Constants.INVOKESPECIAL));

instrumentedInitList.append(iFactory.createPutStatic(java_class.getClassName(),
sFieldName, new
ObjectType("java.lang.StringBuffer")));

instrumentedPatchList.append(instrumentedInitList);
//StringBuffer initialization end

  Ok, now I have one more question, can I get the
statements from the class files? I know we can get the
line numbers, but let's say I want to do something
after every statement is executed
  
  int i = 0;
  int j = 9;
  
  is equal to
  
  int i = 0;int j = 9;
  
If I use the line numbers approach, then both of them
will be treated differently. I basically want to know,
how to get statements from the code fragment

Thanks,
  Nikhil



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

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