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

(-)src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java (-1 / +16 lines)
Lines 133-138 Link Here
133
	 * Returns the path of the added package fragment root.
133
	 * Returns the path of the added package fragment root.
134
	 */
134
	 */
135
	public IPath addPackageFragmentRoot(IPath projectPath, String sourceFolderName, IPath[] exclusionPatterns, String specificOutputLocation) throws JavaModelException {
135
	public IPath addPackageFragmentRoot(IPath projectPath, String sourceFolderName, IPath[] exclusionPatterns, String specificOutputLocation) throws JavaModelException {
136
		return addPackageFragmentRoot(projectPath, sourceFolderName, exclusionPatterns, true/*exclusion patterns*/, specificOutputLocation);
137
	}
138
	
139
	/** Adds a package fragment root to the workspace.  If
140
	 * a package fragment root with the same name already
141
	 * exists, it is not replaced.  A workspace must be open.
142
	 * Returns the path of the added package fragment root.
143
	 */
144
	public IPath addPackageFragmentRoot(IPath projectPath, String sourceFolderName, IPath[] patterns, boolean areExclusionPatterns, String specificOutputLocation) throws JavaModelException {
136
		checkAssertion("a workspace must be open", fIsOpen); //$NON-NLS-1$
145
		checkAssertion("a workspace must be open", fIsOpen); //$NON-NLS-1$
137
		IPath path = getPackageFragmentRootPath(projectPath, sourceFolderName);
146
		IPath path = getPackageFragmentRootPath(projectPath, sourceFolderName);
138
		createFolder(path);
147
		createFolder(path);
Lines 141-147 Link Here
141
			outputPath = getPackageFragmentRootPath(projectPath, specificOutputLocation);
150
			outputPath = getPackageFragmentRootPath(projectPath, specificOutputLocation);
142
			createFolder(outputPath);
151
			createFolder(outputPath);
143
		}
152
		}
144
		IClasspathEntry entry = JavaCore.newSourceEntry(path, exclusionPatterns == null ? new Path[0] : exclusionPatterns, outputPath);
153
		IClasspathEntry entry;
154
		if (areExclusionPatterns)
155
			// exclusion patterns
156
			entry = JavaCore.newSourceEntry(path, patterns == null ? new Path[0] : patterns, outputPath);
157
		else
158
			// inclusion patterns
159
			entry = JavaCore.newSourceEntry(path, patterns == null ? new Path[0] : patterns, new Path[0], outputPath);
145
		addEntry(projectPath, entry);
160
		addEntry(projectPath, entry);
146
		return path;
161
		return path;
147
	}
162
	}
(-)src/org/eclipse/jdt/core/tests/builder/MultiSourceFolderAndOutputFolderTests.java (+25 lines)
Lines 282-285 Link Here
282
		expectingNoPresenceOf(projectPath.append("bin2").append("bin")); //$NON-NLS-1$ //$NON-NLS-2$
282
		expectingNoPresenceOf(projectPath.append("bin2").append("bin")); //$NON-NLS-1$ //$NON-NLS-2$
283
		expectingNoPresenceOf(projectPath.append("bin").append("bin2")); //$NON-NLS-1$ //$NON-NLS-2$
283
		expectingNoPresenceOf(projectPath.append("bin").append("bin2")); //$NON-NLS-1$ //$NON-NLS-2$
284
	}
284
	}
285
	
286
	/*
287
	 * Regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161
288
	 */
289
	public void test0012() throws JavaModelException {
290
		IPath projectPath = env.addProject("P");
291
		env.removePackageFragmentRoot(projectPath, "");
292
		IPath src = env.addPackageFragmentRoot(projectPath, "", new IPath[] {new Path("p1/p2/p3/X.java"), new Path("Y.java")}, false/*inclusion*/, "");
293
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
294
		
295
		env.addClass(src, "p1.p2.p3", "X", 
296
			"package p1.p2.p3;\n" +
297
			"public class X {}"
298
		);
299
		fullBuild();
300
		expectingNoProblems();
301
		
302
		env.addClass(src, "", "Y",
303
			"import p1.p2.p3.X;\n" +
304
			"public class Y extends X {}"
305
		);
306
		incrementalBuild();
307
		expectingNoProblems();
308
	}
