[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Matching declared annotations by annotation parameters
|
Hi,
It works for me (AspectJ 1.6.12.M2):
=== Code2.java ===
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Sample {
String value();
}
@Retention(RetentionPolicy.RUNTIME)
@interface Added {
}
aspect SampleAspect {
declare @field : @Sample("matches") * *: @Added;
}
public class Code2 {
public static void main(String []argv) throws Exception {
// should fail
System.out.println(Code2.class.getDeclaredField("i").getAnnotation(Added.class));
// should work
System.out.println(Code2.class.getDeclaredField("j").getAnnotation(Added.class));
}
@Sample("foo")
int i;
@Sample("matches")
int j;
}
===
ajc -1.5 Code2.java -showWeaveInfo
'int j [RuntimeVisibleAnnotations]' of type 'Code2' (Code2.java) is
annotated with @Added field annotation from 'SampleAspect'
(Code2.java:13)
java Code2
null
@Added()
It is possible that there are issues when the classes are in separate
files but I don't know your exact setup. If you have a scenario that
isn't working like the above, please raise a bugzilla - include the
testcode if you can.
thanks
Andy
On 2 September 2011 06:49, Zoran Regvart <zregvart+aspectj@xxxxxxxxx> wrote:
> Hi!
> it would be rather nifty if one could match on actual parameters of
> the annotation, but I can't seem to find a way to match annotations by
> specific annotation parameters. This is what I would like to do is:
>
> aspect SampleAspect {
> declare @field : @Sample("matches") * *: @Added;
> }
>
> so that every field annotated with @Sample whose value is "matches"
> (or generally any annotation key-value) to have additional annotation
> added (@Added)
>
> thanks!
>
> zoran
> --
> Human by day user by night
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>