View | Details | Raw Unified | Return to bug 181981
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+46 lines)
Lines 9450-9453 Link Here
9450
	}
9450
	}
9451
}
9451
}
9452
9452
9453
/**
9454
 * @bug 181981: [model] Linked Source Folders with Parallel package structure do not work with occurrences
9455
 * @test Ensure that source folder nesting doesn't cause non existing elements to be returned
9456
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=181981"
9457
 */
9458
public void testBug181981() throws CoreException {
9459
	try {
9460
		IJavaProject project = createJavaProject("P", new String[] { "", "src"}, new String[] {"JCL_LIB"}, null, null, "bin", null, null, new String[][] {new String[] {"src/"}, new String[0]}, "1.4");
9461
		createFolder("/P/p1");
9462
		createFile(
9463
			"/P/p1/X.java",
9464
			"package p1;\n" +
9465
			"public class X {\n" +
9466
			"  public void foo() {}\n" +
9467
			"}"
9468
		);
9469
		createFile(
9470
			"/P/p1/Y.java",
9471
			"package p1;\n" +
9472
			"public class Y {\n" +
9473
			"  public void bar(X x) {\n" +
9474
			"    x.foo();\n" +
9475
			"  }\n" +
9476
			"}"
9477
		);
9478
		createFolder("/P/src/p2");
9479
		createFile(
9480
			"/P/src/p2/Z.java",
9481
			"package p2;\n" +
9482
			"public class Z {\n" +
9483
			"  public void bar(p1.X x) {\n" +
9484
			"    x.foo();\n" +
9485
			"  }\n" +
9486
			"}"
9487
		);
9488
		IMethod method = getCompilationUnit("/P/p1/X.java").getType("X").getMethod("foo", new String[0]);
9489
		search(method, REFERENCES, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaProject[] {project}), this.resultCollector);
9490
		assertSearchResults(
9491
			"p1/Y.java void p1.Y.bar(X) [foo()] EXACT_MATCH\n" + 
9492
			"src/p2/Z.java void p2.Z.bar(p1.X) [foo()] EXACT_MATCH"
9493
		);
9494
	}
9495
	finally {
9496
		deleteProject("P");
9497
	}
9498
}
9453
}
9499
}
(-)model/org/eclipse/jdt/internal/core/util/HandleFactory.java (-13 / +14 lines)
Lines 56-62 Link Here
56
	 * Cache package fragment root information to optimize speed performance.
56
	 * Cache package fragment root information to optimize speed performance.
57
	 */
57
	 */
58
	private String lastPkgFragmentRootPath;
58
	private String lastPkgFragmentRootPath;
59
	private IPackageFragmentRoot lastPkgFragmentRoot;
59
	private PackageFragmentRoot lastPkgFragmentRoot;
60
60
61
	/**
61
	/**
62
	 * Cache package handles to optimize memory.
62
	 * Cache package handles to optimize memory.
Lines 90-96 Link Here
90
					|| (rootPathLength = this.lastPkgFragmentRootPath.length()) != resourcePath.length()
90
					|| (rootPathLength = this.lastPkgFragmentRootPath.length()) != resourcePath.length()
91
					|| !resourcePath.regionMatches(0, this.lastPkgFragmentRootPath, 0, rootPathLength)) {
91
					|| !resourcePath.regionMatches(0, this.lastPkgFragmentRootPath, 0, rootPathLength)) {
92
				String jarPath= resourcePath.substring(0, separatorIndex);
92
				String jarPath= resourcePath.substring(0, separatorIndex);
93
				IPackageFragmentRoot root= this.getJarPkgFragmentRoot(jarPath, scope);
93
				PackageFragmentRoot root= getJarPkgFragmentRoot(jarPath, scope);
94
				if (root == null)
94
				if (root == null)
95
					return null; // match is outside classpath
95
					return null; // match is outside classpath
96
				this.lastPkgFragmentRootPath= jarPath;
96
				this.lastPkgFragmentRootPath= jarPath;
Lines 110-116 Link Here
110
			}
110
			}
111
			IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
111
			IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
112
			if (pkgFragment == null) {
112
			if (pkgFragment == null) {
113
				pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
113
				pkgFragment= this.lastPkgFragmentRoot.getPackageFragment(pkgName);
114
				this.packageHandles.put(pkgName, pkgFragment);
114
				this.packageHandles.put(pkgName, pkgFragment);
115
			}
115
			}
116
			IClassFile classFile= pkgFragment.getClassFile(simpleNames[length]);
116
			IClassFile classFile= pkgFragment.getClassFile(simpleNames[length]);
Lines 121-129 Link Here
121
			int rootPathLength = -1;
121
			int rootPathLength = -1;
122
			if (this.lastPkgFragmentRootPath == null 
122
			if (this.lastPkgFragmentRootPath == null 
123
				|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
123
				|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
124
					&& !org.eclipse.jdt.internal.compiler.util.Util.isExcluded(resourcePath.toCharArray(), this.lastPkgFragmentRoot.fullInclusionPatternChars(), this.lastPkgFragmentRoot.fullExclusionPatternChars(), false)
124
					&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
125
					&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
125
					&& resourcePath.charAt(rootPathLength) == '/')) {
126
					&& resourcePath.charAt(rootPathLength) == '/')) {
126
				IPackageFragmentRoot root= this.getPkgFragmentRoot(resourcePath);
127
				PackageFragmentRoot root= getPkgFragmentRoot(resourcePath);
127
				if (root == null)
128
				if (root == null)
128
					return null; // match is outside classpath
129
					return null; // match is outside classpath
129
				this.lastPkgFragmentRoot = root;
130
				this.lastPkgFragmentRoot = root;
Lines 143-149 Link Here
143
			}
144
			}
144
			IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
145
			IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
145
			if (pkgFragment == null) {
146
			if (pkgFragment == null) {
146
				pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
147
				pkgFragment= this.lastPkgFragmentRoot.getPackageFragment(pkgName);
147
				this.packageHandles.put(pkgName, pkgFragment);
148
				this.packageHandles.put(pkgName, pkgFragment);
148
			}
149
			}
149
			String simpleName= simpleNames[length];
150
			String simpleName= simpleNames[length];
Lines 247-253 Link Here
247
	 * See createOpenable(...) for the format of the jar path string.
248
	 * See createOpenable(...) for the format of the jar path string.
248
	 * If not null, uses the given scope as a hint for getting Java project handles.
249
	 * If not null, uses the given scope as a hint for getting Java project handles.
249
	 */
