blob: f2feb625e20b728995838eb69cea2dceb0c7eeb0 (
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
|
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Target({ElementType.TYPE})
@interface TypeAnnotation{}
@Target({ElementType.METHOD})
@interface MethodAnnotation{}
public class AnnotationThrowsPattern {
public void method1() throws MyException {}
public void method2() throws MyNonAnnotatedException {}
}
@TypeAnnotation
class MyException extends Exception {
}
class MyNonAnnotatedException extends Exception {
}
aspect A {
// shouldn't get xlint warnings because @TypeAnnotation is allowed
pointcut required() : execution(* *.*(..) throws (@TypeAnnotation *));
declare warning : required() : "(* *.*(..) throws (@TypeAnnotation *))";
// shouldn't get xlint warnings because @TypeAnnotation is allowed
pointcut forbidden() : execution(* *.*(..) throws !(@TypeAnnotation *));
declare warning : forbidden() : "(* *.*(..) throws !(@TypeAnnotation *))";
// should get an xlint warning here because can only have
// annotations with @Target{ElementType.TYPE} or the default
// @Target (which is everything)
pointcut required1() : execution(* *.*(..) throws (@MethodAnnotation *));
declare warning : required1() : "* *.*(..) throws (@MethodAnnotation *)";
// should get an xlint warning here because can only have
// annotations with @Target{ElementType.TYPE} or the default
// @Target (which is everything)
pointcut forbidden1() : execution(* *.*(..) throws !(@MethodAnnotation *));
declare warning : forbidden1() : "* *.*(..) throws !(@MethodAnnotation *)";
}
|