aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs150/pr115252/MoreThanOneTargetAnnotation.java
blob: 5629960b9558a85b22b56ff9ca5e0a5c6e17c387 (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
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;

@Target({ElementType.METHOD, ElementType.FIELD})
@interface MethodAndFieldAnnotation{}

@Target({ElementType.TYPE, ElementType.METHOD})
@interface TypeAndMethodAnnotation{}


public class MoreThanOneTargetAnnotation {

	public void method1() {}
	
	int field = 1;

}

aspect A {
	
	// shouldn't get an xlint message because @MethodAndFieldAnnotation
	// can be applied to methods and fields
	pointcut pc1() : execution(@MethodAndFieldAnnotation * *(..));
	declare warning : pc1() : "pc1()";
	
	// should get an xlint message because can only have the target
	// ElementType.TYPE as a return type
	pointcut pc2() : execution((@MethodAndFieldAnnotation *) *(..));
	declare warning : pc2() : "pc2()";

	// shouldn't get an xlint message because can have the target
	// ElementType.TYPE as a return type
	pointcut pc3() : execution((@TypeAndMethodAnnotation *) *(..));
	declare warning : pc3() : "pc3()";

	// should get an xlint message because @TypeAndMethodAnnotation
	// can only be applied to types and methods, not fields
	pointcut pc4() : set(@TypeAndMethodAnnotation int *);
	declare warning : pc4() : "pc4()";
		
}