250
	 */
250
	private IPackageFragmentRoot getJarPkgFragmentRoot(String jarPathString, IJavaSearchScope scope) {
251
	private PackageFragmentRoot getJarPkgFragmentRoot(String jarPathString, IJavaSearchScope scope) {
251
252
252
		IPath jarPath= new Path(jarPathString);
253
		IPath jarPath= new Path(jarPathString);
253
		
254
		
Lines 261-267 Link Here
261
			try {
262
			try {
262
				IClasspathEntry entry = javaProject.getClasspathEntryFor(jarPath);
263
				IClasspathEntry entry = javaProject.getClasspathEntryFor(jarPath);
263
				if (entry != null) {
264
				if (entry != null) {
264
					return javaProject.getPackageFragmentRoot(jarFile);
265
					return (PackageFragmentRoot) javaProject.getPackageFragmentRoot(jarFile);
265
				}
266
				}
266
			} catch (JavaModelException e) {
267
			} catch (JavaModelException e) {
267
				// ignore and try to find another project
268
				// ignore and try to find another project
Lines 284-290 Link Here
284
			if (index < length) {
285
			if (index < length) {
285
				System.arraycopy(projects, 0, projects = new IJavaProject[index], 0, index);
286
				System.arraycopy(projects, 0, projects = new IJavaProject[index], 0, index);
286
			}
287
			}
287
			IPackageFragmentRoot root = getJarPkgFragmentRoot(jarPath, target, projects);
288
			PackageFragmentRoot root = getJarPkgFragmentRoot(jarPath, target, projects);
288
			if (root != null) {
289
			if (root != null) {
289
				return root;
290
				return root;
290
			}
291
			}
Lines 300-306 Link Here
300
		return getJarPkgFragmentRoot(jarPath, target, projects);
301
		return getJarPkgFragmentRoot(jarPath, target, projects);
301
	}
302
	}
302
	
303
	
303
	private IPackageFragmentRoot getJarPkgFragmentRoot(
304
	private PackageFragmentRoot getJarPkgFragmentRoot(
304
		IPath jarPath,
305
		IPath jarPath,
305
		Object target,
306
		Object target,
306
		IJavaProject[] projects) {
307
		IJavaProject[] projects) {
Lines 311-324 Link Here
311
				if (classpathEnty != null) {
312
				if (classpathEnty != null) {
312
					if (target instanceof IFile) {
313
					if (target instanceof IFile) {
313
						// internal jar
314
						// internal jar
314
						return javaProject.getPackageFragmentRoot((IFile)target);
315
						return (PackageFragmentRoot) javaProject.getPackageFragmentRoot((IFile)target);
315
					} else {
316
					} else {
316
						// external jar
317
						// external jar
317
						return javaProject.getPackageFragmentRoot0(jarPath);
318
						return (PackageFragmentRoot) javaProject.getPackageFragmentRoot0(jarPath);
318
					}
319
					}
319
				}
320
				}
320
			} catch (JavaModelException e) {
321
			} catch (JavaModelException e) {
321
				// JavaModelException from getResolvedClasspath - a problem occured while accessing project: nothing we can do, ignore
322
				// JavaModelException from getResolvedClasspath - a problem occurred while accessing project: nothing we can do, ignore
322
			}
323
			}
323
		}
324
		}
324
		return null;
325
		return null;
Lines 327-333 Link Here
327
	/**
328
	/**
328
	 * Returns the package fragment root that contains the given resource path.
329
	 * Returns the package fragment root that contains the given resource path.
329
	 */
330
	 */
330
	private IPackageFragmentRoot getPkgFragmentRoot(String pathString) {
331
	private PackageFragmentRoot getPkgFragmentRoot(String pathString) {
331
332
332
		IPath path= new Path(pathString);
333
		IPath path= new Path(pathString);
333
		IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
334
		IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();

Return to bug 181981