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 C E Ezeugoh <ce...@gmail.com> on 2005/12/01 02:27:49 UTC

Re: Accessing OBJECT names on which methods are called from within other methods

Hi there,

Its a tricky question but with the return types of the messages, you can
look through the localvariabletable for the method (
MethodGen.getLocalvariables()) and then find all the localvariables with the
same return type as the init() for example and with the same
instructionhandle.

That is the instructionhandle where you retrieve the call to m2(), say must
be the same with the instructionhandle from the given localvariable (
localvariablegen.containsTarget(ih) must return true where ih is the
instructionhandle for the call to m2()).

HTH

CEE

On 11/30/05, Atam <at...@gmail.com> wrote:
>
> Hi all,
>
> i am also newbie here, but i read alot first about BCEL. My goal is to
> extra from within a method, which other methods are called, and to
> which objects these messages are send.
>
> eg
>
> public voud m1()
> {
>   c2 c2obj = new c2();
>   c2obj.m2();
> }
>
> Here, wihin m1() there are 2 messages: <init> and  m2().
> This information i can extract with the code below.  What i cannot do
> yet, is to know that these messages are sent to the c2obj object. So,
> i need the name of the OBJECT to which the messages are sent. If it is
> a static call, name of object is not needed.
>
> If anyone can please help me with this, i would appreciate it very much.
>
> With kind regards,
>
> Atam
>
> Code :
>
> ClassGen classGen = new ClassGen(myclass.getJavaClass());
>                 MethodGen methodGen = new MethodGen(mymethod,
> myclass.getClassName(), classGen.getConstantPool());
>                 InstructionList il = methodGen.getInstructionList();
>
>                 for (Iterator i = il.iterator(); i.hasNext(); )
>                 {
>                         InstructionHandle handle = (InstructionHandle)
> i.next();
>
>                         if (handle.getInstruction() instanceof
> InvokeInstruction)
>                         {
>                                 InvokeInstruction invokeInstruction =
> (InvokeInstruction)
> handle.getInstruction();
>                                 String calledClass =
> invokeInstruction.getClassName(classGen.getConstantPool());
>                                 String calledMethodName =
> invokeInstruction.getName(classGen.getConstantPool());
>                                 String calledMethodSignature =
> invokeInstruction.getSignature(classGen.getConstantPool());
>                                 boolean isStaticMethod =
> invokeInstruction.getOpcode() ==
> Constants.INVOKESTATIC;
>                             String objectname;
>                             if( isStaticMethod)
>                                 objectname = "static";
>                             else
>                                 objectname = ""; ???????????
>                            }
>                 }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>

Re: Accessing OBJECT names on which methods are called from within other methods

Posted by Dave Brosius <db...@apache.org>.
Without compiling with -g, you are out of luck if you expect to find local 
variable names.
Since this is open source you are working on, it shouldn't be a problem, 
just compile with -g.


----- Original Message ----- 
From: "Atam" <at...@gmail.com>
To: "BCEL Users List" <bc...@jakarta.apache.org>
Sent: Wednesday, November 30, 2005 11:50 PM
Subject: Re: Accessing OBJECT names on which methods are called from within 
other methods


The problem is that the localvariabletable does not contain anything because
the code is not compiled with the debugging option.

What i want to do, is to write a tool, which gets as input java.class files
of an opensource project. It has to compute a UML sequence diagram for me.
In this diagram i need to tknow to which object the message was send.
Because it is different when a message is send to 2 distinct objects of the
same class.

My tool will further do some dynamic coupling analysis with the derived
data.

I will check how to use the stack ect and try to achiev this. If someone is
allready familiar with this plz gime me some hints,

Thanks to all of you guys in helping me

Atam



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


Re: Accessing OBJECT names on which methods are called from within other methods

Posted by Atam <at...@gmail.com>.
The problem is that the localvariabletable does not contain anything because
the code is not compiled with the debugging option.

What i want to do, is to write a tool, which gets as input java.class files
of an opensource project. It has to compute a UML sequence diagram for me.
In this diagram i need to tknow to which object the message was send.
Because it is different when a message is send to 2 distinct objects of the
same class.

My tool will further do some dynamic coupling analysis with the derived
data.

I will check how to use the stack ect and try to achiev this. If someone is
allready familiar with this plz gime me some hints,

Thanks to all of you guys in helping me

Atam



On 12/1/05, C E Ezeugoh <ce...@gmail.com> wrote:
>
> Hi there,
>
> Its a tricky question but with the return types of the messages, you can
> look through the localvariabletable for the method (
> MethodGen.getLocalvariables()) and then find all the localvariables with
> the
> same return type as the init() for example and with the same
> instructionhandle.
>
> That is the instructionhandle where you retrieve the call to m2(), say
> must
> be the same with the instructionhandle from the given localvariable (
> localvariablegen.containsTarget(ih) must return true where ih is the
> instructionhandle for the call to m2()).
>
> HTH
>
> CEE
>
> On 11/30/05, Atam <at...@gmail.com> wrote:
> >
> > Hi all,
> >
> > i am also newbie here, but i read alot first about BCEL. My goal is to
> > extra from within a method, which other methods are called, and to
> > which objects these messages are send.
> >
> > eg
> >
> > public voud m1()
> > {
> >   c2 c2obj = new c2();
> >   c2obj.m2();
> > }
> >
> > Here, wihin m1() there are 2 messages: <init> and  m2().
> > This information i can extract with the code below.  What i cannot do
> > yet, is to know that these messages are sent to the c2obj object. So,
> > i need the name of the OBJECT to which the messages are sent. If it is
> > a static call, name of object is not needed.
> >
> > If anyone can please help me with this, i would appreciate it very much.
> >
> > With kind regards,
> >
> > Atam
> >
> > Code :
> >
> > ClassGen classGen = new ClassGen(myclass.getJavaClass());
> >                 MethodGen methodGen = new MethodGen(mymethod,
> > myclass.getClassName(), classGen.getConstantPool());
> >                 InstructionList il = methodGen.getInstructionList();
> >
> >                 for (Iterator i = il.iterator(); i.hasNext(); )
> >                 {
> >                         InstructionHandle handle = (InstructionHandle)
> > i.next();
> >
> >                         if (handle.getInstruction() instanceof
> > InvokeInstruction)
> >                         {
> >                                 InvokeInstruction invokeInstruction =
> > (InvokeInstruction)
> > handle.getInstruction();
> >                                 String calledClass =
> > invokeInstruction.getClassName(classGen.getConstantPool());
> >                                 String calledMethodName =
> > invokeInstruction.getName(classGen.getConstantPool());
> >                                 String calledMethodSignature =
> > invokeInstruction.getSignature(classGen.getConstantPool());
> >                                 boolean isStaticMethod =
> > invokeInstruction.getOpcode() ==
> > Constants.INVOKESTATIC;
> >                             String objectname;
> >                             if( isStaticMethod)
> >                                 objectname = "static";
> >                             else
> >                                 objectname = ""; ???????????
> >                            }
> >                 }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> >
> >
>
>