Lighter Joul | 6 Feb 2007 10:27
Favicon

How to acquire the method's parameters?


Hi, i'm a newbie in bcel. recently i have to develop an tool, something like
aop weaver. i want to acquire the method's parameters. such as:

m1(int i, String j, Object o )
{
    ......
    m1_org( i, j, o ); //created by bcel
    ......
}

m1_org(int i, String j, Object o)
{
   ......
}

that is, in m1() method, i want to create a method invoking m1_org(), and
the parameters are the same with m1(). 

i have read a lot about bcel docs, and know how to invoke m1_org() method,
but the problem is, i don't know how to acquire and confirm the parameters.
i think of localvariabletable, however, i don't know how to do it excatly.
 can anyone give me some suggestions. any help will be appreciated. looking
forwards your kindly reply!
--

-- 
View this message in context: http://www.nabble.com/How-to-acquire-the-method%27s-parameters--tf3179617.html#a8822943
Sent from the BCEL - User mailing list archive at Nabble.com.
chinmoy chakraborty | 9 Feb 2007 13:01
Favicon

Please help

  
Hi Guys,

Could you please tell me what will be the bcel code to generate following code?

Class cls = abc.class;

Thanks a lot.

Chinmoy
Dave Brosius | 9 Feb 2007 14:08
Picon
Favicon

Re: Please help

There is a fine tool in BCEL called BCELifier which given some java class, 
will generate a class that generates that class.

http://www.onjava.com/pub/a/onjava/2003/10/22/bcel.html?page=2

----- Original Message ----- 
From: "chinmoy chakraborty" <chinu_ss <at> rediffmail.com>
To: <bcel-user <at> jakarta.apache.org>
Sent: Friday, February 09, 2007 7:01 AM
Subject: Please help

Hi Guys,

Could you please tell me what will be the bcel code to generate following 
code?

Class cls = abc.class;

Thanks a lot.

Chinmoy 
Marko Asplund | 9 Feb 2007 20:59
Picon

Re: Please help

> ---------- Forwarded message ----------
>
> Hi Guys,
>
> Could you please tell me what will be the bcel code to generate following code?
>
>
> Class cls = abc.class;
>

you could try putting your code in a class, compiling it and running
BCELifier on it.

marko
Marko Asplund | 10 Feb 2007 10:54
Picon

Re: How to acquire the method's parameters?

Lighter Joul wrote:
> Hi, i'm a newbie in bcel. recently i have to develop an tool, something like
> aop weaver. i want to acquire the method's parameters. such as:
>
> m1(int i, String j, Object o )
> {
>     ......
>     m1_org( i, j, o ); //created by bcel
>     ......
> }
>
> m1_org(int i, String j, Object o)
> {
>    ......
> }
>
> that is, in m1() method, i want to create a method invoking m1_org(), and
> the parameters are the same with m1().
>
> i have read a lot about bcel docs, and know how to invoke m1_org() method,
> but the problem is, i don't know how to acquire and confirm the parameters.
> i think of localvariabletable, however, i don't know how to do it excatly.
>  can anyone give me some suggestions. any help will be appreciated. looking
> forwards your kindly reply!

As far as i understand method parameters are always found in a fixed
location in the local variable array. With instance methods local
variable 0 contains the this-pointer and method parameters start from
index 1.

(Continue reading)

C E Ezeugoh | 14 Feb 2007 03:12
Picon
Gravatar

Re: How to acquire the method's parameters?

Hi ,

I assume that you have an idea of the method name atleast. If that is the
case then you can use regular java reflection a-la Class.getDeclaredMethods()
to track down the method you are looking for and then
Method.getParameterTypes() to find out the parameter types
for a given method.
For things like parameter names you can construct an instance of MethodGen
from the java.lang.reflect.Method retrieved using
Class.getDeclaredMethods(once you have narrowed the result down to the
specific Method you are
interested in). Calling getArgumentNames() on MethodGen will give you the
parameter names (like i, j and o) for the method you are interested in. You
can then modify the original class to add calls to m1_org using the
retrieved parameters.

HTH

EE

On 2/6/07, Lighter Joul <zhouliang531 <at> 163.com> wrote:
>
>
> Hi, i'm a newbie in bcel. recently i have to develop an tool, something
> like
> aop weaver. i want to acquire the method's parameters. such as:
>
> m1(int i, String j, Object o )
> {
>     ......
(Continue reading)


Gmane