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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/util/Util.java (-3 / +6 lines)
Lines 328-342 Link Here
328
}
328
}
329
public static void createSourceZip(String[] pathsAndContents, String zipPath) throws IOException {
329
public static void createSourceZip(String[] pathsAndContents, String zipPath) throws IOException {
330
    String sourcesPath = getOutputDirectory() + File.separator + "sources";
330
    String sourcesPath = getOutputDirectory() + File.separator + "sources";
331
    File sourcesDir = new File(sourcesPath);
331
    createSourceDir(pathsAndContents, sourcesPath);
332
    flushDirectoryContent(sourcesDir);
332
    zip(new File(sourcesPath), zipPath);
333
}
334
335
public static void createSourceDir(String[] pathsAndContents, String sourcesPath) throws IOException {
336
	flushDirectoryContent(new File(sourcesPath));
333
    for (int i = 0, length = pathsAndContents.length; i < length; i+=2) {
337
    for (int i = 0, length = pathsAndContents.length; i < length; i+=2) {
334
        String sourcePath = sourcesPath + File.separator + pathsAndContents[i];
338
        String sourcePath = sourcesPath + File.separator + pathsAndContents[i];
335
        File sourceFile = new File(sourcePath);
339
        File sourceFile = new File(sourcePath);
336
        sourceFile.getParentFile().mkdirs();
340
        sourceFile.getParentFile().mkdirs();
337
        createFile(sourcePath, pathsAndContents[i+1]);
341
        createFile(sourcePath, pathsAndContents[i+1]);
338
    }
342
    }
339
    zip(sourcesDir, zipPath);
340
}
343
}
341
/**
344
/**
342
 * Delete a file or directory and insure that the file is no longer present
345
 * Delete a file or directory and insure that the file is no longer present
(-)src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java (+12 lines)
Lines 232-237 Link Here
232
		addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, null, true, attributes, false));
232
		addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, null, true, attributes, false));
233
	}
233
	}
234
234
235
	public void addExternalFolders(IPath projectPath, String[] folders) throws JavaModelException {
236
		addExternalFolders(projectPath, folders, false);
237
	}
238
239
	public void addExternalFolders(IPath projectPath, String[] folders, boolean isExported) throws JavaModelException {
240
		for (int i = 0, max = folders.length; i < max; i++) {
241
			String folder = folders[i];
242
			checkAssertion("folder name must not end with .zip or .jar", !folder.endsWith(".zip") && !folder.endsWith(".jar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
243
			addEntry(projectPath, JavaCore.newLibraryEntry(new Path(folder), null, null, isExported));
244
		}
245
	}
246
235
	public void addExternalJars(IPath projectPath, String[] jars) throws JavaModelException {
247
	public void addExternalJars(IPath projectPath, String[] jars) throws JavaModelException {
236
		addExternalJars(projectPath, jars, false);
248
		addExternalJars(projectPath, jars, false);
237
	}
249
	}
(-)src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java (-5 / +70 lines)
Lines 13-18 Link Here
13
import junit.framework.*;
13
import junit.framework.*;
14
14
15
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.core.resources.IMarker;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
Lines 38-44 Link Here
38
}
40
}
39
41
40
private String getJdkLevelProblem(String expectedRuntime, String path, int severity) {
42
private String getJdkLevelProblem(String expectedRuntime, String path, int severity) {
41
	Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
43
	Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
42
	long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
44
	long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
43
	String jclRuntime = CompilerOptions.versionFromJdkLevel(libraryJDK);
45
	String jclRuntime = CompilerOptions.versionFromJdkLevel(libraryJDK);
44
	StringBuffer jdkLevelProblem = new StringBuffer("Problem : Incompatible .class files version in required binaries. Project 'Project' is targeting a ");
46
	StringBuffer jdkLevelProblem = new StringBuffer("Problem : Incompatible .class files version in required binaries. Project 'Project' is targeting a ");
Lines 258-263 Link Here
258
}
260
}
259
261
260
/*
262
/*
263
 * Ensures that the changing a type in an external folder and refreshing triggers a rebuild
264
 */
265
public void testChangeExternalFolder() throws CoreException {
266
	String externalLib = Util.getOutputDirectory() + File.separator + "externalLib";
267
	try {
268
		new File(externalLib).mkdirs();
269
		Util.compile(
270
			new String[] {
271
				"p/X.java", 
272
				"package p;\n" +
273
				"public class X {\n" +
274
				"  public void foo() {\n" +
275
				"  }\n" +
276
				"}"
277
			},
278
			new HashMap(),
279
			externalLib
280
		);
281
		
282
		IPath projectPath = env.addProject("Project"); 
283
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
284
		env.addExternalFolders(projectPath, new String[] {externalLib});
285
286
		IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
287
		env.setOutputFolder(projectPath, ""); 
288
289
		IPath classY = env.addClass(root, "q", "Y",  
290
			"package q;\n"+ 
291
			"public class Y {\n" +
292
			"  void bar(p.X x) {\n" +
293
			"    x.foo();\n" +
294
			"  }\n" +
295
			"}"
296
		); 
297
298
		fullBuild(projectPath);
299
		expectingNoProblems();
300
301
		Util.compile(
302
			new String[] {
303
				"p/X.java", 
304
				"package p;\n" +
305
				"public class X {\n" +
306
				"}"
307
			},
308
			new HashMap(),
309
			externalLib
310
		);
311
		// work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=219566
312
		IProject externalFoldersProject = JavaModelManager.getExternalManager().getExternalFoldersProject();
313
		externalFoldersProject.refreshLocal(IResource.DEPTH_INFINITE, null);
314
315
		incrementalBuild(projectPath);
316
		expectingProblemsFor(
317
			classY,
318
			"Problem : The method foo() is undefined for the type X [ resource : </Project/q/Y.java> range : <54,57> category : <50> severity : <2>]"
319
		);
320
	} finally {
321
		new File(externalLib).delete();
322
	}
323
}
324
325
/*
261
 * Ensures that changing an external jar and refreshing the projects triggers a rebuild
326
 * Ensures that changing an external jar and refreshing the projects triggers a rebuild
262
 * (regression test for bug 50207 Compile errors fixed by 'refresh' do not reset problem list or package explorer error states)
327
 * (regression test for bug 50207 Compile errors fixed by 'refresh' do not reset problem list or package explorer error states)
263
 */
328
 */
Lines 565-571 Link Here
565
	List expectedProblems = new ArrayList();
630
	List expectedProblems = new ArrayList();
