### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/ClasspathEntry.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java,v retrieving revision 1.127 diff -u -r1.127 ClasspathEntry.java --- model/org/eclipse/jdt/internal/core/ClasspathEntry.java 26 Oct 2010 15:50:28 -0000 1.127 +++ model/org/eclipse/jdt/internal/core/ClasspathEntry.java 24 Jan 2011 05:25:06 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1002,33 +1002,50 @@ /* * Resolves the ".." in the given path. Returns the given path if it contains no ".." segment. */ - public static IPath resolveDotDot(IPath path) { + public static IPath resolveDotDot(IPath reference, IPath path) { IPath newPath = null; - IPath workspaceLocation = null; - for (int i = 0, length = path.segmentCount(); i < length; i++) { - String segment = path.segment(i); - if (DOT_DOT.equals(segment)) { - if (newPath == null) { - if (i == 0) { - workspaceLocation = workspaceRoot.getLocation(); - newPath = workspaceLocation; + IPath workspaceLocation = workspaceRoot.getLocation(); + if (reference == null || workspaceLocation.isPrefixOf(reference)) { + for (int i = 0, length = path.segmentCount(); i < length; i++) { + String segment = path.segment(i); + if (DOT_DOT.equals(segment)) { + if (newPath == null) { + if (i == 0) { + workspaceLocation = workspaceRoot.getLocation(); + newPath = workspaceLocation; + } else { + newPath = path.removeFirstSegments(i); + } } else { - newPath = path.removeFirstSegments(i); + if (newPath.segmentCount() > 0) { + newPath = newPath.removeLastSegments(1); + } else { + workspaceLocation = workspaceRoot.getLocation(); + newPath = workspaceLocation; + } } - } else { - if (newPath.segmentCount() > 0) { - newPath = newPath.removeLastSegments(1); + } else if (newPath != null) { + if (newPath.equals(workspaceLocation) && workspaceRoot.getProject(segment).isAccessible()) { + newPath = new Path(segment).makeAbsolute(); } else { - workspaceLocation = workspaceRoot.getLocation(); - newPath = workspaceLocation; + newPath = newPath.append(segment); } } - } else if (newPath != null) { - if (newPath.equals(workspaceLocation) && workspaceRoot.getProject(segment).isAccessible()) { - newPath = new Path(segment).makeAbsolute(); - } else { + } + } + else { + for (int i = 0, length = path.segmentCount(); i < length; i++) { + String segment = path.segment(i); + if (DOT_DOT.equals(segment)) { + if (newPath == null){ + newPath = reference; + } + if (newPath.segmentCount() > 0) { + newPath = newPath.removeLastSegments(1); + } + } else if (newPath != null) { newPath = newPath.append(segment); - } + } } } if (newPath == null) @@ -1419,8 +1436,8 @@ return buffer.toString(); } - public ClasspathEntry resolvedDotDot() { - IPath resolvedPath = resolveDotDot(this.path); + public ClasspathEntry resolvedDotDot(IPath reference) { + IPath resolvedPath = resolveDotDot(reference, this.path); if (resolvedPath == this.path) return this; return new ClasspathEntry( @@ -1919,7 +1936,7 @@ // library entry check case IClasspathEntry.CPE_LIBRARY : - path = ClasspathEntry.resolveDotDot(path); + path = ClasspathEntry.resolveDotDot(project.getProject().getLocation(), path); // do not validate entries from Class-Path: in manifest // (these entries are considered optional since the user cannot act on them) Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.464 diff -u -r1.464 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 6 Jan 2011 13:43:57 -0000 1.464 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 24 Jan 2011 05:25:06 -0000 @@ -2409,6 +2409,10 @@ } public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, boolean usePreviousSession) { + return resolveVariableEntry(entry, ResourcesPlugin.getWorkspace().getRoot().getLocation(), usePreviousSession); + } + + public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, IPath projectPath, boolean usePreviousSession) { if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) return entry; @@ -2416,7 +2420,7 @@ IPath resolvedPath = getResolvedVariablePath(entry.getPath(), usePreviousSession); if (resolvedPath == null) return null; - resolvedPath = ClasspathEntry.resolveDotDot(resolvedPath); + resolvedPath = ClasspathEntry.resolveDotDot(projectPath, resolvedPath); Object target = JavaModel.getTarget(resolvedPath, false); if (target == null) Index: model/org/eclipse/jdt/internal/core/JavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v retrieving revision 1.441 diff -u -r1.441 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 22 Dec 2010 05:56:55 -0000 1.441 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 24 Jan 2011 05:25:06 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2588,7 +2588,7 @@ for (int index = 0; index < rawClasspath.length; index++) { IClasspathEntry currentEntry = rawClasspath[index]; if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { - rawLibrariesPath.add(ClasspathEntry.resolveDotDot(currentEntry.getPath())); + rawLibrariesPath.add(ClasspathEntry.resolveDotDot(getProject().getLocation(), currentEntry.getPath())); } } if (referencedEntries != null) { @@ -2619,7 +2619,7 @@ case IClasspathEntry.CPE_VARIABLE : try { - resolvedEntry = manager.resolveVariableEntry(rawEntry, usePreviousSession); + resolvedEntry = manager.resolveVariableEntry(rawEntry, this.getProject().getLocation(), usePreviousSession); } catch (ClasspathEntry.AssertionFailedException e) { // Catch the assertion failure and set status instead // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992 @@ -2676,7 +2676,7 @@ if (cEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // resolve ".." in library path - cEntry = cEntry.resolvedDotDot(); + cEntry = cEntry.resolvedDotDot(getProject().getLocation()); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=313965 // Do not resolve if the system attribute is set to false if (resolveChainedLibraries @@ -2697,7 +2697,7 @@ case IClasspathEntry.CPE_LIBRARY: // resolve ".." in library path - resolvedEntry = ((ClasspathEntry) rawEntry).resolvedDotDot(); + resolvedEntry = ((ClasspathEntry) rawEntry).resolvedDotDot(getProject().getLocation()); if (resolveChainedLibraries && result.rawReverseMap.get(resolvedEntry.getPath()) == null) { // resolve Class-Path: in manifest #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ClasspathTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java,v retrieving revision 1.222 diff -u -r1.222 ClasspathTests.java --- src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 7 Jan 2011 20:47:00 -0000 1.222 +++ src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 24 Jan 2011 05:25:08 -0000 @@ -14,11 +14,13 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.net.URI; import java.util.Hashtable; import java.util.Map; import junit.framework.Test; +import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IMarker; @@ -6861,5 +6863,53 @@ deleteProject("P"); } } +/** + * @bug 274737: [API] Add new API to ease the retrieval of the parameter annotations for an IMethod + * + * Test that for an external project, relative paths are resolve relative to the project location. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737" + * @throws Exception + */ +public void testBug274737() throws Exception { + try { + createExternalFolder("development/third_party"); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("ExternalProject"); + URI uri= URIUtil.toURI(new Path(getExternalResourcePath("development")).append("ExternalProject")); + IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName()); + desc.setLocationURI(uri); + project.create(desc, null); + if (!project.isOpen()) { + project.open(null); + } + + addJavaNature("ExternalProject"); + IJavaProject javaProject = JavaCore.create(project); + IClasspathEntry[] classpath = new IClasspathEntry[2]; + Util.createJar( + new String[0], + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Class-Path: \n", + }, + getExternalResourcePath("development/third_party/lib.jar"), + JavaCore.VERSION_1_4); + createExternalFolder("development/ExternalProject/src"); + createExternalFolder("development/ExternalProject/bin"); + classpath[0] = JavaCore.newSourceEntry(new Path("/ExternalProject/src"), null, null); + classpath[1] = JavaCore.newLibraryEntry(new Path("../third_party/lib.jar"), null, null); + javaProject.setRawClasspath(classpath, new Path("/ExternalProject/bin"), null); + + refresh(javaProject); + waitForAutoBuild(); + assertMarkers("Unexpected markers", "", javaProject); + + } finally { + deleteProject("ExternalProject"); + deleteExternalResource("development"); + + } +} }