[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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!