1 /*******************************************************************************
2 * Copyright (c) 2000, 2015 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.jdt.core.tests.builder;
15
16 import junit.framework.Test;
17
18 import org.eclipse.core.resources.IMarker;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.jdt.core.JavaModelException;
22 import org.eclipse.jdt.core.compiler.CategorizedProblem;
23 import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
24 import org.eclipse.jdt.core.tests.util.Util;
25
26 @SuppressWarnings({"rawtypes", "unchecked"})
27 public class DependencyTests extends BuilderTests {
DependencyTests(String name)28 public DependencyTests(String name) {
29 super(name);
30 }
31
suite()32 public static Test suite() {
33 return buildTestSuite(DependencyTests.class);
34 }
35
testAbstractMethod()36 public void testAbstractMethod() throws JavaModelException {
37 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
38 env.addExternalJars(projectPath, Util.getJavaClassLibs());
39
40 // remove old package fragment root so that names don't collide
41 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
42
43 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
44 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
45
46 env.addClass(root, "p1", "Indicted", //$NON-NLS-1$ //$NON-NLS-2$
47 "package p1;\n"+ //$NON-NLS-1$
48 "public abstract class Indicted {\n"+ //$NON-NLS-1$
49 "}\n" //$NON-NLS-1$
50 );
51
52 IPath collaboratorPath = env.addClass(root, "p2", "Collaborator", //$NON-NLS-1$ //$NON-NLS-2$
53 "package p2;\n"+ //$NON-NLS-1$
54 "import p1.*;\n"+ //$NON-NLS-1$
55 "public class Collaborator extends Indicted{\n"+ //$NON-NLS-1$
56 "}\n" //$NON-NLS-1$
57 );
58
59 fullBuild(projectPath);
60 expectingNoProblems();
61
62 env.addClass(root, "p1", "Indicted", //$NON-NLS-1$ //$NON-NLS-2$
63 "package p1;\n"+ //$NON-NLS-1$
64 "public abstract class Indicted {\n"+ //$NON-NLS-1$
65 " public abstract void foo();\n"+ //$NON-NLS-1$
66 "}\n" //$NON-NLS-1$
67 );
68
69 incrementalBuild(projectPath);
70 expectingOnlyProblemsFor(collaboratorPath);
71 expectingOnlySpecificProblemFor(collaboratorPath, new Problem("Collaborator", "The type Collaborator must implement the inherited abstract method Indicted.foo()", collaboratorPath, 38, 50, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
72 }
73
74 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=168208
testCaseInvariantType()75 public void testCaseInvariantType() throws JavaModelException {
76 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
77 env.addExternalJars(projectPath, Util.getJavaClassLibs());
78
79 // remove old package fragment root so that names don't collide
80 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
81
82 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
83 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
84
85 org.eclipse.jdt.core.IJavaProject p = env.getJavaProject("Project");
86 java.util.Map options = p.getOptions(true);
87 options.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, org.eclipse.jdt.core.JavaCore.DISABLED); //$NON-NLS-1$
88 p.setOptions(options);
89
90 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
91 "package p1;\n"+ //$NON-NLS-1$
92 "public class A {\n" +
93 " class Node {}\n" +
94 "}" //$NON-NLS-1$
95 );
96
97 env.addClass(root, "p1", "Bb", //$NON-NLS-1$ //$NON-NLS-2$
98 "package p1;\n"+ //$NON-NLS-1$
99 "class Bb {}" //$NON-NLS-1$
100 );
101
102 fullBuild(projectPath);
103 expectingNoProblems();
104
105 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
106 "package p1;\n"+ //$NON-NLS-1$
107 "public class A {\n" +
108 " class node {}\n" +
109 "}" //$NON-NLS-1$
110 );
111
112 env.addClass(root, "p1", "Bb", //$NON-NLS-1$ //$NON-NLS-2$
113 "package p1;\n"+ //$NON-NLS-1$
114 "class BB {}" //$NON-NLS-1$
115 );
116
117 incrementalBuild(projectPath);
118 expectingNoProblems();
119 }
120
testExactMethodDeleting()121 public void testExactMethodDeleting() throws JavaModelException {
122 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
123 env.addExternalJars(projectPath, Util.getJavaClassLibs());
124
125 // remove old package fragment root so that names don't collide
126 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
127
128 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
129 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
130
131 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
132 "package p1;\n"+ //$NON-NLS-1$
133 "public class A {\n"+ //$NON-NLS-1$
134 " public int i(int i) {return 1;};\n"+ //$NON-NLS-1$
135 "}\n" //$NON-NLS-1$
136 );
137
138 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
139 "package p2;\n"+ //$NON-NLS-1$
140 "import p1.*;\n"+ //$NON-NLS-1$
141 "public class B extends A{\n"+ //$NON-NLS-1$
142 "}\n" //$NON-NLS-1$
143 );
144
145 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
146 "package p3;\n"+ //$NON-NLS-1$
147 "public class C extends p2.B{\n"+ //$NON-NLS-1$
148 " int j = i(1);\n"+ //$NON-NLS-1$
149 "}\n" //$NON-NLS-1$
150 );
151
152 IPath dPath = env.addClass(root, "p3", "D", //$NON-NLS-1$ //$NON-NLS-2$
153 "package p3;\n"+ //$NON-NLS-1$
154 "public class D extends p2.B{\n"+ //$NON-NLS-1$
155 " public class M {\n"+ //$NON-NLS-1$
156 " int j = i(1);\n"+ //$NON-NLS-1$
157 " }\n"+ //$NON-NLS-1$
158 "}\n" //$NON-NLS-1$
159 );
160
161 IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$
162 "package p4;\n"+ //$NON-NLS-1$
163 "public class X {\n"+ //$NON-NLS-1$
164 " int foo(p3.C c) { return c.i(1); }\n"+ //$NON-NLS-1$
165 "}\n" //$NON-NLS-1$
166 );
167
168 fullBuild(projectPath);
169 expectingNoProblems();
170
171 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
172 "package p1;\n"+ //$NON-NLS-1$
173 "public class A {\n"+ //$NON-NLS-1$
174 "}\n" //$NON-NLS-1$
175 );
176
177 incrementalBuild(projectPath);
178 expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath});
179 expectingSpecificProblemFor(cPath, new Problem("C", "The method i(int) is undefined for the type C", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
180 expectingSpecificProblemFor(dPath, new Problem("D", "The method i(int) is undefined for the type D.M", dPath, 69, 70, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
181 expectingSpecificProblemFor(xPath, new Problem("X", "The method i(int) is undefined for the type C", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
182
183 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
184 "package p2;\n"+ //$NON-NLS-1$
185 "import p1.*;\n"+ //$NON-NLS-1$
186 "public class B extends A{\n"+ //$NON-NLS-1$
187 " protected int i(long l) throws Exception {return 1;};\n"+ //$NON-NLS-1$
188 "}\n" //$NON-NLS-1$
189 );
190
191 incrementalBuild(projectPath);
192 expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath});
193 expectingSpecificProblemFor(cPath, new Problem("C", "Default constructor cannot handle exception type Exception thrown by implicit super constructor. Must define an explicit constructor", cPath, 50, 54, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
194 expectingSpecificProblemFor(dPath, new Problem("D", "Default constructor cannot handle exception type Exception thrown by implicit super constructor. Must define an explicit constructor", dPath, 69, 73, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
195 expectingSpecificProblemFor(xPath, new Problem("X", "The method i(long) from the type B is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
196
197 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
198 "package p1;\n"+ //$NON-NLS-1$
199 "public class A {\n"+ //$NON-NLS-1$
200 " public int i(int i) {return 1;};\n"+ //$NON-NLS-1$
201 "}\n" //$NON-NLS-1$
202 );
203
204 incrementalBuild(projectPath);
205 expectingNoProblems();
206 }
207
testExactMethodVisibility()208 public void testExactMethodVisibility() throws JavaModelException {
209 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
210 env.addExternalJars(projectPath, Util.getJavaClassLibs());
211
212 // remove old package fragment root so that names don't collide
213 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
214
215 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
216 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
217
218 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
219 "package p1;\n"+ //$NON-NLS-1$
220 "public class A {\n"+ //$NON-NLS-1$
221 " public int i() {return 1;};\n"+ //$NON-NLS-1$
222 "}\n" //$NON-NLS-1$
223 );
224
225 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
226 "package p2;\n"+ //$NON-NLS-1$
227 "import p1.*;\n"+ //$NON-NLS-1$
228 "public class B extends A{\n"+ //$NON-NLS-1$
229 "}\n" //$NON-NLS-1$
230 );
231
232 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
233 "package p3;\n"+ //$NON-NLS-1$
234 "public class C extends p2.B{\n"+ //$NON-NLS-1$
235 " int j = i();\n"+ //$NON-NLS-1$
236 "}\n" //$NON-NLS-1$
237 );
238
239 IPath dPath = env.addClass(root, "p3", "D", //$NON-NLS-1$ //$NON-NLS-2$
240 "package p3;\n"+ //$NON-NLS-1$
241 "public class D extends p2.B{\n"+ //$NON-NLS-1$
242 " public class M {\n"+ //$NON-NLS-1$
243 " int j = i();\n"+ //$NON-NLS-1$
244 " }\n"+ //$NON-NLS-1$
245 "}\n" //$NON-NLS-1$
246 );
247
248 IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$
249 "package p4;\n"+ //$NON-NLS-1$
250 "public class X {\n"+ //$NON-NLS-1$
251 " int foo(p3.C c) { return c.i(); }\n"+ //$NON-NLS-1$
252 "}\n" //$NON-NLS-1$
253 );
254
255 fullBuild(projectPath);
256 expectingNoProblems();
257
258 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
259 "package p1;\n"+ //$NON-NLS-1$
260 "public class A {\n"+ //$NON-NLS-1$
261 " int i() {return 1;};\n"+ //$NON-NLS-1$
262 "}\n" //$NON-NLS-1$
263 );
264
265 incrementalBuild(projectPath);
266 expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath});
267 expectingSpecificProblemFor(cPath, new Problem("C", "The method i() from the type A is not visible", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
268 expectingSpecificProblemFor(dPath, new Problem("D", "The method i() from the type A is not visible", dPath, 69, 70, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
269 expectingSpecificProblemFor(xPath, new Problem("X", "The method i() from the type A is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
270
271 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
272 "package p1;\n"+ //$NON-NLS-1$
273 "public class A {\n"+ //$NON-NLS-1$
274 " protected int i() {return 1;};\n"+ //$NON-NLS-1$
275 "}\n" //$NON-NLS-1$
276 );
277
278 incrementalBuild(projectPath);
279 expectingOnlyProblemsFor(new IPath[] {xPath});
280 expectingSpecificProblemFor(xPath, new Problem("X", "The method i() from the type A is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
281
282 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
283 "package p1;\n"+ //$NON-NLS-1$
284 "public class A {\n"+ //$NON-NLS-1$
285 " public int i() {return 1;};\n"+ //$NON-NLS-1$
286 "}\n" //$NON-NLS-1$
287 );
288
289 incrementalBuild(projectPath);
290 expectingNoProblems();
291 }
292
testExternalJarChanged()293 public void testExternalJarChanged() throws CoreException, java.io.IOException {
294 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
295 env.addExternalJars(projectPath, Util.getJavaClassLibs());
296
297 IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
298 IPath classTest = env.addClass(root, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$
299 "package p;\n"+ //$NON-NLS-1$
300 "public class X {\n" + //$NON-NLS-1$
301 " void foo() {\n" + //$NON-NLS-1$
302 " new q.Y().bar();\n" + //$NON-NLS-1$
303 " }\n" + //$NON-NLS-1$
304 "}" //$NON-NLS-1$
305 );
306 String externalJar = Util.getOutputDirectory() + java.io.File.separator + "test.jar"; //$NON-NLS-1$
307 Util.createJar(
308 new String[] {
309 "q/Y.java", //$NON-NLS-1$
310 "package q;\n" + //$NON-NLS-1$
311 "public class Y {\n" + //$NON-NLS-1$
312 "}" //$NON-NLS-1$
313 },
314 new java.util.HashMap(),
315 externalJar
316 );
317 env.addExternalJar(projectPath, externalJar);
318
319 // build -> expecting problems
320 fullBuild();
321 expectingProblemsFor(
322 classTest,
323 "Problem : The method bar() is undefined for the type Y [ resource : </Project/p/X.java> range : <57,60> category : <50> severity : <2>]"
324 );
325
326 // fix jar
327 Util.createJar(
328 new String[] {
329 "q/Y.java", //$NON-NLS-1$
330 "package q;\n" + //$NON-NLS-1$
331 "public class Y {\n" + //$NON-NLS-1$
332 " public void bar() {\n" + //$NON-NLS-1$
333 " }\n" + //$NON-NLS-1$
334 "}" //$NON-NLS-1$
335 },
336 new java.util.HashMap(),
337 externalJar
338 );
339 // add new class to trigger an incremental build
340 env.getProject(projectPath).touch(null);
341
342 // incremental build should notice jar file has changed & do a full build
343 incrementalBuild();
344 expectingNoProblems();
345 }
346
testFieldDeleting()347 public void testFieldDeleting() throws JavaModelException {
348 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
349 env.addExternalJars(projectPath, Util.getJavaClassLibs());
350
351 // remove old package fragment root so that names don't collide
352 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
353
354 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
355 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
356
357 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
358 "package p1;\n"+ //$NON-NLS-1$
359 "public class A {\n"+ //$NON-NLS-1$
360 " public int i;\n"+ //$NON-NLS-1$
361 "}\n" //$NON-NLS-1$
362 );
363
364 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
365 "package p2;\n"+ //$NON-NLS-1$
366 "import p1.*;\n"+ //$NON-NLS-1$
367 "public class B extends A{\n"+ //$NON-NLS-1$
368 "}\n" //$NON-NLS-1$
369 );
370
371 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
372 "package p3;\n"+ //$NON-NLS-1$
373 "public class C extends p2.B{\n"+ //$NON-NLS-1$
374 " int j = i;\n"+ //$NON-NLS-1$
375 "}\n" //$NON-NLS-1$
376 );
377
378 IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$
379 "package p4;\n"+ //$NON-NLS-1$
380 "public class X {\n"+ //$NON-NLS-1$
381 " int foo(p3.C c) { return c.i; }\n"+ //$NON-NLS-1$
382 "}\n" //$NON-NLS-1$
383 );
384
385 fullBuild(projectPath);
386 expectingNoProblems();
387
388 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
389 "package p1;\n"+ //$NON-NLS-1$
390 "public class A {\n"+ //$NON-NLS-1$
391 "}\n" //$NON-NLS-1$
392 );
393
394 incrementalBuild(projectPath);
395 expectingOnlyProblemsFor(new IPath[] {cPath, xPath});
396 expectingSpecificProblemFor(cPath, new Problem("C", "i cannot be resolved to a variable", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
397 expectingSpecificProblemFor(xPath, new Problem("X", "i cannot be resolved or is not a field", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
398
399 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
400 "package p1;\n"+ //$NON-NLS-1$
401 "public class A {\n"+ //$NON-NLS-1$
402 " public int i;\n"+ //$NON-NLS-1$
403 "}\n" //$NON-NLS-1$
404 );
405
406 incrementalBuild(projectPath);
407 expectingNoProblems();
408 }
409
testFieldVisibility()410 public void testFieldVisibility() throws JavaModelException {
411 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
412 env.addExternalJars(projectPath, Util.getJavaClassLibs());
413
414 // remove old package fragment root so that names don't collide
415 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
416
417 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
418 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
419
420 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
421 "package p1;\n"+ //$NON-NLS-1$
422 "public class A {\n"+ //$NON-NLS-1$
423 " public int i;\n"+ //$NON-NLS-1$
424 "}\n" //$NON-NLS-1$
425 );
426
427 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
428 "package p2;\n"+ //$NON-NLS-1$
429 "import p1.*;\n"+ //$NON-NLS-1$
430 "public class B extends A{\n"+ //$NON-NLS-1$
431 "}\n" //$NON-NLS-1$
432 );
433
434 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
435 "package p3;\n"+ //$NON-NLS-1$
436 "public class C extends p2.B{\n"+ //$NON-NLS-1$
437 " int j = i;\n"+ //$NON-NLS-1$
438 "}\n" //$NON-NLS-1$
439 );
440
441 IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$
442 "package p4;\n"+ //$NON-NLS-1$
443 "public class X {\n"+ //$NON-NLS-1$
444 " int foo(p3.C c) { return c.i; }\n"+ //$NON-NLS-1$
445 "}\n" //$NON-NLS-1$
446 );
447
448 fullBuild(projectPath);
449 expectingNoProblems();
450
451 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
452 "package p1;\n"+ //$NON-NLS-1$
453 "public class A {\n"+ //$NON-NLS-1$
454 " int i;\n"+ //$NON-NLS-1$
455 "}\n" //$NON-NLS-1$
456 );
457
458 incrementalBuild(projectPath);
459 expectingOnlyProblemsFor(new IPath[] {cPath, xPath});
460 expectingSpecificProblemFor(cPath, new Problem("C", "The field A.i is not visible", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
461 expectingSpecificProblemFor(xPath, new Problem("X", "The field A.i is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
462
463 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
464 "package p1;\n"+ //$NON-NLS-1$
465 "public class A {\n"+ //$NON-NLS-1$
466 " protected int i;\n"+ //$NON-NLS-1$
467 "}\n" //$NON-NLS-1$
468 );
469
470 incrementalBuild(projectPath);
471 expectingOnlyProblemsFor(new IPath[] {xPath});
472 expectingSpecificProblemFor(xPath, new Problem("X", "The field A.i is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
473
474 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
475 "package p1;\n"+ //$NON-NLS-1$
476 "public class A {\n"+ //$NON-NLS-1$
477 " public int i;\n"+ //$NON-NLS-1$
478 "}\n" //$NON-NLS-1$
479 );
480
481 incrementalBuild(projectPath);
482 expectingNoProblems();
483 }
484
485 // 77272
testInterfaceDeleting()486 public void testInterfaceDeleting() throws JavaModelException {
487 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
488 env.addExternalJars(projectPath, Util.getJavaClassLibs());
489
490 // remove old package fragment root so that names don't collide
491 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
492
493 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
494 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
495
496 env.addClass(root, "p1", "Vehicle", //$NON-NLS-1$ //$NON-NLS-2$
497 "package p1;\n"+ //$NON-NLS-1$
498 "public interface Vehicle {}\n" //$NON-NLS-1$
499 );
500
501 env.addClass(root, "p1", "Car", //$NON-NLS-1$ //$NON-NLS-2$
502 "package p1;\n"+ //$NON-NLS-1$
503 "public interface Car extends Vehicle {}\n" //$NON-NLS-1$
504 );
505
506 env.addClass(root, "p1", "CarImpl", //$NON-NLS-1$ //$NON-NLS-2$
507 "package p1;\n"+ //$NON-NLS-1$
508 "public class CarImpl implements Car {}\n" //$NON-NLS-1$
509 );
510
511 IPath testPath = env.addClass(root, "p1", "Test", //$NON-NLS-1$ //$NON-NLS-2$
512 "package p1;\n"+ //$NON-NLS-1$
513 "public class Test { public Vehicle createVehicle() { return new CarImpl(); } }\n" //$NON-NLS-1$
514 );
515
516 fullBuild(projectPath);
517 expectingNoProblems();
518
519 env.addClass(root, "p1", "Car", //$NON-NLS-1$ //$NON-NLS-2$
520 "package p1;\n"+ //$NON-NLS-1$
521 "public interface Car {}\n" //$NON-NLS-1$
522 );
523
524 incrementalBuild(projectPath);
525 expectingOnlyProblemsFor(testPath);
526 expectingSpecificProblemFor(testPath, new Problem("Test", "Type mismatch: cannot convert from CarImpl to Vehicle", testPath, 72, 85, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
527
528 env.addClass(root, "p1", "Car", //$NON-NLS-1$ //$NON-NLS-2$
529 "package p1;\n"+ //$NON-NLS-1$
530 "public interface Car extends Vehicle {}\n" //$NON-NLS-1$
531 );
532
533 incrementalBuild(projectPath);
534 expectingNoProblems();
535 }
536
testMemberTypeDeleting()537 public void testMemberTypeDeleting() throws JavaModelException {
538 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
539 env.addExternalJars(projectPath, Util.getJavaClassLibs());
540
541 // remove old package fragment root so that names don't collide
542 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
543
544 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
545 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
546
547 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
548 "package p1;\n"+ //$NON-NLS-1$
549 "public class A {\n"+ //$NON-NLS-1$
550 " public class M { public int i; };\n"+ //$NON-NLS-1$
551 "}\n" //$NON-NLS-1$
552 );
553
554 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
555 "package p2;\n"+ //$NON-NLS-1$
556 "import p1.*;\n"+ //$NON-NLS-1$
557 "public class B extends A{\n"+ //$NON-NLS-1$
558 "}\n" //$NON-NLS-1$
559 );
560
561 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
562 "package p3;\n"+ //$NON-NLS-1$
563 "public class C extends p2.B{\n"+ //$NON-NLS-1$
564 " M m;\n"+ //$NON-NLS-1$
565 "}\n" //$NON-NLS-1$
566 );
567
568 IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$
569 "package p4;\n"+ //$NON-NLS-1$
570 "public class X {\n"+ //$NON-NLS-1$
571 " int foo(p3.C.M m) { return m.i; }\n"+ //$NON-NLS-1$
572 "}\n" //$NON-NLS-1$
573 );
574
575 fullBuild(projectPath);
576 expectingNoProblems();
577
578 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
579 "package p1;\n"+ //$NON-NLS-1$
580 "public class A {\n"+ //$NON-NLS-1$
581 "}\n" //$NON-NLS-1$
582 );
583
584 incrementalBuild(projectPath);
585 expectingOnlyProblemsFor(new IPath[] {cPath, xPath});
586 expectingSpecificProblemFor(cPath, new Problem("C", "M cannot be resolved to a type", cPath, 42, 43, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
587 expectingSpecificProblemFor(xPath, new Problem("X", "p3.C.M cannot be resolved to a type", xPath, 38, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
588
589 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
590 "package p1;\n"+ //$NON-NLS-1$
591 "public class A {\n"+ //$NON-NLS-1$
592 " public class M { public int i; };\n"+ //$NON-NLS-1$
593 "}\n" //$NON-NLS-1$
594 );
595
596 incrementalBuild(projectPath);
597 expectingNoProblems();
598 }
599
testMemberTypeVisibility()600 public void testMemberTypeVisibility() throws JavaModelException {
601 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
602 env.addExternalJars(projectPath, Util.getJavaClassLibs());
603
604 // remove old package fragment root so that names don't collide
605 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
606
607 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
608 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
609
610 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
611 "package p1;\n"+ //$NON-NLS-1$
612 "public class A {\n"+ //$NON-NLS-1$
613 " public class M { public int i; };\n"+ //$NON-NLS-1$
614 "}\n" //$NON-NLS-1$
615 );
616
617 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
618 "package p2;\n"+ //$NON-NLS-1$
619 "import p1.*;\n"+ //$NON-NLS-1$
620 "public class B extends A{\n"+ //$NON-NLS-1$
621 "}\n" //$NON-NLS-1$
622 );
623
624 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
625 "package p3;\n"+ //$NON-NLS-1$
626 "public class C extends p2.B{\n"+ //$NON-NLS-1$
627 " M m;\n"+ //$NON-NLS-1$
628 "}\n" //$NON-NLS-1$
629 );
630
631 IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$
632 "package p4;\n"+ //$NON-NLS-1$
633 "public class X {\n"+ //$NON-NLS-1$
634 " int foo(p3.C.M m) { return m.i; }\n"+ //$NON-NLS-1$
635 "}\n" //$NON-NLS-1$
636 );
637
638 fullBuild(projectPath);
639 expectingNoProblems();
640
641 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
642 "package p1;\n"+ //$NON-NLS-1$
643 "public class A {\n"+ //$NON-NLS-1$
644 " class M { public int i; };\n"+ //$NON-NLS-1$
645 "}\n" //$NON-NLS-1$
646 );
647
648 incrementalBuild(projectPath);
649 expectingOnlyProblemsFor(new IPath[] {cPath, xPath});
650 expectingSpecificProblemFor(cPath, new Problem("C", "The type M is not visible", cPath, 42, 43, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
651 expectingSpecificProblemFor(xPath, new Problem("X", "The type p3.C.M is not visible", xPath, 38, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
652
653 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
654 "package p1;\n"+ //$NON-NLS-1$
655 "public class A {\n"+ //$NON-NLS-1$
656 " protected class M { public int i; };\n"+ //$NON-NLS-1$
657 "}\n" //$NON-NLS-1$
658 );
659
660 incrementalBuild(projectPath);
661 expectingOnlyProblemsFor(new IPath[] {xPath});
662 expectingSpecificProblemFor(xPath, new Problem("X", "The type p3.C.M is not visible", xPath, 38, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
663
664 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
665 "package p1;\n"+ //$NON-NLS-1$
666 "public class A {\n"+ //$NON-NLS-1$
667 " public class M { public int i; };\n"+ //$NON-NLS-1$
668 "}\n" //$NON-NLS-1$
669 );
670
671 incrementalBuild(projectPath);
672 expectingNoProblems();
673 }
674
testMethodDeleting()675 public void testMethodDeleting() throws JavaModelException {
676 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
677 env.addExternalJars(projectPath, Util.getJavaClassLibs());
678
679 // remove old package fragment root so that names don't collide
680 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
681
682 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
683 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
684
685 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
686 "package p1;\n"+ //$NON-NLS-1$
687 "public class A {\n"+ //$NON-NLS-1$
688 " public int i(A a) {return 1;};\n"+ //$NON-NLS-1$
689 "}\n" //$NON-NLS-1$
690 );
691
692 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
693 "package p2;\n"+ //$NON-NLS-1$
694 "import p1.*;\n"+ //$NON-NLS-1$
695 "public class B extends A{\n"+ //$NON-NLS-1$
696 "}\n" //$NON-NLS-1$
697 );
698
699 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
700 "package p3;\n"+ //$NON-NLS-1$
701 "public class C extends p2.B{\n"+ //$NON-NLS-1$
702 " int j = i(this);\n"+ //$NON-NLS-1$
703 "}\n" //$NON-NLS-1$
704 );
705
706 IPath dPath = env.addClass(root, "p3", "D", //$NON-NLS-1$ //$NON-NLS-2$
707 "package p3;\n"+ //$NON-NLS-1$
708 "public class D extends p2.B{\n"+ //$NON-NLS-1$
709 " public class M {\n"+ //$NON-NLS-1$
710 " int j = i(new D());\n"+ //$NON-NLS-1$
711 " }\n"+ //$NON-NLS-1$
712 "}\n" //$NON-NLS-1$
713 );
714
715 IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$
716 "package p4;\n"+ //$NON-NLS-1$
717 "public class X {\n"+ //$NON-NLS-1$
718 " int foo(p3.C c) { return c.i(c); }\n"+ //$NON-NLS-1$
719 "}\n" //$NON-NLS-1$
720 );
721
722 fullBuild(projectPath);
723 expectingNoProblems();
724
725 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
726 "package p1;\n"+ //$NON-NLS-1$
727 "public class A {\n"+ //$NON-NLS-1$
728 "}\n" //$NON-NLS-1$
729 );
730
731 incrementalBuild(projectPath);
732 expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath});
733 expectingSpecificProblemFor(cPath, new Problem("C", "The method i(C) is undefined for the type C", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
734 expectingSpecificProblemFor(dPath, new Problem("D", "The method i(D) is undefined for the type D.M", dPath, 69, 70, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
735 expectingSpecificProblemFor(xPath, new Problem("X", "The method i(C) is undefined for the type C", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
736
737 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
738 "package p2;\n"+ //$NON-NLS-1$
739 "import p1.*;\n"+ //$NON-NLS-1$
740 "public class B extends A{\n"+ //$NON-NLS-1$
741 " public int i(B b) {return 1;};\n"+ //$NON-NLS-1$
742 "}\n" //$NON-NLS-1$
743 );
744
745 incrementalBuild(projectPath);
746 expectingNoProblems();
747
748 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
749 "package p1;\n"+ //$NON-NLS-1$
750 "public class A {\n"+ //$NON-NLS-1$
751 " public int i(A a) {return 1;};\n"+ //$NON-NLS-1$
752 "}\n" //$NON-NLS-1$
753 );
754
755 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
756 "package p2;\n"+ //$NON-NLS-1$
757 "import p1.*;\n"+ //$NON-NLS-1$
758 "public class B extends A{\n"+ //$NON-NLS-1$
759 "}\n" //$NON-NLS-1$
760 );
761
762 incrementalBuild(projectPath);
763 expectingNoProblems();
764 }
765
testMethodVisibility()766 public void testMethodVisibility() throws JavaModelException {
767 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
768 env.addExternalJars(projectPath, Util.getJavaClassLibs());
769
770 // remove old package fragment root so that names don't collide
771 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
772
773 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
774 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
775
776 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
777 "package p1;\n"+ //$NON-NLS-1$
778 "public class A {\n"+ //$NON-NLS-1$
779 " public int i(A a) {return 1;};\n"+ //$NON-NLS-1$
780 "}\n" //$NON-NLS-1$
781 );
782
783 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
784 "package p2;\n"+ //$NON-NLS-1$
785 "import p1.*;\n"+ //$NON-NLS-1$
786 "public class B extends A{\n"+ //$NON-NLS-1$
787 "}\n" //$NON-NLS-1$
788 );
789
790 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
791 "package p3;\n"+ //$NON-NLS-1$
792 "public class C extends p2.B{\n"+ //$NON-NLS-1$
793 " int j = i(this);\n"+ //$NON-NLS-1$
794 "}\n" //$NON-NLS-1$
795 );
796
797 IPath dPath = env.addClass(root, "p3", "D", //$NON-NLS-1$ //$NON-NLS-2$
798 "package p3;\n"+ //$NON-NLS-1$
799 "public class D extends p2.B{\n"+ //$NON-NLS-1$
800 " public class M {\n"+ //$NON-NLS-1$
801 " int j = i(new D());\n"+ //$NON-NLS-1$
802 " }\n"+ //$NON-NLS-1$
803 "}\n" //$NON-NLS-1$
804 );
805
806 IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$
807 "package p4;\n"+ //$NON-NLS-1$
808 "public class X {\n"+ //$NON-NLS-1$
809 " int foo(p3.C c) { return c.i(c); }\n"+ //$NON-NLS-1$
810 "}\n" //$NON-NLS-1$
811 );
812
813 fullBuild(projectPath);
814 expectingNoProblems();
815
816 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
817 "package p1;\n"+ //$NON-NLS-1$
818 "public class A {\n"+ //$NON-NLS-1$
819 " int i(A a) {return 1;};\n"+ //$NON-NLS-1$
820 "}\n" //$NON-NLS-1$
821 );
822
823 incrementalBuild(projectPath);
824 expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath});
825 expectingSpecificProblemFor(cPath, new Problem("C", "The method i(A) from the type A is not visible", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
826 expectingSpecificProblemFor(dPath, new Problem("D", "The method i(A) from the type A is not visible", dPath, 69, 70, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
827 expectingSpecificProblemFor(xPath, new Problem("X", "The method i(A) from the type A is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
828
829 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
830 "package p2;\n"+ //$NON-NLS-1$
831 "import p1.*;\n"+ //$NON-NLS-1$
832 "public class B extends A{\n"+ //$NON-NLS-1$
833 " protected int i(B b) {return 1;};\n"+ //$NON-NLS-1$
834 "}\n" //$NON-NLS-1$
835 );
836
837 incrementalBuild(projectPath);
838 expectingOnlyProblemsFor(new IPath[] {xPath});
839 expectingSpecificProblemFor(xPath, new Problem("X", "The method i(B) from the type B is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
840
841 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
842 "package p1;\n"+ //$NON-NLS-1$
843 "public class A {\n"+ //$NON-NLS-1$
844 " public int i(A a) {return 1;};\n"+ //$NON-NLS-1$
845 "}\n" //$NON-NLS-1$
846 );
847
848 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
849 "package p2;\n"+ //$NON-NLS-1$
850 "import p1.*;\n"+ //$NON-NLS-1$
851 "public class B extends A{\n"+ //$NON-NLS-1$
852 "}\n" //$NON-NLS-1$
853 );
854
855 incrementalBuild(projectPath);
856 expectingNoProblems();
857 }
858
testMissingClassFile()859 public void testMissingClassFile() throws JavaModelException {
860 IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$
861 env.addExternalJars(project1Path, Util.getJavaClassLibs());
862
863 // remove old package fragment root so that names don't collide
864 env.removePackageFragmentRoot(project1Path,""); //$NON-NLS-1$
865
866 IPath root1 = env.addPackageFragmentRoot(project1Path, "src"); //$NON-NLS-1$
867 env.setOutputFolder(project1Path, "bin"); //$NON-NLS-1$
868
869 env.addClass(root1, "p1", "MissingClass", //$NON-NLS-1$ //$NON-NLS-2$
870 "package p1;\n"+ //$NON-NLS-1$
871 "public class MissingClass {}" //$NON-NLS-1$
872 );
873
874 IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$
875 env.addExternalJars(project2Path, Util.getJavaClassLibs());
876 env.addRequiredProject(project2Path, project1Path);
877
878 // remove old package fragment root so that names don't collide
879 env.removePackageFragmentRoot(project2Path,""); //$NON-NLS-1$
880
881 IPath root2 = env.addPackageFragmentRoot(project2Path, "src"); //$NON-NLS-1$
882 env.setOutputFolder(project2Path, "bin"); //$NON-NLS-1$
883
884 env.addClass(root2, "p2", "A", //$NON-NLS-1$ //$NON-NLS-2$
885 "package p2;\n"+ //$NON-NLS-1$
886 "import p1.MissingClass;\n" +
887 "public class A {\n"+ //$NON-NLS-1$
888 " public void foo(MissingClass data) {}\n"+ //$NON-NLS-1$
889 " public void foo(String data) {}\n"+ //$NON-NLS-1$
890 "}\n" //$NON-NLS-1$
891 );
892
893 IPath project3Path = env.addProject("Project3"); //$NON-NLS-1$
894 env.addExternalJars(project3Path, Util.getJavaClassLibs());
895 env.addRequiredProject(project3Path, project2Path);
896 // missing required Project1 so MissingClass cannot be found
897
898 // remove old package fragment root so that names don't collide
899 env.removePackageFragmentRoot(project3Path,""); //$NON-NLS-1$
900
901 IPath root3 = env.addPackageFragmentRoot(project3Path, "src"); //$NON-NLS-1$
902 env.setOutputFolder(project3Path, "bin"); //$NON-NLS-1$
903
904 IPath bPath = env.addClass(root3, "p3", "B", //$NON-NLS-1$ //$NON-NLS-2$
905 "package p3;\n"+ //$NON-NLS-1$
906 "import p2.A;\n" +
907 "public class B {\n"+ //$NON-NLS-1$
908 " public static void main(String[] args) {\n" + //$NON-NLS-1$
909 " new A().foo(new String());\n" + //$NON-NLS-1$
910 " }\n" + //$NON-NLS-1$
911 "}\n" //$NON-NLS-1$
912 );
913
914 fullBuild();
915 expectingOnlyProblemsFor(new IPath[] {project3Path, bPath});
916 expectingSpecificProblemFor(project3Path, new Problem("Project3", "The project was not built since its build path is incomplete. Cannot find the class file for p1.MissingClass. Fix the build path then try building this project", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
917 expectingSpecificProblemFor(bPath, new Problem("B", "The type p1.MissingClass cannot be resolved. It is indirectly referenced from required .class files", bPath, 86, 111, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
918
919 env.addClass(root2, "p2", "A", //$NON-NLS-1$ //$NON-NLS-2$
920 "package p2;\n"+ //$NON-NLS-1$
921 "public class A {\n"+ //$NON-NLS-1$
922 " public void foo(String data) {}\n"+ //$NON-NLS-1$
923 "}\n" //$NON-NLS-1$
924 );
925
926 incrementalBuild();
927 expectingNoProblems();
928 }
929
930 // 181269
testSecondaryTypeDeleting()931 public void testSecondaryTypeDeleting() throws JavaModelException {
932 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
933 env.addExternalJars(projectPath, Util.getJavaClassLibs());
934
935 // remove old package fragment root so that names don't collide
936 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
937
938 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
939 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
940
941 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
942 "package p1;\n"+ //$NON-NLS-1$
943 "public class A extends Secondary {}\n"+ //$NON-NLS-1$
944 "class Secondary {}\n" //$NON-NLS-1$
945 );
946
947 fullBuild(projectPath);
948 expectingNoProblems();
949
950 IPath typePath = env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
951 "package p1;\n"+ //$NON-NLS-1$
952 "public class A extends Secondary {}\n" //$NON-NLS-1$
953 );
954
955 incrementalBuild(projectPath);
956 expectingSpecificProblemFor(typePath, new Problem("A", "Secondary cannot be resolved to a type", typePath, 35, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
957 }
958
959 // 72468
testTypeDeleting()960 public void testTypeDeleting() throws JavaModelException {
961 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
962 env.addExternalJars(projectPath, Util.getJavaClassLibs());
963
964 // remove old package fragment root so that names don't collide
965 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
966
967 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
968 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
969
970 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
971 "package p1;\n"+ //$NON-NLS-1$
972 "public class A {}\n" //$NON-NLS-1$
973 );
974
975 IPath bPath = env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
976 "package p2;\n"+ //$NON-NLS-1$
977 "public class B extends p1.A{}\n" //$NON-NLS-1$
978 );
979
980 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
981 "package p3;\n"+ //$NON-NLS-1$
982 "public class C extends p2.B{}\n" //$NON-NLS-1$
983 );
984
985 fullBuild(projectPath);
986 expectingNoProblems();
987
988 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
989 "package p1;\n"+ //$NON-NLS-1$
990 "class Deleted {}\n" //$NON-NLS-1$
991 );
992
993 incrementalBuild(projectPath);
994 expectingOnlyProblemsFor(new IPath[] {bPath, cPath});
995 expectingSpecificProblemFor(bPath, new Problem("B", "p1.A cannot be resolved to a type", bPath, 35, 39, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
996 expectingSpecificProblemFor(cPath, new Problem("C", "The hierarchy of the type C is inconsistent", cPath, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
997
998 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
999 "package p2;\n"+ //$NON-NLS-1$
1000 "public class B {}\n" //$NON-NLS-1$
1001 );
1002
1003 incrementalBuild(projectPath);
1004 expectingNoProblems();
1005 }
1006
1007 // 72468
testTypeVisibility()1008 public void testTypeVisibility() throws JavaModelException {
1009 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
1010 env.addExternalJars(projectPath, Util.getJavaClassLibs());
1011
1012 // remove old package fragment root so that names don't collide
1013 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
1014
1015 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
1016 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
1017
1018 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
1019 "package p1;\n"+ //$NON-NLS-1$
1020 "public class A {}\n" //$NON-NLS-1$
1021 );
1022
1023 IPath bPath = env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
1024 "package p2;\n"+ //$NON-NLS-1$
1025 "public class B extends p1.A{}\n" //$NON-NLS-1$
1026 );
1027
1028 IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$
1029 "package p3;\n"+ //$NON-NLS-1$
1030 "public class C extends p2.B{}\n" //$NON-NLS-1$
1031 );
1032
1033 fullBuild(projectPath);
1034 expectingNoProblems();
1035
1036 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
1037 "package p1;\n"+ //$NON-NLS-1$
1038 "class A {}\n" //$NON-NLS-1$
1039 );
1040
1041 incrementalBuild(projectPath);
1042 expectingOnlyProblemsFor(new IPath[] {bPath, cPath});
1043 expectingSpecificProblemFor(bPath, new Problem("B", "The type p1.A is not visible", bPath, 35, 39, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1044 expectingSpecificProblemFor(cPath, new Problem("C", "The hierarchy of the type C is inconsistent", cPath, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1045
1046 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
1047 "package p2;\n"+ //$NON-NLS-1$
1048 "public class B {}\n" //$NON-NLS-1$
1049 );
1050
1051 incrementalBuild(projectPath);
1052 expectingNoProblems();
1053
1054 env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
1055 "package p2;\n"+ //$NON-NLS-1$
1056 "public class B extends p1.A{}\n" //$NON-NLS-1$
1057 );
1058
1059 incrementalBuild(projectPath);
1060 expectingOnlyProblemsFor(new IPath[] {bPath, cPath});
1061 expectingSpecificProblemFor(bPath, new Problem("B", "The type p1.A is not visible", bPath, 35, 39, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1062 expectingSpecificProblemFor(cPath, new Problem("C", "The hierarchy of the type C is inconsistent", cPath, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1063
1064 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
1065 "package p1;\n"+ //$NON-NLS-1$
1066 "public class A {}\n" //$NON-NLS-1$
1067 );
1068
1069 incrementalBuild(projectPath);
1070 expectingNoProblems();
1071 }
1072
1073 // 79163
testTypeVisibility2()1074 public void testTypeVisibility2() throws JavaModelException {
1075 IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
1076 env.addExternalJars(projectPath, Util.getJavaClassLibs());
1077
1078 // remove old package fragment root so that names don't collide
1079 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
1080
1081 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
1082 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
1083
1084 IPath aPath = env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
1085 "package p1;\n"+ //$NON-NLS-1$
1086 "public class A {\n" + //$NON-NLS-1$
1087 " void foo() { p2.FooFactory.createFoo().foo(); }\n" + //$NON-NLS-1$
1088 " void foos() { p2.FooFactory.createFoos().clone(); }\n" + //$NON-NLS-1$
1089 "}\n" //$NON-NLS-1$
1090 );
1091
1092 // Foo & Foos are not public to get visibility problems
1093 env.addClass(root, "p2", "Foo", //$NON-NLS-1$ //$NON-NLS-2$
1094 "package p2;\n"+ //$NON-NLS-1$
1095 "class Foo { public void foo() {} }\n" //$NON-NLS-1$
1096 );
1097 env.addClass(root, "p2", "Foos", //$NON-NLS-1$ //$NON-NLS-2$
1098 "package p2;\n"+ //$NON-NLS-1$
1099 "class Foos {}\n" //$NON-NLS-1$
1100 );
1101
1102 env.addClass(root, "p2", "FooFactory", //$NON-NLS-1$ //$NON-NLS-2$
1103 "package p2;\n"+ //$NON-NLS-1$
1104 "public class FooFactory {\n" + //$NON-NLS-1$
1105 " public static Foo createFoo() { return null; }\n" + //$NON-NLS-1$
1106 " public static Foos[] createFoos() { return null; }\n" + //$NON-NLS-1$
1107 "}\n" //$NON-NLS-1$
1108 );
1109
1110 fullBuild(projectPath);
1111 expectingOnlyProblemsFor(new IPath[] {aPath});
1112 expectingSpecificProblemFor(aPath, new Problem("A", "The type Foo is not visible", aPath, 43, 68, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1113 expectingSpecificProblemFor(aPath, new Problem("A", "The type Foos is not visible", aPath, 93, 119, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1114
1115 env.addClass(root, "p2", "Foo", //$NON-NLS-1$ //$NON-NLS-2$
1116 "package p2;\n"+ //$NON-NLS-1$
1117 "public class Foo { public void foo() {} }\n" //$NON-NLS-1$
1118 );
1119
1120 incrementalBuild(projectPath);
1121 expectingOnlyProblemsFor(new IPath[] {aPath});
1122 expectingSpecificProblemFor(aPath, new Problem("A", "The type Foos is not visible", aPath, 93, 119, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1123
1124 env.addClass(root, "p2", "Foos", //$NON-NLS-1$ //$NON-NLS-2$
1125 "package p2;\n"+ //$NON-NLS-1$
1126 "public class Foos { }\n" //$NON-NLS-1$
1127 );
1128
1129 incrementalBuild(projectPath);
1130 expectingNoProblems();
1131
1132 env.addClass(root, "p2", "Foo", //$NON-NLS-1$ //$NON-NLS-2$
1133 "package p2;\n"+ //$NON-NLS-1$
1134 "class Foo { public void foo() {} }\n" //$NON-NLS-1$
1135 );
1136 env.addClass(root, "p2", "Foos", //$NON-NLS-1$ //$NON-NLS-2$
1137 "package p2;\n"+ //$NON-NLS-1$
1138 "class Foos {}\n" //$NON-NLS-1$
1139 );
1140
1141 incrementalBuild(projectPath);
1142 expectingOnlyProblemsFor(new IPath[] {aPath});
1143 expectingSpecificProblemFor(aPath, new Problem("A", "The type Foo is not visible", aPath, 43, 68, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1144 expectingSpecificProblemFor(aPath, new Problem("A", "The type Foos is not visible", aPath, 93, 119, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1145 }
1146
testTypeVariable()1147 public void testTypeVariable() throws JavaModelException {
1148 if ((AbstractCompilerTest.getPossibleComplianceLevels() & AbstractCompilerTest.F_1_5) == 0) return;
1149
1150 IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$
1151 env.addExternalJars(projectPath, Util.getJavaClassLibs());
1152
1153 // remove old package fragment root so that names don't collide
1154 env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$
1155
1156 IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
1157 env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
1158
1159 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
1160 "package p1;\n"+ //$NON-NLS-1$
1161 "public class A<T> {}\n" //$NON-NLS-1$
1162 );
1163
1164 IPath bPath = env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$
1165 "package p2;\n"+ //$NON-NLS-1$
1166 "public class B<T> extends p1.A<T> {}\n" //$NON-NLS-1$
1167 );
1168
1169 fullBuild(projectPath);
1170 expectingNoProblems();
1171
1172 IPath aPath = env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
1173 "package p1;\n"+ //$NON-NLS-1$
1174 "public class A {}\n" //$NON-NLS-1$
1175 );
1176
1177 incrementalBuild(projectPath);
1178 expectingOnlyProblemsFor(new IPath[] {bPath});
1179 expectingSpecificProblemFor(bPath, new Problem("B", "The type A is not generic; it cannot be parameterized with arguments <T>", bPath, 38, 42, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1180
1181 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
1182 "package p1;\n"+ //$NON-NLS-1$
1183 "public class A<T extends Comparable> {}\n" //$NON-NLS-1$
1184 );
1185
1186 incrementalBuild(projectPath);
1187 expectingOnlyProblemsFor(new IPath[] {aPath, bPath});
1188 expectingSpecificProblemFor(bPath, new Problem("B", "Bound mismatch: The type T is not a valid substitute for the bounded parameter <T extends Comparable> of the type A<T>", bPath, 43, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1189 expectingSpecificProblemFor(aPath, new Problem("A", "Comparable is a raw type. References to generic type Comparable<T> should be parameterized", aPath, 37, 47, CategorizedProblem.CAT_UNCHECKED_RAW, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$
1190
1191 env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
1192 "package p1;\n"+ //$NON-NLS-1$
1193 "public class A<T> {}\n" //$NON-NLS-1$
1194 );
1195
1196 incrementalBuild(projectPath);
1197 expectingNoProblems();
1198 }
1199
1200 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709
1201 // Full build and incremental build behave differently for deprecation
1202 // warnings, which is unexpected. Guard test for DeprecatedTest#test015 (the
1203 // builder is not the cause of the bug, but we want to ensure that the end to
1204 // end behavior is OK).
test0100()1205 public void test0100() throws JavaModelException {
1206 IPath projectPath = env.addProject("P");
1207 env.addExternalJars(projectPath, Util.getJavaClassLibs());
1208 IPath rootPath = env.getPackageFragmentRootPath(projectPath, "");
1209 env.addClass(rootPath, "a", "N1",
1210 "package a;\n" +
1211 "public class N1 {\n" +
1212 " public void foo() {}\n" +
1213 " /** @deprecated */\n" +
1214 " public class N2 {" +
1215 " public void foo() {}" +
1216 " public class N3 {" +
1217 " public void foo() {}" +
1218 " }" +
1219 " }" +
1220 " void bar() {}\n" +
1221 "}\n"
1222 );
1223 String M1Contents =
1224 "package p;\n" +
1225 "public class M1 {\n" +
1226 " public void foo() {}\n" +
1227 " /** @deprecated */\n" +
1228 " public class M2 {" +
1229 " public void foo() {}" +
1230 " public class M3 {" +
1231 " public void foo() {}" +
1232 " }" +
1233 " }" +
1234 " void bar() {\n" +
1235 " a.N1.N2.N3 m = null;\n" +
1236 " m.foo();\n" +
1237 " }\n" +
1238 "}\n";
1239 IPath M1Path = env.addClass(rootPath, "p", "M1", M1Contents);
1240 fullBuild(projectPath);
1241 expectingOnlyProblemsFor(new IPath[] {M1Path});
1242 expectingSpecificProblemFor(M1Path,
1243 new Problem("", "The type N1.N2.N3 is deprecated",
1244 M1Path, 198, 200, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING));
1245 expectingSpecificProblemFor(M1Path,
1246 new Problem("", "The method foo() from the type N1.N2.N3 is deprecated",
1247 M1Path, 217, 222, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING));
1248 M1Path = env.addClass(rootPath, "p", "M1", M1Contents);
1249 incrementalBuild(projectPath);
1250 expectingOnlyProblemsFor(new IPath[] {M1Path});
1251 expectingSpecificProblemFor(M1Path,
1252 new Problem("", "The type N1.N2.N3 is deprecated",
1253 M1Path, 198, 200, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING));
1254 expectingSpecificProblemFor(M1Path,
1255 new Problem("", "The method foo() from the type N1.N2.N3 is deprecated",
1256 M1Path, 217, 222, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING));
1257 }
1258 }
1259