Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 190377 Details for
Bug 338006
IJavaProject#getPackageFragmentRoots() should return roots in order
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Updated patch
bug_338006.txt (text/plain), 7.76 KB, created by
Jay Arthanareeswaran
on 2011-03-04 08:18:34 EST
(
hide
)
Description:
Updated patch
Filename:
MIME Type:
Creator:
Jay Arthanareeswaran
Created:
2011-03-04 08:18:34 EST
Size:
7.76 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/core/IJavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java,v >retrieving revision 1.106 >diff -u -r1.106 IJavaProject.java >--- model/org/eclipse/jdt/core/IJavaProject.java 24 Feb 2011 16:51:58 -0000 1.106 >+++ model/org/eclipse/jdt/core/IJavaProject.java 4 Mar 2011 13:16:32 -0000 >@@ -49,7 +49,9 @@ > * Java project elements need to be opened before they can be navigated or manipulated. > * The children of a Java project are the package fragment roots that are > * defined by the classpath and contained in this project (in other words, it >- * does not include package fragment roots for other projects). >+ * does not include package fragment roots for other projects). The children >+ * (i.e. the package fragment roots) appear in the order they are defined by >+ * the classpath. > * </p> > * <p> > * An instance of one of these handles can be created via >@@ -518,7 +520,8 @@ > * Returns all of the package fragment roots contained in this > * project, identified on this project's resolved classpath. The result > * does not include package fragment roots in other projects referenced >- * on this project's classpath. >+ * on this project's classpath. The package fragment roots appear in the >+ * order they are defined by the classpath. > * > * <p>NOTE: This is equivalent to <code>getChildren()</code>. > * >Index: model/org/eclipse/jdt/internal/core/DeltaProcessor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java,v >retrieving revision 1.341 >diff -u -r1.341 DeltaProcessor.java >--- model/org/eclipse/jdt/internal/core/DeltaProcessor.java 2 Dec 2010 07:51:52 -0000 1.341 >+++ model/org/eclipse/jdt/internal/core/DeltaProcessor.java 4 Mar 2011 13:16:32 -0000 >@@ -282,12 +282,71 @@ > if (parent != null && parent.isOpen()) { > try { > OpenableElementInfo info = (OpenableElementInfo) parent.getElementInfo(); >- info.addChild(child); >- } catch (JavaModelException e) { >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=338006 >+ // Insert the package fragment roots in the same order as the classpath order. >+ if (child instanceof IPackageFragmentRoot) >+ addPackageFragmentRoot(info, (IPackageFragmentRoot) child); >+ else >+ info.addChild(child); >+ } catch (JavaModelException e) { > // do nothing - we already checked if open > } > } > } >+ >+ private void addPackageFragmentRoot(OpenableElementInfo parent, IPackageFragmentRoot child) >+ throws JavaModelException { >+ >+ IJavaElement[] roots = parent.getChildren(); >+ if (roots.length > 0) { >+ IClasspathEntry[] resolvedClasspath = ((JavaProject) child.getJavaProject()).getResolvedClasspath(); >+ IPath currentEntryPath = child.getResolvedClasspathEntry().getPath(); >+ int indexToInsert = -1; >+ int lastComparedIndex = -1; >+ int i = 0, j = 0; >+ for (; i < roots.length && j < resolvedClasspath.length;) { >+ >+ IClasspathEntry classpathEntry = resolvedClasspath[j]; >+ if (lastComparedIndex != j && currentEntryPath.equals(classpathEntry.getPath())) { >+ indexToInsert = i; >+ break; >+ } >+ lastComparedIndex = j; >+ >+ IClasspathEntry rootEntry = ((IPackageFragmentRoot) roots[i]).getResolvedClasspathEntry(); >+ if (rootEntry.getPath().equals(classpathEntry.getPath())) >+ i++; >+ else >+ j++; >+ } >+ >+ for (; i < roots.length; i++) { >+ // If the new root is already among the children, no need to proceed further. Just return. >+ if (roots[i].equals(child)) { >+ return; >+ } >+ // If we start seeing root's classpath entry different from the child's entry, then the child can't >+ // be present further down the roots array. >+ if (!((IPackageFragmentRoot) roots[i]).getResolvedClasspathEntry().getPath() >+ .equals(currentEntryPath)) >+ break; >+ } >+ >+ if (indexToInsert >= 0) { >+ int newSize = roots.length + 1; >+ IPackageFragmentRoot[] newChildren = new IPackageFragmentRoot[newSize]; >+ >+ if (indexToInsert > 0) >+ System.arraycopy(roots, 0, newChildren, 0, indexToInsert); >+ >+ newChildren[indexToInsert] = child; >+ System.arraycopy(roots, indexToInsert, newChildren, indexToInsert + 1, (newSize - indexToInsert - 1)); >+ parent.setChildren(newChildren); >+ return; >+ } >+ } >+ parent.addChild(child); >+ } > /* > * Process the given delta and look for projects being added, opened, closed or > * with a java nature being added or removed. >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v >retrieving revision 1.243 >diff -u -r1.243 AbstractJavaModelTests.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 21 Feb 2011 00:53:28 -0000 1.243 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 4 Mar 2011 13:16:35 -0000 >@@ -955,6 +955,25 @@ > } > assertEquals(expected, actual); > } >+ protected void assertPackageFragmentRootsEqual(IPackageFragmentRoot[] roots, String expected) { >+ String actual; >+ if (roots == null) { >+ actual = "<null>"; >+ } else { >+ StringBuffer buffer = new StringBuffer(); >+ int length = roots.length; >+ for (int i=0; i<length; i++) { >+ buffer.append(roots[i]); >+ if (i < length-1) >+ buffer.append('\n'); >+ } >+ actual = buffer.toString(); >+ } >+ if (!actual.equals(expected)) { >+ System.out.print(displayString(actual, 2)); >+ } >+ assertEquals(expected, actual); >+ } > /** > * Ensures the element is present after creation. > */ >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.224 >diff -u -r1.224 ClasspathTests.java >--- src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 3 Mar 2011 20:18:28 -0000 1.224 >+++ src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 4 Mar 2011 13:16:36 -0000 >@@ -7150,4 +7150,44 @@ > } > } > >+/** >+ * @bug 338006: IJavaProject#getPackageFragmentRoots() should return roots in order >+ * >+ * Test whether the {@link IJavaProject#getPackageFragmentRoots()} returns the package fragment >+ * roots in the same order as defined by the .classpath even when the elements are added in a >+ * different order. >+ * >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=338006" >+ */ >+public void testBug338006() throws Exception { >+ try { >+ IJavaProject p = this.createJavaProject("P", new String[] {}, "bin"); >+ >+ String content = new String( >+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" >+ + "<classpath>\n" >+ + "<classpathentry kind=\"src\" path=\"src a\"/>\n" >+ + "<classpathentry kind=\"src\" path=\"src x\"/>\n" >+ + "<classpathentry kind=\"lib\" path=\"" >+ + getExternalJCLPath() >+ + "\"/>\n" >+ + "<classpathentry kind=\"output\" path=\"bin\"/>\n" >+ + "</classpath>\n"); >+ >+ editFile("/P/.classpath", content); >+ p.open(null); >+ createFolder("/P/src x"); >+ createFolder("/P/src a"); >+ >+ IPackageFragmentRoot[] roots = p.getPackageFragmentRoots(); >+ assertPackageFragmentRootsEqual(roots, >+ "src a (not open) [in P]\n" + >+ "src x (not open) [in P]\n" + >+ ""+ getExternalJCLPathString() + " (not open)"); >+ >+ } finally { >+ deleteProject("P"); >+ } >+} >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 338006
:
189914
|
190241
|
190348
|
190364
| 190377