View | Details | Raw Unified | Return to bug 115252 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/aspectj/systemtest/ajc150/Ajc150Tests.java (+9 lines)
Lines 718-723 Link Here
718
   */
718
   */
719
  public void testNPEinWeavingAdaptor_pr116626() { runTest("NPE in WeavingAdaptor");}
719
  public void testNPEinWeavingAdaptor_pr116626() { runTest("NPE in WeavingAdaptor");}
720
  
720
  
721
  public void testXlintMessageForImproperAnnotationType_pr115252_Exact() {runTest("xlint message for improper exact annotation type");}
722
  public void testXlintMessageForImproperAnnotationType_pr115252_OR() {runTest("xlint message for improper annotation type inside OR");}
723
  public void testXlintMessageForImproperAnnotationType_pr115252_AND() {runTest("xlint message for improper annotation type inside AND");}
724
  public void testXlintMessageForImproperAnnotationType_pr115252_Return() {runTest("xlint message for improper annotated return type");}  
725
  public void testXlintMessageForImproperAnnotationType_pr115252_Declaring() {runTest("xlint message for improper annotated declaring type");}  
726
  public void testXlintMessageForImproperAnnotationType_pr115252_Parameter() {runTest("xlint message for improper annotated parameter type");}  
727
  public void testXlintMessageForImproperAnnotationType_pr115252_Throws() {runTest("xlint message for improper annotated throws pattern");}  
728
  public void testXlintMessageForImproperAnnotationType_pr115252_MoreThanOne() {runTest("xlint message for more than one improper annotated parameter type");}  
729
    
721
  // helper methods.....
730
  // helper methods.....
722
  
731
  
