Lines 282-293
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 |
if (child instanceof IPackageFragmentRoot) |
288 |
addPackageFragmentRoot(info, (IPackageFragmentRoot) child); |
289 |
else |
290 |
info.addChild(child); |
291 |
} catch (JavaModelException e) { |
287 |
// do nothing - we already checked if open |
292 |
// do nothing - we already checked if open |
288 |
} |
293 |
} |
289 |
} |
294 |
} |
290 |
} |
295 |
} |
|
|
296 |
|
297 |
private void addPackageFragmentRoot(OpenableElementInfo parent, IPackageFragmentRoot child) |
298 |
throws JavaModelException { |
299 |
|
300 |
IJavaElement[] roots = parent.getChildren(); |
301 |
if (roots.length > 0) { |
302 |
IClasspathEntry[] resolvedClasspath = ((JavaProject) child.getJavaProject()).getResolvedClasspath(); |
303 |
IPath currentEntryPath = child.getResolvedClasspathEntry().getPath(); |
304 |
int indexToInsert = -1; |
305 |
int lastComparedIndex = -1; |
306 |
int i = 0, j = 0; |
307 |
for (; i < roots.length && j < resolvedClasspath.length;) { |
308 |
|
309 |
IClasspathEntry classpathEntry = resolvedClasspath[j]; |
310 |
if (lastComparedIndex != j && currentEntryPath.equals(classpathEntry.getPath())) { |
311 |
indexToInsert = i; |
312 |
break; |
313 |
} |
314 |
lastComparedIndex = j; |
315 |
|
316 |
IClasspathEntry rootEntry = ((IPackageFragmentRoot) roots[i]).getResolvedClasspathEntry(); |
317 |
if (rootEntry.getPath().equals(classpathEntry.getPath())) |
318 |
i++; |
319 |
else |
320 |
j++; |
321 |
} |
322 |
|
323 |
for (; i < roots.length; i++) { |
324 |
// If the new root is already among the children, no need to proceed further. Just return. |
325 |
if (roots[i].equals(child)) { |
326 |
return; |
327 |
} |
328 |
// If we start seeing root's classpath entry different from the child's entry, then the child can't |
329 |
// be present further down the roots array. |
330 |
if (!((IPackageFragmentRoot) roots[i]).getResolvedClasspathEntry().getPath() |
331 |
.equals(currentEntryPath)) |
332 |
break; |
333 |
} |
334 |
|
335 |
if (indexToInsert >= 0) { |
336 |
int newSize = roots.length + 1; |
337 |
IPackageFragmentRoot[] newChildren = new IPackageFragmentRoot[newSize]; |
338 |
|
339 |
if (indexToInsert > 0) |
340 |
System.arraycopy(roots, 0, newChildren, 0, indexToInsert); |
341 |
|
342 |
newChildren[indexToInsert] = child; |
343 |
System.arraycopy(roots, indexToInsert, newChildren, indexToInsert + 1, (newSize - indexToInsert - 1)); |
344 |
parent.setChildren(newChildren); |
345 |
return; |
346 |
} |
347 |
} |
348 |
parent.addChild(child); |
349 |
} |
291 |
/* |
350 |
/* |
292 |
* Process the given delta and look for projects being added, opened, closed or |
351 |
* Process the given delta and look for projects being added, opened, closed or |
293 |
* with a java nature being added or removed. |
352 |
* with a java nature being added or removed. |