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

Almost, I want to select annotations that are method parameter annotations, not annotations on the formal types of the method parameters themselves.

I've modified your example slightly to show you what I mean

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class AnnotationBinding {
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {
}
public static class Foo {}
public static class Bar {}
public void x(@TestAnnotation Foo foo) {} // error here
public void x(Bar bar) {} // no error here
static aspect A {
declare error: execution(void AnnotationBinding.x(@TestAnnotation *))
: "parameter annotated with @TestAnnotation";
}
}


Wes <wes@xxxxxxxxxxxxxx> wrote:
Hi Eric -

I'm not sure what kind of static checking happens or is possible using @args(..),
but you can staticly pick them out using the method-execution join point signature:

execution(* *(@Annotation *)) // for any method with one parameter so annotated

In the test below, only the annotation-laden shadow x(..) is flagged as an error.
Would that help?

Wes

--------------------- annot/AnnotationBinding.java
package annot;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class AnnotationBinding {
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {
}
@TestAnnotation
public static class Foo {}
public static class Bar {}
public void x(Foo foo) {} // error here
public void x(Bar bar) {} // no error here
static aspect A {
declare error: execution(void AnnotationBinding.x(@TestAnnotation *))
: "parameter annotated with @TestAnnotation";
}
}


------------Original Message------------
From: Eric Crahen
To: aspectj-users@xxxxxxxxxxx
Date: Sun, Aug-6-2006 3:33 PM
Subject: [aspectj-users] Matching on parameter annotations
Is there any upcoming work being done to allow for parameter annotations to be matched more efficently?

So far I've found that using @args() inserts bytecodes that check the annotations of the object passed in to see if an annotation is present and its not quite what I wanted. And using the static parts of a join point also inserts bytecode into each method. This works, but if you weave 100 methods and only 1 contains a parameter annotation, thats alot of extra code inserted into 99 methods that wouldn't behave any differently.


- Eric


Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail Beta._______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

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



- Eric


Do you Yahoo!?
Get on board. You're invited to try the new Yahoo! Mail Beta.