blob: a407494816f25704bef81b9db70f9f7d895483b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Target({ElementType.TYPE})
@interface TypeAnnotation{}
@Target({ElementType.METHOD})
@interface MethodAnnotation{}
@Target({ElementType.FIELD})
@interface FieldAnnotation{}
@interface AnyAnnotation{}
public class ExactAnnotationTypePattern {
public void method1() {}
@FieldAnnotation
int field = 1;
}
aspect A {
// an xlint message should be displayed because @TypeAnnotation can only
// be applied to types, not methods
pointcut typePC() : execution(@TypeAnnotation * ExactAnnotationTypePattern.method1(..));
declare warning : typePC() : "blah";
// should compile as normal, since @MethodAnnotation can be applied to methods
pointcut methodPC() : execution(@MethodAnnotation * ExactAnnotationTypePattern.method1(..));
declare warning : methodPC() : "blah";
// an xlint message should be displayed because @FieldAnnotation can only
// be applied to fields, not methods
pointcut matchAll() : execution(@FieldAnnotation * *(..));
declare warning : matchAll() : "blah";
// should compile as normal since @FieldAnnotation can be applied to fields
pointcut legalFieldPC() : set(@FieldAnnotation int ExactAnnotationTypePattern.field);
declare warning : legalFieldPC() : "field blah";
// an xlint message should be displayed because @MethodAnnotation can
// only be applied to methods, not fields
pointcut illegalFieldPC() : set(@MethodAnnotation int *);
declare warning : illegalFieldPC() : "field blah blah";
// no xlint message should be displayed here because @AnyAnnotation
// has the default target
pointcut anyAnnotation() : execution(@AnyAnnotation * *(..));
declare warning : anyAnnotation() : "default target is allowed everywhere";
}
|