### 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 04:41:17 -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. *
** 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. * *
NOTE: This is equivalent to getChildren()
.
*
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 04:41:17 -0000
@@ -282,8 +282,56 @@
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.
+ iterate: if (child instanceof IPackageFragmentRoot) {
+ IJavaElement[] roots = info.getChildren();
+ if (roots.length == 0)
+ break iterate;
+
+ IPackageFragmentRoot root = (IPackageFragmentRoot) child;
+ IClasspathEntry[] resolvedClasspath = ((JavaProject)root.getJavaProject()).getResolvedClasspath();
+ IClasspathEntry currentEntry = root.getResolvedClasspathEntry();
+
+ int indexToInsert = -1;
+ int lastComparedIndex = -1;
+ for (int i =0, j=0; i < roots.length && j < resolvedClasspath.length; ) {
+
+ // If the new root is already among the children, no need to proceed further. Just return.
+ // This condition will be checked even if indexToInsert has already been found
+ if(roots[i].getPath().equals(child.getPath())) {
+ return;
+ }
+
+ if (indexToInsert == -1) {
+ if ( lastComparedIndex != j && currentEntry.getPath().equals(resolvedClasspath[j].getPath())) {
+ indexToInsert = i;
+ break;
+ }
+ lastComparedIndex = j;
+
+ IClasspathEntry rootEntry = ((IPackageFragmentRoot)roots[i]).getResolvedClasspathEntry();
+ if (rootEntry.getPath().equals(resolvedClasspath[j].getPath()))
+ i++;
+ else
+ j++;
+ }
+ }
+ 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] = (IPackageFragmentRoot)child;
+ System.arraycopy(roots, indexToInsert, newChildren, indexToInsert+1, (newSize - indexToInsert -1));
+ info.setChildren(newChildren);
+ return;
+ }
+ }
+ info.addChild(child);
+ } catch (JavaModelException e) {
// do nothing - we already checked if open
}
}
#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 04:41:21 -0000
@@ -955,6 +955,25 @@
}
assertEquals(expected, actual);
}
+ protected void assertPackageFragmentRootsEqual(IPackageFragmentRoot[] roots, String expected) {
+ String actual;
+ if (roots == null) {
+ actual = "