309
285
}
310
}
(-)src/org/eclipse/jdt/core/tests/model/InclusionPatternsTests.java (-5 / +69 lines)
Lines 11-24 Link Here
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import org.eclipse.core.resources.*;
13
import org.eclipse.core.resources.*;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.IWorkspaceRunnable;
17
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.Path;
16
import org.eclipse.core.runtime.Path;
20
import org.eclipse.jdt.core.*;
17
import org.eclipse.jdt.core.*;
21
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.search.IJavaSearchConstants;
18
import org.eclipse.jdt.core.search.IJavaSearchConstants;
23
import org.eclipse.jdt.core.search.IJavaSearchScope;
19
import org.eclipse.jdt.core.search.IJavaSearchScope;
24
import org.eclipse.jdt.core.search.SearchEngine;
20
import org.eclipse.jdt.core.search.SearchEngine;
Lines 32-38 Link Here
32
}
28
}
33
29
34
static {
30
static {
35
//	TESTS_NAMES = new String[] { "testSearchWithIncludedPackage2" };
31
//	TESTS_NAMES = new String[] { "testIncludeCUOnly02" };
36
}
32
}
37
public static Test suite() {
33
public static Test suite() {
38
	return buildTestSuite(InclusionPatternsTests.class);
34
	return buildTestSuite(InclusionPatternsTests.class);
Lines 373-378 Link Here
373
		root.getNonJavaResources());
369
		root.getNonJavaResources());
374
}
370
}
375
/*
371
/*
372
 * Ensure that a type can be resolved if it is included but not its super packages.
373
 * (regression test for bug 119161 classes in "deep" packages not fully recognized when using tight inclusion filters)
374
 */
375
public void testIncludeCUOnly01() throws CoreException {
376
	setClasspath(new String[] {"/P/src", "p1/p2/*.java|q/*.java"});
377
	addLibraryEntry(getJavaProject("P"), getExternalJCLPathString(), false);
378
	createFolder("/P/src/p1/p2");
379
	createFile(
380
		"/P/src/p1/p2/X.java",
381
		"package p1.p2;\n" +
382
		"public class X {\n" +
383
		"}"
384
	);
385
	ICompilationUnit workingCopy = null;
386
	try {
387
		ProblemRequestor problemRequestor = new ProblemRequestor();
388
		workingCopy = getWorkingCopy(
389
			"/P/src/Y.java", 
390
			"import p1.p2.X;\n" +
391
			"public class Y extends X {\n" +
392
			"}",
393
			null/*primary owner*/,
394
			problemRequestor);
395
		assertProblems(
396
			"Unepected problems",
397
			"----------\n" + 
398
			"----------\n",
399
			problemRequestor);
400
	} finally {
401
		if (workingCopy != null)
402
			workingCopy.discardWorkingCopy();
403
	}	
404
}
405
/*
406
 * Ensure that a type can be resolved if it is included but not its super packages.
407
 * (regression test for bug 119161 classes in "deep" packages not fully recognized when using tight inclusion filters)
408
 */
409
public void testIncludeCUOnly02() throws CoreException {
410
	setClasspath(new String[] {"/P/src", "p1/p2/p3/*.java|q/*.java"});
411
	addLibraryEntry(getJavaProject("P"), getExternalJCLPathString(), false);
412
	createFolder("/P/src/p1/p2/p3");
413
	createFile(
414
		"/P/src/p1/p2/p3/X.java",
415
		"package p1.p2.p3;\n" +
416
		"public class X {\n" +
417
		"}"
418
	);
419
	ICompilationUnit workingCopy = null;
420
	try {
421
		ProblemRequestor problemRequestor = new ProblemRequestor();
422
		workingCopy = getWorkingCopy(
423
			"/P/src/Y.java", 
424
			"import p1.p2.p3.X;\n" +
425
			"public class Y extends X {\n" +
426
			"}",
427
			null/*primary owner*/,
428
			problemRequestor);
429
		assertProblems(
430
			"Unepected problems",
431
			"----------\n" + 
432
			"----------\n",
433
			problemRequestor);
434
	} finally {
435
		if (workingCopy != null)
436
			workingCopy.discardWorkingCopy();
437
	}	
438
}
439
/*
376
 * Ensures that a cu that is not included is not on the classpath of the project.
440
 * Ensures that a cu that is not included is not on the classpath of the project.
377
 */
