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 Lighter Joul <zh...@163.com> on 2007/02/06 10:27:49 UTC

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.


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


Re: How to acquire the method's parameters?

Posted by C E Ezeugoh <ce...@gmail.com>.
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 <zh...@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 )
> {
>     ......
>     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.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>