[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: Re: [aspectj-users] Method parameter annotations...

We have no immediate plans to implement this feature (i.e. certainly not in the 1.5.x stream, I guess it could be a candidate for 1.6 if enough folks voted for it).

The closest you can get to this functionality with current AJ is to use an "if" pcd that calls out to a static helper method:

e.g.:

before() : execution(* *(..)) && if(hasParameterAnnotation(thisJoinPointStaticPart,Untrusted.class) {
  // ...
}

// might be a good idea to cache this indexed by JoinPoint.StaticPart.. .
private static boolean hasParameterAnnotation(JoinPoint.StaticPart jp, Class<? extends Annotation annClass) {

  // train wreck!
  Annotation[][] anns = ((MethodSignature)jp.getSignature()).getMethod().getParameterAnnotations();

  for( Annotation[] parameterAnns : anns) {
    for (Annotation ann : parameterAnns) {
      if (ann.getClass().equals(annClass)) {
        return true;
     }
    }
  }

  return false;
}

Regards, Adrian.

On 12/05/06, Kyle Lomeli <kyllerss@xxxxxxxxxxx> wrote:

Thanks for the reply, Dean. Does anyone know when AJ5 will support matching on parameter annotations?

 

-Kyle


> Date: Fri, 12 May 2006 10:23:55 -0500
> From: dean@xxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [aspectj-users] Method parameter annotations...
> To: aspectj-users@xxxxxxxxxxx
> CC:


>
> Unless things have changed recently, AJ5 does not yet support matching on annotations on parameters. You could annotate the method and then use reflection on the parameter list to find any annotations. Not nearly as straightforward, unfortunately.
>
> dean
>
> Kyle Lomeli wrote ..
> > I am trying to define a pointcut that will match any method parameters
> > that are annotated with @Untrusted. Among other things, I would like to
> > be able to perform some operations on this parameter before allowing it
> > to be used by the following method body (eg. data invalid character filtering,
> > string truncation, etc...). Here is an example of the code with which I
> > am testing:
> > ...



Join the next generation of Hotmail and you could win the adventure of a lifetime Learn More.

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users





--
-- Adrian
adrian.colyer@xxxxxxxxx