441
 */
378
public void testIsOnClasspath1() throws CoreException {
442
public void testIsOnClasspath1() throws CoreException {
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-1 / +7 lines)
Lines 1496-1503 Link Here
1496
		return getWorkingCopy(path, source, owner, problemRequestor);
1496
		return getWorkingCopy(path, source, owner, problemRequestor);
1497
	}
1497
	}
1498
	public ICompilationUnit getWorkingCopy(String path, String source, WorkingCopyOwner owner, IProblemRequestor problemRequestor) throws JavaModelException {
1498
	public ICompilationUnit getWorkingCopy(String path, String source, WorkingCopyOwner owner, IProblemRequestor problemRequestor) throws JavaModelException {
1499
		ICompilationUnit workingCopy = getCompilationUnit(path).getWorkingCopy(owner, problemRequestor, null/*no progress monitor*/);
1499
		ICompilationUnit workingCopy = getCompilationUnit(path);
1500
		if (owner != null)
1501
			workingCopy = workingCopy.getWorkingCopy(owner, problemRequestor, null/*no progress monitor*/);
1502
		else
1503
			workingCopy.becomeWorkingCopy(problemRequestor, null/*no progress monitor*/);
1500
		workingCopy.getBuffer().setContents(source);
1504
		workingCopy.getBuffer().setContents(source);
1505
		if (problemRequestor instanceof ProblemRequestor)
1506
			((ProblemRequestor) problemRequestor).initialize(source.toCharArray());
1501
		workingCopy.makeConsistent(null/*no progress monitor*/);
1507
		workingCopy.makeConsistent(null/*no progress monitor*/);
1502
		return workingCopy;
1508
		return workingCopy;
1503
	}
1509
	}