566
	for (int i = 0; i < max; i++) {
631
	for (int i = 0; i < max; i++) {
567
		String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
632
		String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
568
		Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
633
		Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
569
		long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
634
		long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
570
		if (libraryJDK > projectRuntimeJDKLevel) {
635
		if (libraryJDK > projectRuntimeJDKLevel) {
571
			expectedProblems.add(getJdkLevelProblem(projectRuntime, path, IMarker.SEVERITY_WARNING));
636
			expectedProblems.add(getJdkLevelProblem(projectRuntime, path, IMarker.SEVERITY_WARNING));
Lines 580-586 Link Here
580
	expectedProblems = new ArrayList();
645
	expectedProblems = new ArrayList();
581
	for (int i = 0; i < max; i++) {
646
	for (int i = 0; i < max; i++) {
582
		String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
647
		String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
583
		Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
648
		Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
584
		long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
649
		long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
585
		if (libraryJDK > projectRuntimeJDKLevel) {
650
		if (libraryJDK > projectRuntimeJDKLevel) {
586
			expectedProblems.add(getJdkLevelProblem(projectRuntime, path, IMarker.SEVERITY_ERROR));
651
			expectedProblems.add(getJdkLevelProblem(projectRuntime, path, IMarker.SEVERITY_ERROR));
Lines 625-631 Link Here
625
		int max = classlibs.length;
690
		int max = classlibs.length;
626
		for (int i = 0; i < max; i++) {
691
		for (int i = 0; i < max; i++) {
627
			String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
692
			String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
628
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
693
			Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
629
			long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
694
			long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
630
			if (libraryJDK > wkspRuntimeJDKLevel) {
695
			if (libraryJDK > wkspRuntimeJDKLevel) {
631
				expectedProblems.add(getJdkLevelProblem(wkspRuntime, path, IMarker.SEVERITY_WARNING));
696
				expectedProblems.add(getJdkLevelProblem(wkspRuntime, path, IMarker.SEVERITY_WARNING));
Lines 640-646 Link Here
640
		expectedProblems = new ArrayList();
705
		expectedProblems = new ArrayList();
641
		for (int i = 0; i < max; i++) {
706
		for (int i = 0; i < max; i++) {
642
			String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
707
			String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
643
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
708
			Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
644
			long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
709
			long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
645
			if (libraryJDK > wkspRuntimeJDKLevel) {
710
			if (libraryJDK > wkspRuntimeJDKLevel) {
646
				expectedProblems.add(getJdkLevelProblem(wkspRuntime, path, IMarker.SEVERITY_ERROR));
711
				expectedProblems.add(getJdkLevelProblem(wkspRuntime, path, IMarker.SEVERITY_ERROR));
(-)model/org/eclipse/jdt/internal/core/DeleteResourceElementsOperation.java (-7 / +4 lines)
Lines 11-19 Link Here
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
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.IResource;
17
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaModelStatusConstants;
16
import org.eclipse.jdt.core.IJavaModelStatusConstants;
Lines 43-49 Link Here
43
 */
40
 */
44
private void deletePackageFragment(IPackageFragment frag)
41
private void deletePackageFragment(IPackageFragment frag)
45
	throws JavaModelException {
42
	throws JavaModelException {
46
	IResource res = frag.getResource();
43
	IResource res = ((JavaElement) frag).resource();
47
	if (res != null) {
44
	if (res != null) {
48
		// collect the children to remove
45
		// collect the children to remove
49
		IJavaElement[] childrenOfInterest = frag.getChildren();
46
		IJavaElement[] childrenOfInterest = frag.getChildren();
Lines 51-57 Link Here
51
			IResource[] resources = new IResource[childrenOfInterest.length];
48
			IResource[] resources = new IResource[childrenOfInterest.length];
52
			// remove the children
49
			// remove the children
53
			for (int i = 0; i < childrenOfInterest.length; i++) {
50
			for (int i = 0; i < childrenOfInterest.length; i++) {
54
				resources[i] = childrenOfInterest[i].getCorrespondingResource();
51
				resources[i] = ((JavaElement) childrenOfInterest[i]).resource();
55
			}
52
			}
56
			deleteResources(resources, force);
53
			deleteResources(resources, force);
57
		}
54
		}
Lines 86-92 Link Here
86
		}
83
		}
87
		if (isEmpty && !frag.isDefaultPackage()/*don't delete default package's folder: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38450*/) {
84
		if (isEmpty && !frag.isDefaultPackage()/*don't delete default package's folder: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38450*/) {
88
			// delete recursively empty folders
85
			// delete recursively empty folders
89
			IResource fragResource =  frag.getResource();
86
			IResource fragResource =  ((JavaElement) frag).resource();
90
			if (fragResource != null) {
87
			if (fragResource != null) {
91
				deleteEmptyPackageFragment(frag, false, fragResource.getParent());
88
				deleteEmptyPackageFragment(frag, false, fragResource.getParent());
92
			}
89
			}
Lines 132-138 Link Here
132
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
129
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
133
	else if (type == IJavaElement.PACKAGE_FRAGMENT && element instanceof JarPackageFragment)
130
	else if (type == IJavaElement.PACKAGE_FRAGMENT && element instanceof JarPackageFragment)
134
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
131
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
135
	IResource resource = element.getResource();
132
	IResource resource = ((JavaElement) element).resource();
136
	if (resource instanceof IFolder) {
133
	if (resource instanceof IFolder) {
137
		if (resource.isLinked()) {
134
		if (resource.isLinked()) {
138
			error(IJavaModelStatusConstants.INVALID_RESOURCE, element);
135
			error(IJavaModelStatusConstants.INVALID_RESOURCE, element);
(-)model/org/eclipse/jdt/internal/core/SourceRefElement.java (-2 / +2 lines)
Lines 187-194 Link Here
187
/*
187
/*
188
 * @see IJavaElement
188
 * @see IJavaElement
189
 */
189
 */
190
public IResource getResource() {
190
public IResource resource() {
191
	return this.getParent().getResource();
191
	return this.parent.resource();
192
}
192
}
193
/**
193
/**
194
 * @see ISourceReference
194
 * @see ISourceReference
(-)model/org/eclipse/jdt/internal/core/MovePackageFragmentRootOperation.java (-2 / +2 lines)
Lines 118-124 Link Here
118
	}
118
	}
119
	protected void executeOperation() throws JavaModelException {
119
	protected void executeOperation() throws JavaModelException {
120
		
120
		
121
		IPackageFragmentRoot root = (IPackageFragmentRoot)this.getElementToProcess();
121
		IPackageFragmentRoot root = (IPackageFragmentRoot) getElementToProcess();
122
		IClasspathEntry rootEntry = root.getRawClasspathEntry();
122
		IClasspathEntry rootEntry = root.getRawClasspathEntry();
123
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
123
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
124
		
124
		
Lines 160-166 Link Here
160
		throws JavaModelException {
160
		throws JavaModelException {
161
			
161
			
162
		final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
162
		final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
163
		IResource rootResource = root.getResource();
163
		IResource rootResource = ((JavaElement) root).resource();
164
		if (rootEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE || exclusionPatterns == null) {
164
		if (rootEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE || exclusionPatterns == null) {
165
			try {
165
			try {
166
				IResource destRes;
166
				IResource destRes;
(-)model/org/eclipse/jdt/internal/core/JavaModelOperation.java (-15 / +1 lines)
Lines 145-157 Link Here
145
	protected JavaModelOperation(IJavaElement element) {
145
	protected JavaModelOperation(IJavaElement element) {
146
		this.elementsToProcess = new IJavaElement[]{element};
146
		this.elementsToProcess = new IJavaElement[]{element};
147
	}
147
	}
148
	/**
149
	 * A common constructor for all Java Model operations.
150
	 */
151
	protected JavaModelOperation(IJavaElement element, boolean force) {
152
		this.elementsToProcess = new IJavaElement[]{element};
153
		this.force= force;
154
	}
155
	
148
	
156
	/*
149
	/*
157
	 * Registers the given action at the end of the list of actions to run.
150
	 * Registers the given action at the end of the list of actions to run.
Lines 292-298 Link Here
292
		IResource rootResource)
285
		IResource rootResource)
293
		throws JavaModelException {
286
		throws JavaModelException {
294
	
287
	
295
		IContainer resource = (IContainer) fragment.getResource();
288
		IContainer resource = (IContainer) ((JavaElement)fragment).resource();
296
	
289
	
297
		try {
290
		try {
298
			resource.delete(
291
			resource.delete(
Lines 438-450 Link Here
438
		return new DocumentAdapter(buffer);
431
		return new DocumentAdapter(buffer);
439
	}
432
	}
440
	/**
433
	/**
441
	 * Returns the elements to which this operation applies,
442
	 * or <code>null</code> if not applicable.
443
	 */
444
	protected IJavaElement[] getElementsToProcess() {
445
		return elementsToProcess;
446
	}
447
	/**
448
	 * Returns the element to which this operation applies,
434
	 * Returns the element to which this operation applies,
449
	 * or <code>null</code> if not applicable.
435
	 * or <code>null</code> if not applicable.
450
	 */
436
	 */
(-)model/org/eclipse/jdt/internal/core/BufferManager.java (-5 / +4 lines)
Lines 16-22 Link Here
16
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.jdt.core.IBuffer;
18
import org.eclipse.jdt.core.IBuffer;
19
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IOpenable;
19
import org.eclipse.jdt.core.IOpenable;
21
20
22
/**
21
/**
Lines 64-71 Link Here
64
	}
63
	}
65
}
64
}
66
public static IBuffer createBuffer(IOpenable owner) {
65
public static IBuffer createBuffer(IOpenable owner) {
67
	IJavaElement element = (IJavaElement)owner;
66
	JavaElement element = (JavaElement) owner;
68
	IResource resource = element.getResource();
67
	IResource resource = element.resource();
69
	return 
68
	return 
70
		new Buffer(
69
		new Buffer(
71
			resource instanceof IFile ? (IFile)resource : null, 
70
			resource instanceof IFile ? (IFile)resource : null, 
Lines 73-80 Link Here
73
			element.isReadOnly());
72
			element.isReadOnly());
74
}
73
}
75
public static IBuffer createNullBuffer(IOpenable owner) {
74
public static IBuffer createNullBuffer(IOpenable owner) {
76
	IJavaElement element = (IJavaElement)owner;
75
	JavaElement element = (JavaElement) owner;
77
	IResource resource = element.getResource();
76
	IResource resource = element.resource();
78
	return 
77
	return 
79
		new NullBuffer(
78
		new NullBuffer(
80
			resource instanceof IFile ? (IFile)resource : null, 
79
			resource instanceof IFile ? (IFile)resource : null, 
(-)model/org/eclipse/jdt/internal/core/ClassFile.java (-9 / +4 lines)
Lines 321-327 Link Here
321
			JavaModelManager.getJavaModelManager().closeZipFile(zip);
321
			JavaModelManager.getJavaModelManager().closeZipFile(zip);
322
		}
322
		}
323
	} else {
323
	} else {
324
		IFile file = (IFile) getResource();
324
		IFile file = (IFile) resource();
325
		return Util.getResourceContentsAsByteArray(file);
325
		return Util.getResourceContentsAsByteArray(file);
326
	}
326
	}
327
}
327
}
Lines 348-354 Link Here
348
		return super.getBuffer();
348
		return super.getBuffer();
349
	} else {
349
	} else {
350
		// .class file not on classpath, create a new buffer to be nice (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=41444)
350
		// .class file not on classpath, create a new buffer to be nice (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=41444)
351
		Object info = ((ClassFile) getClassFile()).getBinaryTypeInfo((IFile) getResource());
351
		Object info = ((ClassFile) getClassFile()).getBinaryTypeInfo((IFile) resource());
352
		IBuffer buffer = openBuffer(null, info);
352
		IBuffer buffer = openBuffer(null, info);
353
		if (buffer != null && !(buffer instanceof NullBuffer))
353
		if (buffer != null && !(buffer instanceof NullBuffer))
354
			return buffer;
354
			return buffer;
Lines 488-500 Link Here
488
/*
488
/*
489
 * @see IJavaElement
489
 * @see IJavaElement
490
 */
490
 */
491
public IResource getResource() {
491
public IResource resource(PackageFragmentRoot root) {
492
	PackageFragmentRoot root = this.getPackageFragmentRoot();
492
	return ((IContainer) ((Openable) this.parent).resource(root)).getFile(new Path(this.getElementName()));
493
	if (root.isArchive()) {
494
		return root.getResource();
495
	} else {
496
		return ((IContainer)this.getParent().getResource()).getFile(new Path(this.getElementName()));
497
	}
498
}
493
}
499
/**
494
/**
500
 * @see ISourceReference
495
 * @see ISourceReference
(-)model/org/eclipse/jdt/internal/core/Openable.java (-2 / +22 lines)
Lines 197-203 Link Here
197
			}
197
			}
198
			break;
198
			break;
199
	}
199
	}
200
	return validateExistence(getResource()).isOK();
200
	return validateExistence(resource()).isOK();
201
}
201
}
202
public String findRecommendedLineSeparator() throws JavaModelException {
202
public String findRecommendedLineSeparator() throws JavaModelException {
203
	IBuffer buffer = getBuffer();
203
	IBuffer buffer = getBuffer();
Lines 234-240 Link Here
234
	openAncestors(newElements, monitor);
234
	openAncestors(newElements, monitor);
235
	
235
	
236
	// validate existence
236
	// validate existence
237
	IResource underlResource = getResource();
237
	IResource underlResource = resource();
238
	IStatus status = validateExistence(underlResource);
238
	IStatus status = validateExistence(underlResource);
239
	if (!status.isOK())
239
	if (!status.isOK())
240
		throw newJavaModelException(status);
240
		throw newJavaModelException(status);
Lines 436-441 Link Here
436
	return null;
436
	return null;
437
}
437
}
438
438
439
public IResource getResource() {
440
	PackageFragmentRoot root = getPackageFragmentRoot();
441
	if (root != null) {
442
		if (root.isExternal())
443
			return null;
444
		if (root.isArchive())
445
			return root.resource(root);
446
	}
447
	return resource(root);
448
}
449
450
public IResource resource() {
451
	PackageFragmentRoot root = getPackageFragmentRoot();
452
	if (root != null && root.isArchive())
453
		return root.resource(root);
454
	return resource(root);
455
}
456
457
protected abstract IResource resource(PackageFragmentRoot root);
458
439
/**
459
/**
440
 * Returns whether the corresponding resource or associated file exists
460
 * Returns whether the corresponding resource or associated file exists
441
 */
461
 */
(-)model/org/eclipse/jdt/internal/core/SourceMapper.java (-82 / +12 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.io.File;
14
import java.io.FilenameFilter;
15
import java.io.IOException;
13
import java.io.IOException;
16
import java.util.ArrayList;
14
import java.util.ArrayList;
17
import java.util.Collections;
15
import java.util.Collections;
Lines 78-91 Link Here
78
		
76
		
79
	public static boolean VERBOSE = false;
77
	public static boolean VERBOSE = false;
80
	/**
78
	/**
81
	 * Specifies the file name filter use to compute the root paths.
82
	 */
83
	private static final FilenameFilter FILENAME_FILTER = new FilenameFilter() {
84
		public boolean accept(File dir, String name) {
85
			return org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name);
86
		}
87
	};
88
	/**
89
	 * Specifies the location of the package fragment roots within
79
	 * Specifies the location of the package fragment roots within
90
	 * the zip (empty specifies the default root). <code>null</code> is
80
	 * the zip (empty specifies the default root). <code>null</code> is
91
	 * not a valid root path.
81
	 * not a valid root path.
Lines 401-407 Link Here
401
				manager.closeZipFile(zip); // handle null case
391
				manager.closeZipFile(zip); // handle null case
402
			}
392
			}
403
		} else {
393
		} else {
404
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), root.getPath(), true);
394
			Object target = JavaModel.getTarget(root.getPath(), true);
405
			if (target instanceof IResource) {
395
			if (target instanceof IResource) {
406
				IResource resource = (IResource) target;
396
				IResource resource = (IResource) target;
407
				if (resource instanceof IContainer) {
397
				if (resource instanceof IContainer) {
Lines 419-437 Link Here
419
						// ignore
409
						// ignore
420
					}
410
					}
421
				}
411
				}
422
			} else if (target instanceof File) {
423
				File file = (File)target;
424
				if (file.isDirectory()) {
425
					File[] files = file.listFiles();
426
					for (int i = 0, max = files.length; i < max; i++) {
427
						File currentFile = files[i];
428
						if (currentFile.isDirectory()) {
429
							firstLevelPackageNames.add(currentFile.getName());
430
						} else if (Util.isClassFileName(currentFile.getName())) {
431
							containsADefaultPackage = true;
432
						}
433
					}
434
				}
435
			}
412
			}
436
		}
413
		}
437
414
Lines 467-482 Link Here
467
				manager.closeZipFile(zip); // handle null case
444
				manager.closeZipFile(zip); // handle null case
468
			}
445
			}
469
		} else {
446
		} else {
470
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.sourcePath, true);
447
			Object target = JavaModel.getTarget(this.sourcePath, true);
471
			if (target instanceof IResource) {
448
			if (target instanceof IContainer) {
472
				if (target instanceof IContainer) {
449
				computeRootPath((IContainer)target, firstLevelPackageNames, containsADefaultPackage, tempRoots);
473
					computeRootPath((IContainer)target, firstLevelPackageNames, containsADefaultPackage, tempRoots);
474
				}
475
			} else if (target instanceof File) {
476
				File file = (File)target;
477
				if (file.isDirectory()) {
478
					computeRootPath(file, firstLevelPackageNames, containsADefaultPackage, tempRoots);
479
				}
480
			}
450
			}
481
		}
451
		}
482
		int size = tempRoots.size();
452
		int size = tempRoots.size();
Lines 517-548 Link Here
517
		}
487
		}
518
	}
488
	}
519
	
489
	
520
	private void computeRootPath(File directory, HashSet firstLevelPackageNames, boolean hasDefaultPackage, Set set) {
521
		File[] files = directory.listFiles();
522
		boolean hasSubDirectories = false;
523
		loop: for (int i = 0, max = files.length; i < max; i++) {
524
			File file = files[i];
525
			if (file.isDirectory()) {
526
				hasSubDirectories = true;
527
				if (firstLevelPackageNames.contains(file.getName())) {
528
					IPath fullPath = new Path(file.getParentFile().getPath());
529
					IPath rootPathEntry = fullPath.removeFirstSegments(this.sourcePath.segmentCount()).setDevice(null);
530
					set.add(rootPathEntry);
531
					break loop;
532
				} else {
533
					computeRootPath(file, firstLevelPackageNames, hasDefaultPackage, set);
534
				}
535
			} else if (i == max - 1 && !hasSubDirectories && hasDefaultPackage) {
536
				File parentDir = file.getParentFile();
537
				if (parentDir.list(FILENAME_FILTER).length != 0) {
538
					IPath fullPath = new Path(parentDir.getPath());
539
					IPath rootPathEntry = fullPath.removeFirstSegments(this.sourcePath.segmentCount()).setDevice(null);
540
					set.add(rootPathEntry);
541
				}
542
			}
543
		}
544
	}	
545
546
	private void computeRootPath(IContainer container, HashSet firstLevelPackageNames, boolean hasDefaultPackage, Set set) {
490
	private void computeRootPath(IContainer container, HashSet firstLevelPackageNames, boolean hasDefaultPackage, Set set) {
547
		try {
491
		try {
548
			IResource[] resources = container.members();
492
			IResource[] resources = container.members();
Lines 958-985 Link Here
958
				manager.closeZipFile(zip); // handle null case
902
				manager.closeZipFile(zip); // handle null case
959
			}
903
			}
960
		} else {
904
		} else {
961
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.sourcePath, true);
905
			Object target = JavaModel.getTarget(this.sourcePath, true);
962
			if (target instanceof IResource) {
906
			if (target instanceof IContainer) {
963
				if (target instanceof IContainer) {
907
				IResource res = ((IContainer)target).findMember(fullName);
964
					IResource res = ((IContainer)target).findMember(fullName);
908
				if (res instanceof IFile) {
965
					if (res instanceof IFile) {
909
					try {
966
						try {
910
						source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
967
							source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
911
					} catch (JavaModelException e) {
968
						} catch (JavaModelException e) {
912
						// ignore
969
							// ignore
970
						}
971
					}
972
				}
973
			} else if (target instanceof File) {
974
				File file = (File)target;
975
				if (file.isDirectory()) {
976
					File sourceFile = new File(file, fullName);
977
					if (sourceFile.isFile()) {
978
						try {
979
							source = Util.getFileCharContent(sourceFile, this.encoding);
980
						} catch (IOException e) {
981
							// ignore
982
						}
983
					}
913
					}
984
				}
914
				}
985
			}
915
			}
(-)model/org/eclipse/jdt/internal/core/CopyPackageFragmentRootOperation.java (-3 / +3 lines)
Lines 58-64 Link Here
58
		final IWorkspaceRoot workspaceRoot)
58
		final IWorkspaceRoot workspaceRoot)
59
		throws JavaModelException {
59
		throws JavaModelException {
60
		final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
60
		final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
61
		IResource rootResource = root.getResource();
61
		IResource rootResource = ((JavaElement) root).resource();
62
		if (root.getKind() == IPackageFragmentRoot.K_BINARY || exclusionPatterns == null) {
62
		if (root.getKind() == IPackageFragmentRoot.K_BINARY || exclusionPatterns == null) {
63
			try {
63
			try {
64
				IResource destRes;
64
				IResource destRes;
Lines 212-223 Link Here
212
		if (!status.isOK()) {
212
		if (!status.isOK()) {
213
			return status;
213
			return status;
214
		}
214
		}
215
		IPackageFragmentRoot root = (IPackageFragmentRoot)getElementToProcess();
215
		PackageFragmentRoot root = (PackageFragmentRoot)getElementToProcess();
216
		if (root == null || !root.exists()) {
216
		if (root == null || !root.exists()) {
217
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, root);
217
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, root);
218
		}
218
		}
219
219
220
		IResource resource = root.getResource();
220
		IResource resource = root.resource();
221
		if (resource instanceof IFolder) {
221
		if (resource instanceof IFolder) {
222
			if (resource.isLinked()) {
222
			if (resource.isLinked()) {
223
				return new JavaModelStatus(IJavaModelStatusConstants.INVALID_RESOURCE, root);
223
				return new JavaModelStatus(IJavaModelStatusConstants.INVALID_RESOURCE, root);
(-)model/org/eclipse/jdt/internal/core/LocalVariable.java (-2 / +2 lines)
Lines 251-258 Link Here
251
		return this.parent.getPath();
251
		return this.parent.getPath();
252
	}
252
	}
253
253
254
	public IResource getResource() {
254
	public IResource resource() {
255
		return this.parent.getResource();
255
		return this.parent.resource();
256
	}
256
	}
257
257
258
	/**
258
	/**
(-)model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java (+7 lines)
Lines 60-65 Link Here
60
			// since some clients rely on the project references when run inside an IWorkspaceRunnable
60
			// since some clients rely on the project references when run inside an IWorkspaceRunnable
61
			new ProjectReferenceChange(project, change.oldResolvedClasspath).updateProjectReferencesIfNecessary();
61
			new ProjectReferenceChange(project, change.oldResolvedClasspath).updateProjectReferencesIfNecessary();
62
			
62
			
63
			// and ensure that external folders are updated as well
64
			new ExternalFolderChange(project, change.oldResolvedClasspath).updateExternalFoldersIfNecessary(null);
65
			
63
		} else {
66
		} else {
64
			JavaElementDelta delta = new JavaElementDelta(getJavaModel());
67
			JavaElementDelta delta = new JavaElementDelta(getJavaModel());
65
			int result = change.generateDelta(delta);
68
			int result = change.generateDelta(delta);
Lines 77-82 Link Here
77
				// ensure project references are updated on next build
80
				// ensure project references are updated on next build
78
				state.addProjectReferenceChange(project, change.oldResolvedClasspath);
81
				state.addProjectReferenceChange(project, change.oldResolvedClasspath);
79
			}
82
			}
83
			if ((result & ClasspathChange.HAS_LIBRARY_CHANGE) != 0) {
84
				// ensure external folders are updated on next build
85
				state.addExternalFolderChange(project, change.oldResolvedClasspath);
86
			}
80
		}
87
		}
81
	}
88
	}
82
89
(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (-9 / +4 lines)
Lines 833-849 Link Here
833
	if (checkOwner && isPrimary()) return this;
833
	if (checkOwner && isPrimary()) return this;
834
	return new CompilationUnit((PackageFragment)getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
834
	return new CompilationUnit((PackageFragment)getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
835
}
835
}
836
/**
836
/*
837
 * @see IJavaElement#getResource()
837
 * @see Openable#resource(PackageFragmentRoot)
838
 */
838
 */
839
public IResource getResource() {
839
public IResource resource(PackageFragmentRoot root) {
840
	PackageFragmentRoot root = getPackageFragmentRoot();
841
	if (root == null) return null; // working copy not in workspace
840
	if (root == null) return null; // working copy not in workspace
842
	if (root.isArchive()) {
841
	return ((IContainer) ((Openable) this.parent).resource(root)).getFile(new Path(getElementName()));
843
		return root.getResource();
844
	} else {
845
		return ((IContainer) getParent().getResource()).getFile(new Path(getElementName()));
846
	}
847
}
842
}
848
/**
843
/**
849
 * @see ISourceReference#getSource()
844
 * @see ISourceReference#getSource()
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-12 / +27 lines)
Lines 503-509 Link Here
503
503
504
				if (projectPath.isPrefixOf(entryPath)){
504
				if (projectPath.isPrefixOf(entryPath)){
505
					if (checkExistency) {
505
					if (checkExistency) {
506
						Object target = JavaModel.getTarget(workspaceRoot, entryPath, checkExistency);
506
						Object target = JavaModel.getTarget(entryPath, checkExistency);
507
						if (target == null) return;
507
						if (target == null) return;
508
	
508
	
509
						if (target instanceof IFolder || target instanceof IProject){
509
						if (target instanceof IFolder || target instanceof IProject){
Lines 521-536 Link Here
521
				if (referringEntry != null  && !resolvedEntry.isExported()) return;
521
				if (referringEntry != null  && !resolvedEntry.isExported()) return;
522
				
522
				
523
				if (checkExistency) {
523
				if (checkExistency) {
524
					Object target = JavaModel.getTarget(workspaceRoot, entryPath, checkExistency);
524
					Object target = JavaModel.getTarget(entryPath, checkExistency);
525
					if (target == null) return;
525
					if (target == null) return;
526
	
526
	
527
					if (target instanceof IResource){
527
					if (target instanceof IResource){
528
						// internal target
528
						// internal target
529
						root = getPackageFragmentRoot((IResource) target);
529
						root = getPackageFragmentRoot((IResource) target, entryPath);
530
					} else {
530
					} else if (target instanceof File) {
531
						// external target - only JARs allowed
531
						// external target
532
						if (JavaModel.isFile(target) && (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(entryPath.lastSegment()))) {
532
						if (JavaModel.isFile(target) && (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(entryPath.lastSegment()))) {
533
							root = new JarPackageFragmentRoot(entryPath, this);
533
							root = new JarPackageFragmentRoot(entryPath, this);
534
						} else if (((File) target).isDirectory()) {
535
							root = new ExternalPackageFragmentRoot(entryPath, this);
534
						}
536
						}
535
					}
537
					}
536
				} else {
538
				} else {
Lines 672-681 Link Here
672
		IPath fullPath = resource.getFullPath();
674
		IPath fullPath = resource.getFullPath();
673
		IPath innerMostOutput = output.isPrefixOf(fullPath) ? output : null;
675
		IPath innerMostOutput = output.isPrefixOf(fullPath) ? output : null;
674
		IClasspathEntry innerMostEntry = null;
676
		IClasspathEntry innerMostEntry = null;
677
		ExternalFoldersManager foldersManager = JavaModelManager.getExternalManager();
675
		for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
678
		for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
676
			IClasspathEntry entry = classpath[j];
679
			IClasspathEntry entry = classpath[j];
677
		
680
		
678
			IPath entryPath = entry.getPath();
681
			IPath entryPath = entry.getPath();
682
			if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
683
				IResource linkedFolder = foldersManager.getFolder(entryPath);
684
				if (linkedFolder != null)
685
					entryPath = linkedFolder.getFullPath();
686
			}
679
			if ((innerMostEntry == null || innerMostEntry.getPath().isPrefixOf(entryPath))
687
			if ((innerMostEntry == null || innerMostEntry.getPath().isPrefixOf(entryPath))
680
					&& entryPath.isPrefixOf(fullPath)) {
688
					&& entryPath.isPrefixOf(fullPath)) {
681
				innerMostEntry = entry;
689
				innerMostEntry = entry;
Lines 1641-1647 Link Here
1641
	 * @see IJavaProject
1649
	 * @see IJavaProject
1642
	 */
1650
	 */
1643
	public IPackageFragmentRoot getPackageFragmentRoot(IResource resource) {
1651
	public IPackageFragmentRoot getPackageFragmentRoot(IResource resource) {
1644
1652
		return getPackageFragmentRoot(resource, null/*no entry path*/);
1653
	}
1654
		
1655
	private IPackageFragmentRoot getPackageFragmentRoot(IResource resource, IPath entryPath) {
1645
		switch (resource.getType()) {
1656
		switch (resource.getType()) {
1646
			case IResource.FILE:
1657
			case IResource.FILE:
1647
				if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resource.getName())) {
1658
				if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resource.getName())) {
Lines 1650-1655 Link Here
1650
					return null;
1661
					return null;
1651
				}
1662
				}
1652
			case IResource.FOLDER:
1663
			case IResource.FOLDER:
1664
				if (ExternalFoldersManager.isExternal(resource.getFullPath()))
1665
					return new ExternalPackageFragmentRoot(resource, entryPath, this);
1653
				return new PackageFragmentRoot(resource, this);
1666
				return new PackageFragmentRoot(resource, this);
1654
			case IResource.PROJECT:
1667
			case IResource.PROJECT:
1655
				return new PackageFragmentRoot(resource, this);
1668
				return new PackageFragmentRoot(resource, this);
Lines 1661-1677 Link Here
1661
	/**
1674
	/**
1662
	 * @see IJavaProject
1675
	 * @see IJavaProject
1663
	 */
1676
	 */
1664
	public IPackageFragmentRoot getPackageFragmentRoot(String jarPath) {
1677
	public IPackageFragmentRoot getPackageFragmentRoot(String libraryPath) {
1665
1678
1666
		return getPackageFragmentRoot0(JavaProject.canonicalizedPath(new Path(jarPath)));
1679
		return getPackageFragmentRoot0(JavaProject.canonicalizedPath(new Path(libraryPath)));
1667
	}
1680
	}
1668
1681
1669
	/*
1682
	/*
1670
	 * no path canonicalization
1683
	 * no path canonicalization
1671
	 */
1684
	 */
1672
	public IPackageFragmentRoot getPackageFragmentRoot0(IPath jarPath) {
1685
	public IPackageFragmentRoot getPackageFragmentRoot0(IPath libraryPath) {
1673
1686
		if (!org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(libraryPath.lastSegment()))
1674
		return new JarPackageFragmentRoot(jarPath, this);
1687
			return new ExternalPackageFragmentRoot(libraryPath, this);
1688
		return new JarPackageFragmentRoot(libraryPath, this);
1689
		
1675
	}
1690
	}
1676
1691
1677
	/**
1692
	/**
Lines 1879-1885 Link Here
1879
	/**
1894
	/**
1880
	 * @see IJavaElement
1895
	 * @see IJavaElement
1881
	 */
1896
	 */
1882
	public IResource getResource() {
1897
	public IResource resource(PackageFragmentRoot root) {
1883
		return this.project;
1898
		return this.project;
1884
	}
1899
	}
1885
1900
(-)model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java (+2 lines)
Lines 54-59 Link Here
54
 * @exception JavaModelException  The resource associated with this package fragment does not exist
54
 * @exception JavaModelException  The resource associated with this package fragment does not exist
55
 */
55
 */
56
static Object[] computeFolderNonJavaResources(JavaProject project, IContainer folder, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException {
56
static Object[] computeFolderNonJavaResources(JavaProject project, IContainer folder, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException {
57
	if (ExternalFoldersManager.isExternal(folder.getFullPath()))
58
		return NO_NON_JAVA_RESOURCES;
57
	Object[] nonJavaResources = new IResource[5];
59
	Object[] nonJavaResources = new IResource[5];
58
	int nonJavaResourcesCounter = 0;
60
	int nonJavaResourcesCounter = 0;
59
	try {
61
	try {
(-)model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java (-6 / +7 lines)
Lines 14-20 Link Here
14
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.IBuffer;
16
import org.eclipse.jdt.core.IBuffer;
17
import org.eclipse.jdt.core.IClassFile;
18
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaModelStatusConstants;
18
import org.eclipse.jdt.core.IJavaModelStatusConstants;
20
import org.eclipse.jdt.core.JavaModelException;
19
import org.eclipse.jdt.core.JavaModelException;
Lines 31-40 Link Here
31
 */
30
 */
32
public class ClassFileWorkingCopy extends CompilationUnit {
31
public class ClassFileWorkingCopy extends CompilationUnit {
33
	
32
	
34
	public IClassFile classFile;
33
	public ClassFile classFile;
35
	
34
	
36
public ClassFileWorkingCopy(IClassFile classFile, WorkingCopyOwner owner) {
35
public ClassFileWorkingCopy(ClassFile classFile, WorkingCopyOwner owner) {
37
	super((PackageFragment) classFile.getParent(), ((BinaryType) ((ClassFile) classFile).getType()).getSourceFileName(null/*no info available*/), owner);
36
	super((PackageFragment) classFile.getParent(), ((BinaryType) classFile.getType()).getSourceFileName(null/*no info available*/), owner);
38
	this.classFile = classFile;
37
	this.classFile = classFile;
39
}
38
}
40
39
Lines 70-77 Link Here
70
	return new ClassFileWorkingCopy(this.classFile, DefaultWorkingCopyOwner.PRIMARY);
69
	return new ClassFileWorkingCopy(this.classFile, DefaultWorkingCopyOwner.PRIMARY);
71
}
70
}
72
71
73
public IResource getResource() {
72
public IResource resource(PackageFragmentRoot root) {
74
	return this.classFile.getResource();
73
	if (root.isArchive())
74
		return root.resource(root);
75
	return this.classFile.resource(root);
75
}
76
}
76
77
77
/**
78
/**
(-)model/org/eclipse/jdt/internal/core/JavaModel.java (-26 / +39 lines)
Lines 15-21 Link Here
15
import java.util.HashSet;
15
import java.util.HashSet;
16
import java.util.Map;
16
import java.util.Map;
17
17
18
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFolder;
19
import org.eclipse.core.resources.IFolder;
21
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProject;
Lines 235-241 Link Here
235
/*
234
/*
236
 * @see IJavaElement
235
 * @see IJavaElement
237
 */
236
 */
238
public IResource getResource() {
237
public IResource resource(PackageFragmentRoot root) {
239
	return ResourcesPlugin.getWorkspace().getRoot();
238
	return ResourcesPlugin.getWorkspace().getRoot();
240
}
239
}
241
/**
240
/**
Lines 313-358 Link Here
313
 * or null if unbound
312
 * or null if unbound
314
 * Internal items must be referred to using container relative paths.
313
 * Internal items must be referred to using container relative paths.
315
 */
314
 */
316
public static Object getTarget(IContainer container, IPath path, boolean checkResourceExistence) {
315
public static Object getTarget(IPath path, boolean checkResourceExistence) {
317
316
	Object target = getWorkspaceTarget(path); // Implicitly checks resource existence
318
	if (path == null) return null;
317
	if (target != null)
319
	
318
		return target;
320
	// lookup - inside the container
319
	return getExternalTarget(path, checkResourceExistence);
321
	if (path.getDevice() == null) { // container relative paths should not contain a device 
320
}
322
												// (see http://dev.eclipse.org/bugs/show_bug.cgi?id=18684)
321
public static Object getWorkspaceTarget(IPath path) {
323
												// (case of a workspace rooted at d:\ )
322
	if (path == null || path.getDevice() != null)
324
		IResource resource = container.findMember(path);
323
		return null;
325
		if (resource != null){
324
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
326
			if (!checkResourceExistence ||resource.exists()) return resource;
325
	if (workspace == null)
327
			return null;
326
		return null;
327
	return workspace.getRoot().findMember(path);
328
}
329
public static Object getExternalTarget(IPath path, boolean checkResourceExistence) {
330
	if (path == null)
331
		return null;
332
	ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
333
	Object linkedFolder = externalFoldersManager.getFolder(path);
334
	if (linkedFolder != null) {
335
		if (checkResourceExistence) {
336
			// check if external folder is present
337
			File externalFile = new File(path.toOSString());
338
			if (!externalFile.isDirectory()) {
339
				return null;
340
			}
328
		}
341
		}
342
		return linkedFolder;
329
	}
343
	}
330
	
331
	// if path is relative, it cannot be an external path
332
	// (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
333
	if (!path.isAbsolute()) return null; 
334
335
	// lookup - outside the container
336
	return getTargetAsExternalFile(path, checkResourceExistence);	
337
}
338
private synchronized static Object getTargetAsExternalFile(IPath path, boolean checkResourceExistence) {
339
	File externalFile = new File(path.toOSString());
344
	File externalFile = new File(path.toOSString());
340
	if (!checkResourceExistence) {
345
	if (!checkResourceExistence) {
341
		return externalFile;
346
		return externalFile;
342
	} else if (existingExternalFiles.contains(externalFile)) {
347
	} else if (existingExternalFilesContains(externalFile)) {
343
		return externalFile;
348
		return externalFile;
344
	} else { 
349
	} else { 
345
		if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
350
		if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
346
			System.out.println("(" + Thread.currentThread() + ") [JavaModel.getTarget(...)] Checking existence of " + path.toString()); //$NON-NLS-1$ //$NON-NLS-2$
351
			System.out.println("(" + Thread.currentThread() + ") [JavaModel.getTarget(...)] Checking existence of " + path.toString()); //$NON-NLS-1$ //$NON-NLS-2$
347
		}
352
		}
348
		if (externalFile.exists()) {
353
		if (externalFile.isFile()) { // isFile() checks for existence (it returns false if a directory)
349
			// cache external file
354
			// cache external file
350
			existingExternalFiles.add(externalFile);
355
			existingExternalFilesAdd(externalFile);
351
			return externalFile;
356
			return externalFile;
357
		} else if (externalFile.isDirectory()) {
358
			return externalFoldersManager.addFolder(path);
352
		}
359
		}
353
	}
360
	}
354
	return null;
361
	return null;
355
}
362
}
363
private synchronized static void existingExternalFilesAdd(File externalFile) {
364
	existingExternalFiles.add(externalFile);
365
}
366
private synchronized static boolean existingExternalFilesContains(File externalFile) {
367
	return existingExternalFiles.contains(externalFile);
368
}
356
369
357
/**
370
/**
358
 * Helper method - returns whether an object is afile (ie. which returns true to {@link java.io.File#isFile()}.
371
 * Helper method - returns whether an object is afile (ie. which returns true to {@link java.io.File#isFile()}.
(-)model/org/eclipse/jdt/internal/core/PackageFragment.java (-15 / +10 lines)
Lines 297-303 Link Here
297
		// We don't want to show non java resources of the default package (see PR #1G58NB8)
297
		// We don't want to show non java resources of the default package (see PR #1G58NB8)
298
		return JavaElementInfo.NO_NON_JAVA_RESOURCES;
298
		return JavaElementInfo.NO_NON_JAVA_RESOURCES;
299
	} else {
299
	} else {
300
		return ((PackageFragmentInfo) getElementInfo()).getNonJavaResources(getResource(), getPackageFragmentRoot());
300
		return ((PackageFragmentInfo) getElementInfo()).getNonJavaResources(resource(), getPackageFragmentRoot());
301
	}
301
	}
302
}
302
}
303
/**
303
/**
Lines 317-338 Link Here
317
	}
317
	}
318
}
318
}
319
/**
319
/**
320
 * @see IJavaElement#getResource()
320
 * @see JavaElement#resource()
321
 */
321
 */
322
public IResource getResource() {
322
public IResource resource(PackageFragmentRoot root) {
323
	PackageFragmentRoot root = this.getPackageFragmentRoot();
323
	int length = this.names.length;
324
	if (root.isArchive()) {
324
	if (length == 0) {
325
		return root.getResource();
325
		return root.resource(root);
326
	} else {
326
	} else {
327
		int length = this.names.length;
327
		IPath path = new Path(this.names[0]);
328
		if (length == 0) {
328
		for (int i = 1; i < length; i++)
329
			return root.getResource();
329
			path = path.append(this.names[i]);
330
		} else {
330
		return ((IContainer)root.resource(root)).getFolder(path);
331
			IPath path = new Path(this.names[0]);
332
			for (int i = 1; i < length; i++)
333
				path = path.append(this.names[i]);
334
			return ((IContainer)root.getResource()).getFolder(path);
335
		}
336
	}
331
	}
337
}
332
}
338
/**
333
/**
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-33 / +98 lines)
Lines 13-18 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.util.*;
14
import java.util.*;
15
15
16
import org.eclipse.core.resources.IContainer;
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFolder;
18
import org.eclipse.core.resources.IFolder;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IProject;
Lines 112-118 Link Here
112
				if (resource != null) {
113
				if (resource != null) {
113
					this.root = this.project.getPackageFragmentRoot(resource);
114
					this.root = this.project.getPackageFragmentRoot(resource);
114
				} else {
115
				} else {
115
					Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.rootPath, false/*don't check existence*/);
116
					Object target = JavaModel.getTarget(this.rootPath, false/*don't check existence*/);
116
					if (target instanceof IResource) {
117
					if (target instanceof IResource) {
117
						this.root = this.project.getPackageFragmentRoot((IResource)target);
118
						this.root = this.project.getPackageFragmentRoot((IResource)target);
118
					} else {
119
					} else {
Lines 340-345 Link Here
340
							readRawClasspath(javaProject);
341
							readRawClasspath(javaProject);
341
							// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121569)
342
							// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121569)
342
							checkProjectReferenceChange(project, javaProject);
343
							checkProjectReferenceChange(project, javaProject);
344
							// and external folders as well
345
							checkExternalFolderChange(project, javaProject);
343
						}
346
						}
344
						
347
						
345
						this.state.rootsAreStale = true; 
348
						this.state.rootsAreStale = true; 
Lines 359-364 Link Here
359
										readRawClasspath(javaProject);
362
										readRawClasspath(javaProject);
360
										// ensure project references are updated
363
										// ensure project references are updated
361
										checkProjectReferenceChange(project, javaProject);
364
										checkProjectReferenceChange(project, javaProject);
365
										// and external folders as well
366
										checkExternalFolderChange(project, javaProject);
362
									}
367
									}
363
								} else {
368
								} else {
364
									try {
369
									try {
Lines 386-391 Link Here
386
										readRawClasspath(javaProject);
391
										readRawClasspath(javaProject);
387
										// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172666)
392
										// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172666)
388
										checkProjectReferenceChange(project, javaProject);
393
										checkProjectReferenceChange(project, javaProject);
394
										// and external folders as well
395
										checkExternalFolderChange(project, javaProject);
389
									} else {
396
									} else {
390
										// remove classpath cache so that initializeRoots() will not consider the project has a classpath
397
										// remove classpath cache so that initializeRoots() will not consider the project has a classpath
391
										this.manager.removePerProjectInfo(javaProject);
398
										this.manager.removePerProjectInfo(javaProject);
Lines 471-476 Link Here
471
		}
478
		}
472
	}
479
	}
473
480
481
	private void checkExternalFolderChange(IProject project, JavaProject javaProject) {
482
		ClasspathChange change = (ClasspathChange) this.classpathChanges.get(project);
483
		this.state.addExternalFolderChange(javaProject, change == null ? null : change.oldResolvedClasspath);
484
	}
485
474
	private void checkProjectReferenceChange(IProject project, JavaProject javaProject) {
486
	private void checkProjectReferenceChange(IProject project, JavaProject javaProject) {
475
		ClasspathChange change = (ClasspathChange) this.classpathChanges.get(project);
487
		ClasspathChange change = (ClasspathChange) this.classpathChanges.get(project);
476
		this.state.addProjectReferenceChange(javaProject, change == null ? null : change.oldResolvedClasspath);
488
		this.state.addProjectReferenceChange(javaProject, change == null ? null : change.oldResolvedClasspath);
Lines 487-500 Link Here
487
		}
499
		}
488
	}
500
	}
489
	private void checkSourceAttachmentChange(IResourceDelta delta, IResource res) {
501
	private void checkSourceAttachmentChange(IResourceDelta delta, IResource res) {
490
		IPath rootPath = (IPath)this.state.sourceAttachments.get(res.getFullPath());
502
		IPath rootPath = (IPath)this.state.sourceAttachments.get(externalPath(res));
491
		if (rootPath != null) {
503
		if (rootPath != null) {
492
			RootInfo rootInfo = this.rootInfo(rootPath, delta.getKind());
504
			RootInfo rootInfo = this.rootInfo(rootPath, delta.getKind());
493
			if (rootInfo != null) {
505
			if (rootInfo != null) {
494
				IJavaProject projectOfRoot = rootInfo.project;
506
				IJavaProject projectOfRoot = rootInfo.project;
495
				IPackageFragmentRoot root = null;
507
				IPackageFragmentRoot root = null;
496
				try {
508
				try {
497
					// close the root so that source attachement cache is flushed
509
					// close the root so that source attachment cache is flushed
498
					root = projectOfRoot.findPackageFragmentRoot(rootPath);
510
					root = projectOfRoot.findPackageFragmentRoot(rootPath);
499
					if (root != null) {
511
					if (root != null) {
500
						root.close();
512
						root.close();
Lines 610-616 Link Here
610
					if (rootInfo.project.contains(resource)) {
622
					if (rootInfo.project.contains(resource)) {
611
						PackageFragmentRoot root = (PackageFragmentRoot) rootInfo.getPackageFragmentRoot(null);
623
						PackageFragmentRoot root = (PackageFragmentRoot) rootInfo.getPackageFragmentRoot(null);
612
						// create package handle
624
						// create package handle
613
						IPath pkgPath = path.removeFirstSegments(rootInfo.rootPath.segmentCount());
625
						IPath pkgPath = path.removeFirstSegments(root.resource().getFullPath().segmentCount());
614
						String[] pkgName = pkgPath.segments();
626
						String[] pkgName = pkgPath.segments();
615
						element = root.getPackageFragment(pkgName);
627
						element = root.getPackageFragment(pkgName);
616
					}
628
					}
Lines 834-840 Link Here
834
					if (status == null){
846
					if (status == null){
835
						
847
						
836
						// compute shared status
848
						// compute shared status
837
						Object targetLibrary = JavaModel.getTarget(wksRoot, entryPath, true);
849
						Object targetLibrary = JavaModel.getTarget(entryPath, true);
838
		
850
		
839
						if (targetLibrary == null){ // missing JAR
851
						if (targetLibrary == null){ // missing JAR
840
							if (this.state.getExternalLibTimeStamps().remove(entryPath) != null){
852
							if (this.state.getExternalLibTimeStamps().remove(entryPath) != null){
Lines 1047-1053 Link Here
1047
				}
1059
				}
1048
				
1060
				
1049
				// find the element type of the moved from element
1061
				// find the element type of the moved from element
1050
				RootInfo movedFromInfo = this.enclosingRootInfo(movedFromPath, IResourceDelta.REMOVED);
1062
				IPath rootPath = externalPath(movedFromRes);
1063
				RootInfo movedFromInfo = this.enclosingRootInfo(rootPath, IResourceDelta.REMOVED);
1051
				int movedFromType = 
1064
				int movedFromType = 
1052
					this.elementType(
1065
					this.elementType(
1053
						movedFromRes, 
1066
						movedFromRes, 
Lines 1133-1139 Link Here
1133
			}
1146
			}
1134
1147
1135
			// find the element type of the moved from element
1148
			// find the element type of the moved from element
1136
			RootInfo movedToInfo = this.enclosingRootInfo(movedToPath, IResourceDelta.ADDED);
1149
			IPath rootPath = externalPath(movedToRes);
1150
			RootInfo movedToInfo = this.enclosingRootInfo(rootPath, IResourceDelta.ADDED);
1137
			int movedToType = 
1151
			int movedToType = 
1138
				this.elementType(
1152
				this.elementType(
1139
					movedToRes, 
1153
					movedToRes, 
Lines 1208-1214 Link Here
1208
			case IJavaElement.PACKAGE_FRAGMENT_ROOT:
1222
			case IJavaElement.PACKAGE_FRAGMENT_ROOT:
1209
			case IJavaElement.PACKAGE_FRAGMENT:
1223
			case IJavaElement.PACKAGE_FRAGMENT:
1210
				if (rootInfo == null) {
1224
				if (rootInfo == null) {
1211
					rootInfo = this.enclosingRootInfo(res.getFullPath(), kind);
1225
					IPath rootPath = externalPath(res);
1226
					rootInfo = this.enclosingRootInfo(rootPath, kind);
1212
				}
1227
				}
1213
				if (rootInfo == null) {
1228
				if (rootInfo == null) {
1214
					return NON_JAVA_RESOURCE;
1229
					return NON_JAVA_RESOURCE;
Lines 1235-1246 Link Here
1235
					return IJavaElement.COMPILATION_UNIT;
1250
					return IJavaElement.COMPILATION_UNIT;
1236
				} else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) {
1251
				} else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) {
1237
					return IJavaElement.CLASS_FILE;
1252
					return IJavaElement.CLASS_FILE;
1238
				} else if ((rootInfo = this.rootInfo(res.getFullPath(), kind)) != null 
1239
						&& rootInfo.project.getProject().getFullPath().isPrefixOf(res.getFullPath()) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) {
1240
					// case of proj=src=bin and resource is a jar file on the classpath
1241
					return IJavaElement.PACKAGE_FRAGMENT_ROOT;
1242
				} else {
1253
				} else {
1243
					return NON_JAVA_RESOURCE;
1254
					IPath rootPath = externalPath(res);
1255
					if ((rootInfo = this.rootInfo(rootPath, kind)) != null 
1256
							&& rootInfo.project.getProject().getFullPath().isPrefixOf(rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) {
1257
						// case of proj=src=bin and resource is a jar file on the classpath
1258
						return IJavaElement.PACKAGE_FRAGMENT_ROOT;
1259
					} else {
1260
						return NON_JAVA_RESOURCE;
1261
					}
1244
				}
1262
				}
1245
				
1263
				
1246
			default:
1264
			default:
Lines 1253-1259 Link Here
1253
	public void flush() {
1271
	public void flush() {
1254
		this.javaModelDeltas = new ArrayList();
1272
		this.javaModelDeltas = new ArrayList();
1255
	}
1273
	}
1256
1274
	
1257
	private SourceElementParser getSourceElementParser(Openable element) {
1275
	private SourceElementParser getSourceElementParser(Openable element) {
1258
		if (this.sourceElementParserCache == null)
1276
		if (this.sourceElementParserCache == null)
1259
			this.sourceElementParserCache = this.manager.indexManager.getSourceElementParser(element.getJavaProject(), null/*requestor will be set by indexer*/);
1277
			this.sourceElementParserCache = this.manager.indexManager.getSourceElementParser(element.getJavaProject(), null/*requestor will be set by indexer*/);
Lines 1271-1276 Link Here
1271
		}
1289
		}
1272
		return null;
1290
		return null;
1273
	}
1291
	}
1292
1293
	private IPath externalPath(IResource res) {
1294
		IPath resourcePath = res.getFullPath();
1295
		if (ExternalFoldersManager.isExternal(resourcePath))
1296
			return res.getLocation();
1297
		return resourcePath;
1298
	}
1299
1274
	/*
1300
	/*
1275
	 * Fire Java Model delta, flushing them after the fact after post_change notification.
1301
	 * Fire Java Model delta, flushing them after the fact after post_change notification.
1276
	 * If the firing mode has been turned off, this has no effect. 
1302
	 * If the firing mode has been turned off, this has no effect. 
Lines 1391-1397 Link Here
1391
						}
1417
						}
1392
						return true;
1418
						return true;
1393
					}
1419
					}
1394
				});
1420
				},
1421
				IContainer.INCLUDE_HIDDEN);
1395
			} catch(FoundRelevantDeltaException e) {
1422
			} catch(FoundRelevantDeltaException e) {
1396
				//System.out.println("RELEVANT DELTA detected in: "+ (System.currentTimeMillis() - start));
1423
				//System.out.println("RELEVANT DELTA detected in: "+ (System.currentTimeMillis() - start));
1397
				return true;
1424
				return true;
Lines 1556-1563 Link Here
1556
	 * <li>An entry is made in the delta reporting a content change (K_CHANGE with F_CONTENT flag set).
1583
	 * <li>An entry is made in the delta reporting a content change (K_CHANGE with F_CONTENT flag set).
1557
	 * </ul>
1584
	 * </ul>
1558
	 */
1585
	 */
1559
	private void nonJavaResourcesChanged(Openable element, IResourceDelta delta)
1586
	private void nonJavaResourcesChanged(Openable element, IResourceDelta delta) 	throws JavaModelException {
1560
		throws JavaModelException {
1587
		if (ExternalFoldersManager.isExternal(delta.getFullPath()))
1588
			return;
1561
1589
1562
		// reset non-java resources if element was open
1590
		// reset non-java resources if element was open
1563
		if (element.isOpen()) {
1591
		if (element.isOpen()) {
Lines 1655-1661 Link Here
1655
			if (this.currentElement instanceof IPackageFragmentRoot) {
1683
			if (this.currentElement instanceof IPackageFragmentRoot) {
1656
				currentElementPath = ((IPackageFragmentRoot)this.currentElement).getPath();
1684
				currentElementPath = ((IPackageFragmentRoot)this.currentElement).getPath();
1657
			} else {
1685
			} else {
1658
				IResource currentElementResource = this.currentElement.getResource();
1686
				IResource currentElementResource = this.currentElement.resource();
1659
				if (currentElementResource != null) {
1687
				if (currentElementResource != null) {
1660
					currentElementPath = currentElementResource.getFullPath();
1688
					currentElementPath = currentElementResource.getFullPath();
1661
				}
1689
				}
Lines 1698-1704 Link Here
1698
			this.currentElement = null;
1726
			this.currentElement = null;
1699
			
1727
			
1700
			// get the workspace delta, and start processing there.
1728
			// get the workspace delta, and start processing there.
1701
			IResourceDelta[] deltas = changes.getAffectedChildren();
1729
			IResourceDelta[] deltas = changes.getAffectedChildren(IResourceDelta.ADDED | IResourceDelta.REMOVED | IResourceDelta.CHANGED, IContainer.INCLUDE_HIDDEN);
1702
			for (int i = 0; i < deltas.length; i++) {
1730
			for (int i = 0; i < deltas.length; i++) {
1703
				IResourceDelta delta = deltas[i];
1731
				IResourceDelta delta = deltas[i];
1704
				IResource res = delta.getResource();
1732
				IResource res = delta.getResource();
Lines 1712-1719 Link Here
1712
				if (!wasJavaProject && !isJavaProject) {
1740
				if (!wasJavaProject && !isJavaProject) {
1713
					elementType = NON_JAVA_RESOURCE;
1741
					elementType = NON_JAVA_RESOURCE;
1714
				} else {
1742
				} else {
1715
					rootInfo = this.enclosingRootInfo(res.getFullPath(), delta.getKind());
1743
					IPath rootPath = externalPath(res);
1716
					if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) {
1744
					rootInfo = this.enclosingRootInfo(rootPath, delta.getKind());
1745
					if (rootInfo != null && rootInfo.isRootOfProject(rootPath)) {
1717
						elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT;
1746
						elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT;
1718
					} else {
1747
					} else {
1719
						elementType = IJavaElement.JAVA_PROJECT; 
1748
						elementType = IJavaElement.JAVA_PROJECT; 
Lines 1843-1848 Link Here
1843
									if ((result & ClasspathChange.HAS_PROJECT_CHANGE) != 0) {
1872
									if ((result & ClasspathChange.HAS_PROJECT_CHANGE) != 0) {
1844
										this.state.addProjectReferenceChange(change.project, change.oldResolvedClasspath);
1873
										this.state.addProjectReferenceChange(change.project, change.oldResolvedClasspath);
1845
									}
1874
									}
1875
									if ((result & ClasspathChange.HAS_LIBRARY_CHANGE) != 0) {
1876
										state.addExternalFolderChange(change.project, change.oldResolvedClasspath);
1877
									}
1846
								}
1878
								}
1847
								this.classpathChanges.clear();
1879
								this.classpathChanges.clear();
1848
								if (!hasDelta)
1880
								if (!hasDelta)
Lines 1853-1862 Link Here
1853
							if (elementsToRefresh == null) {
1885
							if (elementsToRefresh == null) {
1854
								elementsToRefresh = this.state.removeExternalElementsToRefresh();
1886
								elementsToRefresh = this.state.removeExternalElementsToRefresh();
1855
							} else {
1887
							} else {
1856
								HashSet existingElements = this.state.removeExternalElementsToRefresh();
1888
								HashSet newElementsToRefresh = this.state.removeExternalElementsToRefresh();
1857
								if (existingElements != null) {
1889
								if (newElementsToRefresh != null)
1858
									elementsToRefresh.addAll(existingElements);
1890
									elementsToRefresh.addAll(newElementsToRefresh);
1859
								}
1860
							}
1891
							}
1861
							
1892
							
1862
							// generate external archive change deltas
1893
							// generate external archive change deltas
Lines 1893-1898 Link Here
1893
				boolean isAffected = isAffectedBy(delta);
1924
				boolean isAffected = isAffectedBy(delta);
1894
				boolean needCycleValidation = isAffected && validateClasspaths(delta);
1925
				boolean needCycleValidation = isAffected && validateClasspaths(delta);
1895
1926
1927
				// update external folders if necessary
1928
			    ExternalFolderChange[] folderChanges = this.state.removeExternalFolderChanges();
1929
				if (folderChanges != null) {
1930
				    for (int i = 0, length = folderChanges.length; i < length; i++) {
1931
				        try {
1932
					        folderChanges[i].updateExternalFoldersIfNecessary(null);
1933
				        } catch (JavaModelException e) {
1934
				        	if (!e.isDoesNotExist())
1935
				        		Util.log(e, "Exception while updating external folders"); //$NON-NLS-1$
1936
				        }
1937
				    }
1938
				}
1939
				
1896
				// create classpath markers if necessary
1940
				// create classpath markers if necessary
1897
				ClasspathValidation[] validations = this.state.removeClasspathValidations();
1941
				ClasspathValidation[] validations = this.state.removeClasspathValidations();
1898
				if (validations != null) {
1942
				if (validations != null) {
Lines 1910-1915 Link Here
1910
					        projectRefChanges[i].updateProjectReferencesIfNecessary();
1954
					        projectRefChanges[i].updateProjectReferencesIfNecessary();
1911
				        } catch(JavaModelException e) {
1955
				        } catch(JavaModelException e) {
1912
				            // project doesn't exist any longer, continue with next one
1956
				            // project doesn't exist any longer, continue with next one
1957
				        	if (!e.isDoesNotExist())
1958
				        		Util.log(e, "Exception while updating project references"); //$NON-NLS-1$
1913
				        }
1959
				        }
1914
				    }
1960
				    }
1915
				}
1961
				}
Lines 2016-2024 Link Here
2016
				this.checkSourceAttachmentChange(child, childRes);
2062
				this.checkSourceAttachmentChange(child, childRes);
2017
				
2063
				
2018
				// find out whether the child is a package fragment root of the current project
2064
				// find out whether the child is a package fragment root of the current project
2019
				IPath childPath = childRes.getFullPath();
2065
				IPath childPath = externalPath(childRes);
2020
				int childKind = child.getKind();
2066
				int childKind = child.getKind();
2021
				RootInfo childRootInfo = this.rootInfo(childPath, childKind);
2067
				RootInfo childRootInfo = this.rootInfo(childPath, childKind);
2068
				RootInfo originalChildRootInfo = childRootInfo;
2022
				if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
2069
				if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
2023
					// package fragment root of another project (dealt with later)
2070
					// package fragment root of another project (dealt with later)
2024
					childRootInfo = null;
2071
					childRootInfo = null;
Lines 2091-2098 Link Here
2091
				// or if it is not a package fragment root of the current project
2138
				// or if it is not a package fragment root of the current project
2092
				// but it is a package fragment root of another project, traverse delta too
2139
				// but it is a package fragment root of another project, traverse delta too
2093
				if (isNestedRoot 
2140
				if (isNestedRoot 
2094
						|| (childRootInfo == null && (childRootInfo = this.rootInfo(childPath, childKind)) != null)) {
2141
						|| (childRootInfo == null && originalChildRootInfo != null)) {
2095
					this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, childRootInfo, null); // binary output of childRootInfo.project cannot be this root
2142
					this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, null); // binary output of childRootInfo.project cannot be this root
2096
				}
2143
				}
2097
	
2144
	
2098
				// if the child is a package fragment root of one or several other projects
2145
				// if the child is a package fragment root of one or several other projects
Lines 2100-2108 Link Here
2100
				if ((rootList = this.otherRootsInfo(childPath, childKind)) != null) {
2147
				if ((rootList = this.otherRootsInfo(childPath, childKind)) != null) {
2101
					Iterator iterator = rootList.iterator();
2148
					Iterator iterator = rootList.iterator();
2102
					while (iterator.hasNext()) {
2149
					while (iterator.hasNext()) {
2103
						childRootInfo = (RootInfo) iterator.next();
2150
						originalChildRootInfo = (RootInfo) iterator.next();
2104
						this.currentElement = null; // ensure that 2 roots refering to the same resource don't share the current element (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 )
2151
						this.currentElement = null; // ensure that 2 roots refering to the same resource don't share the current element (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 )
2105
						this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, childRootInfo, null); // binary output of childRootInfo.project cannot be this root
2152
						this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, null); // binary output of childRootInfo.project cannot be this root
2106
					}
2153
					}
2107
				}
2154
				}
2108
			}
2155
			}
Lines 2285-2291 Link Here
2285
				return elementType == IJavaElement.PACKAGE_FRAGMENT;
2332
				return elementType == IJavaElement.PACKAGE_FRAGMENT;
2286
			case IResourceDelta.CHANGED :
2333
			case IResourceDelta.CHANGED :
2287
				int flags = delta.getFlags();
2334
				int flags = delta.getFlags();
2288
				if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.ENCODING) != 0) {
2335
				if (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT && (flags & IResourceDelta.LOCAL_CHANGED) != 0) {
2336
					// external folder added or removed
2337
					deltaRes = delta.getResource();
2338
					Object target = JavaModel.getExternalTarget(deltaRes.getLocation(), true/*check resource existence*/);
2339
					element = createElement(deltaRes, elementType, rootInfo);
2340
					updateIndex(element, delta);
2341
					if (target != null) {
2342
						// external folder added
2343
						elementAdded(element, delta, rootInfo);
2344
					} else {
2345
						// external folder removed
2346
						elementRemoved(element, delta, rootInfo);
2347
					}
2348
					this.state.addClasspathValidation(rootInfo.project);
2349
				} else if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.ENCODING) != 0) {
2289
					// content or encoding has changed
2350
					// content or encoding has changed
2290
					element = createElement(delta.getResource(), elementType, rootInfo);
2351
					element = createElement(delta.getResource(), elementType, rootInfo);
2291
					if (element == null) return false;
2352
					if (element == null) return false;
Lines 2397-2403 Link Here
2397
					break;
2458
					break;
2398
				}
2459
				}
2399
				int kind = delta.getKind();
2460
				int kind = delta.getKind();
2400
				if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED) {
2461
				if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED || (kind == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.LOCAL_CHANGED) != 0)) {
2401
					PackageFragmentRoot root = (PackageFragmentRoot)element;
2462
					PackageFragmentRoot root = (PackageFragmentRoot)element;
2402
					this.updateRootIndex(root, CharOperation.NO_STRINGS, delta);
2463
					this.updateRootIndex(root, CharOperation.NO_STRINGS, delta);
2403
					break;
2464
					break;
Lines 2405-2410 Link Here
2405
				// don't break as packages of the package fragment root can be indexed below
2466
				// don't break as packages of the package fragment root can be indexed below
2406
			case IJavaElement.PACKAGE_FRAGMENT :
2467
			case IJavaElement.PACKAGE_FRAGMENT :
2407
				switch (delta.getKind()) {
2468
				switch (delta.getKind()) {
2469
					case IResourceDelta.CHANGED:
2470
						if ((delta.getFlags() & IResourceDelta.LOCAL_CHANGED) == 0)
2471
							break;
2408
					case IResourceDelta.ADDED:
2472
					case IResourceDelta.ADDED:
2409
					case IResourceDelta.REMOVED:
2473
					case IResourceDelta.REMOVED:
2410
						IPackageFragment pkg = null;
2474
						IPackageFragment pkg = null;
Lines 2442-2448 Link Here
2442
			case IJavaElement.CLASS_FILE :
2506
			case IJavaElement.CLASS_FILE :
2443
				IFile file = (IFile) delta.getResource();
2507
				IFile file = (IFile) delta.getResource();
2444
				IJavaProject project = element.getJavaProject();
2508
				IJavaProject project = element.getJavaProject();
2445
				IPath binaryFolderPath = element.getPackageFragmentRoot().getPath();
2509
				PackageFragmentRoot root = element.getPackageFragmentRoot();
2510
				IPath binaryFolderPath = root.isExternal() && !root.isArchive() ? root.resource().getFullPath() : root.getPath();
2446
				// if the class file is part of the binary output, it has been created by
2511
				// if the class file is part of the binary output, it has been created by
2447
				// the java builder -> ignore
2512
				// the java builder -> ignore
2448
				try {
2513
				try {
(-)model/org/eclipse/jdt/internal/core/JavaElement.java (-1 / +5 lines)
Lines 350-355 Link Here
350
	public IJavaElement getPrimaryElement(boolean checkOwner) {
350
	public IJavaElement getPrimaryElement(boolean checkOwner) {
351
		return this;
351
		return this;
352
	}
352
	}
353
	public IResource getResource() {
354
		return resource();
355
	}
356
	public abstract IResource resource();
353
	/**
357
	/**
354
	 * Returns the element that is located at the given source position
358
	 * Returns the element that is located at the given source position
355
	 * in this element.  This is a helper method for <code>ICompilationUnit#getElementAt</code>,
359
	 * in this element.  This is a helper method for <code>ICompilationUnit#getElementAt</code>,
Lines 410-416 Link Here
410
	 * @see org.eclipse.jdt.core.IJavaElement#getSchedulingRule()
414
	 * @see org.eclipse.jdt.core.IJavaElement#getSchedulingRule()
411
	 */
415
	 */
412
	public ISchedulingRule getSchedulingRule() {
416
	public ISchedulingRule getSchedulingRule() {
413
		IResource resource = getResource();
417
		IResource resource = resource();
414
		if (resource == null) {
418
		if (resource == null) {
415
			class NoResourceSchedulingRule implements ISchedulingRule {
419
			class NoResourceSchedulingRule implements ISchedulingRule {
416
				public IPath path;
420
				public IPath path;
(-)model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java (-25 / +20 lines)
Lines 62-68 Link Here
62
			monitor.beginTask(Messages.element_attachingSource, 2); 
62
			monitor.beginTask(Messages.element_attachingSource, 2); 
63
		}
63
		}
64
		SourceMapper oldMapper= getSourceMapper();
64
		SourceMapper oldMapper= getSourceMapper();
65
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
66
		boolean rootNeedsToBeClosed= false;
65
		boolean rootNeedsToBeClosed= false;
67
66
68
		if (sourcePath == null) {
67
		if (sourcePath == null) {
Lines 80-86 Link Here
80
		*/
79
		*/
81
		} else {
80
		} else {
82
		/*
81
		/*
83
			// fire a delta to notify the UI about the source attachement.
82
			// fire a delta to notify the UI about the source attachment.
84
			JavaModelManager manager = (JavaModelManager) JavaModelManager.getJavaModelManager();
83
			JavaModelManager manager = (JavaModelManager) JavaModelManager.getJavaModelManager();
85
			JavaModel model = (JavaModel) getJavaModel();
84
			JavaModel model = (JavaModel) getJavaModel();
86
			JavaElementDelta attachedSourceDelta = new JavaElementDelta(model);
85
			JavaElementDelta attachedSourceDelta = new JavaElementDelta(model);
Lines 101-107 Link Here
101
				}
100
				}
102
			}
101
			}
103
			// check if source path is valid
102
			// check if source path is valid
104
			Object target = JavaModel.getTarget(workspace.getRoot(), sourcePath, false);
103
			Object target = JavaModel.getTarget(sourcePath, false);
105
			if (target == null) {
104
			if (target == null) {
106
				throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, sourcePath));
105
				throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, sourcePath));
107
			}
106
			}
Lines 153-159 Link Here
153
 */
152
 */
154
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
153
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
155
	((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
154
	((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
156
	return computeChildren(info);
155
	return computeChildren(info, underlyingResource);
157
}
156
}
158
157
159
SourceMapper createSourceMapper(IPath sourcePath, IPath rootPath) {
158
SourceMapper createSourceMapper(IPath sourcePath, IPath rootPath) {
Lines 181-193 Link Here
181
 * 
180
 * 
182
 * @exception JavaModelException  The resource associated with this package fragment root does not exist
181
 * @exception JavaModelException  The resource associated with this package fragment root does not exist
183
 */
182
 */
184
protected boolean computeChildren(OpenableElementInfo info) throws JavaModelException {
183
protected boolean computeChildren(OpenableElementInfo info, IResource underlyingResource) throws JavaModelException {
185
	// Note the children are not opened (so not added to newElements) for a regular package fragment root
184
	// Note the children are not opened (so not added to newElements) for a regular package fragment root
186
	// Howver they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren)
185
	// However they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren)
187
	try {
186
	try {
188
		// the underlying resource may be a folder or a project (in the case that the project folder
187
		// the underlying resource may be a folder or a project (in the case that the project folder
189
		// is actually the package fragment root)
188
		// is actually the package fragment root)
190
		IResource underlyingResource = getResource();
191
		if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
189
		if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
192
			ArrayList vChildren = new ArrayList(5);
190
			ArrayList vChildren = new ArrayList(5);
193
			IContainer rootFolder = (IContainer) underlyingResource;
191
			IContainer rootFolder = (IContainer) underlyingResource;
Lines 324-330 Link Here
324
	if (!(o instanceof PackageFragmentRoot))
322
	if (!(o instanceof PackageFragmentRoot))
325
		return false;
323
		return false;
326
	PackageFragmentRoot other = (PackageFragmentRoot) o;
324
	PackageFragmentRoot other = (PackageFragmentRoot) o;
327
	return getResource().equals(other.getResource()) && 
325
	return resource().equals(other.resource()) && 
328
			this.parent.equals(other.parent);
326
			this.parent.equals(other.parent);
329
}
327
}
330
328
Lines 332-345 Link Here
332
	try {
330
	try {
333
		IPath rootPath = this.getPath();
331
		IPath rootPath = this.getPath();
334
		IClasspathEntry entry;
332
		IClasspathEntry entry;
335
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
336
		
333
		
337
		// try on enclosing project first
334
		// try on enclosing project first
338
		JavaProject parentProject = (JavaProject) getJavaProject();
335
		JavaProject parentProject = (JavaProject) getJavaProject();
339
		try {
336
		try {
340
			entry = parentProject.getClasspathEntryFor(rootPath);
337
			entry = parentProject.getClasspathEntryFor(rootPath);
341
			if (entry != null){
338
			if (entry != null){
342
				Object target = JavaModel.getTarget(workspaceRoot, entry.getSourceAttachmentPath(), true);
339
				Object target = JavaModel.getTarget(entry.getSourceAttachmentPath(), true);
343
				if (target instanceof IResource) {
340
				if (target instanceof IResource) {
344
					if (target instanceof IFile) {
341
					if (target instanceof IFile) {
345
						IFile file = (IFile) target;
342
						IFile file = (IFile) target;
Lines 374-380 Link Here
374
			try {
371
			try {
375
				entry = jProject.getClasspathEntryFor(rootPath);
372
				entry = jProject.getClasspathEntryFor(rootPath);
376
				if (entry != null){
373
				if (entry != null){
377
					Object target = JavaModel.getTarget(workspaceRoot, entry.getSourceAttachmentPath(), true);
374
					Object target = JavaModel.getTarget(entry.getSourceAttachmentPath(), true);
378
					if (target instanceof IResource) {
375
					if (target instanceof IResource) {
379
						if (target instanceof IFile){
376
						if (target instanceof IFile){
380
							IFile file = (IFile) target;
377
							IFile file = (IFile) target;
Lines 386-397 Link Here
386
						}
383
						}
387
					} else if (target instanceof java.io.File){
384
					} else if (target instanceof java.io.File){
388
						java.io.File file = (java.io.File) target;
385
						java.io.File file = (java.io.File) target;
389
						if (file.isFile()) {
386
						if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
390
							if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
391
								return entry;
392
							}
393
						} else {
394
							// external directory
395
							return entry;
387
							return entry;
396
						}
388
						}
397
					}
389
					}
Lines 441-447 Link Here
441
	}
433
	}
442
}		
434
}		
443
public String getElementName() {
435
public String getElementName() {
444
	IResource res = getResource();
436
	IResource res = resource();
445
	if (res instanceof IFolder)
437
	if (res instanceof IFolder)
446
		return ((IFolder) res).getName();
438
		return ((IFolder) res).getName();
447
	return ""; //$NON-NLS-1$
439
	return ""; //$NON-NLS-1$
Lines 492-501 Link Here
492
 */
484
 */
493
protected void getHandleMemento(StringBuffer buff) {
485
protected void getHandleMemento(StringBuffer buff) {
494
	IPath path;
486
	IPath path;
495
	IResource underlyingResource = getResource();
487
	IResource underlyingResource = resource();
496
	if (underlyingResource != null) {
488
	if (underlyingResource != null) {
497
		// internal jar or regular root
489
		// internal jar or regular root
498
		if (getResource().getProject().equals(getJavaProject().getProject())) {
490
		if (resource().getProject().equals(getJavaProject().getProject())) {
499
			path = underlyingResource.getProjectRelativePath();
491
			path = underlyingResource.getProjectRelativePath();
500
		} else {
492
		} else {
501
			path = underlyingResource.getFullPath();
493
			path = underlyingResource.getFullPath();
Lines 519-525 Link Here
519
 * Returns an array of non-java resources contained in the receiver.
511
 * Returns an array of non-java resources contained in the receiver.
520
 */
512
 */
521
public Object[] getNonJavaResources() throws JavaModelException {
513
public Object[] getNonJavaResources() throws JavaModelException {
522
	return ((PackageFragmentRootInfo) getElementInfo()).getNonJavaResources(getJavaProject(), getResource(), this);
514
	return ((PackageFragmentRootInfo) getElementInfo()).getNonJavaResources(getJavaProject(), resource(), this);
523
}
515
}
524
516
525
/**
517
/**
Lines 556-564 Link Here
556
 * @see IJavaElement
548
 * @see IJavaElement
557
 */
549
 */
558
public IPath getPath() {
550
public IPath getPath() {
559
	return getResource().getFullPath();
551
	return internalPath();
560
}
552
}
561
553
554
public IPath internalPath() {
555
	return resource().getFullPath();
556
}
562
/*
557
/*
563
 * @see IPackageFragmentRoot 
558
 * @see IPackageFragmentRoot 
564
 */
559
 */
Lines 580-586 Link Here
580
/*
575
/*
581
 * @see IJavaElement
576
 * @see IJavaElement
582
 */
577
 */
583
public IResource getResource() {
578
public IResource resource(PackageFragmentRoot root) {
584
	return (IResource)this.resource;
579
	return (IResource)this.resource;
585
}
580
}
586
581
Lines 692-698 Link Here
692
 */
687
 */
693
public IResource getUnderlyingResource() throws JavaModelException {
688
public IResource getUnderlyingResource() throws JavaModelException {
694
	if (!exists()) throw newNotPresentException();
689
	if (!exists()) throw newNotPresentException();
695
	return getResource();
690
	return resource();
696
}
691
}
697
692
698
/**
693
/**
Lines 704-710 Link Here
704
}
699
}
705
700
706
public int hashCode() {
701
public int hashCode() {
707
	return getResource().hashCode();
702
	return resource().hashCode();
708
}
703
}
709
704
710
/**
705
/**
(-)model/org/eclipse/jdt/internal/core/DeletePackageFragmentRootOperation.java (-3 / +3 lines)
Lines 62-68 Link Here
62
		IClasspathEntry rootEntry)
62
		IClasspathEntry rootEntry)
63
		throws JavaModelException {
63
		throws JavaModelException {
64
		final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
64
		final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
65
		IResource rootResource = root.getResource();
65
		IResource rootResource = ((JavaElement) root).resource();
66
		if (rootEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE || exclusionPatterns == null) {
66
		if (rootEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE || exclusionPatterns == null) {
67
			try {
67
			try {
68
				rootResource.delete(this.updateResourceFlags, progressMonitor);
68
				rootResource.delete(this.updateResourceFlags, progressMonitor);
Lines 147-158 Link Here
147
		if (!status.isOK()) {
147
		if (!status.isOK()) {
148
			return status;
148
			return status;
149
		}
149
		}
150
		IPackageFragmentRoot root = (IPackageFragmentRoot) this.getElementToProcess();
150
		IJavaElement root = getElementToProcess();
151
		if (root == null || !root.exists()) {
151
		if (root == null || !root.exists()) {
152
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, root);
152
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, root);
153
		}
153
		}
154
154
155
		IResource resource = root.getResource();
155
		IResource resource = ((JavaElement) root).resource();
156
		if (resource instanceof IFolder) {
156
		if (resource instanceof IFolder) {
157
			if (resource.isLinked()) {
157
			if (resource.isLinked()) {
158
				return new JavaModelStatus(IJavaModelStatusConstants.INVALID_RESOURCE, root);
158
				return new JavaModelStatus(IJavaModelStatusConstants.INVALID_RESOURCE, root);
(-)model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java (-1 / +1 lines)
Lines 248-254 Link Here
248
		try {
248
		try {
249
			if (!root.isOpen()) {
249
			if (!root.isOpen()) {
250
				PackageFragmentRootInfo info = root.isArchive() ? new JarPackageFragmentRootInfo() : new PackageFragmentRootInfo();
250
				PackageFragmentRootInfo info = root.isArchive() ? new JarPackageFragmentRootInfo() : new PackageFragmentRootInfo();
251
				((PackageFragmentRoot) root).computeChildren(info);
251
				((PackageFragmentRoot) root).computeChildren(info, ((JavaElement) root).resource());
252
				frags = info.children;
252
				frags = info.children;
253
			} else 
253
			} else 
254
				frags = root.getChildren();
254
				frags = root.getChildren();
(-)model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java (-4 / +4 lines)
Lines 74-80 Link Here
74
		JavaElementDelta delta = null;
74
		JavaElementDelta delta = null;
75
		PackageFragmentRoot root = (PackageFragmentRoot) getParentElement();
75
		PackageFragmentRoot root = (PackageFragmentRoot) getParentElement();
76
		beginTask(Messages.operation_createPackageFragmentProgress, this.pkgName.length); 
76
		beginTask(Messages.operation_createPackageFragmentProgress, this.pkgName.length); 
77
		IContainer parentFolder = (IContainer) root.getResource();
77
		IContainer parentFolder = (IContainer) root.resource();
78
		String[] sideEffectPackageName = CharOperation.NO_STRINGS; 
78
		String[] sideEffectPackageName = CharOperation.NO_STRINGS; 
79
		ArrayList results = new ArrayList(this.pkgName.length);
79
		ArrayList results = new ArrayList(this.pkgName.length);
80
		char[][] inclusionPatterns = root.fullInclusionPatternChars();
80
		char[][] inclusionPatterns = root.fullInclusionPatternChars();
Lines 114-120 Link Here
114
protected ISchedulingRule getSchedulingRule() {
114
protected ISchedulingRule getSchedulingRule() {
115
	if (this.pkgName.length == 0)
115
	if (this.pkgName.length == 0)
116
		return null; // no resource is going to be created
116
		return null; // no resource is going to be created
117
	IResource parentResource = getParentElement().getResource();
117
	IResource parentResource = ((JavaElement) getParentElement()).resource();
118
	IResource resource = ((IContainer) parentResource).getFolder(new Path(this.pkgName[0]));
118
	IResource resource = ((IContainer) parentResource).getFolder(new Path(this.pkgName[0]));
119
	return resource.getWorkspace().getRuleFactory().createRule(resource);
119
	return resource.getWorkspace().getRuleFactory().createRule(resource);
120
}
120
}
Lines 143-153 Link Here
143
	if (this.pkgName == null || (this.pkgName.length > 0 && JavaConventions.validatePackageName(packageName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR)) {
143
	if (this.pkgName == null || (this.pkgName.length > 0 && JavaConventions.validatePackageName(packageName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR)) {
144
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, packageName);
144
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, packageName);
145
	}
145
	}
146
	IPackageFragmentRoot root = (IPackageFragmentRoot) getParentElement();
146
	IJavaElement root = getParentElement();
147
	if (root.isReadOnly()) {
147
	if (root.isReadOnly()) {
148
		return new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, root);
148
		return new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, root);
149
	}
149
	}
150
	IContainer parentFolder = (IContainer) root.getResource();
150
	IContainer parentFolder = (IContainer) ((JavaElement) root).resource();
151
	int i;
151
	int i;
152
	for (i = 0; i < this.pkgName.length; i++) {
152
	for (i = 0; i < this.pkgName.length; i++) {
153
		IResource subFolder = parentFolder.findMember(this.pkgName[i]);
153
		IResource subFolder = parentFolder.findMember(this.pkgName[i]);
(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-7 / +7 lines)
Lines 233-240 Link Here
233
				classpathEntryName = manager.intern(getPath().segment(0));
233
				classpathEntryName = manager.intern(getPath().segment(0));
234
			} else {
234
			} else {
235
				classpathEntryType = AccessRestriction.LIBRARY;
235
				classpathEntryType = AccessRestriction.LIBRARY;
236
				Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, false);
236
				Object target = JavaModel.getWorkspaceTarget(path);
237
				if (target instanceof java.io.File) {
237
				if (target == null) {
238
					classpathEntryName = manager.intern(path.toOSString());
238
					classpathEntryName = manager.intern(path.toOSString());
239
				} else {
239
				} else {
240
					classpathEntryName = manager.intern(path.makeRelative().toString());
240
					classpathEntryName = manager.intern(path.makeRelative().toString());
Lines 1624-1630 Link Here
1624
			case IClasspathEntry.CPE_LIBRARY :
1624
			case IClasspathEntry.CPE_LIBRARY :
1625
				if (path.isAbsolute() && !path.isEmpty()) {
1625
				if (path.isAbsolute() && !path.isEmpty()) {
1626
					IPath sourceAttachment = entry.getSourceAttachmentPath();
1626
					IPath sourceAttachment = entry.getSourceAttachmentPath();
1627
					Object target = JavaModel.getTarget(workspaceRoot, path, true);
1627
					Object target = JavaModel.getTarget(path, true);
1628
					if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
1628
					if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
1629
						long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
1629
						long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
1630
						long libraryJDK = Util.getJdkLevel(target);
1630
						long libraryJDK = Util.getJdkLevel(target);
Lines 1640-1646 Link Here
1640
									if (checkSourceAttachment
1640
									if (checkSourceAttachment
1641
										&& sourceAttachment != null
1641
										&& sourceAttachment != null
1642
										&& !sourceAttachment.isEmpty()
1642
										&& !sourceAttachment.isEmpty()
1643
										&& JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
1643
										&& JavaModel.getTarget(sourceAttachment, true) == null){
1644
										return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
1644
										return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
1645
									}
1645
									}
1646
								} else {
1646
								} else {
Lines 1651-1657 Link Here
1651
								if (checkSourceAttachment
1651
								if (checkSourceAttachment
1652
									&& sourceAttachment != null
1652
									&& sourceAttachment != null
1653
									&& !sourceAttachment.isEmpty()
1653
									&& !sourceAttachment.isEmpty()
1654
									&& JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
1654
									&& JavaModel.getTarget(sourceAttachment, true) == null){
1655
									return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
1655
									return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
1656
								}
1656
								}
1657
						}
1657
						}
Lines 1664-1670 Link Here
1664
					    } else if (checkSourceAttachment
1664
					    } else if (checkSourceAttachment
1665
								&& sourceAttachment != null
1665
								&& sourceAttachment != null
1666
								&& !sourceAttachment.isEmpty()
1666
								&& !sourceAttachment.isEmpty()
1667
								&& JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
1667
								&& JavaModel.getTarget(sourceAttachment, true) == null){
1668
								return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), projectName}));
1668
								return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), projectName}));
1669
					    }
1669
					    }
1670
					} else {
1670
					} else {
Lines 1719-1725 Link Here
1719
				}
1719
				}
1720
				if (path.isAbsolute() && !path.isEmpty()) {
1720
				if (path.isAbsolute() && !path.isEmpty()) {
1721
					IPath projectPath= project.getProject().getFullPath();
1721
					IPath projectPath= project.getProject().getFullPath();
1722
					if (!projectPath.isPrefixOf(path) || JavaModel.getTarget(workspaceRoot, path, true) == null){
1722
					if (!projectPath.isPrefixOf(path) || JavaModel.getTarget(path, true) == null){
1723
						return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceFolder, new String[] {entryPathMsg, projectName}));
1723
						return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceFolder, new String[] {entryPathMsg, projectName}));
1724
					}
1724
					}
1725
				} else {
1725
				} else {
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-10 / +23 lines)
Lines 407-412 Link Here
407
	/* whether an AbortCompilationUnit should be thrown when the source of a compilation unit cannot be retrieved */
407
	/* whether an AbortCompilationUnit should be thrown when the source of a compilation unit cannot be retrieved */
408
	public ThreadLocal abortOnMissingSource = new ThreadLocal();
408
	public ThreadLocal abortOnMissingSource = new ThreadLocal();
409
	
409
	
410
	private ExternalFoldersManager externalFoldersManager = new ExternalFoldersManager();
411
	
410
	/**
412
	/**
411
	 * Returns whether the given full path (for a package) conflicts with the output location
413
	 * Returns whether the given full path (for a package) conflicts with the output location
412
	 * of the given project.
414
	 * of the given project.
Lines 899-909 Link Here
899
	 * the package fragment the given resource is located in, or <code>null</code>
901
	 * the package fragment the given resource is located in, or <code>null</code>
900
	 * if the given resource is not on the classpath of the given project.
902
	 * if the given resource is not on the classpath of the given project.
901
	 */
903
	 */
902
	public static IJavaElement determineIfOnClasspath(
904
	public static IJavaElement determineIfOnClasspath(IResource resource, IJavaProject project) {
903
		IResource resource,
904
		IJavaProject project) {
905
			
906
		IPath resourcePath = resource.getFullPath();
905
		IPath resourcePath = resource.getFullPath();
906
		boolean isExternal = ExternalFoldersManager.isExternal(resourcePath);
907
		if (isExternal)
908
			resourcePath = resource.getLocation();
909
		
907
		try {
910
		try {
908
			JavaProjectElementInfo projectInfo = (JavaProjectElementInfo) getJavaModelManager().getInfo(project);
911
			JavaProjectElementInfo projectInfo = (JavaProjectElementInfo) getJavaModelManager().getInfo(project);
909
			ProjectCache projectCache = projectInfo == null ? null : projectInfo.projectCache;
912
			ProjectCache projectCache = projectInfo == null ? null : projectInfo.projectCache;
Lines 927-933 Link Here
927
						// allow creation of package fragment if it contains a .java file that is included
930
						// allow creation of package fragment if it contains a .java file that is included
928
						if (!Util.isExcluded(resource, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars())) {
931
						if (!Util.isExcluded(resource, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars())) {
929
							// given we have a resource child of the root, it cannot be a JAR pkg root
932
							// given we have a resource child of the root, it cannot be a JAR pkg root
930
							PackageFragmentRoot root =(PackageFragmentRoot) ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
933
							PackageFragmentRoot root = 
934
								isExternal ? 
935
									new ExternalPackageFragmentRoot(rootPath, (JavaProject) project) : 
936
									(PackageFragmentRoot) ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
931
							if (root == null) return null;
937
							if (root == null) return null;
932
							IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
938
							IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
933
	
939
	
Lines 1031-1045 Link Here
1031
		public void rememberExternalLibTimestamps() {
1037
		public void rememberExternalLibTimestamps() {
1032
			IClasspathEntry[] classpath = this.resolvedClasspath;
1038
			IClasspathEntry[] classpath = this.resolvedClasspath;
1033
			if (classpath == null) return;
1039
			if (classpath == null) return;
1034
			IWorkspaceRoot wRoot = ResourcesPlugin.getWorkspace().getRoot();
1035
			Map externalTimeStamps = JavaModelManager.getJavaModelManager().deltaState.getExternalLibTimeStamps();
1040
			Map externalTimeStamps = JavaModelManager.getJavaModelManager().deltaState.getExternalLibTimeStamps();
1036
			for (int i = 0, length = classpath.length; i < length; i++) {
1041
			for (int i = 0, length = classpath.length; i < length; i++) {
1037
				IClasspathEntry entry = classpath[i];
1042
				IClasspathEntry entry = classpath[i];
1038
				if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
1043
				if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
1039
					IPath path = entry.getPath();
1044
					IPath path = entry.getPath();
1040
					if (externalTimeStamps.get(path) == null) {
1045
					if (externalTimeStamps.get(path) == null) {
1041
						Object target = JavaModel.getTarget(wRoot, path, true);
1046
						Object target = JavaModel.getExternalTarget(path, true);
1042
						if (target instanceof java.io.File) {
1047
						if (target instanceof File) {
1043
							long timestamp = DeltaProcessor.getTimeStamp((java.io.File)target);
1048
							long timestamp = DeltaProcessor.getTimeStamp((java.io.File)target);
1044
							externalTimeStamps.put(path, new Long(timestamp));
1049
							externalTimeStamps.put(path, new Long(timestamp));
1045
						}
1050
						}
Lines 1643-1648 Link Here
1643
		return this.elementsOutOfSynchWithBuffers;
1648
		return this.elementsOutOfSynchWithBuffers;
1644
	}
1649
	}
1645
1650
1651
	public static ExternalFoldersManager getExternalManager() {
1652
		return MANAGER.externalFoldersManager;
1653
	}
1654
1646
	public static IndexManager getIndexManager() {
1655
	public static IndexManager getIndexManager() {
1647
		return MANAGER.indexManager;
1656
		return MANAGER.indexManager;
1648
	}
1657
	}
Lines 3653-3658 Link Here
3653
					&& this.workspaceScope != null) { 
3662
					&& this.workspaceScope != null) { 
3654
				manager.cleanUpIndexes();
3663
				manager.cleanUpIndexes();
3655
			}
3664
			}
3665
			
3666
			// clean up external folders on full save
3667
			this.externalFoldersManager.cleanUp(null);
3656
		}
3668
		}
3657
	
3669
	
3658
		IProject savedProject = context.getProject();
3670
		IProject savedProject = context.getProject();
Lines 3689-3694 Link Here
3689
		
3701
		
3690
		// save external libs timestamps
3702
		// save external libs timestamps
3691
		this.deltaState.saveExternalLibTimeStamps();
3703
		this.deltaState.saveExternalLibTimeStamps();
3704
		
3692
	}
3705
	}
3693
3706
3694
	/**
3707
	/**
Lines 4073-4080 Link Here
4073
				while (names.hasNext()) {
4086
				while (names.hasNext()) {
4074
					Map.Entry entry2 = (Map.Entry) names.next();
4087
					Map.Entry entry2 = (Map.Entry) names.next();
4075
					String typeName = (String) entry2.getKey();
4088
					String typeName = (String) entry2.getKey();
4076
					IType type = (IType) entry2.getValue();
4089
					JavaElement type = (JavaElement) entry2.getValue();
4077
					if (file.equals(type.getResource())) {
4090
					if (file.equals(type.resource())) {
4078
						if (removedNames == null) removedNames = new String[namesSize];
4091
						if (removedNames == null) removedNames = new String[namesSize];
4079
						namesSize--;
4092
						namesSize--;
4080
						removedNames[removedNamesCount++] = typeName;
4093
						removedNames[removedNamesCount++] = typeName;
(-)model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java (-14 / +9 lines)
Lines 15-21 Link Here
15
import java.util.zip.ZipFile;
15
import java.util.zip.ZipFile;
16
16
17
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.jdt.core.*;
20
import org.eclipse.jdt.core.*;
Lines 67-73 Link Here
67
	 * These are all of the directory zip entries, and any directories implied
66
	 * These are all of the directory zip entries, and any directories implied
68
	 * by the path of class files contained in the jar of this package fragment root.
67
	 * by the path of class files contained in the jar of this package fragment root.
69
	 */
68
	 */
70
	protected boolean computeChildren(OpenableElementInfo info) throws JavaModelException {
69
	protected boolean computeChildren(OpenableElementInfo info, IResource underlyingResource) throws JavaModelException {
71
		HashtableOfArrayToObject rawPackageInfo = new HashtableOfArrayToObject();
70
		HashtableOfArrayToObject rawPackageInfo = new HashtableOfArrayToObject();
72
		IJavaElement[] children;
71
		IJavaElement[] children;
73
		ZipFile jar = null;
72
		ZipFile jar = null;
Lines 168-189 Link Here
168
	public PackageFragment getPackageFragment(String[] pkgName) {
167
	public PackageFragment getPackageFragment(String[] pkgName) {
169
		return new JarPackageFragment(this, pkgName);
168
		return new JarPackageFragment(this, pkgName);
170
	}
169
	}
171
	/**
170
	public IPath internalPath() {
172
	 * @see IPackageFragmentRoot
173
	 */
174
	public IPath getPath() {
175
		if (isExternal()) {
171
		if (isExternal()) {
176
			return this.jarPath;
172
			return this.jarPath;
177
		} else {
173
		} else {
178
			return super.getPath();
174
			return super.internalPath();
179
		}
175
		}
180
	}
176
	}	
181
	public IResource getResource() {
177
	public IResource resource(PackageFragmentRoot root) {
182
		if (this.resource == null) {
178
		if (this.resource == null && org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(this.jarPath.lastSegment())) {
183
			this.resource = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.jarPath, false);
179
			this.resource = JavaModel.getTarget(this.jarPath, false);
184
		}
180
		}
185
		if (this.resource instanceof IResource) {
181
		if (this.resource instanceof IResource) {
186
			return super.getResource();
182
			return super.resource(root);
187
		} else {
183
		} else {
188
			// external jar
184
			// external jar
189
			return null;
185
			return null;
Lines 257-263 Link Here
257
	 * @see IPackageFragmentRoot
253
	 * @see IPackageFragmentRoot
258
	 */
254
	 */
259
	public boolean isExternal() {
255
	public boolean isExternal() {
260
		return getResource() == null;
256
		return resource() == null;
261
	}
257
	}
262
	/**
258
	/**
263
	 * Jars and jar entries are all read only
259
	 * Jars and jar entries are all read only
Lines 273-279 Link Here
273
	if (underlyingResource == null) {
269
	if (underlyingResource == null) {
274
		return 
270
		return 
275
			JavaModel.getTarget(
271
			JavaModel.getTarget(
276
				ResourcesPlugin.getWorkspace().getRoot(), 
277
				getPath(), // don't make the path relative as this is an external archive
272
				getPath(), // don't make the path relative as this is an external archive
278
				true) != null;
273
				true) != null;
279
	} else {
274
	} else {
(-)model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java (-15 / +15 lines)
Lines 108-114 Link Here
108
		for (int i = 0; i < children.length; i++) {
108
		for (int i = 0; i < children.length; i++) {
109
			IJavaElement child = children[i];
109
			IJavaElement child = children[i];
110
			if (child.getElementType() == childOfInterest) {
110
			if (child.getElementType() == childOfInterest) {
111
				correctKindChildren.add(child.getResource());
111
				correctKindChildren.add(((JavaElement) child).resource());
112
			}
112
			}
113
		}
113
		}
114
		// Gather non-java resources
114
		// Gather non-java resources
Lines 140-146 Link Here
140
	 */
140
	 */
141
	private boolean createNeededPackageFragments(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean moveFolder) throws JavaModelException {
141
	private boolean createNeededPackageFragments(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean moveFolder) throws JavaModelException {
142
		boolean containsReadOnlyPackageFragment = false;
142
		boolean containsReadOnlyPackageFragment = false;
143
		IContainer parentFolder = (IContainer) root.getResource();
143
		IContainer parentFolder = (IContainer) root.resource();
144
		JavaElementDelta projectDelta = null;
144
		JavaElementDelta projectDelta = null;
145
		String[] sideEffectPackageName = null;
145
		String[] sideEffectPackageName = null;
146
		char[][] inclusionPatterns = root.fullInclusionPatternChars();
146
		char[][] inclusionPatterns = root.fullInclusionPatternChars();
Lines 368-379 Link Here
368
	private void processPackageFragmentResource(PackageFragment source, PackageFragmentRoot root, String newName) throws JavaModelException {
368
	private void processPackageFragmentResource(PackageFragment source, PackageFragmentRoot root, String newName) throws JavaModelException {
369
		try {
369
		try {
370
			String[] newFragName = (newName == null) ? source.names : Util.getTrimmedSimpleNames(newName);
370
			String[] newFragName = (newName == null) ? source.names : Util.getTrimmedSimpleNames(newName);
371
			IPackageFragment newFrag = root.getPackageFragment(newFragName);
371
			PackageFragment newFrag = root.getPackageFragment(newFragName);
372
			IResource[] resources = collectResourcesOfInterest(source);
372
			IResource[] resources = collectResourcesOfInterest(source);
373
			
373
			
374
			// if isMove() can we move the folder itself ? (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=22458)
374
			// if isMove() can we move the folder itself ? (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=22458)
375
			boolean shouldMoveFolder = isMove() && !newFrag.getResource().exists(); // if new pkg fragment exists, it is an override
375
			boolean shouldMoveFolder = isMove() && !newFrag.resource().exists(); // if new pkg fragment exists, it is an override
376
			IFolder srcFolder = (IFolder)source.getResource();
376
			IFolder srcFolder = (IFolder)source.resource();
377
			IPath destPath = newFrag.getPath();
377
			IPath destPath = newFrag.getPath();
378
			if (shouldMoveFolder) {
378
			if (shouldMoveFolder) {
379
				// check if destination is not included in source
379
				// check if destination is not included in source
Lines 390-396 Link Here
390
					}
390
					}
391
				}	
391
				}	
392
			}
392
			}
393
			boolean containsReadOnlySubPackageFragments = createNeededPackageFragments((IContainer) source.getParent().getResource(), root, newFragName, shouldMoveFolder);
393
			boolean containsReadOnlySubPackageFragments = createNeededPackageFragments((IContainer) source.parent.resource(), root, newFragName, shouldMoveFolder);
394
			boolean sourceIsReadOnly = Util.isReadOnly(srcFolder);
394
			boolean sourceIsReadOnly = Util.isReadOnly(srcFolder);
395
	
395
	
396
			// Process resources
396
			// Process resources
Lines 479-485 Link Here
479
			if (isMove()) {
479
			if (isMove()) {
480
				// delete remaining files in this package (.class file in the case where Proj=src=bin)
480
				// delete remaining files in this package (.class file in the case where Proj=src=bin)
481
				// in case of a copy
481
				// in case of a copy
482
				updateReadOnlyPackageFragmentsForMove((IContainer) source.getParent().getResource(), root, newFragName, sourceIsReadOnly);
482
				updateReadOnlyPackageFragmentsForMove((IContainer) source.parent.resource(), root, newFragName, sourceIsReadOnly);
483
				if (srcFolder.exists()) {
483
				if (srcFolder.exists()) {
484
					IResource[] remaining = srcFolder.members();
484
					IResource[] remaining = srcFolder.members();
485
					for (int i = 0, length = remaining.length; i < length; i++) {
485
					for (int i = 0, length = remaining.length; i < length; i++) {
Lines 498-506 Link Here
498
					IResource rootResource;
498
					IResource rootResource;
499
					// check if source is included in destination
499
					// check if source is included in destination
500
					if (destPath.isPrefixOf(srcFolder.getFullPath())) {
500
					if (destPath.isPrefixOf(srcFolder.getFullPath())) {
501
						rootResource = newFrag.getResource();
501
						rootResource = newFrag.resource();
502
					} else {
502
					} else {
503
						rootResource =  source.getParent().getResource();
503
						rootResource =  source.parent.resource();
504
					}
504
					}
505
					
505
					
506
					// delete recursively empty folders
506
					// delete recursively empty folders
Lines 508-514 Link Here
508
				}
508
				}
509
			} else if (containsReadOnlySubPackageFragments) {
509
			} else if (containsReadOnlySubPackageFragments) {
510
				// in case of a copy
510
				// in case of a copy
511
				updateReadOnlyPackageFragmentsForCopy((IContainer) source.getParent().getResource(), root, newFragName);
511
				updateReadOnlyPackageFragmentsForCopy((IContainer) source.parent.resource(), root, newFragName);
512
			}
512
			}
513
			// workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=24505
513
			// workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=24505
514
			if (isEmpty && isMove() && !(Util.isExcluded(source) || Util.isExcluded(newFrag))) {
514
			if (isEmpty && isMove() && !(Util.isExcluded(source) || Util.isExcluded(newFrag))) {
Lines 592-599 Link Here
592
		}
592
		}
593
	}
593
	}
594
	
594
	
595
	private void updateReadOnlyPackageFragmentsForCopy(IContainer sourceFolder, IPackageFragmentRoot root, String[] newFragName) {
595
	private void updateReadOnlyPackageFragmentsForCopy(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName) {
596
		IContainer parentFolder = (IContainer) root.getResource();
596
		IContainer parentFolder = (IContainer) root.resource();
597
		for (int i = 0, length = newFragName.length; i <length; i++) {
597
		for (int i = 0, length = newFragName.length; i <length; i++) {
598
			String subFolderName = newFragName[i];
598
			String subFolderName = newFragName[i];
599
			parentFolder = parentFolder.getFolder(new Path(subFolderName));
599
			parentFolder = parentFolder.getFolder(new Path(subFolderName));
Lines 604-611 Link Here
604
		}
604
		}
605
	}
605
	}
606
606
607
	private void updateReadOnlyPackageFragmentsForMove(IContainer sourceFolder, IPackageFragmentRoot root, String[] newFragName, boolean sourceFolderIsReadOnly) {
607
	private void updateReadOnlyPackageFragmentsForMove(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean sourceFolderIsReadOnly) {
608
		IContainer parentFolder = (IContainer) root.getResource();
608
		IContainer parentFolder = (IContainer) root.resource();
609
		for (int i = 0, length = newFragName.length; i < length; i++) {
609
		for (int i = 0, length = newFragName.length; i < length; i++) {
610
			String subFolderName = newFragName[i];
610
			String subFolderName = newFragName[i];
611
			parentFolder = parentFolder.getFolder(new Path(subFolderName));
611
			parentFolder = parentFolder.getFolder(new Path(subFolderName));
Lines 682-688 Link Here
682
		if (element.isReadOnly() && (isRename() || isMove()))
682
		if (element.isReadOnly() && (isRename() || isMove()))
683
			error(IJavaModelStatusConstants.READ_ONLY, element);
683
			error(IJavaModelStatusConstants.READ_ONLY, element);
684
684
685
		IResource resource = element.getResource();
685
		IResource resource = ((JavaElement) element).resource();
686
		if (resource instanceof IFolder) {
686
		if (resource instanceof IFolder) {
687
			if (resource.isLinked()) {
687
			if (resource.isLinked()) {
688
				error(IJavaModelStatusConstants.INVALID_RESOURCE, element);
688
				error(IJavaModelStatusConstants.INVALID_RESOURCE, element);
(-)model/org/eclipse/jdt/internal/core/ClasspathChange.java (-13 / +22 lines)
Lines 39-45 Link Here
39
public class ClasspathChange {
39
public class ClasspathChange {
40
	public static int NO_DELTA = 0x00;
40
	public static int NO_DELTA = 0x00;
41
	public static int HAS_DELTA = 0x01;
41
	public static int HAS_DELTA = 0x01;
42
	public static int HAS_PROJECT_CHANGE = 0x10;
42
	public static int HAS_PROJECT_CHANGE = 0x02;
43
	public static int HAS_LIBRARY_CHANGE = 0x04;
43
	
44
	
44
	JavaProject project;
45
	JavaProject project;
45
	IClasspathEntry[] oldRawClasspath;
46
	IClasspathEntry[] oldRawClasspath;
Lines 297-312 Link Here
297
			int index = classpathContains(newResolvedClasspath, this.oldResolvedClasspath[i]);
298
			int index = classpathContains(newResolvedClasspath, this.oldResolvedClasspath[i]);
298
			if (index == -1) {
299
			if (index == -1) {
299
				// remote project changes
300
				// remote project changes
300
				if (this.oldResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
301
				int entryKind = this.oldResolvedClasspath[i].getEntryKind();
302
				if (entryKind == IClasspathEntry.CPE_PROJECT) {
301
					result |= HAS_PROJECT_CHANGE;
303
					result |= HAS_PROJECT_CHANGE;
302
					continue; 
304
					continue; 
303
				}
305
				}
306
				if (entryKind == IClasspathEntry.CPE_LIBRARY) {
307
					result |= HAS_LIBRARY_CHANGE;
308
				}
304
309
305
				IPackageFragmentRoot[] pkgFragmentRoots = null;
310
				PackageFragmentRoot[] pkgFragmentRoots = null;
306
				if (removedRoots != null) {
311
				if (removedRoots != null) {
307
					IPackageFragmentRoot oldRoot = (IPackageFragmentRoot)  removedRoots.get(this.oldResolvedClasspath[i].getPath());
312
					PackageFragmentRoot oldRoot = (PackageFragmentRoot)  removedRoots.get(this.oldResolvedClasspath[i].getPath());
308
					if (oldRoot != null) { // use old root if any (could be none if entry wasn't bound)
313
					if (oldRoot != null) { // use old root if any (could be none if entry wasn't bound)
309
						pkgFragmentRoots = new IPackageFragmentRoot[] { oldRoot };
314
						pkgFragmentRoots = new PackageFragmentRoot[] { oldRoot };
310
					}
315
					}
311
				}
316
				}
312
				if (pkgFragmentRoots == null) {
317
				if (pkgFragmentRoots == null) {
Lines 319-340 Link Here
319
							accumulatedRoots, 
324
							accumulatedRoots, 
320
							rootIDs,
325
							rootIDs,
321
							null, // inside original project
326
							null, // inside original project
322
							false, // don't check existency
327
							true, // check existency
323
							false, // don't retrieve exported roots
328
							false, // don't retrieve exported roots
324
							null); /*no reverse map*/
329
							null); /*no reverse map*/
325
						pkgFragmentRoots = new IPackageFragmentRoot[accumulatedRoots.size()];
330
						pkgFragmentRoots = new PackageFragmentRoot[accumulatedRoots.size()];
326
						accumulatedRoots.copyInto(pkgFragmentRoots);
331
						accumulatedRoots.copyInto(pkgFragmentRoots);
327
					} catch (JavaModelException e) {
332
					} catch (JavaModelException e) {
328
						pkgFragmentRoots =  new IPackageFragmentRoot[] {};
333
						pkgFragmentRoots =  new PackageFragmentRoot[] {};
329
					}
334
					}
330
				}
335
				}
331
				addClasspathDeltas(delta, pkgFragmentRoots, IJavaElementDelta.F_REMOVED_FROM_CLASSPATH);
336
				addClasspathDeltas(delta, pkgFragmentRoots, IJavaElementDelta.F_REMOVED_FROM_CLASSPATH);
332
				
337
				
333
				// remember timestamp of jars that were removed (in case they are added as external jar in the same operation)
338
				// remember timestamp of jars that were removed (in case they are added as external jar in the same operation)
334
				for (int j = 0, length = pkgFragmentRoots.length; j < length; j++) {
339
				for (int j = 0, length = pkgFragmentRoots.length; j < length; j++) {
335
					IPackageFragmentRoot root = pkgFragmentRoots[j];
340
					PackageFragmentRoot root = pkgFragmentRoots[j];
336
					if (root.isArchive() && !root.isExternal()) {
341
					if (root.isArchive() && !root.isExternal()) {
337
						URI location = root.getResource().getLocationURI();
342
						URI location = root.resource().getLocationURI();
338
						File file = null;
343
						File file = null;
339
						try {
344
						try {
340
							IFileStore fileStore = EFS.getStore(location);
345
							IFileStore fileStore = EFS.getStore(location);
Lines 391-400 Link Here
391
			int index = classpathContains(this.oldResolvedClasspath, newResolvedClasspath[i]);
396
			int index = classpathContains(this.oldResolvedClasspath, newResolvedClasspath[i]);
392
			if (index == -1) {
397
			if (index == -1) {
393
				// remote project changes
398
				// remote project changes
394
				if (newResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
399
				int entryKind = newResolvedClasspath[i].getEntryKind();
400
				if (entryKind == IClasspathEntry.CPE_PROJECT) {
395
					result |= HAS_PROJECT_CHANGE;
401
					result |= HAS_PROJECT_CHANGE;
396
					continue; 
402
					continue; 
397
				}
403
				}
404
				if (entryKind == IClasspathEntry.CPE_LIBRARY) {
405
					result |= HAS_LIBRARY_CHANGE;
406
				}
398
				addClasspathDeltas(delta, this.project.computePackageFragmentRoots(newResolvedClasspath[i]), IJavaElementDelta.F_ADDED_TO_CLASSPATH);
407
				addClasspathDeltas(delta, this.project.computePackageFragmentRoots(newResolvedClasspath[i]), IJavaElementDelta.F_ADDED_TO_CLASSPATH);
399
			} // classpath reordering has already been generated in previous loop
408
			} // classpath reordering has already been generated in previous loop
400
		}
409
		}
Lines 403-409 Link Here
403
		if ((newOutputLocation == null && this.oldOutputLocation != null) 
412
		if ((newOutputLocation == null && this.oldOutputLocation != null) 
404
				|| (newOutputLocation != null && !newOutputLocation.equals(this.oldOutputLocation))) {
413
				|| (newOutputLocation != null && !newOutputLocation.equals(this.oldOutputLocation))) {
405
			try {
414
			try {
406
				ArrayList added= determineAffectedPackageFragments(this.oldOutputLocation);
415
				ArrayList added = determineAffectedPackageFragments(this.oldOutputLocation);
407
				Iterator iter = added.iterator();
416
				Iterator iter = added.iterator();
408
				while (iter.hasNext()){
417
				while (iter.hasNext()){
409
					IPackageFragment frag= (IPackageFragment)iter.next();
418
					IPackageFragment frag= (IPackageFragment)iter.next();
Lines 412-418 Link Here
412
				}
421
				}
413
			
422
			
414
				// see if this will cause any package fragments to be removed
423
				// see if this will cause any package fragments to be removed
415
				ArrayList removed= determineAffectedPackageFragments(newOutputLocation);
424
				ArrayList removed = determineAffectedPackageFragments(newOutputLocation);
416
				iter = removed.iterator();
425
				iter = removed.iterator();
417
				while (iter.hasNext()) {
426
				while (iter.hasNext()) {
418
					IPackageFragment frag= (IPackageFragment)iter.next();
427
					IPackageFragment frag= (IPackageFragment)iter.next();
(-)model/org/eclipse/jdt/internal/core/DeltaProcessingState.java (-3 / +23 lines)
Lines 84-93 Link Here
84
	private HashMap classpathValidations = new HashMap();
84
	private HashMap classpathValidations = new HashMap();
85
	
85
	
86
	/* A table from JavaProject to ProjectReferenceChange */
86
	/* A table from JavaProject to ProjectReferenceChange */
87
	private HashMap projectReferenceChanges= new HashMap();
87
	private HashMap projectReferenceChanges = new HashMap();
88
89
	/* A table from JavaProject to ExternalFolderChange */
90
	private HashMap externalFolderChanges = new HashMap();
88
91
89
	/**
92
	/**
90
	 * Workaround for bug 15168 circular errors not reported  
93
	 * Workaround for bug 15168 circular errors not reported 
91
	 * This is a cache of the projects before any project addition/deletion has started.
94
	 * This is a cache of the projects before any project addition/deletion has started.
92
	 */
95
	 */
93
	private HashSet javaProjectNamesCache;
96
	private HashSet javaProjectNamesCache;
Lines 170-175 Link Here
170
		return validation;
173
		return validation;
171
	}
174
	}
172
	
175
	
176
	public synchronized void addExternalFolderChange(JavaProject project, IClasspathEntry[] oldResolvedClasspath) {
177
		ExternalFolderChange change = (ExternalFolderChange) this.externalFolderChanges.get(project);
178
		if (change == null) {
179
			change = new ExternalFolderChange(project, oldResolvedClasspath);
180
			this.externalFolderChanges.put(project, change);
181
	    }
182
	}
183
	
173
	public synchronized void addProjectReferenceChange(JavaProject project, IClasspathEntry[] oldResolvedClasspath) {
184
	public synchronized void addProjectReferenceChange(JavaProject project, IClasspathEntry[] oldResolvedClasspath) {
174
		ProjectReferenceChange change = (ProjectReferenceChange) this.projectReferenceChanges.get(project);
185
		ProjectReferenceChange change = (ProjectReferenceChange) this.projectReferenceChanges.get(project);
175
		if (change == null) {
186
		if (change == null) {
Lines 297-302 Link Here
297
	    return validations;
308
	    return validations;
298
	}
309
	}
299
	
310
	
311
	public synchronized ExternalFolderChange[] removeExternalFolderChanges() {
312
	    int length = this.externalFolderChanges.size();
313
	    if (length == 0) return null;
314
	    ExternalFolderChange[]  updates = new ExternalFolderChange[length];
315
	    this.externalFolderChanges.values().toArray(updates);
316
	    this.externalFolderChanges.clear();
317
	    return updates;
318
	}
319
	
300
	public synchronized ProjectReferenceChange[] removeProjectReferenceChanges() {
320
	public synchronized ProjectReferenceChange[] removeProjectReferenceChanges() {
301
	    int length = this.projectReferenceChanges.size();
321
	    int length = this.projectReferenceChanges.size();
302
	    if (length == 0) return null;
322
	    if (length == 0) return null;
Lines 305-311 Link Here
305
	    this.projectReferenceChanges.clear();
325
	    this.projectReferenceChanges.clear();
306
	    return updates;
326
	    return updates;
307
	}
327
	}
308
	
328
309
	public synchronized HashSet removeExternalElementsToRefresh() {
329
	public synchronized HashSet removeExternalElementsToRefresh() {
310
		HashSet result = this.externalElementsToRefresh;
330
		HashSet result = this.externalElementsToRefresh;
311
		this.externalElementsToRefresh = null;
331
		this.externalElementsToRefresh = null;
(-)model/org/eclipse/jdt/core/IJavaProject.java (-5 / +6 lines)
Lines 473-487 Link Here
473
	IPath getOutputLocation() throws JavaModelException;
473
	IPath getOutputLocation() throws JavaModelException;
474
474
475
	/**
475
	/**
476
	 * Returns a package fragment root for the JAR at the specified file system path.
476
	 * Returns a package fragment root for library (a JAR or - since 3.4 - a class folder)
477
	 * at the specified file system path.
477
	 * This is a handle-only method.  The underlying <code>java.io.File</code>
478
	 * This is a handle-only method.  The underlying <code>java.io.File</code>
478
	 * may or may not exist. No resource is associated with this local JAR
479
	 * may or may not exist. No resource is associated with this local library
479
	 * package fragment root.
480
	 * package fragment root.
480
	 * 
481
	 * 
481
	 * @param jarPath the jars's file system path
482
	 * @param libraryPath the library's file system path
482
	 * @return a package fragment root for the JAR at the specified file system path
483
	 * @return a package fragment root for the library at the specified file system path
483
	 */
484
	 */
484
	IPackageFragmentRoot getPackageFragmentRoot(String jarPath);
485
	IPackageFragmentRoot getPackageFragmentRoot(String libraryPath);
485
486
486
	/**
487
	/**
487
	 * Returns a package fragment root for the given resource, which
488
	 * Returns a package fragment root for the given resource, which
(-)model/org/eclipse/jdt/core/JavaCore.java (-12 / +26 lines)
Lines 3168-3179 Link Here
3168
		if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
3168
		if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
3169
			return entry;
3169
			return entry;
3170
3170
3171
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
3172
		IPath resolvedPath = JavaCore.getResolvedVariablePath(entry.getPath());
3171
		IPath resolvedPath = JavaCore.getResolvedVariablePath(entry.getPath());
3173
		if (resolvedPath == null)
3172
		if (resolvedPath == null)
3174
			return null;
3173
			return null;
3175
3174
3176
		Object target = JavaModel.getTarget(workspaceRoot, resolvedPath, false);
3175
		Object target = JavaModel.getTarget(resolvedPath, false);
3177
		if (target == null)
3176
		if (target == null)
3178
			return null;
3177
			return null;
3179
3178
Lines 3214-3223 Link Here
3214
							entry.isExported());
3213
							entry.isExported());
3215
			}
3214
			}
3216
		}
3215
		}
3217
		// outside the workspace
3218
		if (target instanceof File) {
3216
		if (target instanceof File) {
3219
			File externalFile = JavaModel.getFile(target);
3217
			File externalFile = JavaModel.getFile(target);
3220
			if (externalFile != null) {
3218
			if (externalFile != null) {
3219
				// outside the workspace
3221
				String fileName = externalFile.getName().toLowerCase();
3220
				String fileName = externalFile.getName().toLowerCase();
3222
				if (fileName.endsWith(SuffixConstants.SUFFIX_STRING_jar) || fileName.endsWith(SuffixConstants.SUFFIX_STRING_zip)) {
3221
				if (fileName.endsWith(SuffixConstants.SUFFIX_STRING_jar) || fileName.endsWith(SuffixConstants.SUFFIX_STRING_zip)) {
3223
					// external binary archive
3222
					// external binary archive
Lines 3229-3235 Link Here
3229
							entry.getExtraAttributes(),
3228
							entry.getExtraAttributes(),
3230
							entry.isExported());
3229
							entry.isExported());
3231
				}
3230
				}
3232
			} else { // external binary folder
3231
			} else { 
3232
				// non-existing file
3233
				if (resolvedPath.isAbsolute()){
3233
				if (resolvedPath.isAbsolute()){
3234
					return JavaCore.newLibraryEntry(
3234
					return JavaCore.newLibraryEntry(
3235
							resolvedPath,
3235
							resolvedPath,
Lines 3240-3246 Link Here
3240
							entry.isExported());
3240
							entry.isExported());
3241
				}
3241
				}
3242
			}
3242
			}
3243
		}
3243
		} 
3244
		return null;
3244
		return null;
3245
	}
3245
	}
3246
3246
Lines 3385-3403 Link Here
3385
			}
3385
			}
3386
			
3386
			
3387
			// avoid leaking source attachment properties (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183413 )
3387
			// avoid leaking source attachment properties (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183413 )
3388
			// and recreate links for external folders if needed
3388
			if (monitor != null)
3389
			if (monitor != null)
3389
				monitor.subTask(Messages.javamodel_resetting_source_attachment_properties);
3390
				monitor.subTask(Messages.javamodel_resetting_source_attachment_properties);
3391
			boolean externalFoldersProjectExists = JavaModelManager.getExternalManager().getExternalFoldersProject().isAccessible();
3390
			final IJavaProject[] projects = manager.getJavaModel().getJavaProjects();
3392
			final IJavaProject[] projects = manager.getJavaModel().getJavaProjects();
3391
			HashSet visitedPaths = new HashSet();
3393
			HashSet visitedPaths = new HashSet();
3392
			for (int i = 0, length = projects.length; i < length; i++) {
3394
			for (int i = 0, length = projects.length; i < length; i++) {
3395
				JavaProject javaProject = (JavaProject) projects[i];
3393
				IClasspathEntry[] classpath;
3396
				IClasspathEntry[] classpath;
3394
				try {
3397
				try {
3395
					classpath = ((JavaProject) projects[i]).getResolvedClasspath();
3398
					classpath = javaProject.getResolvedClasspath();
3396
				} catch (JavaModelException e) {
3399
				} catch (JavaModelException e) {
3397
					// project no longer exist: ignore
3400
					// project no longer exist: ignore
3398
					continue;
3401
					continue;
3399
				}
3402
				}
3400
				if (classpath != null) {
3403
				if (classpath != null) {
3404
					boolean needExternalFolderCreation = false;
3401
					for (int j = 0, length2 = classpath.length; j < length2; j++) {
3405
					for (int j = 0, length2 = classpath.length; j < length2; j++) {
3402
						IClasspathEntry entry = classpath[j];
3406
						IClasspathEntry entry = classpath[j];
3403
						if (entry.getSourceAttachmentPath() != null) {
3407
						if (entry.getSourceAttachmentPath() != null) {
Lines 3407-3413 Link Here
3407
							}
3411
							}
3408
						}
3412
						}
3409
						// else source might have been attached by IPackageFragmentRoot#attachSource(...), we keep it
3413
						// else source might have been attached by IPackageFragmentRoot#attachSource(...), we keep it
3414
						if (!needExternalFolderCreation && !externalFoldersProjectExists && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
3415
							Object target = JavaModel.getTarget(entry.getPath(), false/*don't check existence*/);
3416
							if (target instanceof IFolder && ExternalFoldersManager.isExternal(((IFolder) target).getFullPath()))
3417
								needExternalFolderCreation = true;
3418
						}
3410
					}
3419
					}
3420
					if (needExternalFolderCreation)
3421
						manager.deltaState.addExternalFolderChange(javaProject, null/*act as if all external folders were new*/);
3411
				}
3422
				}
3412
			}
3423
			}
3413
			
3424
			
Lines 3842-3847 Link Here
3842
	 * @param path the absolute path of the binary archive
3853
	 * @param path the absolute path of the binary archive
3843
	 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
3854
	 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
3844
	 *    or <code>null</code> if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
3855
	 *    or <code>null</code> if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
3856
	 *    Since 3.4, this path can also denote a path external to the workspace.
3845
	 *   and will be automatically converted to <code>null</code>.
3857
	 *   and will be automatically converted to <code>null</code>.
3846
	 * @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
3858
	 * @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
3847
	 *    or <code>null</code> if this location should be automatically detected.
3859
	 *    or <code>null</code> if this location should be automatically detected.
Lines 3872-3878 Link Here
3872
	 * @param path the absolute path of the binary archive
3884
	 * @param path the absolute path of the binary archive
3873
	 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
3885
	 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
3874
	 *    or <code>null</code> if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
3886
	 *    or <code>null</code> if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
3875
	 *   and will be automatically converted to <code>null</code>.
3887
	 *   and will be automatically converted to <code>null</code>. Since 3.4, this path can also denote a path external
3888
	 *   to the workspace.
3876
	 * @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
3889
	 * @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
3877
	 *    or <code>null</code> if this location should be automatically detected.
3890
	 *    or <code>null</code> if this location should be automatically detected.
3878
	 * @param isExported indicates whether this entry is contributed to dependent
3891
	 * @param isExported indicates whether this entry is contributed to dependent
Lines 3902-3916 Link Here
3902
	 * <p>
3915
	 * <p>
3903
	 * A library entry is used to denote a prerequisite JAR or root folder containing binaries.
3916
	 * A library entry is used to denote a prerequisite JAR or root folder containing binaries.
3904
	 * The target JAR can either be defined internally to the workspace (absolute path relative
3917
	 * The target JAR can either be defined internally to the workspace (absolute path relative
3905
	 * to the workspace root) or externally to the workspace (absolute path in the file system).
3918
	 * to the workspace root), or externally to the workspace (absolute path in the file system).
3906
	 * The target root folder can only be defined internally to the workspace (absolute path relative
3919
	 * The target root folder can also be defined internally to the workspace (absolute path relative
3907
	 * to the workspace root). To use a binary folder external to the workspace, it must first be
3920
	 * to the workspace root), or - since 3.4 - externally to the workspace (absolute path in the file system). 
3908
	 * linked (see IFolder#createLink(...)).
3909
	 * <p>
3921
	 * <p>
3910
	 * e.g. Here are some examples of binary path usage<ul>
3922
	 * e.g. Here are some examples of binary path usage<ul>
3911
	 *	<li><code> "c:\jdk1.2.2\jre\lib\rt.jar" </code> - reference to an external JAR on Windows</li>
3923
	 *	<li><code> "c:\jdk1.2.2\jre\lib\rt.jar" </code> - reference to an external JAR on Windows</li>
3912
	 *	<li><code> "/Project/someLib.jar" </code> - reference to an internal JAR on Windows or Linux</li>
3924
	 *	<li><code> "/Project/someLib.jar" </code> - reference to an internal JAR on Windows or Linux</li>
3913
	 *	<li><code> "/Project/classes/" </code> - reference to an internal binary folder on Windows or Linux</li>
3925
	 *	<li><code> "/Project/classes/" </code> - reference to an internal binary folder on Windows or Linux</li>
3926
	 *	<li><code> "/home/usr/classes" </code> - reference to an external binary folder on Linux</li>
3914
	 * </ul>
3927
	 * </ul>
3915
	 * Note that on non-Windows platform, a path <code>"/some/lib.jar"</code> is ambiguous.
3928
	 * Note that on non-Windows platform, a path <code>"/some/lib.jar"</code> is ambiguous.
3916
	 * It can be a path to an external JAR (its file system path being <code>"/some/lib.jar"</code>)
3929
	 * It can be a path to an external JAR (its file system path being <code>"/some/lib.jar"</code>)
Lines 3943-3949 Link Here
3943
	 * @param path the absolute path of the binary archive
3956
	 * @param path the absolute path of the binary archive
3944
	 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
3957
	 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
3945
	 *    or <code>null</code> if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
3958
	 *    or <code>null</code> if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
3946
	 *   and will be automatically converted to <code>null</code>.
3959
	 *   and will be automatically converted to <code>null</code>. Since 3.4, this path can also denote a path external
3960
	 *   to the workspace.
3947
	 * @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
3961
	 * @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
3948
	 *    or <code>null</code> if this location should be automatically detected.
3962
	 *    or <code>null</code> if this location should be automatically detected.
3949
	 * @param accessRules the possibly empty list of access rules for this entry
3963
	 * @param accessRules the possibly empty list of access rules for this entry
(-)model/org/eclipse/jdt/core/ToolFactory.java (-1 / +2 lines)
Lines 31-36 Link Here
31
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
31
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
32
import org.eclipse.jdt.internal.compiler.util.Util;
32
import org.eclipse.jdt.internal.compiler.util.Util;
33
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
33
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
34
import org.eclipse.jdt.internal.core.JavaElement;
34
import org.eclipse.jdt.internal.core.JavaModelManager;
35
import org.eclipse.jdt.internal.core.JavaModelManager;
35
import org.eclipse.jdt.internal.core.PackageFragment;
36
import org.eclipse.jdt.internal.core.PackageFragment;
36
import org.eclipse.jdt.internal.core.util.ClassFileReader;
37
import org.eclipse.jdt.internal.core.util.ClassFileReader;
Lines 226-232 Link Here
226
				} else {
227
				} else {
227
					InputStream in = null;
228
					InputStream in = null;
228
					try {
229
					try {
229
						in = ((IFile) classfile.getResource()).getContents();
230
						in = ((IFile) ((JavaElement) classfile).resource()).getContents();
230
						return createDefaultClassFileReader(in, decodingFlag);
231
						return createDefaultClassFileReader(in, decodingFlag);
231
					} finally {
232
					} finally {
232
						if (in != null)
233
						if (in != null)
(-)model/org/eclipse/jdt/core/IJavaElement.java (-1 / +1 lines)
Lines 310-316 Link Here
310
	 * Returns the innermost resource enclosing this element.
310
	 * Returns the innermost resource enclosing this element.
311
	 * If this element is included in an archive and this archive is not external,
311
	 * If this element is included in an archive and this archive is not external,
312
	 * this is the underlying resource corresponding to the archive.
312
	 * this is the underlying resource corresponding to the archive.
313
	 * If this element is included in an external archive, <code>null</code>
313
	 * If this element is included in an external library, <code>null</code>
314
	 * is returned.
314
	 * is returned.
315
	 * This is a handle-only method.
315
	 * This is a handle-only method.
316
	 *
316
	 *
(-)search/org/eclipse/jdt/internal/core/search/IndexSelector.java (-13 / +24 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core.search;
11
package org.eclipse.jdt.internal.core.search;
12
12
13
import org.eclipse.core.resources.IFolder;
13
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.jdt.core.IClasspathEntry;
15
import org.eclipse.jdt.core.IClasspathEntry;
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IJavaElement;
Lines 20-25 Link Here
20
import org.eclipse.jdt.core.search.SearchPattern;
21
import org.eclipse.jdt.core.search.SearchPattern;
21
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
22
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
22
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
23
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
24
import org.eclipse.jdt.internal.core.JavaModel;
23
import org.eclipse.jdt.internal.core.JavaModelManager;
25
import org.eclipse.jdt.internal.core.JavaModelManager;
24
import org.eclipse.jdt.internal.core.JavaProject;
26
import org.eclipse.jdt.internal.core.JavaProject;
25
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
27
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
Lines 122-129 Link Here
122
	SimpleSet locations = new SimpleSet();
124
	SimpleSet locations = new SimpleSet();
123
	IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
125
	IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
124
	if (focus == null) {
126
	if (focus == null) {
125
		for (int i = 0; i < projectsAndJars.length; i++)
127
		for (int i = 0; i < projectsAndJars.length; i++) {
126
			locations.add(manager.computeIndexLocation(projectsAndJars[i]));
128
			IPath path = projectsAndJars[i];
129
			Object target = JavaModel.getTarget(path, false/*don't check existence*/);
130
			if (target instanceof IFolder) // case of an external folder
131
				path = ((IFolder) target).getFullPath();
132
			locations.add(manager.computeIndexLocation(path));
133
		}
127
	} else {
134
	} else {
128
		try {
135
		try {
129
			// find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
136
			// find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
Lines 131-137 Link Here
131
			JavaProject[] projectsCanSeeFocus = new JavaProject[length];
138
			JavaProject[] projectsCanSeeFocus = new JavaProject[length];
132
			SimpleSet visitedProjects = new SimpleSet(length);
139
			SimpleSet visitedProjects = new SimpleSet(length);
133
			int projectIndex = 0;
140
			int projectIndex = 0;
134
			SimpleSet jarsToCheck = new SimpleSet(length);
141
			SimpleSet externalLibsToCheck = new SimpleSet(length);
135
			IClasspathEntry[] focusEntries = null;
142
			IClasspathEntry[] focusEntries = null;
136
			if (this.pattern instanceof MethodPattern) { // should consider polymorphic search for method patterns
143
			if (this.pattern instanceof MethodPattern) { // should consider polymorphic search for method patterns
137
				JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus;
144
				JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus;
Lines 148-173 Link Here
148
						projectsCanSeeFocus[projectIndex++] = project;
155
						projectsCanSeeFocus[projectIndex++] = project;
149
					}
156
					}
150
				} else {
157
				} else {
151
					jarsToCheck.add(path);
158
					externalLibsToCheck.add(path);
152
				}
159
				}
153
			}
160
			}
154
			for (int i = 0; i < projectIndex && jarsToCheck.elementSize > 0; i++) {
161
			for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
155
				IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
162
				IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
156
				for (int j = entries.length; --j >= 0;) {
163
				for (int j = entries.length; --j >= 0;) {
157
					IClasspathEntry entry = entries[j];
164
					IClasspathEntry entry = entries[j];
158
					if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
165
					if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
159
						IPath path = entry.getPath();
166
						IPath path = entry.getPath();
160
						if (jarsToCheck.includes(path)) {
167
						if (externalLibsToCheck.remove(path) != null) {
161
							locations.add(manager.computeIndexLocation(entry.getPath()));
168
							Object target = JavaModel.getTarget(path, false/*don't check existence*/);
162
							jarsToCheck.remove(path);
169
							if (target instanceof IFolder) // case of an external folder
170
								path = ((IFolder) target).getFullPath();
171
							locations.add(manager.computeIndexLocation(path));
163
						}
172
						}
164
					}
173
					}
165
				}
174
				}
166
			}
175
			}
167
			// jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
176
			// jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
168
			if (jarsToCheck.elementSize > 0) {
177
			if (externalLibsToCheck.elementSize > 0) {
169
				IJavaProject[] allProjects = model.getJavaProjects();
178
				IJavaProject[] allProjects = model.getJavaProjects();
170
				for (int i = 0, l = allProjects.length; i < l && jarsToCheck.elementSize > 0; i++) {
179
				for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
171
					JavaProject project = (JavaProject) allProjects[i];
180
					JavaProject project = (JavaProject) allProjects[i];
172
					if (!visitedProjects.includes(project)) {
181
					if (!visitedProjects.includes(project)) {
173
						IClasspathEntry[] entries = project.getResolvedClasspath();
182
						IClasspathEntry[] entries = project.getResolvedClasspath();
Lines 175-183 Link Here
175
							IClasspathEntry entry = entries[j];
184
							IClasspathEntry entry = entries[j];
176
							if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
185
							if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
177
								IPath path = entry.getPath();
186
								IPath path = entry.getPath();
178
								if (jarsToCheck.includes(path)) {
187
								if (externalLibsToCheck.remove(path) != null) {
179
									locations.add(manager.computeIndexLocation(entry.getPath()));
188
									Object target = JavaModel.getTarget(path, false/*don't check existence*/);
180
									jarsToCheck.remove(path);
189
									if (target instanceof IFolder) // case of an external folder
190
										path = ((IFolder) target).getFullPath();
191
									locations.add(manager.computeIndexLocation(path));
181
								}
192
								}
182
							}
193
							}
183
						}
194
						}
(-)search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java (-2 / +2 lines)
Lines 153-162 Link Here
153
		|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
153
		|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
154
			&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
154
			&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
155
			&& resourcePath.charAt(rootPathLength) == '/')) {
155
			&& resourcePath.charAt(rootPathLength) == '/')) {
156
		IPackageFragmentRoot root = ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
156
		PackageFragmentRoot root = (PackageFragmentRoot) ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
157
		if (root == null) return null;
157
		if (root == null) return null;
158
		this.lastPkgFragmentRoot = root;
158
		this.lastPkgFragmentRoot = root;
159
		this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
159
		this.lastPkgFragmentRootPath = root.internalPath().toString();
160
		this.packageHandles = new HashtableOfArrayToObject(5);
160
		this.packageHandles = new HashtableOfArrayToObject(5);
161
	}
161
	}
162
	// create handle
162
	// create handle
(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (-16 / +25 lines)
Lines 14-19 Link Here
14
import java.util.HashSet;
14
import java.util.HashSet;
15
import java.util.Map;
15
import java.util.Map;
16
16
17
import org.eclipse.core.resources.IFolder;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.resources.ResourcesPlugin;
Lines 36-41 Link Here
36
import org.eclipse.jdt.internal.core.JavaModelManager;
37
import org.eclipse.jdt.internal.core.JavaModelManager;
37
import org.eclipse.jdt.internal.core.JavaProject;
38
import org.eclipse.jdt.internal.core.JavaProject;
38
import org.eclipse.jdt.internal.core.PackageFragment;
39
import org.eclipse.jdt.internal.core.PackageFragment;
40
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
39
import org.eclipse.jdt.internal.core.util.Util;
41
import org.eclipse.jdt.internal.core.util.Util;
40
42
41
/**
43
/**
Lines 146-154 Link Here
146
						if ((includeMask & APPLICATION_LIBRARIES) != 0) {
148
						if ((includeMask & APPLICATION_LIBRARIES) != 0) {
147
							IPath path = entry.getPath();
149
							IPath path = entry.getPath();
148
							if (pathToAdd == null || pathToAdd.equals(path)) {
150
							if (pathToAdd == null || pathToAdd.equals(path)) {
151
								Object target = JavaModel.getTarget(path, false/*don't check existence*/);
152
								if (target instanceof IFolder) // case of an external folder
153
									path = ((IFolder) target).getFullPath();
149
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
154
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
150
								add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
155
								add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
151
								addEnclosingProjectOrJar(path);
156
								addEnclosingProjectOrJar(entry.getPath());
152
							}
157
							}
153
						}
158
						}
154
						break;
159
						break;
Lines 168-176 Link Here
168
						}
173
						}
169
						IPath path = entry.getPath();
174
						IPath path = entry.getPath();
170
						if (pathToAdd == null || pathToAdd.equals(path)) {
175
						if (pathToAdd == null || pathToAdd.equals(path)) {
176
							Object target = JavaModel.getTarget(path, false/*don't check existence*/);
177
							if (target instanceof IFolder) // case of an external folder
178
								path = ((IFolder) target).getFullPath();
171
							String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
179
							String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
172
							add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
180
							add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
173
							addEnclosingProjectOrJar(path);
181
							addEnclosingProjectOrJar(entry.getPath());
174
						}
182
						}
175
						break;
183
						break;
176
				}
184
				}
Lines 179-185 Link Here
179
				if ((includeMask & REFERENCED_PROJECTS) != 0) {
187
				if ((includeMask & REFERENCED_PROJECTS) != 0) {
180
					IPath path = entry.getPath();
188
					IPath path = entry.getPath();
181
					if (pathToAdd == null || pathToAdd.equals(path)) {
189
					if (pathToAdd == null || pathToAdd.equals(path)) {
182
						add((JavaProject) model.getJavaProject(entry.getPath().lastSegment()), null, includeMask, visitedProjects, cpEntry);
190
						add((JavaProject) model.getJavaProject(path.lastSegment()), null, includeMask, visitedProjects, cpEntry);
183
					}
191
					}
184
				}
192
				}
185
				break;
193
				break;
Lines 202-207 Link Here
202
public void add(IJavaElement element) throws JavaModelException {
210
public void add(IJavaElement element) throws JavaModelException {
203
	IPath containerPath = null;
211
	IPath containerPath = null;
204
	String containerPathToString = null;
212
	String containerPathToString = null;
213
	PackageFragmentRoot root = null;
205
	int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
214
	int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
206
	switch (element.getElementType()) {
215
	switch (element.getElementType()) {
207
		case IJavaElement.JAVA_MODEL:
216
		case IJavaElement.JAVA_MODEL:
Lines 211-221 Link Here
211
			add((JavaProject)element, null, includeMask, new HashSet(2), null);
220
			add((JavaProject)element, null, includeMask, new HashSet(2), null);
212
			break;
221
			break;
213
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
222
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
214
			IPackageFragmentRoot root = (IPackageFragmentRoot)element;
223
			root = (PackageFragmentRoot)element;
215
			IPath rootPath = root.getPath();
224
			IPath rootPath = root.internalPath();
216
			containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
225
			containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
217
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
226
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
218
			IResource rootResource = root.getResource();
227
			IResource rootResource = root.resource();
219
			String projectPath = root.getJavaProject().getPath().toString();
228
			String projectPath = root.getJavaProject().getPath().toString();
220
			if (rootResource != null && rootResource.isAccessible()) {
229
			if (rootResource != null && rootResource.isAccessible()) {
221
				String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
230
				String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
Lines 225-231 Link Here
225
			}
234
			}
226
			break;
235
			break;
227
		case IJavaElement.PACKAGE_FRAGMENT:
236
		case IJavaElement.PACKAGE_FRAGMENT:
228
			root = (IPackageFragmentRoot)element.getParent();
237
			root = (PackageFragmentRoot)element.getParent();
229
			projectPath = root.getJavaProject().getPath().toString();
238
			projectPath = root.getJavaProject().getPath().toString();
230
			if (root.isArchive()) {
239
			if (root.isArchive()) {
231
				String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
240
				String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
Lines 233-242 Link Here
233
				containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
242
				containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
234
				add(projectPath, relativePath, containerPathToString, true/*package*/, null);
243
				add(projectPath, relativePath, containerPathToString, true/*package*/, null);
235
			} else {
244
			} else {
236
				IResource resource = element.getResource();
245
				IResource resource = ((JavaElement) element).resource();
237
				if (resource != null) {
246
				if (resource != null) {
238
					if (resource.isAccessible()) {
247
					if (resource.isAccessible()) {
239
						containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath();
248
						containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath();
240
					} else {
249
					} else {
241
						// for working copies, get resource container full path
250
						// for working copies, get resource container full path
242
						containerPath = resource.getParent().getFullPath();
251
						containerPath = resource.getParent().getFullPath();
Lines 255-276 Link Here
255
				}
264
				}
256
				this.elements.add(element);
265
				this.elements.add(element);
257
			}
266
			}
258
			root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
267
			root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
259
			projectPath = root.getJavaProject().getPath().toString();
268
			projectPath = root.getJavaProject().getPath().toString();
260
			String relativePath;
269
			String relativePath;
261
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
270
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
262
				containerPath = root.getParent().getPath();
271
				containerPath = root.getParent().getPath();
263
				relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segmet*/);
272
				relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segment*/);
264
			} else {
273
			} else {
265
				containerPath = root.getPath();
274
				containerPath = root.internalPath();
266
				relativePath = getPath(element, true/*relative path*/).toString();
275
				relativePath = getPath(element, true/*relative path*/).toString();
267
			}
276
			}
268
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
277
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
269
			add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
278
			add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
270
	}
279
	}
271
	
280
	
272
	if (containerPath != null)
281
	if (root != null)
273
		addEnclosingProjectOrJar(containerPath);
282
		addEnclosingProjectOrJar(root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath());
274
}
283
}
275
284
276
/**
285
/**
Lines 597-608 Link Here
597
			if (isJarFile) {
606
			if (isJarFile) {
598
				return project.getPackageFragmentRoot(this.containerPaths[index]);
607
				return project.getPackageFragmentRoot(this.containerPaths[index]);
599
			}
608
			}
600
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(this.containerPaths[index]+'/'+this.relativePaths[index]), false);
609
			Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[index]+'/'+this.relativePaths[index]));
601
			if (target instanceof IProject) {
610
			if (target instanceof IProject) {
602
				return project.getPackageFragmentRoot((IProject) target);
611
				return project.getPackageFragmentRoot((IProject) target);
603
			}
612
			}
604
			if (target instanceof IResource) {
613
			if (target instanceof IResource) {
605
				IJavaElement element = JavaCore.create((IResource)target);
614
				IJavaElement element = JavaModelManager.create((IResource) target, project);
606
				return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
615
				return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
607
			}
616
			}
608
		}
617
		}
(-)search/org/eclipse/jdt/internal/core/search/HierarchyScope.java (-4 / +3 lines)
Lines 72-78 Link Here
72
		IPackageFragmentRoot root = (IPackageFragmentRoot)type.getPackageFragment().getParent();
72
		IPackageFragmentRoot root = (IPackageFragmentRoot)type.getPackageFragment().getParent();
73
		if (root.isArchive()) {
73
		if (root.isArchive()) {
74
			IPath jarPath = root.getPath();
74
			IPath jarPath = root.getPath();
75
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), jarPath, true);
75
			Object target = JavaModel.getTarget(jarPath, true);
76
			String zipFileName;
76
			String zipFileName;
77
			if (target instanceof IFile) {
77
			if (target instanceof IFile) {
78
				// internal jar
78
				// internal jar
Lines 101-110 Link Here
101
		HashMap resources = new HashMap();
101
		HashMap resources = new HashMap();
102
		HashMap paths = new HashMap();
102
		HashMap paths = new HashMap();
103
		this.types = this.hierarchy.getAllTypes();
103
		this.types = this.hierarchy.getAllTypes();
104
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
105
		for (int i = 0; i < this.types.length; i++) {
104
		for (int i = 0; i < this.types.length; i++) {
106
			IType type = this.types[i];
105
			IType type = this.types[i];
107
			IResource resource = type.getResource();
106
			IResource resource = ((JavaElement) type).resource();
108
			if (resource != null && resources.get(resource) == null) {
107
			if (resource != null && resources.get(resource) == null) {
109
				resources.put(resource, resource);
108
				resources.put(resource, resource);
110
				add(resource);
109
				add(resource);
Lines 115-121 Link Here
115
				// type in a jar
114
				// type in a jar
116
				JarPackageFragmentRoot jar = (JarPackageFragmentRoot) root;
115
				JarPackageFragmentRoot jar = (JarPackageFragmentRoot) root;
117
				IPath jarPath = jar.getPath();
116
				IPath jarPath = jar.getPath();
118
				Object target = JavaModel.getTarget(workspaceRoot, jarPath, true);
117
				Object target = JavaModel.getTarget(jarPath, true);
119
				String zipFileName;
118
				String zipFileName;
120
				if (target instanceof IFile) {
119
				if (target instanceof IFile) {
121
					// internal jar
120
					// internal jar
(-)search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java (-1 / +1 lines)
Lines 1140-1146 Link Here
1140
			Util.verbose("	- java element: "+enclosingElement); //$NON-NLS-1$
1140
			Util.verbose("	- java element: "+enclosingElement); //$NON-NLS-1$
1141
		}
1141
		}
1142
		IJavaSearchScope scope = createJavaSearchScope(new IJavaElement[] {enclosingElement});
1142
		IJavaSearchScope scope = createJavaSearchScope(new IJavaElement[] {enclosingElement});
1143
		IResource resource = enclosingElement.getResource();
1143
		IResource resource = ((JavaElement) enclosingElement).resource();
1144
		if (enclosingElement instanceof IMember) {
1144
		if (enclosingElement instanceof IMember) {
1145
			IMember member = (IMember) enclosingElement;
1145
			IMember member = (IMember) enclosingElement;
1146
			ICompilationUnit cu = member.getCompilationUnit();
1146
			ICompilationUnit cu = member.getCompilationUnit();
(-)model/org/eclipse/jdt/internal/core/util/Util.java (-3 / +4 lines)
Lines 50-55 Link Here
50
import org.eclipse.jdt.internal.core.JavaElement;
50
import org.eclipse.jdt.internal.core.JavaElement;
51
import org.eclipse.jdt.internal.core.JavaModelManager;
51
import org.eclipse.jdt.internal.core.JavaModelManager;
52
import org.eclipse.jdt.internal.core.MemberValuePair;
52
import org.eclipse.jdt.internal.core.MemberValuePair;
53
import org.eclipse.jdt.internal.core.PackageFragment;
53
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
54
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
54
import org.eclipse.jface.text.BadLocationException;
55
import org.eclipse.jface.text.BadLocationException;
55
import org.eclipse.text.edits.MalformedTreeException;
56
import org.eclipse.text.edits.MalformedTreeException;
Lines 1312-1323 Link Here
1312
				return false;
1313
				return false;
1313
1314
1314
			case IJavaElement.PACKAGE_FRAGMENT:
1315
			case IJavaElement.PACKAGE_FRAGMENT:
1315
				PackageFragmentRoot root = (PackageFragmentRoot)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
1316
				PackageFragmentRoot root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
1316
				IResource resource = element.getResource();
1317
				IResource resource = ((PackageFragment) element).resource();
1317
				return resource != null && isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars());
1318
				return resource != null && isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars());
1318
				
1319
				
1319
			case IJavaElement.COMPILATION_UNIT:
1320
			case IJavaElement.COMPILATION_UNIT:
1320
				root = (PackageFragmentRoot)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
1321
				root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
1321
				resource = element.getResource();
1322
				resource = element.getResource();
1322
				if (resource == null) 
1323
				if (resource == null) 
1323
					return false;
1324
					return false;
(-)model/org/eclipse/jdt/internal/core/util/HandleFactory.java (-11 / +3 lines)
Lines 33-50 Link Here
33
import org.eclipse.jdt.core.compiler.CharOperation;
33
import org.eclipse.jdt.core.compiler.CharOperation;
34
import org.eclipse.jdt.core.search.IJavaSearchScope;
34
import org.eclipse.jdt.core.search.IJavaSearchScope;
35
import org.eclipse.jdt.internal.compiler.ast.*;
35
import org.eclipse.jdt.internal.compiler.ast.*;
36
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
37
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
38
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
39
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
36
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
40
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
37
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
41
import org.eclipse.jdt.internal.compiler.lookup.Scope;
38
import org.eclipse.jdt.internal.compiler.lookup.Scope;
42
import org.eclipse.jdt.internal.core.*;
39
import org.eclipse.jdt.internal.core.*;
43
import org.eclipse.jdt.internal.core.JavaModel;
44
import org.eclipse.jdt.internal.core.JavaModelManager;
45
import org.eclipse.jdt.internal.core.JavaProject;
46
import org.eclipse.jdt.internal.core.Openable;
47
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
48
import org.eclipse.jdt.internal.core.util.Util;
40
import org.eclipse.jdt.internal.core.util.Util;
49
41
50
/**
42
/**
Lines 128-134 Link Here
128
				if (root == null)
120
				if (root == null)
129
					return null; // match is outside classpath
121
					return null; // match is outside classpath
130
				this.lastPkgFragmentRoot = root;
122
				this.lastPkgFragmentRoot = root;
131
				this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
123
				this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.internalPath().toString();
132
				this.packageHandles = new HashtableOfArrayToObject(5);
124
				this.packageHandles = new HashtableOfArrayToObject(5);
133
			}
125
			}
134
			// create handle
126
			// create handle
Lines 252-258 Link Here
252
244
253
		IPath jarPath= new Path(jarPathString);
245
		IPath jarPath= new Path(jarPathString);
254
		
246
		
255
		Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), jarPath, false);
247
		Object target = JavaModel.getTarget(jarPath, false);
256
		if (target instanceof IFile) {
248
		if (target instanceof IFile) {
257
			// internal jar: is it on the classpath of its project?
249
			// internal jar: is it on the classpath of its project?
258
			//  e.g. org.eclipse.swt.win32/ws/win32/swt.jar 
250
			//  e.g. org.eclipse.swt.win32/ws/win32/swt.jar 
Lines 341-347 Link Here
341
				IPackageFragmentRoot[] roots= javaProject.getPackageFragmentRoots();
333
				IPackageFragmentRoot[] roots= javaProject.getPackageFragmentRoots();
342
				for (int j= 0, rootCount= roots.length; j < rootCount; j++) {
334
				for (int j= 0, rootCount= roots.length; j < rootCount; j++) {
343
					PackageFragmentRoot root= (PackageFragmentRoot)roots[j];
335
					PackageFragmentRoot root= (PackageFragmentRoot)roots[j];
344
					if (root.getPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) {
336
					if (root.internalPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) {
345
						return root;
337
						return root;
346
					}
338
					}
347
				}
339
				}
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-4 / +4 lines)
Lines 278-284 Link Here
278
	IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
278
	IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
279
	try {
279
	try {
280
		if (!root.isArchive())
280
		if (!root.isArchive())
281
			return Util.newClassFileReader(type.getResource());
281
			return Util.newClassFileReader(((JavaElement) type).resource());
282
282
283
		ZipFile zipFile = null;
283
		ZipFile zipFile = null;
284
		try {
284
		try {
Lines 425-431 Link Here
425
	if (binaryType == null) {
425
	if (binaryType == null) {
426
		ClassFile classFile = (ClassFile) type.getClassFile();
426
		ClassFile classFile = (ClassFile) type.getClassFile();
427
		try {
427
		try {
428
			binaryType = getBinaryInfo(classFile, classFile.getResource());
428
			binaryType = getBinaryInfo(classFile, classFile.resource());
429
		} catch (CoreException e) {
429
		} catch (CoreException e) {
430
			if (e instanceof JavaModelException) {
430
			if (e instanceof JavaModelException) {
431
				throw (JavaModelException) e;
431
				throw (JavaModelException) e;
Lines 1186-1192 Link Here
1186
			JavaProject javaProject = (JavaProject) openable.getJavaProject();
1186
			JavaProject javaProject = (JavaProject) openable.getJavaProject();
1187
			resource = workingCopy != null ? workingCopy.getResource() : openable.getResource();
1187
			resource = workingCopy != null ? workingCopy.getResource() : openable.getResource();
1188
			if (resource == null)
1188
			if (resource == null)
1189
				resource = javaProject.getProject(); // case of a file in an external jar
1189
				resource = javaProject.getProject(); // case of a file in an external jar or external folder
1190
			if (!javaProject.equals(previousJavaProject)) {
1190
			if (!javaProject.equals(previousJavaProject)) {
1191
				// locate matches in previous project
1191
				// locate matches in previous project
1192
				if (previousJavaProject != null) {
1192
				if (previousJavaProject != null) {
Lines 1559-1565 Link Here
1559
		if (unit.isEmpty()) {
1559
		if (unit.isEmpty()) {
1560
			if (this.currentPossibleMatch.openable instanceof ClassFile) {
1560
			if (this.currentPossibleMatch.openable instanceof ClassFile) {
1561
				ClassFile classFile = (ClassFile) this.currentPossibleMatch.openable;
1561
				ClassFile classFile = (ClassFile) this.currentPossibleMatch.openable;
1562
				IBinaryType info = getBinaryInfo(classFile, this.currentPossibleMatch.resource);
1562
				IBinaryType info = getBinaryInfo(classFile, classFile.resource());
1563
				if (info != null) {
1563
				if (info != null) {
1564
					boolean mayBeGeneric = this.patternLocator.mayBeGeneric;
1564
					boolean mayBeGeneric = this.patternLocator.mayBeGeneric;
1565
					this.patternLocator.mayBeGeneric = false; // there's no longer generics in class files
1565
					this.patternLocator.mayBeGeneric = false; // there's no longer generics in class files
(-)search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java (-1 / +1 lines)
Lines 98-104 Link Here
98
				ZipFile zipFile = manager.getZipFile(path);
98
				ZipFile zipFile = manager.getZipFile(path);
99
				cpLocations[index++] = new ClasspathJar(zipFile, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet());
99
				cpLocations[index++] = new ClasspathJar(zipFile, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet());
100
			} else {
100
			} else {
101
				Object target = JavaModel.getTarget(workspaceRoot, path, false);
101
				Object target = JavaModel.getTarget(path, true);
102
				if (target == null) {
102
				if (target == null) {
103
					// target doesn't exist any longer
103
					// target doesn't exist any longer
104
					// just resize cpLocations
104
					// just resize cpLocations
(-)model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java (-2 / +2 lines)
Lines 96-102 Link Here
96
	nextEntry : for (int i = 0, l = classpathEntries.length; i < l; i++) {
96
	nextEntry : for (int i = 0, l = classpathEntries.length; i < l; i++) {
97
		ClasspathEntry entry = (ClasspathEntry) classpathEntries[i];
97
		ClasspathEntry entry = (ClasspathEntry) classpathEntries[i];
98
		IPath path = entry.getPath();
98
		IPath path = entry.getPath();
99
		Object target = JavaModel.getTarget(root, path, true);
99
		Object target = JavaModel.getTarget(path, true);
100
		if (target == null) continue nextEntry;
100
		if (target == null) continue nextEntry;
101
101
102
		switch(entry.getEntryKind()) {
102
		switch(entry.getEntryKind()) {
Lines 128-134 Link Here
128
				nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) {
128
				nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) {
129
					IClasspathEntry prereqEntry = prereqClasspathEntries[j];
129
					IClasspathEntry prereqEntry = prereqClasspathEntries[j];
130
					if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
130
					if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
131
						Object prereqTarget = JavaModel.getTarget(root, prereqEntry.getPath(), true);
131
						Object prereqTarget = JavaModel.getTarget(prereqEntry.getPath(), true);
132
						if (!(prereqTarget instanceof IContainer)) continue nextPrereqEntry;
132
						if (!(prereqTarget instanceof IContainer)) continue nextPrereqEntry;
133
						IPath prereqOutputPath = prereqEntry.getOutputLocation() != null 
133
						IPath prereqOutputPath = prereqEntry.getOutputLocation() != null 
134
							? prereqEntry.getOutputLocation() 
134
							? prereqEntry.getOutputLocation() 
(-)model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java (-1 / +7 lines)
Lines 429-434 Link Here
429
	if (javaProject == null || workspaceRoot == null) return new IProject[0];
429
	if (javaProject == null || workspaceRoot == null) return new IProject[0];
430
430
431
	ArrayList projects = new ArrayList();
431
	ArrayList projects = new ArrayList();
432
	ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
432
	try {
433
	try {
433
		IClasspathEntry[] entries = javaProject.getExpandedClasspath();
434
		IClasspathEntry[] entries = javaProject.getExpandedClasspath();
434
		for (int i = 0, l = entries.length; i < l; i++) {
435
		for (int i = 0, l = entries.length; i < l; i++) {
Lines 445-452 Link Here
445
					if (includeBinaryPrerequisites && path.segmentCount() > 1) {
446
					if (includeBinaryPrerequisites && path.segmentCount() > 1) {
446
						// some binary resources on the class path can come from projects that are not included in the project references
447
						// some binary resources on the class path can come from projects that are not included in the project references
447
						IResource resource = workspaceRoot.findMember(path.segment(0));
448
						IResource resource = workspaceRoot.findMember(path.segment(0));
448
						if (resource instanceof IProject)
449
						if (resource instanceof IProject) {
449
							p = (IProject) resource;
450
							p = (IProject) resource;
451
						} else {
452
							resource = externalFoldersManager.getFolder(path);
453
							if (resource != null)
454
								p = resource.getProject();
455
						}
450
					}
456
					}
451
			}
457
			}
452
			if (p != null && !projects.contains(p))
458
			if (p != null && !projects.contains(p))
(-)search/org/eclipse/jdt/core/search/SearchParticipant.java (-4 / +1 lines)
Lines 11-18 Link Here
11
package org.eclipse.jdt.core.search;
11
package org.eclipse.jdt.core.search;
12
12
13
import org.eclipse.core.resources.IResource;
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.resources.IWorkspaceRoot;
15
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.runtime.*;
14
import org.eclipse.core.runtime.*;
17
import org.eclipse.jdt.internal.core.JavaModel;
15
import org.eclipse.jdt.internal.core.JavaModel;
18
import org.eclipse.jdt.internal.core.JavaModelManager;
16
import org.eclipse.jdt.internal.core.JavaModelManager;
Lines 196-203 Link Here
196
	 */
194
	 */
197
	public final void scheduleDocumentIndexing(SearchDocument document, IPath indexLocation) {
195
	public final void scheduleDocumentIndexing(SearchDocument document, IPath indexLocation) {
198
		IPath documentPath = new Path(document.getPath());
196
		IPath documentPath = new Path(document.getPath());
199
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
197
		Object file = JavaModel.getTarget(documentPath, true);
200
		Object file = JavaModel.getTarget(root, documentPath, true);
201
		IPath containerPath = documentPath;
198
		IPath containerPath = documentPath;
202
		if (file instanceof IResource) {
199
		if (file instanceof IResource) {
203
			containerPath = ((IResource)file).getProject().getFullPath();
200
			containerPath = ((IResource)file).getProject().getFullPath();
(-)model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java (-1 / +1 lines)
Lines 697-703 Link Here
697
					if (classFile.getPackageFragmentRoot().isArchive()) {
697
					if (classFile.getPackageFragmentRoot().isArchive()) {
698
						binaryType = this.builder.createInfoFromClassFileInJar(classFile);
698
						binaryType = this.builder.createInfoFromClassFileInJar(classFile);
699
					} else {
699
					} else {
700
						IResource file = classFile.getResource();
700
						IResource file = classFile.resource();
701
						binaryType = this.builder.createInfoFromClassFile(classFile, file);
701
						binaryType = this.builder.createInfoFromClassFile(classFile, file);
702
					}
702
					}
703
				}
703
				}
(-)codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java (-1 / +1 lines)
Lines 1133-1139 Link Here
1133
				} 
1133
				} 
1134
			} else { // binary type
1134
			} else { // binary type
1135
				ClassFile classFile = (ClassFile) context.getClassFile();
1135
				ClassFile classFile = (ClassFile) context.getClassFile();
1136
				ClassFileReader reader = (ClassFileReader) classFile.getBinaryTypeInfo((IFile) classFile.getResource(), false/*don't fully initialize so as to keep constant pool (used below)*/);
1136
				ClassFileReader reader = (ClassFileReader) classFile.getBinaryTypeInfo((IFile) classFile.resource(), false/*don't fully initialize so as to keep constant pool (used below)*/);
1137
				CompilationResult result = new CompilationResult(reader.getFileName(), 1, 1, this.compilerOptions.maxProblemsPerUnit);
1137
				CompilationResult result = new CompilationResult(reader.getFileName(), 1, 1, this.compilerOptions.maxProblemsPerUnit);
1138
				parsedUnit = new CompilationUnitDeclaration(this.parser.problemReporter(), result, 0);
1138
				parsedUnit = new CompilationUnitDeclaration(this.parser.problemReporter(), result, 0);
1139
				HashSetOfCharArrayArray typeNames = new HashSetOfCharArrayArray();
1139
				HashSetOfCharArrayArray typeNames = new HashSetOfCharArrayArray();
(-)search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java (-9 / +3 lines)
Lines 353-368 Link Here
353
	// requestingProject is no longer used to cancel jobs but leave it here just in case
353
	// requestingProject is no longer used to cancel jobs but leave it here just in case
354
	if (JavaCore.getPlugin() == null) return;
354
	if (JavaCore.getPlugin() == null) return;
355
355
356
	Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true);
356
	Object target = JavaModel.getTarget(path, true);
357
	IndexRequest request = null;
357
	IndexRequest request = null;
358
	if (target instanceof IFile) {
358
	if (target instanceof IFile) {
359
		request = new AddJarFileToIndex((IFile) target, this);
359
		request = new AddJarFileToIndex((IFile) target, this);
360
	} else if (target instanceof File) {
360
	} else if (target instanceof File) {
361
		if (((File) target).isFile()) {
361
		request = new AddJarFileToIndex(path, this);
362
			request = new AddJarFileToIndex(path, this);
363
		} else {
364
			return;
365
		}
366
	} else if (target instanceof IContainer) {
362
	} else if (target instanceof IContainer) {
367
		request = new IndexBinaryFolder((IContainer) target, this);
363
		request = new IndexBinaryFolder((IContainer) target, this);
368
	} else {
364
	} else {
Lines 417-425 Link Here
417
	return Messages.process_name; 
413
	return Messages.process_name; 
418
}
414
}
419
private void rebuildIndex(IPath indexLocation, IPath containerPath) {
415
private void rebuildIndex(IPath indexLocation, IPath containerPath) {
420
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
416
	Object target = JavaModel.getTarget(containerPath, true);
421
	if (workspace == null) return;
422
	Object target = JavaModel.getTarget(workspace.getRoot(), containerPath, true);
423
	if (target == null) return;
417
	if (target == null) return;
424
418
425
	if (VERBOSE)
419
	if (VERBOSE)
(-)model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java (+187 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
12
13
import java.io.FileOutputStream;
14
import java.io.IOException;
15
import java.util.HashMap;
16
import java.util.Iterator;
17
18
import org.eclipse.core.resources.IFolder;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProjectDescription;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IWorkspaceRunnable;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.jdt.core.IJavaProject;
28
import org.eclipse.jdt.core.JavaCore;
29
import org.eclipse.jdt.internal.core.util.Util;
30
31
public class ExternalFoldersManager {
32
	private static final boolean DEBUG = false;
33
	private static final String EXTERNAL_PROJECT_NAME = ".org.eclipse.jdt.core.external.folders"; //$NON-NLS-1$
34
	private static final String LINKED_FOLDER_NAME = ".link"; //$NON-NLS-1$
35
	private HashMap folders;
36
	private int counter = 0;
37
	
38
	{
39
		this.folders = new HashMap();
40
		IProject project = getExternalFoldersProject();
41
		if (project.isAccessible()) {
42
			try {
43
				IResource[] members = project.members();
44
				for (int i = 0, length = members.length; i < length; i++) {
45
					IResource member = members[i];
46
					if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) {
47
						IPath externalFolderPath = member.getLocation();
48
						this.folders.put(externalFolderPath, member);
49
					}
50
				}
51
			} catch (CoreException e) {
52
				Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$
53
			}
54
		}
55
	}
56
	
57
	public static boolean isExternal(IPath resourcePath) {
58
		return EXTERNAL_PROJECT_NAME.equals(resourcePath.segment(0));
59
	}
60
61
	public IFolder addFolder(IPath externalFolderPath) {
62
		return addFolder(externalFolderPath, getExternalFoldersProject());
63
	}
64
65
	private synchronized IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) {
66
		Object existing = this.folders.get(externalFolderPath);
67
		if (existing != null) {
68
			return (IFolder) existing;
69
		}
70
		IFolder result;
71
		do {
72
			result = externalFoldersProject.getFolder(LINKED_FOLDER_NAME + this.counter++);
73
		} while (result.exists());
74
		this.folders.put(externalFolderPath, result);
75
		return result;
76
	}
77
	
78
	public IFolder createLinkFolder(IPath externalFolderPath, IProgressMonitor monitor) throws CoreException {
79
		IProject externalFoldersProject = createExternalFoldersProject(monitor); // run outside synchronized as this can create a resource
80
		IFolder result = addFolder(externalFolderPath, externalFoldersProject);
81
		if (!result.exists())
82
			result.createLink(externalFolderPath, IResource.ALLOW_MISSING_LOCAL, monitor);
83
		else
84
			result.refreshLocal(IResource.DEPTH_INFINITE,  monitor);
85
		return result;
86
	}
87
	
88
	public synchronized void cleanUp(IProgressMonitor monitor) throws CoreException {
89
		DeltaProcessingState state = JavaModelManager.getDeltaState();
90
		HashMap roots = state.roots;
91
		HashMap sourceAttachments = state.sourceAttachments;
92
		if (roots == null && sourceAttachments == null)
93
			return;
94
		Iterator iterator = this.folders.keySet().iterator();
95
		while (iterator.hasNext()) {
96
			IPath path = (IPath) iterator.next();
97
			if ((roots != null && !roots.containsKey(path))
98
					&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) {
99
				IFolder folder = (IFolder) this.folders.get(path);
100
				if (folder != null)
101
					folder.delete(true, monitor);
102
			}
103
		}
104
		IProject project = getExternalFoldersProject();
105
		if (project.isAccessible() && project.members().length == 1/*remaining member is .project*/)
106
			project.delete(true, monitor);
107
	}
108
	
109
	public IProject getExternalFoldersProject() {
110
		return ResourcesPlugin.getWorkspace().getRoot().getProject(EXTERNAL_PROJECT_NAME);
111
	}
112
	private IProject createExternalFoldersProject(IProgressMonitor monitor) {
113
		IProject project = getExternalFoldersProject();
114
		if (!project.isAccessible()) {
115
			try {
116
				if (!project.exists()) {
117
					IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
118
					IPath stateLocation = JavaCore.getPlugin().getStateLocation();
119
					desc.setLocation(stateLocation.append(EXTERNAL_PROJECT_NAME));
120
					project.create(DEBUG ? null : desc, DEBUG ? IResource.NONE : IResource.HIDDEN, monitor);
121
				}
122
				try {
123
					project.open(monitor);
124
				} catch (CoreException e1) {
125
					// .project or folder on disk have been deleted, recreate them
126
					IPath stateLocation = DEBUG ? ResourcesPlugin.getWorkspace().getRoot().getLocation() : JavaCore.getPlugin().getStateLocation();
127
					IPath projectPath = stateLocation.append(EXTERNAL_PROJECT_NAME);
128
					projectPath.toFile().mkdirs();
129
				    FileOutputStream output = new FileOutputStream(projectPath.append(".project").toOSString()); //$NON-NLS-1$
130
				    try {
131
				        output.write((
132
				        		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$
133
				        		"<projectDescription>\n" + //$NON-NLS-1$
134
				        		"	<name>" + EXTERNAL_PROJECT_NAME + "</name>\n" + //$NON-NLS-1$ //$NON-NLS-2$
135
				        		"	<comment></comment>\n" + //$NON-NLS-1$
136
				        		"	<projects>\n" + //$NON-NLS-1$
137
				        		"	</projects>\n" + //$NON-NLS-1$
138
				        		"	<buildSpec>\n" + //$NON-NLS-1$
139
				        		"	</buildSpec>\n" + //$NON-NLS-1$
140
				        		"	<natures>\n" + //$NON-NLS-1$
141
				        		"	</natures>\n" + //$NON-NLS-1$
142
				        		"</projectDescription>").getBytes()); //$NON-NLS-1$
143
				    } finally {
144
				        output.close();
145
				    }
146
					project.open(null);
147
				}
148
			} catch (CoreException e) {
149
				Util.log(e, "Problem creating hidden project for external folders"); //$NON-NLS-1$
150
				return project;
151
			} catch (IOException e) {
152
				Util.log(e, "Problem creating hidden project for external folders"); //$NON-NLS-1$
153
				return project;
154
			}
155
		}
156
		return project;
157
	}
158
	
159
	public synchronized IFolder getFolder(IPath externalFolderPath) {
160
		return (IFolder) this.folders.get(externalFolderPath);
161
	}
162
	
163
	public void refreshExternalFolders(IProgressMonitor monitor) throws CoreException {
164
		final IProject project = getExternalFoldersProject();
165
		
166
		// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=63782
167
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
168
		IJavaProject[] projects = manager.getJavaModel().getJavaProjects();
169
		DeltaProcessingState deltaState = JavaModelManager.getDeltaState();
170
		for (int i = 0, length = projects.length; i < length; i++) {
171
			JavaProject javaProject = (JavaProject) projects[i];
172
			deltaState.addClasspathValidation(javaProject);
173
		}
174
		
175
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable(){
176
			public void run(IProgressMonitor pm) throws CoreException {
177
				project.touch(pm);
178
				project.refreshLocal(IResource.DEPTH_INFINITE, pm);
179
			}
180
		}, monitor);
181
	}
182
	
183
	public synchronized IFolder removeFolder(IPath externalFolderPath) {
184
		return (IFolder) this.folders.remove(externalFolderPath);
185
	}
186
187
}
(-)model/org/eclipse/jdt/internal/core/ExternalFolderChange.java (+84 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
12
13
import java.io.File;
14
import java.util.HashSet;
15
import java.util.Iterator;
16
17
import org.eclipse.core.resources.IFolder;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.jdt.core.IClasspathEntry;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.internal.compiler.util.Util;
24
25
public class ExternalFolderChange {
26
	
27
	private JavaProject project;
28
	private IClasspathEntry[] oldResolvedClasspath;
29
	
30
	public ExternalFolderChange(JavaProject project, IClasspathEntry[] oldResolvedClasspath) {
31
		this.project = project;
32
		this.oldResolvedClasspath = oldResolvedClasspath;
33
	}
34
	
35
	private HashSet getExternalFolders(IClasspathEntry[] classpath) {
36
		HashSet folders = new HashSet();
37
		for (int i = 0; i < classpath.length; i++) {
38
			IClasspathEntry entry = classpath[i];
39
			if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
40
				addExternalFolder(entry.getPath(), folders);
41
				addExternalFolder(entry.getSourceAttachmentPath(), folders);
42
			}
43
		}
44
		return folders;
45
	}
46
47
	private void addExternalFolder(IPath path, HashSet folders) {
48
		if (path == null || Util.isArchiveFileName(path.lastSegment())) 
49
			return;
50
		Object target = JavaModel.getTarget(path, false/*don't check resource existence*/);
51
		if (target instanceof File) {
52
			if (!((File) target).isFile()) {
53
				folders.add(path);
54
			}
55
		} else if (target instanceof IFolder && ExternalFoldersManager.isExternal(((IFolder) target).getFullPath())) {
56
			folders.add(path);
57
		}
58
	}
59
60
	/*
61
	 * Update external folders
62
	 */
63
	public void updateExternalFoldersIfNecessary(IProgressMonitor monitor) throws JavaModelException {
64
		HashSet oldFolders = this.oldResolvedClasspath == null ? new HashSet() : getExternalFolders(this.oldResolvedClasspath);
65
		IClasspathEntry[] newResolvedClasspath = this.project.getResolvedClasspath();
66
		HashSet newFolders = getExternalFolders(newResolvedClasspath);
67
		ExternalFoldersManager foldersManager = JavaModelManager.getExternalManager();
68
		Iterator iterator = newFolders.iterator();
69
		while (iterator.hasNext()) {
70
			Object folderPath = iterator.next();
71
			if (!oldFolders.remove(folderPath)) {
72
				try {
73
					foldersManager.createLinkFolder((IPath) folderPath, monitor);
74
				} catch (CoreException e) {
75
					throw new JavaModelException(e);
76
				}
77
			}
78
		}
79
		// removal of linked folders is done during save
80
	}
81
	public String toString() {
82
		return "ExternalFolderChange: " + this.project.getElementName(); //$NON-NLS-1$
83
	}
84
}
(-)model/org/eclipse/jdt/internal/core/ExternalPackageFragmentRoot.java (+112 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
12
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IPackageFragmentRoot;
17
import org.eclipse.jdt.core.JavaModelException;
18
19
/**
20
 * A package fragment root that corresponds to an external class folder.
21
 *
22
 * <p>NOTE: An external package fragment root never has an associated resource.
23
 *
24
 * @see org.eclipse.jdt.core.IPackageFragmentRoot
25
 * @see org.eclipse.jdt.internal.core.PackageFragmentRootInfo
26
 */
27
public class ExternalPackageFragmentRoot extends PackageFragmentRoot {
28
	
29
	/**
30
	 * The path to the external folder
31
	 * (an OS path)
32
	 */
33
	protected final IPath externalPath;
34
35
	/**
36
	 * Constructs a package fragment root which is the root of the Java package directory hierarchy 
37
	 * based on an external folder that is not contained in a <code>IJavaProject</code> and
38
	 * does not have an associated <code>IResource</code>.
39
	 */
40
	protected ExternalPackageFragmentRoot(IPath externalPath, JavaProject project) {
41
		super(null, project);
42
		this.externalPath = externalPath;
43
	}
44
45
	protected ExternalPackageFragmentRoot(IResource linkedFolder, IPath externalPath, JavaProject project) {
46
		super(linkedFolder, project);
47
		this.externalPath = externalPath == null ? linkedFolder.getLocation() : externalPath;
48
	}
49
	
50
	/**
51
	 * An external class folder is always K_BINARY.
52
	 */
53
	protected int determineKind(IResource underlyingResource) {
54
		return IPackageFragmentRoot.K_BINARY;
55
	}
56
	/**
57
	 * Returns true if this handle represents the same external folder
58
	 * as the given handle.
59
	 *
60
	 * @see Object#equals
61
	 */
62
	public boolean equals(Object o) {
63
		if (this == o)
64
			return true;
65
		if (o instanceof ExternalPackageFragmentRoot) {
66
			ExternalPackageFragmentRoot other= (ExternalPackageFragmentRoot) o;
67
			return this.externalPath.equals(other.externalPath);
68
		}
69
		return false;
70
	}
71
	public String getElementName() {
72
		return this.externalPath.lastSegment();
73
	}
74
	/**
75
	 * @see IPackageFragmentRoot
76
	 */
77
	public int getKind() {
78
		return IPackageFragmentRoot.K_BINARY;
79
	}
80
	/**
81
	 * @see IPackageFragmentRoot
82
	 */
83
	public IPath getPath() {
84
		return this.externalPath;
85
	}
86
87
	/**
88
	 * @see IJavaElement
89
	 */
90
	public IResource getUnderlyingResource() throws JavaModelException {
91
		return null;
92
	}
93
	public int hashCode() {
94
		return this.externalPath.hashCode();
95
	}
96
	/**
97
	 * @see IPackageFragmentRoot
98
	 */
99
	public boolean isExternal() {
100
		return true;
101
	}
102
	
103
	public IResource resource(PackageFragmentRoot root) {
104
		if (this.resource == null)
105
			return (IResource) (this.resource = JavaModelManager.getExternalManager().getFolder(this.externalPath));
106
		return super.resource(root);
107
	}
108
109
	protected void toStringAncestors(StringBuffer buffer) {
110
		// don't show project as it is irrelevant for external folders.
111
	}
112
}
(-)src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java (+20 lines)
Lines 890-895 Link Here
890
	}
890
	}
891
}
891
}
892
892
893
public void testContainerInitializer21() throws CoreException {
894
	try {
895
		createProject("P1");
896
		createExternalFolder("externalLib");
897
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", getExternalFolderPath("externalLib")}));
898
		IJavaProject p2 = createJavaProject(
899
				"P2", 
900
				new String[] {}, 
901
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
902
				"");
903
		IPackageFragmentRoot root = p2.getPackageFragmentRoot(getExternalFolderPath("externalLib"));
904
		assertTrue(getExternalFolderPath("externalLib") + " should exist", root.exists());
905
	} finally {
906
		stopDeltas();
907
		deleteExternalFolder("externalLib");
908
		deleteProject("P1");
909
		deleteProject("P2");
910
	}
911
}
912
893
public void testVariableInitializer01() throws CoreException {
913
public void testVariableInitializer01() throws CoreException {
894
	try {
914
	try {
895
		createProject("P1");
915
		createProject("P1");
(-)src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java (-3 lines)
Lines 44-52 Link Here
44
//		TESTS_NUMBERS = new int[] { 79860, 80918, 91078 };
44
//		TESTS_NUMBERS = new int[] { 79860, 80918, 91078 };
45
//		TESTS_RANGE = new int[] { 83304, -1 };
45
//		TESTS_RANGE = new int[] { 83304, -1 };
46
}
46
}
47
private void touch(File f) {
48
	f.setLastModified(f.lastModified() + 10000);
49
}
50
47
51
/*
48
/*
52
 * Ensures that passing an empty scope to refreshExternalArchives(..) doesn't throw a NPE
49
 * Ensures that passing an empty scope to refreshExternalArchives(..) doesn't throw a NPE
(-)src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java (+262 lines)
Lines 55-60 Link Here
55
	super.tearDownSuite();
55
	super.tearDownSuite();
56
}
56
}
57
57
58
/*
59
 * Ensures that adding a library entry for an existing empty external library folder updates the model
60
 */
61
public void testAddExternalLibFolder1() throws CoreException {
62
	try {
63
		IJavaProject p = createJavaProject("P");
64
		createExternalFolder("externalLib");
65
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
66
		assertElementDescendants(
67
			"Unexpected project content", 
68
			"P\n" + 
69
			"  "+ getExternalPath() + "externalLib\n" + 
70
			"    <default> (...)",
71
			p
72
		);
73
	} finally {
74
		deleteExternalFolder("externalLib");
75
		deleteProject("P");
76
	}
77
}
78
79
/*
80
 * Ensures that adding a library entry for an non-existing external library folder updates the model
81
 */
82
public void testAddExternalLibFolder2() throws CoreException {
83
	try {
84
		IJavaProject p = createJavaProject("P");
85
		IPath path = new Path(getExternalFolderPath("externalLib"));
86
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
87
		assertElementDescendants(
88
			"Unexpected project content", 
89
			"P",
90
			p
91
		);
92
	} finally {
93
		deleteProject("P");
94
	}
95
}
96
97
/*
98
 * Ensures that adding a library entry for an existing non-empty external library folder updates the model
99
 */
100
public void testAddExternalLibFolder3() throws CoreException, IOException {
101
	try {
102
		IJavaProject p = createJavaProject("P");
103
		createExternalFolder("externalLib/p");
104
		createExternalFile("externalLib/p/X.class", "");
105
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
106
		assertElementDescendants(
107
			"Unexpected project content", 
108
			"P\n" + 
109
			"  "+ getExternalPath() + "externalLib\n" + 
110
			"    <default> (...)\n" + 
111
			"    p (...)\n" + 
112
			"      X.class",
113
			p
114
		);
115
	} finally {
116
		deleteExternalFolder("externalLib");
117
		deleteProject("P");
118
	}
119
}
120
121
/*
122
 * Ensures that creating an external library folder referenced by a library entry and refreshing updates the model
123
 */
124
public void testAddExternalLibFolder4() throws CoreException {
125
	try {
126
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
127
		expandAll(p);
128
		createExternalFolder("externalLib");
129
		refresh(p);
130
		assertElementDescendants(
131
			"Unexpected project content", 
132
			"P\n" + 
133
			"  "+ getExternalPath() + "externalLib\n" + 
134
			"    <default> (...)",
135
			p
136
		);
137
	} finally {
138
		deleteExternalFolder("externalLib");
139
		deleteProject("P");
140
	}
141
}
142
143
/*
144
 * Ensures that importing a Java project with a library entry for an existing empty external library folder after restart
145
 * updates the model
146
 */
147
public void testAddExternalLibFolder5() throws CoreException {
148
	try {
149
		simulateExitRestart();
150
		createExternalFolder("externalLib/p");
151
		createExternalFile("externalLib/p/X.class", "");
152
		IJavaProject p = importJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
153
		waitForAutoBuild();
154
		assertElementDescendants(
155
			"Unexpected project content", 
156
			"P\n" + 
157
			"  "+ getExternalPath() + "externalLib\n" + 
158
			"    <default> (...)\n" + 
159
			"    p (...)\n" + 
160
			"      X.class",
161
			p
162
		);
163
	} finally {
164
		deleteExternalFolder("externalLib");
165
		deleteProject("P");
166
	}
167
}
58
168
59
/**
169
/**
60
 * Test adding a non-java resource in a package fragment root that correspond to
170
 * Test adding a non-java resource in a package fragment root that correspond to
Lines 140-145 Link Here
140
	IResource corr= type.getCorrespondingResource();
250
	IResource corr= type.getCorrespondingResource();
141
	assertTrue("incorrect corresponding resource", corr == null);
251
	assertTrue("incorrect corresponding resource", corr == null);
142
}
252
}
253
254
/*
255
 * Ensures that changing the content of an external library folder and refreshing updates the model
256
 */
257
public void testChangeExternalLibFolder1() throws CoreException, IOException {
258
	try {
259
		createExternalFolder("externalLib");
260
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "bin");
261
		expandAll(p);
262
		
263
		createExternalFolder("externalLib/p");
264
		createExternalFile("externalLib/p/X.class", "");
265
		refresh(p);
266
		assertElementDescendants(
267
			"Unexpected project content", 
268
			"P\n" + 
269
			"  "+ getExternalPath() + "externalLib\n" + 
270
			"    <default> (...)\n" + 
271
			"    p (...)\n" + 
272
			"      X.class",
273
			p
274
		);
275
	} finally {
276
		deleteExternalFolder("externalLib");
277
		deleteProject("P");
278
	}
279
}
280
281
/*
282
 * Ensures that changing the content of an external library folder and refreshing updates the model
283
 */
284
public void testChangeExternalLibFolder2() throws CoreException, IOException {
285
	try {
286
		createExternalFolder("externalLib/p");
287
		createExternalFile("externalLib/p/X.class", "");
288
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "bin");
289
		expandAll(p);
290
		
291
		deleteExternalFolder("externalLib/p");
292
		refresh(p);
293
		assertElementDescendants(
294
			"Unexpected project content", 
295
			"P\n" + 
296
			"  "+ getExternalPath() + "externalLib\n" + 
297
			"    <default> (...)",
298
			p
299
		);
300
	} finally {
301
		deleteExternalFolder("externalLib");
302
		deleteProject("P");
303
	}
304
}
305
143
/**
306
/**
144
 * When the output location is changed, package fragments can be added/removed
307
 * When the output location is changed, package fragments can be added/removed
145
 */
308
 */
Lines 856-861 Link Here
856
}
1019
}
857
1020
858
/*
1021
/*
1022
 * Ensure that the non-Java resources of a package in an external library folder are correct.
1023
 */
1024
public void testPackageFragmentNonJavaResources12() throws CoreException {
1025
	try {
1026
		createExternalFolder("externalLib/p/META-INF");
1027
		createExternalFile("externalLib/p/test.txt", "test");
1028
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1029
		IPackageFragment pkg = getPackageFragmentRoot("P", getExternalFolderPath("externalLib")).getPackageFragment("p");
1030
		Object[] resources = pkg.getNonJavaResources();
1031
		assertResourceTreeEquals(
1032
			"unexpected non java resources", 
1033
			"",
1034
			resources);
1035
	} finally {
1036
		deleteProject("P");
1037
		deleteExternalFolder("externalLib");
1038
	}
1039
}
1040
1041
/*
859
 * Ensures that the package-info.class file doesn't appear as a child of a package if proj=src
1042
 * Ensures that the package-info.class file doesn't appear as a child of a package if proj=src
860
 * (regression test for bug 99654 [5.0] JavaModel returns both IClassFile and ICompilationUnit for package-info.java)
1043
 * (regression test for bug 99654 [5.0] JavaModel returns both IClassFile and ICompilationUnit for package-info.java)
861
 */
1044
 */
Lines 997-1002 Link Here
997
		"lib.jar [in JavaProjectTests]",
1180
		"lib.jar [in JavaProjectTests]",
998
		parentRoot);
1181
		parentRoot);
999
}
1182
}
1183
/*
1184
 * Ensures that the non-Java resources of an external library package fragment root are correct
1185
 */
1186
public void testPackageFragmentRootNonJavaResources8() throws CoreException {
1187
	try {
1188
		createExternalFolder("externalLib/META-INF");
1189
		createExternalFile("externalLib/test.txt", "test");
1190
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1191
		IPackageFragmentRoot root = getPackageFragmentRoot("P", getExternalFolderPath("externalLib"));
1192
		Object[] resources = root.getNonJavaResources();
1193
		assertResourceTreeEquals(
1194
			"unexpected non java resources", 
1195
			"",
1196
			resources);
1197
	} finally {
1198
		deleteProject("P");
1199
		deleteExternalFolder("externalLib");
1200
	}
1201
}
1000
/**
1202
/**
1001
 * Test raw entry inference performance for package fragment root
1203
 * Test raw entry inference performance for package fragment root
1002
 */
1204
 */
Lines 1395-1400 Link Here
1395
	}
1597
	}
1396
}
1598
}
1397
1599
1600
/*
1601
 * Ensures that removing a library entry for an existing external library folder updates the model
1602
 */
1603
public void testRemoveExternalLibFolder1() throws CoreException {
1604
	try {
1605
		createExternalFolder("externalLib");
1606
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1607
		expandAll(p);
1608
		setClasspath(p, new IClasspathEntry[] {});
1609
		assertElementDescendants(
1610
			"Unexpected project content", 
1611
			"P",
1612
			p
1613
		);
1614
	} finally {
1615
		deleteExternalFolder("externalLib");
1616
		deleteProject("P");
1617
	}
1618
}
1619
1620
/*
1621
 * Ensures that removing a library entry for a non-existing external library folder updates the model
1622
 */
1623
public void testRemoveExternalLibFolder2() throws CoreException {
1624
	try {
1625
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1626
		expandAll(p);
1627
		setClasspath(p, new IClasspathEntry[] {});
1628
		assertElementDescendants(
1629
			"Unexpected project content", 
1630
			"P",
1631
			p
1632
		);
1633
	} finally {
1634
		deleteProject("P");
1635
	}
1636
}
1637
1638
1639
/*
1640
 * Ensures that removing an external library folder referenced by a library entry and refreshing updates the model
1641
 */
1642
public void testRemoveExternalLibFolder3() throws CoreException {
1643
	try {
1644
		createExternalFolder("externalLib");
1645
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1646
		expandAll(p);
1647
		deleteExternalFolder("externalLib");
1648
		refresh(p);
1649
		assertElementDescendants(
1650
			"Unexpected project content", 
1651
			"P",
1652
			p
1653
		);
1654
	} finally {
1655
		deleteExternalFolder("externalLib");
1656
		deleteProject("P");
1657
	}
1658
}
1659
1398
/**
1660
/**
1399
 * Test that the correct package fragments exist in the project.
1661
 * Test that the correct package fragments exist in the project.
1400
 */
1662
 */
(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (+33 lines)
Lines 696-701 Link Here
696
    }
696
    }
697
}
697
}
698
/*
698
/*
699
 * Ensures that subtypes are found in an external library folder
700
 */
701
public void testExternalFolder() throws CoreException, IOException {
702
	try {
703
		createExternalFolder("externalLib");
704
		Util.compile(
705
			new String[] {
706
				"p/X.java",
707
				"package p;\n" +
708
				"public class X {\n" +
709
				"}",
710
				"p/Y.java",
711
				"package p;\n" +
712
				"public class Y extends X {\n" +
713
				"}",
714
			},
715
			new HashMap(),
716
			getExternalFolderPath("externalLib"));
717
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
718
		IClassFile classFile = getClassFile("P", getExternalFolderPath("externalLib"), "p", "X.class");
719
		ITypeHierarchy hierarchy = classFile.getType().newTypeHierarchy(null);
720
		assertHierarchyEquals(
721
			"Focus: X [in X.class [in p [in "+ getExternalPath() + "externalLib]]]\n" + 
722
			"Super types:\n" + 
723
			"Sub types:\n" + 
724
			"  Y [in Y.class [in p [in "+ getExternalPath() + "externalLib]]]\n",
725
			hierarchy);
726
	} finally {
727
		deleteProject("P");
728
		deleteExternalFolder("externalLib");
729
	}
730
}
731
/*
699
 * Ensures that a call to IJavaProject.findType("java.lang.Object") doesn't cause the hierarchy
732
 * Ensures that a call to IJavaProject.findType("java.lang.Object") doesn't cause the hierarchy
700
 * computation to throw a StackOverFlow
733
 * computation to throw a StackOverFlow
701
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=209222)
734
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=209222)
(-)src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java (+84 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.io.File;
13
import java.io.IOException;
14
import java.io.IOException;
14
15
15
import junit.framework.Test;
16
import junit.framework.Test;
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFolder;
17
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.IncrementalProjectBuilder;
21
import org.eclipse.core.resources.IncrementalProjectBuilder;
19
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IPath;
Lines 52-57 Link Here
52
public AttachSourceTests(String name) {
55
public AttachSourceTests(String name) {
53
	super(name);
56
	super(name);
54
}
57
}
58
protected String getExternalFolder() {
59
	return getExternalFolderPath("externalFolder");
60
}
55
public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) {
61
public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) {
56
	ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2);
62
	ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2);
57
	parser.setSource(classFile);
63
	parser.setSource(classFile);
Lines 74-79 Link Here
74
	this.pkgFragmentRoot = this.currentProject.getPackageFragmentRoot(this.getFile("/AttachSourceTests/attach.jar"));
80
	this.pkgFragmentRoot = this.currentProject.getPackageFragmentRoot(this.getFile("/AttachSourceTests/attach.jar"));
75
	setUpGenericJar();
81
	setUpGenericJar();
76
	setUpInnerClassesJar();
82
	setUpInnerClassesJar();
83
	setupExternalLibrary();
84
}
85
private void setupExternalLibrary() throws IOException {
86
	String externalFolder = getExternalFolder();
87
	String[] pathsAndContents = 
88
		new String[] {
89
			"p/X.java",
90
			"package p;\n" +
91
			"public class X {\n" +
92
			"}"
93
		};
94
	org.eclipse.jdt.core.tests.util.Util.createClassFolder(pathsAndContents, externalFolder + "lib", "1.4");
95
	org.eclipse.jdt.core.tests.util.Util.createSourceDir(pathsAndContents, externalFolder + "src");
77
}
96
}
78
private void setUpGenericJar() throws IOException, CoreException {
97
private void setUpGenericJar() throws IOException, CoreException {
79
	String[] pathAndContents = new String[] {
98
	String[] pathAndContents = new String[] {
Lines 161-166 Link Here
161
 * Reset the jar placeholder and delete project.
180
 * Reset the jar placeholder and delete project.
162
 */
181
 */
163
public void tearDownSuite() throws Exception {
182
public void tearDownSuite() throws Exception {
183
	org.eclipse.jdt.core.tests.util.Util.flushDirectoryContent(new File(getExternalFolder()));
164
	deleteProject(this.currentProject);
184
	deleteProject(this.currentProject);
165
	super.tearDownSuite();
185
	super.tearDownSuite();
166
}
186
}
Lines 323-328 Link Here
323
	assertTrue("Source attachment root path should be null", null ==this.pkgFragmentRoot.getSourceAttachmentRootPath());
343
	assertTrue("Source attachment root path should be null", null ==this.pkgFragmentRoot.getSourceAttachmentRootPath());
324
}
344
}
325
/*
345
/*
346
 * Ensures that one can attach an external source folder to a library folder.
347
 */
348
public void testExternalFolder1() throws CoreException {
349
	try {
350
		IProject p = createProject("P1");
351
		IFolder lib = p.getFolder("lib");
352
		lib.createLink(new Path(getExternalFolder() + "lib"), IResource.NONE, null);
353
		IJavaProject javaProject = createJavaProject("P2", new String[0], new String[] {"/P1/lib"}, "");
354
		IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(lib);
355
		attachSource(root, getExternalFolder() + "src", "");
356
		IType type = root.getPackageFragment("p").getClassFile("X.class").getType();
357
		assertSourceEquals(
358
			"Unexpected source",
359
			"public class X {\n" + 
360
			"}",
361
			type.getSource());
362
	} finally {
363
		deleteProject("P1");
364
		deleteProject("P2");
365
	}
366
}
367
/*
368
 * Ensures that one can attach a source folder to an external library folder.
369
 */
370
public void testExternalFolder2() throws CoreException {
371
	try {
372
		IProject p = createProject("P1");
373
		IFolder src = p.getFolder("src");
374
		src.createLink(new Path(getExternalFolder() + "src"), IResource.NONE, null);
375
		String externalLib = getExternalFolder() + "lib";
376
		IJavaProject javaProject = createJavaProject("P2", new String[0], new String[] {externalLib}, "");
377
		IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(externalLib);
378
		attachSource(root, "/P1/src", "");
379
		IType type = root.getPackageFragment("p").getClassFile("X.class").getType();
380
		assertSourceEquals(
381
			"Unexpected source",
382
			"public class X {\n" + 
383
			"}",
384
			type.getSource());
385
	} finally {
386
		deleteProject("P1");
387
		deleteProject("P2");
388
	}
389
}
390
/*
391
 * Ensures that one can attach an external source folder to an external library folder.
392
 */
393
public void testExternalFolder3() throws CoreException {
394
	try {
395
		String externalLib = getExternalFolder() + "lib";
396
		IJavaProject javaProject = createJavaProject("P", new String[0], new String[] {externalLib}, "");
397
		IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(externalLib);
398
		attachSource(root, getExternalFolder() + "src", "");
399
		IType type = root.getPackageFragment("p").getClassFile("X.class").getType();
400
		assertSourceEquals(
401
			"Unexpected source",
402
			"public class X {\n" + 
403
			"}",
404
			type.getSource());
405
	} finally {
406
		deleteProject("P");
407
	}
408
}
409
/*
326
 * Ensures that the source of a generic method can be retrieved.
410
 * Ensures that the source of a generic method can be retrieved.
327
 */
411
 */
328
public void testGeneric1() throws JavaModelException {
412
public void testGeneric1() throws JavaModelException {
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-8 / +176 lines)
Lines 142-152 Link Here
142
	file.setLastModified(System.currentTimeMillis() + 2000);
142
	file.setLastModified(System.currentTimeMillis() + 2000);
143
	return file;
143
	return file;
144
}
144
}
145
protected File createFolder(File parent, String name) {
146
	File file = new File(parent, name);
147
	file.mkdirs();
148
	return file;
149
}
150
protected int numberOfCycleMarkers(IJavaProject javaProject) throws CoreException {
145
protected int numberOfCycleMarkers(IJavaProject javaProject) throws CoreException {
151
	IMarker[] markers = javaProject.getProject().findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
146
	IMarker[] markers = javaProject.getProject().findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
152
	int result = 0;
147
	int result = 0;
Lines 161-166 Link Here
161
}
156
}
162
157
163
/*
158
/*
159
 * Ensures that adding a library entry for an existing external library folder doesn't generate a marker
160
 */
161
public void testAddExternalLibFolder1() throws CoreException {
162
	try {
163
		IJavaProject p = createJavaProject("P");
164
		createExternalFolder("externalLib");
165
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
166
		assertMarkers("Unexpected markers", "", p);
167
	} finally {
168
		deleteExternalFolder("externalLib");
169
		deleteProject("P");
170
	}
171
}
172
173
/*
174
 * Ensures that creating a project with a library entry for an existing external library folder doesn't generate a marker
175
 */
176
public void testAddExternalLibFolder2() throws CoreException {
177
	try {
178
		createExternalFolder("externalLib");
179
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
180
		assertMarkers("Unexpected markers", "", p);
181
	} finally {
182
		deleteExternalFolder("externalLib");
183
		deleteProject("P");
184
	}
185
}
186
187
/*
188
 * Ensures that adding a library entry for a non-existing external library folder generates a marker
189
 */
190
public void testAddExternalLibFolder3() throws CoreException {
191
	try {
192
		waitForAutoBuild();
193
		IJavaProject p = createJavaProject("P");
194
		IPath path = new Path(getExternalFolderPath("externalLib"));
195
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
196
		assertMarkers(
197
			"Unexpected markers", 
198
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
199
			p);
200
	} finally {
201
		deleteProject("P");
202
	}
203
}
204
205
/*
206
 * Ensures that creating a project with a library entry for a non-existing external library folder generates a marker
207
 */
208
public void testAddExternalLibFolder4() throws CoreException {
209
	try {
210
		waitForAutoBuild();
211
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
212
		assertMarkers(
213
			"Unexpected markers", 
214
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
215
			p);
216
	} finally {
217
		deleteProject("P");
218
	}
219
}
220
221
/*
222
 * Ensures that creating an external library folder referenced by a library entry and refreshing removes the marker
223
 */
224
public void testAddExternalLibFolder5() throws CoreException {
225
	try {
226
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
227
		waitForAutoBuild();
228
		createExternalFolder("externalLib");
229
		refresh(p);
230
		assertMarkers("Unexpected markers", "", p);
231
	} finally {
232
		deleteExternalFolder("externalLib");
233
		deleteProject("P");
234
	}
235
}
236
237
/*
238
 * Ensures that creating an external library folder referenced by a library entry and refreshing after a restart
239
 * removes the marker
240
 */
241
public void testAddExternalLibFolder6() throws CoreException {
242
	try {
243
		simulateExitRestart();
244
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
245
		waitForAutoBuild();
246
		createExternalFolder("externalLib");
247
		refresh(p);
248
		assertMarkers("Unexpected markers", "", p);
249
	} finally {
250
		deleteExternalFolder("externalLib");
251
		deleteProject("P");
252
	}
253
}
254
255
/*
164
 * Ensures that adding a project to a container triggers a classpath delta
256
 * Ensures that adding a project to a container triggers a classpath delta
165
 * (regression test for 154071 No notification of change if a project is added or removed from a container)
257
 * (regression test for 154071 No notification of change if a project is added or removed from a container)
166
 */
258
 */
Lines 2528-2545 Link Here
2528
	}
2620
	}
2529
}
2621
}
2530
/*
2622
/*
2531
 * Ensures that an external class folder cannot be put on the classpath.
2623
 * Ensures that an attempting to put a non-existing external class folder on the classpath
2624
 * creates the correct marker.
2532
 */
2625
 */
2533
public void testInvalidExternalClassFolder() throws CoreException {
2626
public void testInvalidExternalClassFolder() throws CoreException {
2534
	try {
2627
	try {
2535
		String externalPath = getExternalPath();
2628
		String externalPath = getExternalPath() + "nonExisting";
2536
		// remove trailing slash
2629
		// remove trailing slash
2537
		if (Path.fromOSString(externalPath).segmentCount() > 0)
2630
		if (Path.fromOSString(externalPath).segmentCount() > 0)
2538
			externalPath = externalPath.substring(0, externalPath.length()-1);
2631
			externalPath = externalPath.substring(0, externalPath.length()-1);
2539
		IJavaProject proj =  createJavaProject("P", new String[] {}, new String[] {externalPath}, "bin");
2632
		IJavaProject proj =  createJavaProject("P", new String[] {}, new String[] {externalPath}, "bin");
2540
		assertMarkers(
2633
		assertMarkers(
2541
			"Unexpected markers",
2634
			"Unexpected markers",
2542
			"Required library cannot denote external folder: \'" + externalPath + "\' for project 'P'",
2635
			"Project \'P\' is missing required library: \'" + externalPath + "\'",
2543
			proj);
2636
			proj);
2544
	} finally {
2637
	} finally {
2545
		deleteProject("P");
2638
		deleteProject("P");
Lines 3842-3847 Link Here
3842
}
3935
}
3843
3936
3844
/*
3937
/*
3938
 * Ensures that removing a library entry for an existing external library folder doesn't generate a marker
3939
 */
3940
public void testRemoveExternalLibFolder1() throws CoreException {
3941
	try {
3942
		createExternalFolder("externalLib");
3943
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
3944
		waitForAutoBuild();
3945
		setClasspath(p, new IClasspathEntry[] {});
3946
		assertMarkers("Unexpected markers", "", p);
3947
	} finally {
3948
		deleteExternalFolder("externalLib");
3949
		deleteProject("P");
3950
	}
3951
}
3952
3953
/*
3954
 * Ensures that removing a library entry for a non-existing external library folder removes the marker
3955
 */
3956
public void testRemoveExternalLibFolder2() throws CoreException {
3957
	try {
3958
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
3959
		waitForAutoBuild();
3960
		setClasspath(p, new IClasspathEntry[] {});
3961
		assertMarkers(
3962
			"Unexpected markers", 
3963
			"",
3964
			p);
3965
	} finally {
3966
		deleteProject("P");
3967
	}
3968
}
3969
3970
/*
3971
 * Ensures that removing an external library folder referenced by a library entry creates a marker
3972
 */
3973
public void testRemoveExternalLibFolder3() throws CoreException {
3974
	try {
3975
		createExternalFolder("externalLib");
3976
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
3977
		waitForAutoBuild();
3978
		deleteExternalFolder("externalLib");
3979
		refresh(p);
3980
		assertMarkers(
3981
			"Unexpected markers", 
3982
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
3983
			p);
3984
	} finally {
3985
		deleteExternalFolder("externalLib");
3986
		deleteProject("P");
3987
	}
3988
}
3989
3990
/*
3991
 * Ensures that removing an external library folder referenced by a library entry and refreshing after a restart
3992
 * creates a marker
3993
 */
3994
public void testRemoveExternalLibFolder4() throws CoreException {
3995
	try {
3996
		simulateExitRestart();
3997
		createExternalFolder("externalLib");
3998
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
3999
		waitForAutoBuild();
4000
		deleteExternalFolder("externalLib");
4001
		refresh(p);
4002
		assertMarkers(
4003
			"Unexpected markers", 
4004
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
4005
			p);
4006
	} finally {
4007
		deleteExternalFolder("externalLib");
4008
		deleteProject("P");
4009
	}
4010
}
4011
4012
/*
3845
 * Ensures that renaming a .jar file and updating the classpath in a PRE_BUILD event doesn't leave markers
4013
 * Ensures that renaming a .jar file and updating the classpath in a PRE_BUILD event doesn't leave markers
3846
 * (regression test for bug 177922 FlexibleProjectContainer refresh logic sporadically leaves project with "missing library" error on rename/delete)
4014
 * (regression test for bug 177922 FlexibleProjectContainer refresh logic sporadically leaves project with "missing library" error on rename/delete)
3847
 */
4015
 */
(-)src/org/eclipse/jdt/core/tests/model/OverflowingCacheTests.java (-1 / +1 lines)
Lines 229-235 Link Here
229
			return null;
229
			return null;
230
		}
230
		}
231
231
232
		public IResource getResource() {
232
		public IResource resource(PackageFragmentRoot root) {
233
			return null;
233
			return null;
234
		}
234
		}
235
235
(-)src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java (-1 / +18 lines)
Lines 31-37 Link Here
31
protected void assertElementDescendants(String message,  String expected, IJavaElement element) throws CoreException {
31
protected void assertElementDescendants(String message,  String expected, IJavaElement element) throws CoreException {
32
	String actual = expandAll(element);
32
	String actual = expandAll(element);
33
	if (!expected.equals(actual)){
33
	if (!expected.equals(actual)){
34
	 	System.out.println(Util.displayString(actual, 4));
34
	 	System.out.print(displayString(actual, 3));
35
	 	System.out.println(",");
35
	}
36
	}
36
	assertEquals(
37
	assertEquals(
37
		message,
38
		message,
Lines 85-90 Link Here
85
	}
86
	}
86
}
87
}
87
88
89
protected boolean createExternalFolder(String relativePath) {
90
	return new File(getExternalPath(), relativePath).mkdirs();
91
}
92
93
protected void createExternalFile(String relativePath, String contents) {
94
	Util.writeToFile(contents, getExternalPath() + relativePath);
95
}
96
88
protected IFile createFile(String path, InputStream content) throws CoreException {
97
protected IFile createFile(String path, InputStream content) throws CoreException {
89
	IFile file = getFile(path);
98
	IFile file = getFile(path);
90
	file.create(content, true, null);
99
	file.create(content, true, null);
Lines 106-114 Link Here
106
protected IFile createFile(String path, String content, String charsetName) throws CoreException, UnsupportedEncodingException {
115
protected IFile createFile(String path, String content, String charsetName) throws CoreException, UnsupportedEncodingException {
107
	return createFile(path, content.getBytes(charsetName));
116
	return createFile(path, content.getBytes(charsetName));
108
}
117
}
118
protected File createFolder(File parent, String name) {
119
	File file = new File(parent, name);
120
	file.mkdirs();
121
	return file;
122
}
109
protected IFolder createFolder(String path) throws CoreException {
123
protected IFolder createFolder(String path) throws CoreException {
110
	return createFolder(new Path(path));
124
	return createFolder(new Path(path));
111
}
125
}
126
protected void deleteExternalFolder(String relativePath) {
127
	deleteFile(new File(getExternalPath() + relativePath));
128
}
112
protected void deleteFile(String filePath) throws CoreException {
129
protected void deleteFile(String filePath) throws CoreException {
113
	deleteResource(this.getFile(filePath));
130
	deleteResource(this.getFile(filePath));
114
}
131
}
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (-2 / +2 lines)
Lines 338-344 Link Here
338
338
339
		createJavaProject("P2", new String[] {}, new String[] {}, null, null, new String[] {"/P1"}, null, null, new boolean[] {true}, "", null, null, null, "1.4");
339
		createJavaProject("P2", new String[] {}, new String[] {}, null, null, new String[] {"/P1"}, null, null, new boolean[] {true}, "", null, null, null, "1.4");
340
340
341
		createJavaProject("P3", new String[] {"src"}, new String[] {"JCL_LIB"}, null, null, new String[] {"/P2"}, null, new String[][] {new String[] {"**/X"}}, false/*don't combine access restrictions*/, new boolean[] {true}, "bin", null, null, null, "1.4");
341
		createJavaProject("P3", new String[] {"src"}, new String[] {"JCL_LIB"}, null, null, new String[] {"/P2"}, null, new String[][] {new String[] {"**/X"}}, false/*don't combine access restrictions*/, new boolean[] {true}, "bin", null, null, null, "1.4", false/*don't import*/);
342
		setUpWorkingCopy("/P3/src/Y.java", "public class Y extends p.X {}");
342
		setUpWorkingCopy("/P3/src/Y.java", "public class Y extends p.X {}");
343
		assertProblems(
343
		assertProblems(
344
			"Unexpected problems",
344
			"Unexpected problems",
Lines 361-367 Link Here
361
361
362
		createJavaProject("P2", new String[] {}, new String[] {}, null, null, new String[] {"/P1"}, null, null, new boolean[] {true}, "", null, null, null, "1.4");
362
		createJavaProject("P2", new String[] {}, new String[] {}, null, null, new String[] {"/P1"}, null, null, new boolean[] {true}, "", null, null, null, "1.4");
363
363
364
		createJavaProject("P3", new String[] {"src"}, new String[] {"JCL_LIB"}, null, null, new String[] {"/P2"}, null, new String[][] {new String[] {"**/X"}}, true/*combine access restrictions*/, new boolean[] {true}, "bin", null, null, null, "1.4");
364
		createJavaProject("P3", new String[] {"src"}, new String[] {"JCL_LIB"}, null, null, new String[] {"/P2"}, null, new String[][] {new String[] {"**/X"}}, true/*combine access restrictions*/, new boolean[] {true}, "bin", null, null, null, "1.4", false/*don't import*/);
365
		setUpWorkingCopy("/P3/src/Y.java", "public class Y extends p.X {}");
365
		setUpWorkingCopy("/P3/src/Y.java", "public class Y extends p.X {}");
366
		assertProblems(
366
		assertProblems(
367
			"Unexpected problems",
367
			"Unexpected problems",
(-)src/org/eclipse/jdt/core/tests/model/JavaElementDeltaTests.java (-15 / +302 lines)
Lines 13-38 Link Here
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
14
15
import org.eclipse.core.resources.*;
15
import org.eclipse.core.resources.*;
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IWorkspaceRunnable;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.Path;
19
import org.eclipse.core.runtime.Path;
24
import org.eclipse.jdt.core.*;
20
import org.eclipse.jdt.core.*;
25
import org.eclipse.jdt.core.ElementChangedEvent;
26
import org.eclipse.jdt.core.IClasspathEntry;
27
import org.eclipse.jdt.core.ICompilationUnit;
28
import org.eclipse.jdt.core.IElementChangedListener;
29
import org.eclipse.jdt.core.IJavaElementDelta;
30
import org.eclipse.jdt.core.IJavaProject;
31
import org.eclipse.jdt.core.IPackageFragment;
32
import org.eclipse.jdt.core.JavaCore;
33
import org.eclipse.jdt.internal.core.*;
21
import org.eclipse.jdt.internal.core.*;
34
import org.eclipse.jdt.internal.core.JavaModelManager;
35
import org.eclipse.jdt.internal.core.JavaProject;
36
22
37
import junit.framework.Test;
23
import junit.framework.Test;
38
24
Lines 275-280 Link Here
275
		deleteProject("P");
261
		deleteProject("P");
276
	}
262
	}
277
}
263
}
264
265
/*
266
 * Ensures that adding a library entry for an existing external library folder triggers the correct delta
267
 */
268
public void testAddExternalLibFolder1() throws CoreException {
269
	try {
270
		IJavaProject p = createJavaProject("P");
271
		createExternalFolder("externalLib");
272
		refresh(p);
273
		startDeltas();
274
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
275
		assertDeltas(
276
			"Unexpected delta", 
277
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
278
			"	<project root>[*]: {REMOVED FROM CLASSPATH}\n" + 
279
			"	"+ getExternalPath() + "externalLib[*]: {ADDED TO CLASSPATH}\n" + 
280
			"	"+ getExternalJCLPathString() + "[*]: {REMOVED FROM CLASSPATH}\n" + 
281
			"	ResourceDelta(/P/.classpath)[*]"
282
		);
283
	} finally {
284
		stopDeltas();
285
		deleteExternalFolder("externalLib");
286
		deleteProject("P");
287
	}
288
}
289
290
/*
291
 * Ensures that adding a library entry for a non-existing external library folder triggers the correct delta
292
 */
293
public void testAddExternalLibFolder2() throws CoreException {
294
	try {
295
		IJavaProject p = createJavaProject("P");
296
		refresh(p);
297
		IPath path = new Path(getExternalFolderPath("externalLib"));
298
		startDeltas();
299
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
300
		assertDeltas(
301
			"Unexpected delta", 
302
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
303
			"	<project root>[*]: {REMOVED FROM CLASSPATH}\n" + 
304
			"	"+ getExternalJCLPathString() + "[*]: {REMOVED FROM CLASSPATH}\n" + 
305
			"	ResourceDelta(/P/.classpath)[*]"
306
		);
307
	} finally {
308
		stopDeltas();
309
		deleteProject("P");
310
	}
311
}
312
313
/*
314
 * Ensures that creating an external library folder referenced by a library entry and refreshing triggers the correct delta
315
 */
316
public void testAddExternalLibFolder3() throws CoreException {
317
	try {
318
		IJavaProject p =createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
319
		waitForAutoBuild(); // wait for the creation of the linked folder
320
		startDeltas();
321
		createExternalFolder("externalLib");
322
		refresh(p);
323
		assertDeltas(
324
			"Unexpected delta", 
325
			"P[*]: {CHILDREN}\n" + 
326
			"	"+ getExternalPath() + "externalLib[+]: {}"
327
		);
328
	} finally {
329
		stopDeltas();
330
		deleteExternalFolder("externalLib");
331
		deleteProject("P");
332
	}
333
}
334
335
/*
336
 * Ensures that creating an external library folder referenced by a library entry and refreshing after a restart triggers the correct delta
337
 */
338
public void testAddExternalLibFolder4() throws CoreException {
339
	try {
340
		simulateExitRestart();
341
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
342
		waitForAutoBuild(); // wait for the creation of the linked folder
343
		startDeltas();
344
		createExternalFolder("externalLib");
345
		refresh(p);
346
		assertDeltas(
347
			"Unexpected delta", 
348
			"P[*]: {CHILDREN}\n" + 
349
			"	"+ getExternalPath() + "externalLib[+]: {}"
350
		);
351
	} finally {
352
		stopDeltas();
353
		deleteExternalFolder("externalLib");
354
		deleteProject("P");
355
	}
356
}
357
278
/*
358
/*
279
 * Ensure that a resource delta is fired when a file is added to a non-java project.
359
 * Ensure that a resource delta is fired when a file is added to a non-java project.
280
 * (regression test for bug 18698 Seeing non-java projects in package view)
360
 * (regression test for bug 18698 Seeing non-java projects in package view)
Lines 698-703 Link Here
698
	}
778
	}
699
}
779
}
700
780
781
/*
782
 * Ensures that changing an external library folder referenced by a library entry and refreshing triggers the correct delta
783
 */
784
public void testChangeExternalLibFolder1() throws CoreException {
785
	try {
786
		createExternalFolder("externalLib");
787
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
788
		startDeltas();
789
		createExternalFolder("externalLib/p");
790
		refresh(p);
791
		assertDeltas(
792
			"Unexpected delta", 
793
			"P[*]: {CHILDREN}\n" + 
794
			"	"+ getExternalPath() + "externalLib[*]: {CHILDREN}\n" + 
795
			"		p[+]: {}"
796
		);
797
	} finally {
798
		stopDeltas();
799
		deleteExternalFolder("externalLib");
800
		deleteProject("P");
801
	}
802
}
803
804
/*
805
 * Ensures that changing an external library folder referenced by a library entry and refreshing triggers the correct delta
806
 */
807
public void testChangeExternalLibFolder2() throws CoreException {
808
	try {
809
		createExternalFolder("externalLib/p");
810
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
811
		startDeltas();
812
		createExternalFile("externalLib/p/X.class", "");
813
		refresh(p);
814
		assertDeltas(
815
			"Unexpected delta", 
816
			"P[*]: {CHILDREN}\n" + 
817
			"	"+ getExternalPath() + "externalLib[*]: {CHILDREN}\n" + 
818
			"		p[*]: {CHILDREN}\n" + 
819
			"			X.class[+]: {}"
820
		);
821
	} finally {
822
		stopDeltas();
823
		deleteExternalFolder("externalLib");
824
		deleteProject("P");
825
	}
826
}
827
828
/*
829
 * Ensures that changing an external library folder referenced by a library entry and refreshing triggers the correct delta
830
 */
831
public void testChangeExternalLibFolder3() throws CoreException {
832
	try {
833
		createExternalFolder("externalLib/p");
834
		createExternalFile("externalLib/p/X.class", "");
835
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
836
		startDeltas();
837
		touch(getExternalFile("externalLib/p/X.class"));
838
		refresh(p);
839
		assertDeltas(
840
			"Unexpected delta", 
841
			"P[*]: {CHILDREN}\n" + 
842
			"	"+ getExternalPath() + "externalLib[*]: {CHILDREN}\n" + 
843
			"		p[*]: {CHILDREN}\n" + 
844
			"			X.class[*]: {CONTENT}"
845
		);
846
	} finally {
847
		stopDeltas();
848
		deleteExternalFolder("externalLib");
849
		deleteProject("P");
850
	}
851
}
852
853
/*
854
 * Ensures that changing an external library folder referenced by a library entry and refreshing triggers the correct delta
855
 */
856
public void testChangeExternalLibFolder4() throws CoreException {
857
	try {
858
		createExternalFolder("externalLib/p");
859
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
860
		startDeltas();
861
		createExternalFile("externalLib/p/test.txt", "test");
862
		refresh(p);
863
		assertDeltas(
864
			"Unexpected delta", 
865
			""
866
		);
867
	} finally {
868
		stopDeltas();
869
		deleteExternalFolder("externalLib");
870
		deleteProject("P");
871
	}
872
}
873
874
/*
875
 * Ensures that changing an external source folder referenced by a library entry as source attachment and refreshing triggers the correct delta
876
 */
877
public void testChangeExternalSourceAttachment() throws CoreException {
878
	try {
879
		createExternalFolder("externalLib");
880
		createExternalFolder("externalSrc");
881
		IJavaProject project = createJavaProject("P");
882
		addLibraryEntry(project, getExternalFolderPath("externalLib"), getExternalFolderPath("externalSrc"));
883
		startDeltas();
884
		createExternalFile("externalSrc/X.java", "public class X {}");
885
		refresh(project);
886
		assertDeltas(
887
			"Unexpected delta", 
888
			"P[*]: {CHILDREN}\n" + 
889
			"	"+ getExternalPath() + "externalLib[*]: {SOURCE ATTACHED | SOURCE DETACHED}"
890
			);
891
	} finally {
892
		stopDeltas();
893
		deleteExternalFolder("externalLib");
894
		deleteExternalFolder("externalSrc");
895
		deleteProject("P");
896
	}
897
}
898
701
/**
899
/**
702
 * Ensures that the setting the classpath with a library entry
900
 * Ensures that the setting the classpath with a library entry
703
 * triggers a F_REMOVED_FROM_CLASSPATH and F_ADDED_TO_CLASSPATH delta.
901
 * triggers a F_REMOVED_FROM_CLASSPATH and F_ADDED_TO_CLASSPATH delta.
Lines 2053-2061 Link Here
2053
			"	src[*]: {REMOVED FROM CLASSPATH}\n" + 
2251
			"	src[*]: {REMOVED FROM CLASSPATH}\n" + 
2054
			"	ResourceDelta(/P/.classpath)[-]\n" +
2252
			"	ResourceDelta(/P/.classpath)[-]\n" +
2055
			"	ResourceDelta(/P/.classpath2)[+]"
2253
			"	ResourceDelta(/P/.classpath2)[+]"
2056
			);
2254
		);
2255
	} finally {
2256
		stopDeltas();
2257
		deleteProject("P");
2258
	}
2259
}
2260
2261
/*
2262
 * Ensures that removing a library entry for an existing external library folder triggers the correct delta
2263
 */
2264
public void testRemoveExternalLibFolder1() throws CoreException {
2265
	try {
2266
		createExternalFolder("externalLib");
2267
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
2268
		startDeltas();
2269
		setClasspath(p, new IClasspathEntry[] {});
2270
		assertDeltas(
2271
			"Unexpected delta", 
2272
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
2273
			"	"+ getExternalPath() + "externalLib[*]: {REMOVED FROM CLASSPATH}\n" + 
2274
			"	ResourceDelta(/P/.classpath)[*]"
2275
		);
2276
	} finally {
2277
		stopDeltas();
2278
		deleteExternalFolder("externalLib");
2279
		deleteProject("P");
2280
	}
2281
}
2282
2283
/*
2284
 * Ensures that removing a library entry for a non-existing external library folder triggers the correct delta
2285
 */
2286
public void testRemoveExternalLibFolder2() throws CoreException {
2287
	try {
2288
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
2289
		startDeltas();
2290
		setClasspath(p, new IClasspathEntry[] {});
2291
		assertDeltas(
2292
			"Unexpected delta", 
2293
			"P[*]: {CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
2294
			"	ResourceDelta(/P/.classpath)[*]"
2295
		);
2296
	} finally {
2297
		stopDeltas();
2298
		deleteProject("P");
2299
	}
2300
}
2301
2302
/*
2303
 * Ensures that removing an external library folder referenced by a library entry triggers the correct delta
2304
 */
2305
public void testRemoveExternalLibFolder3() throws CoreException {
2306
	try {
2307
		createExternalFolder("externalLib");
2308
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
2309
		waitForAutoBuild(); // wait for the creation of the linked folder
2310
		startDeltas();
2311
		deleteExternalFolder("externalLib");
2312
		refresh(p);
2313
		assertDeltas(
2314
			"Unexpected delta", 
2315
			"P[*]: {CHILDREN}\n" + 
2316
			"	"+ getExternalPath() + "externalLib[-]: {}"
2317
		);
2318
	} finally {
2319
		stopDeltas();
2320
		deleteExternalFolder("externalLib");
2321
		deleteProject("P");
2322
	}
2323
}
2324
2325
/*
2326
 * Ensures that removing an external library folder referenced by a library entry after a restart
2327
 * triggers the correct delta
2328
 */
2329
public void testRemoveExternalLibFolder4() throws CoreException {
2330
	try {
2331
		simulateExitRestart();
2332
		createExternalFolder("externalLib");
2333
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
2334
		waitForAutoBuild(); // wait for the creation of the linked folder
2335
		startDeltas();
2336
		deleteExternalFolder("externalLib");
2337
		refresh(p);
2338
		assertDeltas(
2339
			"Unexpected delta", 
2340
			"P[*]: {CHILDREN}\n" + 
2341
			"	"+ getExternalPath() + "externalLib[-]: {}"
2342
		);
2057
	} finally {
2343
	} finally {
2058
		stopDeltas();
2344
		stopDeltas();
2345
		deleteExternalFolder("externalLib");
2059
		deleteProject("P");
2346
		deleteProject("P");
2060
	}
2347
	}
2061
}
2348
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (+71 lines)
Lines 12-17 Link Here
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.util.HashMap;
15
import java.util.Hashtable;
16
import java.util.Hashtable;
16
17
17
import junit.framework.Test;
18
import junit.framework.Test;
Lines 527-532 Link Here
527
		"", 
528
		"", 
528
		this.resultCollector);
529
		this.resultCollector);
529
}
530
}
531
/*
532
 * Ensures that a method declaration in an external library folder can be found
533
 */
534
public void testExternalFolder1() throws CoreException {
535
	try {
536
		createExternalFolder("externalLib");
537
		Util.compile(
538
			new String[] {
539
				"p/X.java", 
540
				"package p;\n" +
541
				"public class X {\n" +
542
				"  public void foo() {\n" +
543
				"  }\n" +
544
				"}"
545
			},
546
			new HashMap(),
547
			getExternalFolderPath("externalLib")
548
		);
549
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
550
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("P")});
551
		search("foo", METHOD, DECLARATIONS, scope);
552
		assertSearchResults(
553
			getExternalPath() + "externalLib void p.X.foo()",
554
			this.resultCollector);
555
	} finally {
556
		deleteProject("P");
557
		deleteExternalFolder("externalLib");
558
	}
559
}
560
561
/*
562
 * Ensures that search all type names returns the types in an external library folder
563
 */
564
public void testExternalFolder2() throws CoreException {
565
	try {
566
		createExternalFolder("externalLib");
567
		Util.compile(
568
			new String[] {
569
				"p/ExternalType.java", 
570
				"package p;\n" +
571
				"public class ExternalType {\n" +
572
				"}"
573
			},
574
			new HashMap(),
575
			getExternalFolderPath("externalLib")
576
		);
577
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
578
		
579
		TypeNameMatchCollector collector = new TypeNameMatchCollector();
580
		new SearchEngine(this.workingCopies).searchAllTypeNames(
581
			null,
582
			SearchPattern.R_EXACT_MATCH,
583
			"ExternalType".toCharArray(),
584
			SearchPattern.R_EXACT_MATCH,
585
			TYPE,
586
			SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("P")}),
587
			collector,
588
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
589
			null
590
		);
591
		assertSearchResults(
592
			"ExternalType (not open) [in ExternalType.class [in p [in "+ getExternalPath() + "externalLib]]]",
593
			collector
594
		);
595
	} finally {
596
		deleteProject("P");
597
		deleteExternalFolder("externalLib");
598
	}
599
600
}
530
/**
601
/**
531
 * Simple field declaration test.
602
 * Simple field declaration test.
532
 */
603
 */
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-11 / +77 lines)
Lines 32-37 Link Here
32
import org.eclipse.jdt.internal.core.JavaCorePreferenceInitializer;
32
import org.eclipse.jdt.internal.core.JavaCorePreferenceInitializer;
33
import org.eclipse.jdt.internal.core.JavaElement;
33
import org.eclipse.jdt.internal.core.JavaElement;
34
import org.eclipse.jdt.internal.core.JavaModelManager;
34
import org.eclipse.jdt.internal.core.JavaModelManager;
35
import org.eclipse.jdt.internal.core.JavaProject;
35
import org.eclipse.jdt.internal.core.NameLookup;
36
import org.eclipse.jdt.internal.core.NameLookup;
36
import org.eclipse.jdt.internal.core.ResolvedSourceMethod;
37
import org.eclipse.jdt.internal.core.ResolvedSourceMethod;
37
import org.eclipse.jdt.internal.core.ResolvedSourceType;
38
import org.eclipse.jdt.internal.core.ResolvedSourceType;
Lines 323-338 Link Here
323
	protected void addLibraryEntry(IJavaProject project, IPath path, boolean exported) throws JavaModelException {
324
	protected void addLibraryEntry(IJavaProject project, IPath path, boolean exported) throws JavaModelException {
324
		addLibraryEntry(project, path, null, null, null, null, exported);
325
		addLibraryEntry(project, path, null, null, null, null, exported);
325
	} 
326
	} 
326
	protected void addLibraryEntry(IJavaProject project, String path, String srcAttachmentPath, String srcAttachmentPathRoot, boolean exported) throws JavaModelException{
327
	protected void addLibraryEntry(IJavaProject project, String path, String srcAttachmentPath) throws JavaModelException{
327
		addLibraryEntry(
328
		addLibraryEntry(
328
			project,
329
			project,
329
			new Path(path),
330
			new Path(path),
330
			srcAttachmentPath == null ? null : new Path(srcAttachmentPath),
331
			srcAttachmentPath == null ? null : new Path(srcAttachmentPath),
331
			srcAttachmentPathRoot == null ? null : new Path(srcAttachmentPathRoot),
332
			null,
332
			null,
333
			null,
333
			null,
334
			null,
334
			new IClasspathAttribute[0],
335
			new IClasspathAttribute[0],
335
			exported
336
			false
336
		);
337
		);
337
	}
338
	}
338
	protected void addLibraryEntry(IJavaProject project, IPath path, IPath srcAttachmentPath, IPath srcAttachmentPathRoot, IPath[] accessibleFiles, IPath[] nonAccessibleFiles, boolean exported) throws JavaModelException{
339
	protected void addLibraryEntry(IJavaProject project, IPath path, IPath srcAttachmentPath, IPath srcAttachmentPathRoot, IPath[] accessibleFiles, IPath[] nonAccessibleFiles, boolean exported) throws JavaModelException{
Lines 543-549 Link Here
543
		}
544
		}
544
		String actual = buffer.toString();
545
		String actual = buffer.toString();
545
		if (!expectedMarkers.equals(actual)) {
546
		if (!expectedMarkers.equals(actual)) {
546
		 	System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actual, 2));
547
		 	System.out.println(displayString(actual, 2));
547
		}
548
		}
548
		assertEquals(message, expectedMarkers, actual);
549
		assertEquals(message, expectedMarkers, actual);
549
	}
550
	}
Lines 1042-1053 Link Here
1042
				null/*no project*/, 
1043
				null/*no project*/, 
1043
				null/*no inclusion pattern*/,
1044
				null/*no inclusion pattern*/,
1044
				null/*no exclusion pattern*/,
1045
				null/*no exclusion pattern*/,
1046
				true/*combine access restrictions by default*/,
1045
				null/*no exported project*/, 
1047
				null/*no exported project*/, 
1046
				output, 
1048
				output, 
1047
				null/*no source outputs*/,
1049
				null/*no source outputs*/,
1048
				null/*no inclusion pattern*/,
1050
				null/*no inclusion pattern*/,
1049
				null/*no exclusion pattern*/,
1051
				null/*no exclusion pattern*/,
1050
				"1.4"
1052
				"1.4",
1053
				false/*don't import*/
1051
			);
1054
			);
1052
	}
1055
	}
1053
	protected IJavaProject createJavaProject(String projectName, String[] sourceFolders, String[] libraries, String output, String compliance) throws CoreException {
1056
	protected IJavaProject createJavaProject(String projectName, String[] sourceFolders, String[] libraries, String output, String compliance) throws CoreException {
Lines 1185-1191 Link Here
1185
			sourceOutputs,
1188
			sourceOutputs,
1186
			inclusionPatterns,
1189
			inclusionPatterns,
1187
			exclusionPatterns,
1190
			exclusionPatterns,
1188
			compliance);
1191
			compliance, 
1192
			false/*don't import*/);
1189
	}
1193
	}
1190
	protected IJavaProject createJavaProject(
1194
	protected IJavaProject createJavaProject(
1191
			final String projectName,
1195
			final String projectName,
Lines 1202-1208 Link Here
1202
			final String[] sourceOutputs,
1206
			final String[] sourceOutputs,
1203
			final String[][] inclusionPatterns,
1207
			final String[][] inclusionPatterns,
1204
			final String[][] exclusionPatterns,
1208
			final String[][] exclusionPatterns,
1205
			final String compliance) throws CoreException {
1209
			final String compliance, 
1210
			final boolean simulateImport) throws CoreException {
1206
		final IJavaProject[] result = new IJavaProject[1];
1211
		final IJavaProject[] result = new IJavaProject[1];
1207
		IWorkspaceRunnable create = new IWorkspaceRunnable() {
1212
		IWorkspaceRunnable create = new IWorkspaceRunnable() {
1208
			public void run(IProgressMonitor monitor) throws CoreException {
1213
			public void run(IProgressMonitor monitor) throws CoreException {
Lines 1390-1402 Link Here
1390
				if (outputPath.segmentCount() > 0) {
1395
				if (outputPath.segmentCount() > 0) {
1391
					IFolder output = project.getFolder(outputPath);
1396
					IFolder output = project.getFolder(outputPath);
1392
					if (!output.exists()) {
1397
					if (!output.exists()) {
1393
						output.create(true, true, null);
1398
						output.create(true, true, monitor);
1394
					}
1399
					}
1395
				}
1400
				}
1396
				
1401
				
1397
				// set classpath and output location
1402
				// set classpath and output location
1398
				IJavaProject javaProject = JavaCore.create(project);
1403
				JavaProject javaProject = (JavaProject) JavaCore.create(project);
1399
				javaProject.setRawClasspath(entries, projectPath.append(outputPath), null);
1404
				if (simulateImport)
1405
					javaProject.saveClasspath(entries, projectPath.append(outputPath));
1406
				else
1407
					javaProject.setRawClasspath(entries, projectPath.append(outputPath), monitor);
1400
				
1408
				
1401
				// set compliance level options
1409
				// set compliance level options
1402
				if ("1.5".equals(compliance)) {
1410
				if ("1.5".equals(compliance)) {
Lines 1413-1418 Link Here
1413
		getWorkspace().run(create, null);	
1421
		getWorkspace().run(create, null);	
1414
		return result[0];
1422
		return result[0];
1415
	}
1423
	}
1424
	protected IJavaProject importJavaProject(String projectName, String[] sourceFolders, String[] libraries, String output) throws CoreException {
1425
		return 
1426
			createJavaProject(
1427
				projectName, 
1428
				sourceFolders, 
1429
				libraries, 
1430
				null/*no inclusion pattern*/,
1431
				null/*no exclusion pattern*/,
1432
				null/*no project*/, 
1433
				null/*no inclusion pattern*/,
1434
				null/*no exclusion pattern*/,
1435
				true/*combine access restrictions by default*/,
1436
				null/*no exported project*/, 
1437
				output, 
1438
				null/*no source outputs*/,
1439
				null/*no inclusion pattern*/,
1440
				null/*no exclusion pattern*/,
1441
				"1.4",
1442
				true/*import*/
1443
			);
1444
	}
1416
	/*
1445
	/*
1417
	 * Create simple project.
1446
	 * Create simple project.
1418
	 */
1447
	 */
Lines 1604-1609 Link Here
1604
		}
1633
		}
1605
		return result;
1634
		return result;
1606
	}
1635
	}
1636
	
1637
	protected File getExternalFile(String relativePath) {
1638
		return new File(getExternalPath(), relativePath);
1639
	}
1640
	
1641
	protected String getExternalFolderPath(String name) {
1642
		return getExternalPath() + name + File.separatorChar;
1643
	}
1607
1644
1608
	/**
1645
	/**
1609
	 * Returns the IPath to the external java class library (e.g. jclMin.jar)
1646
	 * Returns the IPath to the external java class library (e.g. jclMin.jar)
Lines 1886-1891 Link Here
1886
		toDisplay = 
1923
		toDisplay = 
1887
    		CharOperation.replace(
1924
    		CharOperation.replace(
1888
    			toDisplay, 
1925
    			toDisplay, 
1926
    			getExternalPath().toCharArray(), 
1927
    			"getExternalPath()".toCharArray());
1928
		
1929
		toDisplay = 
1930
    		CharOperation.replace(
1931
    			toDisplay, 
1889
    			org.eclipse.jdt.core.tests.util.Util.displayString(getExternalJCLSourcePathString(), 0).toCharArray(), 
1932
    			org.eclipse.jdt.core.tests.util.Util.displayString(getExternalJCLSourcePathString(), 0).toCharArray(), 
1890
    			"getExternalJCLSourcePathString()".toCharArray());
1933
    			"getExternalJCLSourcePathString()".toCharArray());
1891
		toDisplay = 
1934
		toDisplay = 
Lines 1893-1899 Link Here
1893
    			toDisplay, 
1936
    			toDisplay, 
1894
    			org.eclipse.jdt.core.tests.util.Util.displayString(getExternalJCLSourcePathString("1.5"), 0).toCharArray(), 
1937
    			org.eclipse.jdt.core.tests.util.Util.displayString(getExternalJCLSourcePathString("1.5"), 0).toCharArray(), 
1895
    			"getExternalJCLSourcePathString(\"1.5\")".toCharArray());
1938
    			"getExternalJCLSourcePathString(\"1.5\")".toCharArray());
1939
		
1896
    	toDisplay = org.eclipse.jdt.core.tests.util.Util.displayString(new String(toDisplay), indent).toCharArray();
1940
    	toDisplay = org.eclipse.jdt.core.tests.util.Util.displayString(new String(toDisplay), indent).toCharArray();
1941
    	
1897
    	toDisplay = 
1942
    	toDisplay = 
1898
    		CharOperation.replace(
1943
    		CharOperation.replace(
1899
    			toDisplay, 
1944
    			toDisplay, 
Lines 1914-1919 Link Here
1914
    			toDisplay, 
1959
    			toDisplay, 
1915
    			"getExternalJCLSourcePathString(\\\"1.5\\\")".toCharArray(), 
1960
    			"getExternalJCLSourcePathString(\\\"1.5\\\")".toCharArray(), 
1916
    			("\"+ getExternalJCLSourcePathString(\"1.5\") + \"").toCharArray());
1961
    			("\"+ getExternalJCLSourcePathString(\"1.5\") + \"").toCharArray());
1962
    	toDisplay = 
1963
    		CharOperation.replace(
1964
    			toDisplay, 
1965
    			"getExternalPath()".toCharArray(), 
1966
    			("\"+ getExternalPath() + \"").toCharArray());
1917
    	return new String(toDisplay);
1967
    	return new String(toDisplay);
1918
    }
1968
    }
1919
	
1969
	
Lines 1962-1967 Link Here
1962
		stream.close();
2012
		stream.close();
1963
		return fileBytes;
2013
		return fileBytes;
1964
	}
2014
	}
2015
2016
	public void refresh(final IJavaProject javaProject) throws CoreException {
2017
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
2018
			public void run(IProgressMonitor pm) throws CoreException {
2019
				// work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=219566
2020
				IProject externalFoldersProject = JavaModelManager.getExternalManager().getExternalFoldersProject();
2021
				externalFoldersProject.refreshLocal(IResource.DEPTH_INFINITE, pm);
2022
				
2023
				javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, pm);
2024
			}
2025
		}, null);
2026
	}
2027
1965
	protected void removeJavaNature(String projectName) throws CoreException {
2028
	protected void removeJavaNature(String projectName) throws CoreException {
1966
		IProject project = this.getProject(projectName);
2029
		IProject project = this.getProject(projectName);
1967
		IProjectDescription description = project.getDescription();
2030
		IProjectDescription description = project.getDescription();
Lines 2552-2558 Link Here
2552
		}
2615
		}
2553
		return result;
2616
		return result;
2554
	}
2617
	}
2555
	protected String toString(String[] strings) {
2618
	protected void touch(File f) {
2619
		f.setLastModified(f.lastModified() + 10000);
2620
	}
2621
protected String toString(String[] strings) {
2556
		return toString(strings, false/*don't add extra new line*/);
2622
		return toString(strings, false/*don't add extra new line*/);
2557
	}
2623
	}
2558
	protected String toString(String[] strings, boolean addExtraNewLine) {
2624
	protected String toString(String[] strings, boolean addExtraNewLine) {
(-)src/org/eclipse/jdt/core/tests/model/ClassFileTests.java (-1 / +20 lines)
Lines 720-725 Link Here
720
}
720
}
721
721
722
/*
722
/*
723
 * Ensures that the resource of a .class file in an external folder is null
724
 */
725
public void testGetResource() throws Exception {
726
	try {
727
		createExternalFolder("externalLib/p");
728
		createExternalFile("externalLib/p/X.class", "");
729
		createJavaProject("P1", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
730
		IClassFile classFile1 = getClassFile("P1", getExternalFolderPath("externalLib"), "p", "X.class");
731
		assertEquals(
732
			"Unexpected resource",
733
			null,
734
			classFile1.getResource());
735
	} finally {
736
		deleteExternalFolder("externalLib");
737
		deleteProject("P1");
738
	}
739
}
740
741
/*
723
 * Ensures that IType#getSuperclassTypeSignature() is correct for a binary type.
742
 * Ensures that IType#getSuperclassTypeSignature() is correct for a binary type.
724
 * (regression test for bug 78520 [model] IType#getSuperInterfaceTypeSignatures() doesn't include type arguments)
743
 * (regression test for bug 78520 [model] IType#getSuperInterfaceTypeSignatures() doesn't include type arguments)
725
 */
744
 */
Lines 761-767 Link Here
761
		// create an invalid package fragment root and an invalid package fragment
780
		// create an invalid package fragment root and an invalid package fragment
762
		IPackageFragment invalidPkg = p.getPackageFragmentRoot("/P1/classFolder.jar").getPackageFragment("p");
781
		IPackageFragment invalidPkg = p.getPackageFragmentRoot("/P1/classFolder.jar").getPackageFragment("p");
763
		
782
		
764
		// ensure that the class fille cannot be opened with a valid excepption
783
		// ensure that the class file cannot be opened with a valid exception
765
		IClassFile openable = invalidPkg.getClassFile("X.class");
784
		IClassFile openable = invalidPkg.getClassFile("X.class");
766
		JavaModelException expected = null;
785
		JavaModelException expected = null;
767
		try {
786
		try {

Return to bug 182537