723
  public SyntheticRepository createRepos(File cpentry) {
732
  public SyntheticRepository createRepos(File cpentry) {
(-)src/org/aspectj/systemtest/ajc150/ajc150.xml (-1 / +77 lines)
Lines 1024-1029 Link Here
1024
        </compile>
1024
        </compile>
1025
    </ajc-test>
1025
    </ajc-test>
1026
1026
1027
	<ajc-test dir="bugs150/pr115252" title="xlint message for improper exact annotation type">
1028
        <compile files="ExactAnnotationTypePattern.java" options="-1.5">
1029
			<message kind="warning" line="20" text="field blah"/>
1030
        	<message kind="warning" line="28" text="does not match because annotation @TypeAnnotation has @Target{ElementType.TYPE} [Xlint:unmatchedTargetKind]"/>
1031
        	<message kind="warning" line="37" text="does not match because annotation @FieldAnnotation has @Target{ElementType.FIELD} [Xlint:unmatchedTargetKind]"/>
1032
            <message kind="warning" line="46" text="does not match because annotation @MethodAnnotation has @Target{ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
1033
        </compile>
1034
    </ajc-test>
1035
1036
	<ajc-test dir="bugs150/pr115252" title="xlint message for improper annotation type inside OR">
1037
        <compile files="OrTypePattern.java" options="-1.5">
1038
            <message kind="warning" line="26" text="does not match because annotation @FieldAnnotation has @Target{ElementType.FIELD} [Xlint:unmatchedTargetKind]"/>
1039
        	<message kind="warning" line="31" text="does not match because annotation @TypeAnnotation has @Target{ElementType.TYPE} [Xlint:unmatchedTargetKind]"/>
1040
        	<message kind="warning" line="31" text="does not match because annotation @FieldAnnotation has @Target{ElementType.FIELD} [Xlint:unmatchedTargetKind]"/>
1041
        </compile>
1042
    </ajc-test>
1043
1044
	<ajc-test dir="bugs150/pr115252" title="xlint message for improper annotation type inside AND">
1045
        <compile files="AndTypePattern.java" options="-1.5">
1046
            <message kind="warning" line="23" text="does not match because annotation @FieldAnnotation has @Target{ElementType.FIELD} [Xlint:unmatchedTargetKind]"/>
1047
        </compile>
1048
    </ajc-test>
1049
1050
	<ajc-test dir="bugs150/pr115252" title="xlint message for improper annotated return type">
1051
        <compile files="AnnotationReturnType.java" options="-1.5">
1052
            <!-- warnings coming from matching pointcuts and corresponding declare warnings -->
1053
			<message kind="warning" line="12" text="(@TypeAnnotation *) *(..)"/>
1054
			<message kind="warning" line="12" text="(@(TypeAnnotation || MethodAnnotation) *) *(..)"/>
1055
            <!-- xlint warnings that were put in as part of fix for pr115252 -->
1056
        	<message kind="warning" line="32" text="does not match because annotation @MethodAnnotation has @Target{ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
1057
        	<message kind="warning" line="37" text="does not match because annotation @MethodAnnotation has @Target{ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
1058
        </compile>
1059
    </ajc-test>
1060
1061
	<ajc-test dir="bugs150/pr115252" title="xlint message for improper annotated declaring type">
1062
        <compile files="AnnotationDeclaringType.java" options="-1.5">
1063
            <!-- warning coming from matching pointcuts and corresponding declare warnings -->
1064
			<message kind="warning" line="13" text="* (@TypeAnnotation *).*(..)"/>
1065
            <!-- xlint warning that was put in as part of fix for pr115252 -->
1066
        	<message kind="warning" line="27" text="does not match because annotation @MethodAnnotation has @Target{ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
1067
        </compile>
1068
    </ajc-test>
1069
1070
	<ajc-test dir="bugs150/pr115252" title="xlint message for improper annotated parameter type">
1071
        <compile files="AnnotationParameterType.java" options="-1.5">
1072
            <!-- warning coming from matching pointcuts and corresponding declare warnings -->
1073
			<message kind="warning" line="12" text="* *(@TypeAnnotation *)"/>
1074
            <!-- xlint warning that was put in as part of fix for pr115252 -->
1075
        	<message kind="warning" line="31" text="does not match because annotation @MethodAnnotation has @Target{ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
1076
        </compile>
1077
    </ajc-test>
1078
1079
	<ajc-test dir="bugs150/pr115252" title="xlint message for improper annotated throws pattern">
1080
        <compile files="AnnotationThrowsPattern.java" options="-1.5">
1081
            <!-- warnings coming from matching pointcuts and corresponding declare warnings -->
1082
			<message kind="warning" line="12" text="(* *.*(..) throws (@TypeAnnotation *))"/>
1083
			<message kind="warning" line="12" text="* *.*(..) throws !(@MethodAnnotation *)"/>
1084
			<message kind="warning" line="14" text="(* *.*(..) throws !(@TypeAnnotation *))"/>
1085
			<message kind="warning" line="14" text="* *.*(..) throws !(@MethodAnnotation *)"/>
1086
            <!-- xlint warnings that were put in as part of fix for pr115252 -->
1087
        	<message kind="warning" line="40" text="does not match because annotation @MethodAnnotation has @Target{ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
1088
        	<message kind="warning" line="46" text="does not match because annotation @MethodAnnotation has @Target{ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
1089
        </compile>
1090
    </ajc-test>
1091
1092
	<ajc-test dir="bugs150/pr115252" title="xlint message for more than one improper annotated parameter type">
1093
        <compile files="MoreThanOneTargetAnnotation.java" options="-1.5">
1094
            <!-- xlint warning that was put in as part of fix for pr115252 -->
1095
        	<message kind="warning" line="28" text="does not match because annotation @MethodAndFieldAnnotation has @Target{ElementType.FIELD,ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
1096
        	<message kind="warning" line="38" text="does not match because annotation @TypeAndMethodAnnotation has @Target{ElementType.METHOD,ElementType.TYPE} [Xlint:unmatchedTargetKind]"/>
1097
        </compile>
1098
    </ajc-test>
1099
1027
    <!-- ============================================================================ -->
1100
    <!-- ============================================================================ -->
1028
    <!-- ============================================================================ -->
1101
    <!-- ============================================================================ -->
1029
    
1102
    
Lines 2870-2876 Link Here
2870
        <compile files="Base.java,Colored.java,WrongTarget.aj" options="-1.5" xlintfile="ignoreTypeNotExposed.properties">
2943
        <compile files="Base.java,Colored.java,WrongTarget.aj" options="-1.5" xlintfile="ignoreTypeNotExposed.properties">
2871
           <message kind="error" line="8" text="The annotation @MethodColoring is disallowed for this location"/>
2944
           <message kind="error" line="8" text="The annotation @MethodColoring is disallowed for this location"/>
2872
           <message kind="error" line="9" text="The annotation @TypeColoring is disallowed for this location"/>
2945
           <message kind="error" line="9" text="The annotation @TypeColoring is disallowed for this location"/>
2873
        </compile>
2946
           <!-- xlint warnings that were put in as part of fix for pr115252 -->
2947
           <message kind="warning" line="13" text="does not match because annotation @MethodColoring has @Target{ElementType.METHOD} [Xlint:unmatchedTargetKind]"/>
2948
           <message kind="warning" line="16" text="does not match because annotation @TypeColoring has @Target{ElementType.TYPE} [Xlint:unmatchedTargetKind]"/>
2949
  </compile>
2874
   </ajc-test>
2950
   </ajc-test>
2875
    
2951
    
2876
   <ajc-test dir="java5/annotations/declare/atfield" title="declare @field - right target - source weaving">
2952
   <ajc-test dir="java5/annotations/declare/atfield" title="declare @field - right target - source weaving">
(-)bugs150/pr115252/AndTypePattern.java (+26 lines)
Added Link Here
1
import java.lang.annotation.Target;
2
import java.lang.annotation.ElementType;
3
4
@Target({ElementType.METHOD})
5
@interface MethodAnnotation{}
6
7
@Target({ElementType.FIELD})
8
@interface FieldAnnotation{}
9
10
public class AndTypePattern {
11
12
	public void method1() {}
13
	
14
	@FieldAnnotation
15
	int field = 1;
16
17
}
18
19
aspect A {
20
	
21
	// should display an xlint message because @FieldAnnotation can't be
22
	// applied to methods
23
	pointcut andPointcut() : execution(@(FieldAnnotation && MethodAnnotation) * *(..));
24
	declare warning : andPointcut() : "andPointcut()";
25
26
}
(-)bugs150/pr115252/AnnotationDeclaringType.java (+29 lines)
Added Link Here
1
import java.lang.annotation.Target;
2
import java.lang.annotation.ElementType;
3
4
@Target({ElementType.TYPE})
5
@interface TypeAnnotation{}
6
7
@Target({ElementType.METHOD})
8
@interface MethodAnnotation{}
9
10
@TypeAnnotation
11
public class AnnotationDeclaringType {
12
13
	public void method1() {
14
	}
15
	
16
}
17
18
aspect A {
19
	
20
	// matches the execution of any method where the declaring type
21
	// has the @TypeAnnotation - should compile ok and get no xlint errors
22
	pointcut pc() : execution(* (@TypeAnnotation *).*(..));
23
	declare warning : pc() : "* (@TypeAnnotation *).*(..)";
24
	
25
	// should get an xlint warning because declaring types can only
26
	// have the default @Target or @Target{ElementType.TYPE} target
27
	pointcut pc2() : execution(* (@MethodAnnotation *).*(..));
28
	declare warning : pc2() : "* (@MethodAnnotation *).*(..)";
29
}
(-)bugs150/pr115252/AnnotationParameterType.java (+34 lines)
Added Link Here
1
import java.lang.annotation.Target;
2
import java.lang.annotation.ElementType;
3
4
@Target({ElementType.TYPE})
5
@interface TypeAnnotation{}
6
7
@Target({ElementType.METHOD})
8
@interface MethodAnnotation{}
9
10
public class AnnotationParameterType {
11
12
	public void method1(MyClass m) {
13
	}
14
	
15
}
16
17
@TypeAnnotation
18
class MyClass {
19
	
20
}
21
22
aspect A {
23
	
24
	// shouldn't get an xlint warning because looking method which
25
	// takes an argument that has the @TypeAnnotation
26
	pointcut pc() : execution(* *(@TypeAnnotation *));
27
	declare warning : pc() : "* *(@TypeAnnotation *)";
28
	
29
	// should get an xlint warning because can only have the default, 
30
	// or @Target{ElementType.TYPE} as an argument type
31
	pointcut incorrectArgumentType() : execution(* *(@MethodAnnotation *));
32
	declare warning : incorrectArgumentType() : "argument type can only have @Target{ElementType.TYPE}";
33
		
34
}
(-)bugs150/pr115252/AnnotationReturnType.java (+40 lines)
Added Link Here
1
import java.lang.annotation.Target;
2
import java.lang.annotation.ElementType;
3
4
@Target({ElementType.TYPE})
5
@interface TypeAnnotation{}
6
7
@Target({ElementType.METHOD})
8
@interface MethodAnnotation{}
9
10
public class AnnotationReturnType {
11
12
	public MyClass method1() {
13
		return new MyClass();
14
	}
15
	
16
}
17
18
@TypeAnnotation
19
class MyClass {
20
	
21
}
22
23
aspect A {
24
	
25
	// shouldn't get an xlint warning because looking for a return type
26
	// which has the @TypeAnnotation annotation
27
	pointcut pc() : execution((@TypeAnnotation *) *(..));
28
	declare warning : pc() : "(@TypeAnnotation *) *(..)";
29
	
30
	// should get an xlint warning because can only have the default, 
31
	// or @Target{ElementType.TYPE} as a return type
32
	pointcut incorrectReturnType() : execution((@MethodAnnotation *) *(..));
33
	declare warning : incorrectReturnType() : "return type can only have @Target{ElementType.TYPE}";
34
	
35
	// should get an xlint warning because @MethodAnnotation can never match
36
	// but also get a declare warning because the @TypeAnnotation matches
37
	pointcut orPointcut() : execution((@(TypeAnnotation || MethodAnnotation) *) *(..));
38
	declare warning : orPointcut() : "(@(TypeAnnotation || MethodAnnotation) *) *(..)";
39
	
40
}
(-)bugs150/pr115252/AnnotationThrowsPattern.java (+49 lines)
Added Link Here
1
import java.lang.annotation.Target;
2
import java.lang.annotation.ElementType;
3
4
@Target({ElementType.TYPE})
5
@interface TypeAnnotation{}
6
7
@Target({ElementType.METHOD})
8
@interface MethodAnnotation{}
9
10
public class AnnotationThrowsPattern {
11
12
	public void method1() throws MyException {}
13
	
14
	public void method2() throws MyNonAnnotatedException {}
15
	
16
}
17
18
@TypeAnnotation
19
class MyException extends Exception {
20
	
21
}
22
23
class MyNonAnnotatedException extends Exception {
24
	
25
}
26
27
aspect A {
28
29
	// shouldn't get xlint warnings because @TypeAnnotation is allowed
30
	pointcut required() : execution(* *.*(..) throws (@TypeAnnotation *));
31
	declare warning : required() : "(* *.*(..) throws (@TypeAnnotation *))";
32
33
	// shouldn't get xlint warnings because @TypeAnnotation is allowed
34
	pointcut forbidden() : execution(* *.*(..) throws !(@TypeAnnotation *));
35
	declare warning : forbidden() : "(* *.*(..) throws !(@TypeAnnotation *))";
36
	
37
	// should get an xlint warning here because can only have
38
	// annotations with @Target{ElementType.TYPE} or the default
39
	// @Target (which is everything)
40
	pointcut required1() : execution(* *.*(..) throws (@MethodAnnotation *));
41
	declare warning : required1() : "* *.*(..) throws (@MethodAnnotation *)";
42
43
	// should get an xlint warning here because can only have
44
	// annotations with @Target{ElementType.TYPE} or the default
45
	// @Target (which is everything)
46
	pointcut forbidden1() : execution(* *.*(..) throws !(@MethodAnnotation *));
47
	declare warning : forbidden1() : "* *.*(..) throws !(@MethodAnnotation *)";
48
49
}
(-)bugs150/pr115252/ExactAnnotationTypePattern.java (+54 lines)
Added Link Here
1
import java.lang.annotation.Target;
2
import java.lang.annotation.ElementType;
3
4
@Target({ElementType.TYPE})
5
@interface TypeAnnotation{}
6
7
@Target({ElementType.METHOD})
8
@interface MethodAnnotation{}
9
10
@Target({ElementType.FIELD})
11
@interface FieldAnnotation{}
12
13
@interface AnyAnnotation{}
14
15
public class ExactAnnotationTypePattern {
16
17
	public void method1() {}
18
	
19
	@FieldAnnotation
20
	int field = 1;
21
22
}
23
24
aspect A {
25
	
26
	// an xlint message should be displayed because @TypeAnnotation can only
27
	// be applied to types, not methods
28
	pointcut typePC() : execution(@TypeAnnotation * ExactAnnotationTypePattern.method1(..));
29
	declare warning : typePC() : "blah";
30
	
31
	// should compile as normal, since @MethodAnnotation can be applied to methods
32
	pointcut methodPC() : execution(@MethodAnnotation * ExactAnnotationTypePattern.method1(..));
33
	declare warning : methodPC() : "blah";
34
	
35
	// an xlint message should be displayed because @FieldAnnotation can only
36
	// be applied to fields, not methods
37
	pointcut matchAll() : execution(@FieldAnnotation * *(..));
38
	declare warning : matchAll() : "blah";
39
40
	// should compile as normal since @FieldAnnotation can be applied to fields
41
	pointcut legalFieldPC() : set(@FieldAnnotation int ExactAnnotationTypePattern.field);
42
	declare warning : legalFieldPC() : "field blah";
43
	
44
	// an xlint message should be displayed because @MethodAnnotation can
45
	// only be applied to methods, not fields
46
	pointcut illegalFieldPC() : set(@MethodAnnotation int *);
47
	declare warning : illegalFieldPC() : "field blah blah";
48
	
49
	// no xlint message should be displayed here because @AnyAnnotation
50
	// has the default target
51
	pointcut anyAnnotation() : execution(@AnyAnnotation * *(..));
52
	declare warning : anyAnnotation() : "default target is allowed everywhere";
53
54
}
(-)bugs150/pr115252/MoreThanOneTargetAnnotation.java (+41 lines)
Added Link Here
1
import java.lang.annotation.Target;
2
import java.lang.annotation.ElementType;
3
4
@Target({ElementType.METHOD, ElementType.FIELD})
5
@interface MethodAndFieldAnnotation{}
6
7
@Target({ElementType.TYPE, ElementType.METHOD})
8
@interface TypeAndMethodAnnotation{}
9
10
11
public class MoreThanOneTargetAnnotation {
12
13
	public void method1() {}
14
	
15
	int field = 1;
16
17
}
18
19
aspect A {
20
	
21
	// shouldn't get an xlint message because @MethodAndFieldAnnotation
22
	// can be applied to methods and fields
23
	pointcut pc1() : execution(@MethodAndFieldAnnotation * *(..));
24
	declare warning : pc1() : "pc1()";
25
	
26
	// should get an xlint message because can only have the target
27
	// ElementType.TYPE as a return type
28
	pointcut pc2() : execution((@MethodAndFieldAnnotation *) *(..));
29
	declare warning : pc2() : "pc2()";
30
31
	// shouldn't get an xlint message because can have the target
32
	// ElementType.TYPE as a return type
33
	pointcut pc3() : execution((@TypeAndMethodAnnotation *) *(..));
34
	declare warning : pc3() : "pc3()";
35
36
	// should get an xlint message because @TypeAndMethodAnnotation
37
	// can only be applied to types and methods, not fields
38
	pointcut pc4() : set(@TypeAndMethodAnnotation int *);
39
	declare warning : pc4() : "pc4()";
40
		
41
}
(-)bugs150/pr115252/OrTypePattern.java (+34 lines)
Added Link Here
1
import java.lang.annotation.Target;
2
import java.lang.annotation.ElementType;
3
4
@Target({ElementType.TYPE})
5
@interface TypeAnnotation{}
6
7
@Target({ElementType.METHOD})
8
@interface MethodAnnotation{}
9
10
@Target({ElementType.FIELD})
11
@interface FieldAnnotation{}
12
13
public class OrTypePattern {
14
15
	public void method1() {}
16
	
17
	@FieldAnnotation
18
	int field = 1;
19
20
}
21
22
aspect A {
23
	
24
	// should display an xlint message because @FieldAnnotation can't be
25
	// applied to methods
26
	pointcut orPointcut() : execution(@(FieldAnnotation || MethodAnnotation) * *(..));
27
	declare warning : orPointcut() : "orPointcut()";
28
	
29
	// two xlint messages should be displayed because neither @FieldAnnotation
30
	// or @TypeAnnotation can match methods
31
	pointcut orPointcut2() : execution(@(FieldAnnotation || TypeAnnotation) * *(..));
32
	declare warning : orPointcut2() : "orPointcut2()";
33
34
}

Return to bug 115252