(-)model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java (-1 / +1 lines)
Lines 49-55 Link Here
49
49
50
	try {
50
	try {
51
		IResource container = binaryFolder.findMember(qualifiedPackageName); // this is a case-sensitive check
51
		IResource container = binaryFolder.findMember(qualifiedPackageName); // this is a case-sensitive check
52
		if (container instanceof IContainer && !isExcluded(container)) {
52
		if (container instanceof IContainer) {
53
			IResource[] members = ((IContainer) container).members();
53
			IResource[] members = ((IContainer) container).members();
54
			dirList = new String[members.length];
54
			dirList = new String[members.length];
55
			int index = 0;
55
			int index = 0;
(-)model/org/eclipse/jdt/internal/core/SearchableEnvironment.java (-16 / +11 lines)
Lines 341-362 Link Here
341
	 * @see org.eclipse.jdt.internal.compiler.env.INameEnvironment#isPackage(char[][], char[])
341
	 * @see org.eclipse.jdt.internal.compiler.env.INameEnvironment#isPackage(char[][], char[])
342
	 */
342
	 */
343
	public boolean isPackage(char[][] parentPackageName, char[] subPackageName) {
343
	public boolean isPackage(char[][] parentPackageName, char[] subPackageName) {
344
		if (subPackageName == null || CharOperation.contains('.', subPackageName))
344
		String[] pkgName;
345
			return false;
345
		if (parentPackageName == null)
346
		if (parentPackageName == null || parentPackageName.length == 0)
346
			pkgName = new String[] {new String(subPackageName)};
347
			return isTopLevelPackage(subPackageName);
347
		else {
348
		for (int i = 0, length = parentPackageName.length; i < length; i++)
348
			int length = parentPackageName.length;
349
			if (parentPackageName[i] == null || CharOperation.contains('.', parentPackageName[i]))
349
			pkgName = new String[length+1];
350
				return false;
350
			for (int i = 0; i < length; i++)
351
351
				pkgName[i] = new String(parentPackageName[i]);
352
		String packageName = new String(CharOperation.concatWith(parentPackageName, subPackageName, '.'));
352
			pkgName[length] = new String(subPackageName);
353
		return this.nameLookup.findPackageFragments(packageName, false) != null;
353
		}
354
	}
354
		return this.nameLookup.isPackage(pkgName);
355
356
	public boolean isTopLevelPackage(char[] packageName) {
357
		return packageName != null &&
358
			!CharOperation.contains('.', packageName) &&
359
			this.nameLookup.findPackageFragments(new String(packageName), false) != null;
360
	}
355
	}
361
356
362
	/**
357
	/**
(-)model/org/eclipse/jdt/internal/core/NameLookup.java (-7 / +31 lines)
Lines 99-104 Link Here
99
	 * replaces the array.
99
	 * replaces the array.
100
	 */
100
	 */
101
	protected HashtableOfArrayToObject packageFragments;
101
	protected HashtableOfArrayToObject packageFragments;
102
	
103
	/*
104
	 * A set of names (String[]) that are not to be package names.
105
	 * Value is not null for known package.
106
	 */
107
	protected HashtableOfArrayToObject isPackageCache;
102
108
103
	/**
109
	/**
104
	 * Reverse map from root path to corresponding resolved CP entry
110
	 * Reverse map from root path to corresponding resolved CP entry
Lines 197-202 Link Here
197
				}
203
				}
198
			}
204
			}
199
		}
205
		}
206
		
207
		// cache whether each package and its including packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
208
		// are actual packages
209
		this.isPackageCache = new HashtableOfArrayToObject();
210
		for (int i = 0, size = this.packageFragments.keyTable.length; i < size; i++) {
211
			String[] pkgName = (String[]) this.packageFragments.keyTable[i];
212
			if (pkgName == null) continue;
213
			this.isPackageCache.put(pkgName, pkgName);
214
			int length = pkgName.length;
215
			for (int j = length-1; j > 0; j--) {
216
				String[] subPkgName = new String[j];
217
				System.arraycopy(pkgName, 0, subPkgName, 0, j);
218
				this.isPackageCache.put(subPkgName, subPkgName);
219
			}
220
		}
200
		this.rootToResolvedEntries = rootToResolvedEntries;
221
		this.rootToResolvedEntries = rootToResolvedEntries;
201
        if (VERBOSE) {
222
        if (VERBOSE) {
202
            Util.verbose(" -> spent: " + (start - System.currentTimeMillis()) + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
223
            Util.verbose(" -> spent: " + (start - System.currentTimeMillis()) + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
Lines 465-484 Link Here
465
		} else {
486
		} else {
466
			String[] splittedName = Util.splitOn('.', name, 0, name.length());
487
			String[] splittedName = Util.splitOn('.', name, 0, name.length());
467
			Object value = this.packageFragments.get(splittedName);
488
			Object value = this.packageFragments.get(splittedName);
489
			if (value == null)
490
				return null;
468
			if (value instanceof PackageFragmentRoot) {
491
			if (value instanceof PackageFragmentRoot) {
469
				return new IPackageFragment[] {((PackageFragmentRoot) value).getPackageFragment(splittedName)};
492
				return new IPackageFragment[] {((PackageFragmentRoot) value).getPackageFragment(splittedName)};
470
			} else {
493
			} else {
471
				IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value;
494
				IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value;
472
				if (roots != null) {
495
				IPackageFragment[] result = new IPackageFragment[roots.length];
473
					IPackageFragment[] result = new IPackageFragment[roots.length];
496
				for (int i= 0; i < roots.length; i++) {
474
					for (int i= 0; i < roots.length; i++) {
497
					result[i] = ((PackageFragmentRoot) roots[i]).getPackageFragment(splittedName);
475
						result[i] = ((PackageFragmentRoot) roots[i]).getPackageFragment(splittedName);
476
					}
477
					return result;
478
				}
498
				}
499
				return result;
479
			}
500
			}
480
		}
501
		}
481
		return null;
482
	}
502
	}
483
503
484
	/*
504
	/*
Lines 629-634 Link Here
629
		}
649
		}
630
		return type;
650
		return type;
631
	}
651
	}
652
	
653
	public boolean isPackage(String[] pkgName) {
654
		return this.isPackageCache.get(pkgName) != null;
655
	}
632
656
633
	/**
657
	/**
634
	 * Returns true if the given element's name matches the
658
	 * Returns true if the given element's name matches the

Return to bug 119161