Hi Bhaskar and Mohan,
I think Bhaskar is trying to access method NAMES, not actual values. You can
access method names in AspectJ, using MethodSignature.getParameterNames ..
for example:

void around() : test(){
  Signature s = thisJoinPointStaticPart.getSignature();
  // Warning, this means you are weaving a method, otherwise there will be
of another subclass of Signature
  MethodSignature m = (MethodSignature)s;
  String[] names = m.getParameterName();
  Object[] values = thisJoinPoint.getArgs();
  for (int i = 0; i < names.length; i++) {
    System.out.println(names[i] + " : " + values[i]);
  }
  proceed();
}

Names are present only if target code (the class you are weaving) has been
compiled with debug symbols, which is true for 99% of java code actually
available, but still could happen that you are weaving into a third party
library which has been compiled without debug symbols.

Simone

2010/5/28 Mohan Radhakrishnan <[email protected]>

> Hi Bhaskar,
>
> I am using a simple around advice. The argument is printed. Is this
> simiilar to what you are looking for ?
>
>        pointcut test() : call( * com.test.TestClass.test1(..) );
>
>        void around() : test(){
>
>                System.out.println( thisJoinPoint.getArgs()[ 0 ] );
>
>                proceed();
>        }
>
>
>        public void test1( int i){
>        }
>
> Thanks,
> Mohan
>
> On Thu, May 27, 2010 at 3:35 AM, Bhaskar Maddala <[email protected]>
> wrote:
> > Hello,
> >
> >    I am trying to write a logging aspect. Something that logs method
> > arguments when the method executed. I was looking up the reflection
> > apis for aspectj and did not find anything in either StaticPart,
> > ProceedingJoinPoint or Signature that would give me the method
> > arguments names.
> >
> > As as example
> >    @Pointcut("execution(@Unit * *(..)) && @annotation(u) &&
> > @within(ct) && this(cinstance)")
> >    public void unit(Auditable cinstance, Container ct, Unit u) {
> >    }
> >
> >    @Around(unit(ct, u))
> >    public void do(ProceedingJoinPoint pjp, Auditable cinstance,
> > Container ct, Unit u){
> >      pjp.getMethodArgNames(); //???
> >    }
> >
> >  Any ideas on where I can get the method argument names?
> >
> > Thanks
> > Bhaskar
> > _______________________________________________
> > aspectj-users mailing list
> > [email protected]
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to