Lines 282-289
Link Here
|
282 |
if (parent != null && parent.isOpen()) { |
282 |
if (parent != null && parent.isOpen()) { |
283 |
try { |
283 |
try { |
284 |
OpenableElementInfo info = (OpenableElementInfo) parent.getElementInfo(); |
284 |
OpenableElementInfo info = (OpenableElementInfo) parent.getElementInfo(); |
285 |
info.addChild(child); |
285 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338006 |
286 |
} catch (JavaModelException e) { |
286 |
// Insert the package fragment roots in the same order as the classpath order. |
|
|
287 |
iterate: if (child instanceof IPackageFragmentRoot) { |
288 |
IJavaElement[] roots = info.getChildren(); |
289 |
if (roots.length == 0) |
290 |
break iterate; |
291 |
|
292 |
IPackageFragmentRoot root = (IPackageFragmentRoot) child; |
293 |
IClasspathEntry[] resolvedClasspath = ((JavaProject)root.getJavaProject()).getResolvedClasspath(); |
294 |
IClasspathEntry currentEntry = root.getResolvedClasspathEntry(); |
295 |
|
296 |
int indexToInsert = -1; |
297 |
int lastComparedIndex = -1; |
298 |
for (int i =0, j=0; i < roots.length && j < resolvedClasspath.length; ) { |
299 |
|
300 |
// If the new root is already among the children, no need to proceed further. Just return. |
301 |
// This condition will be checked even if indexToInsert has already been found |
302 |
if(roots[i].getPath().equals(child.getPath())) { |
303 |
return; |
304 |
} |
305 |
|
306 |
if (indexToInsert == -1) { |
307 |
if ( lastComparedIndex != j && currentEntry.getPath().equals(resolvedClasspath[j].getPath())) { |
308 |
indexToInsert = i; |
309 |
break; |
310 |
} |
311 |
lastComparedIndex = j; |
312 |
|
313 |
IClasspathEntry rootEntry = ((IPackageFragmentRoot)roots[i]).getResolvedClasspathEntry(); |
314 |
if (rootEntry.getPath().equals(resolvedClasspath[j].getPath())) |
315 |
i++; |
316 |
else |
317 |
j++; |
318 |
} |
319 |
} |
320 |
if (indexToInsert >= 0) { |
321 |
int newSize = roots.length + 1; |
322 |
IPackageFragmentRoot[] newChildren = new IPackageFragmentRoot[newSize]; |
323 |
|
324 |
if(indexToInsert > 0) |
325 |
System.arraycopy(roots, 0, newChildren, 0, indexToInsert); |
326 |
|
327 |
newChildren[indexToInsert] = (IPackageFragmentRoot)child; |
328 |
System.arraycopy(roots, indexToInsert, newChildren, indexToInsert+1, (newSize - indexToInsert -1)); |
329 |
info.setChildren(newChildren); |
330 |
return; |
331 |
} |
332 |
} |
333 |
info.addChild(child); |
334 |
} catch (JavaModelException e) { |
287 |
// do nothing - we already checked if open |
335 |
// do nothing - we already checked if open |
288 |
} |
336 |
} |
289 |
} |
337 |
} |