Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2009, Walter Harley and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* Walter Harley (eclipse@cafewalter.com) - initial implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.builder; |
12 |
|
13 |
import junit.framework.Test; |
14 |
|
15 |
import org.eclipse.core.runtime.IPath; |
16 |
import org.eclipse.jdt.core.tests.util.Util; |
17 |
|
18 |
/** |
19 |
* Tests to verify that annotation changes cause recompilation of dependent types. |
20 |
* See http://bugs.eclipse.org/149768 |
21 |
*/ |
22 |
public class AnnotationDependencyTests extends BuilderTests { |
23 |
private IPath srcRoot = null; |
24 |
private IPath projectPath = null; |
25 |
|
26 |
public AnnotationDependencyTests(String name) { |
27 |
super(name); |
28 |
} |
29 |
|
30 |
public static Test suite() { |
31 |
return buildTestSuite(AnnotationDependencyTests.class); |
32 |
} |
33 |
|
34 |
public void setUp() throws Exception { |
35 |
super.setUp(); |
36 |
|
37 |
this.projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ |
38 |
env.addExternalJars(this.projectPath, Util.getJavaClassLibs()); |
39 |
|
40 |
// remove old package fragment root so that names don't collide |
41 |
env.removePackageFragmentRoot(this.projectPath,""); //$NON-NLS-1$ |
42 |
|
43 |
this.srcRoot = env.addPackageFragmentRoot(this.projectPath, "src"); //$NON-NLS-1$ |
44 |
env.setOutputFolder(this.projectPath, "bin"); //$NON-NLS-1$ |
45 |
} |
46 |
|
47 |
protected void tearDown() throws Exception { |
48 |
this.projectPath = null; |
49 |
this.srcRoot = null; |
50 |
|
51 |
super.tearDown(); |
52 |
} |
53 |
|
54 |
private void addAnnotationType() { |
55 |
String annoCode = "package p1;\n" |
56 |
+ "@interface Anno {\n" |
57 |
+ "String value();\n" |
58 |
+ "}\n"; |
59 |
env.addClass(this.srcRoot, "p1", "Anno", annoCode); |
60 |
} |
61 |
|
62 |
/** |
63 |
* This test makes sure that changing an annotation on type A causes type B |
64 |
* to be recompiled, if B references A. See http://bugs.eclipse.org/149768 |
65 |
*/ |
66 |
public void testTypeAnnotationDependency() throws Exception |
67 |
{ |
68 |
String a1Code = "package p1; " + "\n" |
69 |
+ "@Anno(\"A1\")" + "\n" |
70 |
+ "public class A {}"; |
71 |
String a2Code = "package p1; " + "\n" |
72 |
+ "@Anno(\"A2\")" + "\n" |
73 |
+ "public class A {}"; |
74 |
String bCode = "package p1; " + "\n" |
75 |
+ "public class B {" + "\n" |
76 |
+ " public A a;" + "\n" |
77 |
+ "}"; |
78 |
|
79 |
env.addClass( this.srcRoot, "p1", "A", a1Code ); |
80 |
env.addClass( this.srcRoot, "p1", "B", bCode ); |
81 |
addAnnotationType(); |
82 |
|
83 |
fullBuild( this.projectPath ); |
84 |
expectingNoProblems(); |
85 |
|
86 |
// edit annotation in A |
87 |
env.addClass( this.srcRoot, "p1", "A", a2Code ); |
88 |
incrementalBuild( this.projectPath ); |
89 |
expectingNoProblems(); |
90 |
|
91 |
// verify that B was recompiled |
92 |
expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); |
93 |
} |
94 |
|
95 |
/** |
96 |
* This test makes sure that changing an annotation on a field within type A |
97 |
* causes type B to be recompiled, if B references A. |
98 |
* See http://bugs.eclipse.org/149768 |
99 |
*/ |
100 |
public void testFieldAnnotationDependency() throws Exception |
101 |
{ |
102 |
String a1Code = "package p1; " + "\n" |
103 |
+ "public class A {" + "\n" |
104 |
+ " @Anno(\"A1\")" + "\n" |
105 |
+ " protected int f;" + "\n" |
106 |
+ "}"; |
107 |
String a2Code = "package p1; " + "\n" |
108 |
+ "public class A {" + "\n" |
109 |
+ " @Anno(\"A2\")" + "\n" |
110 |
+ " protected int f;" + "\n" |
111 |
+ "}"; |
112 |
String bCode = "package p1; " + "\n" |
113 |
+ "public class B {" + "\n" |
114 |
+ " public A a;" + "\n" |
115 |
+ "}"; |
116 |
|
117 |
env.addClass( this.srcRoot, "p1", "A", a1Code ); |
118 |
env.addClass( this.srcRoot, "p1", "B", bCode ); |
119 |
addAnnotationType(); |
120 |
|
121 |
fullBuild( this.projectPath ); |
122 |
expectingNoProblems(); |
123 |
|
124 |
// edit annotation in A |
125 |
env.addClass( this.srcRoot, "p1", "A", a2Code ); |
126 |
incrementalBuild( this.projectPath ); |
127 |
expectingNoProblems(); |
128 |
|
129 |
// verify that B was recompiled |
130 |
expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); |
131 |
} |
132 |
|
133 |
/** |
134 |
* This test makes sure that changing an annotation on a method within type A |
135 |
* causes type B to be recompiled, if B references A. |
136 |
* See http://bugs.eclipse.org/149768 |
137 |
*/ |
138 |
public void testMethodAnnotationDependency() throws Exception |
139 |
{ |
140 |
String a1Code = "package p1; " + "\n" |
141 |
+ "public class A {" + "\n" |
142 |
+ " @Anno(\"A1\")" + "\n" |
143 |
+ " protected int f() { return 0; }" + "\n" |
144 |
+ "}"; |
145 |
String a2Code = "package p1; " + "\n" |
146 |
+ "public class A {" + "\n" |
147 |
+ " @Anno(\"A2\")" + "\n" |
148 |
+ " protected int f() { return 0; }" + "\n" |
149 |
+ "}"; |
150 |
String bCode = "package p1; " + "\n" |
151 |
+ "public class B {" + "\n" |
152 |
+ " public A a;" + "\n" |
153 |
+ "}"; |
154 |
|
155 |
env.addClass( this.srcRoot, "p1", "A", a1Code ); |
156 |
env.addClass( this.srcRoot, "p1", "B", bCode ); |
157 |
addAnnotationType(); |
158 |
|
159 |
fullBuild( this.projectPath ); |
160 |
expectingNoProblems(); |
161 |
|
162 |
// edit annotation in A |
163 |
env.addClass( this.srcRoot, "p1", "A", a2Code ); |
164 |
incrementalBuild( this.projectPath ); |
165 |
expectingNoProblems(); |
166 |
|
167 |
// verify that B was recompiled |
168 |
expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); |
169 |
} |
170 |
|
171 |
/** |
172 |
* This test makes sure that changing an annotation on an inner type X within type A |
173 |
* causes type B to be recompiled, if B references A. |
174 |
* Note that B does not directly reference A.X, only A. |
175 |
* See http://bugs.eclipse.org/149768 |
176 |
*/ |
177 |
public void testInnerTypeAnnotationDependency() throws Exception |
178 |
{ |
179 |
String a1Code = "package p1; " + "\n" |
180 |
+ "public class A {" + "\n" |
181 |
+ " @Anno(\"A1\")" + "\n" |
182 |
+ " public class X { }" + "\n" |
183 |
+ "}"; |
184 |
String a2Code = "package p1; " + "\n" |
185 |
+ "public class A {" + "\n" |
186 |
+ " @Anno(\"A2\")" + "\n" |
187 |
+ " public class X { }" + "\n" |
188 |
+ "}"; |
189 |
String bCode = "package p1; " + "\n" |
190 |
+ "public class B {" + "\n" |
191 |
+ " public A a;" + "\n" |
192 |
+ "}"; |
193 |
|
194 |
env.addClass( this.srcRoot, "p1", "A", a1Code ); |
195 |
env.addClass( this.srcRoot, "p1", "B", bCode ); |
196 |
addAnnotationType(); |
197 |
|
198 |
fullBuild( this.projectPath ); |
199 |
expectingNoProblems(); |
200 |
|
201 |
// edit annotation in A |
202 |
env.addClass( this.srcRoot, "p1", "A", a2Code ); |
203 |
incrementalBuild( this.projectPath ); |
204 |
expectingNoProblems(); |
205 |
|
206 |
// verify that B was recompiled |
207 |
expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.A$X", "p1.B" }); |
208 |
} |
209 |
|
210 |
/** |
211 |
* This test makes sure that changing an annotation on a type A |
212 |
* does not cause type B to be recompiled, if B does not reference A. |
213 |
* See http://bugs.eclipse.org/149768 |
214 |
*/ |
215 |
public void testUnrelatedTypeAnnotationDependency() throws Exception |
216 |
{ |
217 |
String a1Code = "package p1; " + "\n" |
218 |
+ "@Anno(\"A1\")" + "\n" |
219 |
+ "public class A {}"; |
220 |
String a2Code = "package p1; " + "\n" |
221 |
+ "@Anno(\"A2\")" + "\n" |
222 |
+ "public class A {}"; |
223 |
String bCode = "package p1; " + "\n" |
224 |
+ "public class B {" + "\n" |
225 |
+ "}"; |
226 |
|
227 |
env.addClass( this.srcRoot, "p1", "A", a1Code ); |
228 |
env.addClass( this.srcRoot, "p1", "B", bCode ); |
229 |
addAnnotationType(); |
230 |
|
231 |
fullBuild( this.projectPath ); |
232 |
expectingNoProblems(); |
233 |
|
234 |
// edit annotation in A |
235 |
env.addClass( this.srcRoot, "p1", "A", a2Code ); |
236 |
incrementalBuild( this.projectPath ); |
237 |
expectingNoProblems(); |
238 |
|
239 |
// verify that B was not recompiled |
240 |
expectingUniqueCompiledClasses(new String[] { "p1.A" }); |
241 |
} |
242 |
|
243 |
} |