Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Capturing annotations with args


From the AspectJ developers notebook:

/**
* matches any join point with at least one argument, and where the
* type of the first argument has the @Classified annotation
*/
pointcut classifiedArgument() : @args(Classified,..);


So it matches if the TYPE of the parameter has the annotation.

There is some info on why we don't (right now) support parameter annotation matching here:

http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/ajdk15notebook/annotations-pointcuts-and-advice.html#d0e1395

As to why your program is failing with a verifyerror, we had a few bugs in the initial support - but they should all be ironed out by AspectJ1.5.0M2 (which is inside AJDT 1.2.0M3) - what versions of the compiler or tools are you using?  I tried your program in 1.2.0M3 and it didn't crash - it didn't print anything though, probably because the @args() didn't match.

Andy.
---
Andy Clement
AspectJ Development



Rodrigo Gonçalves <locomotiva_diesel@xxxxxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

15/04/2005 09:30

Please respond to
aspectj-users@xxxxxxxxxxx

To
aspectj-users@xxxxxxxxxxx
cc
Subject
[aspectj-users] Capturing annotations with args





Hello,
 
I am currently trying to write a piece of code that allows me to understand if the args designator is sensitive to the parameter annotation or to the argument annotation.
 
I defined an annotation type, RuntimeAnnotation, to preform the annotation on class fields. Here’s the definition:
 
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
 
/** Defining a Tiger Annotation for FIELDS with RUNTIME Retention Policy.*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface RuntimeAnnotation {
 
}
 
And then I coded a simple test class with annotated fields and a built-in aspect that contains an anonymous pointcut that captures the args context. I believe that the pointcut syntax is correct but I seem to get a strange error from AJDT:
 
java.lang.VerifyError: (class: AnnotatedClasses, method: caller signature: ()V) Expecting to find object/array on stack
Exception in thread "main"
 
Why is this happening? Also, if someone can answer my original question (“is the args designator is sensitive to the parameter annotation or to the argument annotation?”) I would be grateful.
 
Here’s the test class code:
 
import static java.lang.System.out;
 
public class AnnotatedClasses
{
    /* annotated field */
    @RuntimeAnnotation int anInt = 1;
    /* negative control */
    int uglyDuck = 0;
         
    private void aMethod(int anInt_)
    {      }
   
    private void anotherMethod(int uglyDuck_)
    {     }
   
    public void caller()
    {
       aMethod(anInt);
       anotherMethod(uglyDuck);
    }
   
   
public static void main (String [] args)
    {
       AnnotatedClasses ac = new AnnotatedClasses();
       ac.caller();
    }
   
    static private aspect CaptureArgs
    {
      before(RuntimeAnnotation arg_) : call (* *.*(..)) && !within(CaptureArgs) && @args(arg_)
      {
          out.println(arg_);
      }
       
    }  
   
}
 
Thanks a lot,
 
Rodrigo Gonçalves


Yahoo! Acesso Grátis: Internet rápida e grátis. Instale o discador agora!_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top