4242import java .util .Map ;
4343
4444/**
45- *
45+ *
4646 */
4747@ SuppressWarnings ("restriction" )
4848public final class ClasspathUtilities {
@@ -77,7 +77,7 @@ public Class<?> find(ClassLoader classLoader, String className) {
7777 /**
7878 * Finds all the classpath containers in the specified project that match the
7979 * provided container ID.
80- *
80+ *
8181 * @param javaProject the project to query
8282 * @param containerId The container ID we are trying to match.
8383 * @return an array of matching classpath containers.
@@ -87,6 +87,7 @@ public static IClasspathEntry[] findClasspathContainersWithContainerId(
8787 throws JavaModelException {
8888
8989 Predicate <IClasspathEntry > matchPredicate = new Predicate <IClasspathEntry >() {
90+ @ Override
9091 public boolean apply (IClasspathEntry entry ) {
9192 if (entry .getEntryKind () == IClasspathEntry .CPE_CONTAINER ) {
9293 IPath containerPath = entry .getPath ();
@@ -123,7 +124,7 @@ public boolean apply(IClasspathEntry entry) {
123124 /**
124125 * Returns the {@link IClasspathEntry#CPE_CONTAINER} entry with the specified
125126 * container ID or <code>null</code> if one could not be found.
126- *
127+ *
127128 * @param classpathEntries array of classpath entries
128129 * @param containerId container ID
129130 * @return {@link IClasspathEntry#CPE_CONTAINER} entry with the specified
@@ -141,7 +142,7 @@ public static IClasspathEntry findClasspathEntryContainer(
141142 /**
142143 * Return the raw classpath entry on the project's classpath that contributes
143144 * the given type to the project.
144- *
145+ *
145146 * @param javaProject The java project
146147 * @param fullyQualifiedName The fully-qualified type name
147148 * @return The raw classpath entry that contributes the type to the project,
@@ -160,8 +161,20 @@ public static IClasspathEntry findRawClasspathEntryFor(
160161 IClasspathEntry [] rawClasspath = javaProject .getRawClasspath ();
161162 for (IClasspathEntry rawClasspathEntry : rawClasspath ) {
162163 IClasspathEntry [] resolvedClasspath = jProject .resolveClasspath (new IClasspathEntry [] {rawClasspathEntry });
163- IPackageFragmentRoot [] computePackageFragmentRoots = jProject .computePackageFragmentRoots (
164- resolvedClasspath , true , null );
164+
165+ // was this - which is no longer, internal api refactor
166+ //IPackageFragmentRoot[] computePackageFragmentRoots = jProject.computePackageFragmentRoots(resolvedClasspath, true, null);
167+
168+ // now this - from IPackage
169+ List <IPackageFragmentRoot > fragmentRoots = new ArrayList <IPackageFragmentRoot >();
170+ for (IClasspathEntry classPathEntry : resolvedClasspath ) {
171+ IPackageFragmentRoot [] foundRoots = javaProject .findPackageFragmentRoots (classPathEntry );
172+ fragmentRoots .addAll (Arrays .asList (foundRoots ));
173+ }
174+
175+ IPackageFragmentRoot [] computePackageFragmentRoots = new IPackageFragmentRoot [fragmentRoots .size ()];
176+ fragmentRoots .toArray (computePackageFragmentRoots );
177+
165178 if (Arrays .asList (computePackageFragmentRoots ).contains (
166179 packageFragmentRoot )) {
167180 return rawClasspathEntry ;
@@ -177,7 +190,7 @@ public static IClasspathEntry findRawClasspathEntryFor(
177190 /**
178191 * Returns a String (in the format of the JVM classpath argument) which
179192 * contains the given classpath entries.
180- *
193+ *
181194 * @param classpathEntries array of runtime classpath entries
182195 * @return flattened String of the given classpath entries in the format
183196 * suitable for passing as a JVM argument
@@ -217,7 +230,7 @@ public static IClasspathEntry getNullableRawClasspathEntryForPackageFragmentRoot
217230 /**
218231 * Determines whether a ClasspathContainer exists on the provided project that
219232 * matches the provided container ID.
220- *
233+ *
221234 * @param javaProject the project to query
222235 * @param containerId The container ID we are trying to match.
223236 * @return whether at least one classpath container exists that matches the
@@ -235,7 +248,7 @@ public static boolean includesClasspathContainerWithContainerId(
235248 * Returns the first index of the specified
236249 * {@link IClasspathEntry#CPE_CONTAINER} entry with the specified container ID
237250 * or -1 if one could not be found.
238- *
251+ *
239252 * @param classpathEntries array of classpath entries
240253 * @param containerId container ID
241254 * @return index of the specified {@link IClasspathEntry#CPE_CONTAINER} entry
@@ -263,11 +276,11 @@ public static int indexOfClasspathEntryContainer(
263276 /**
264277 * Replace an {@link IClasspathEntry#CPE_CONTAINER} entry with the given
265278 * container ID, with its corresponding resolved classpath entries.
266- *
279+ *
267280 * @param javaProject java project
268281 * @param containerId container ID to replace
269282 * @return true if a container was replaced
270- *
283+ *
271284 * @throws JavaModelException
272285 */
273286 public static boolean replaceContainerWithClasspathEntries (
@@ -294,7 +307,7 @@ public static boolean replaceContainerWithClasspathEntries(
294307 /**
295308 * Replaces a project's classpath container entry with a new one or appends it
296309 * to the classpath if none were found.
297- *
310+ *
298311 * @param javaProject The target project
299312 * @param containerId the identifier of the classpath container type
300313 * @param newContainerPath the path for the new classpath. Note: this path
@@ -333,30 +346,31 @@ public static void replaceOrAppendContainer(IJavaProject javaProject,
333346 * more information: <a
334347 * href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=243692"
335348 * >http://bugs.eclipse.org/bugs/show_bug.cgi?id=243692</a>
336- *
349+ *
337350 * <p>
338351 * Note that this method is asynchronous, so the caller will regain control
339352 * immediately, and the raw classpath will be set at some future time. Right
340353 * now, there is no way to tell the caller when the operation has completed.
341354 * If this becomes a concern in the future, a callback parameter can be
342355 * introduced.
343356 * </p>
344- *
357+ *
345358 * <p>
346359 * This method does not accept an IProgressMonitor, unlike the equivalent
347360 * method in IJavaProject, because there is an implicit progress monitor
348361 * provided when running the setRawClasspath operation as a task. In the
349362 * future, this method could be modified to accept a user-specified progress
350363 * monitor.
351364 * </p>
352- *
365+ *
353366 * NOTE: If you are already running in a job, you probably don't want to call
354367 * this method.
355368 */
356369 public static void setRawClasspath (final IJavaProject javaProject ,
357370 final IClasspathEntry [] newClasspathEntries ) {
358371
359372 IWorkspaceRunnable runnable = new IWorkspaceRunnable () {
373+ @ Override
360374 public void run (IProgressMonitor monitor ) throws CoreException ,
361375 OperationCanceledException {
362376 javaProject .setRawClasspath (newClasspathEntries , monitor );
@@ -376,15 +390,15 @@ public void run(IProgressMonitor monitor) throws CoreException,
376390 * more information: <a
377391 * href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=243692"
378392 * >http://bugs.eclipse.org/bugs/show_bug.cgi?id=243692</a>
379- *
393+ *
380394 * <p>
381395 * Note that this method is asynchronous, so the caller will regain control
382396 * immediately, and the raw classpath will be set at some future time. Right
383397 * now, there is no way to tell the caller when the operation has completed.
384398 * If this becomes a concern in the future, a callback parameter can be
385399 * introduced.
386400 * </p>
387- *
401+ *
388402 * <p>
389403 * This method does not accept an IProgressMonitor, unlike the equivalent
390404 * method in IJavaProject, because there is an implicit progress monitor
@@ -401,7 +415,7 @@ public static void setRawClasspath(final IJavaProject javaProject,
401415 /**
402416 * Waits indefinitely until the given classpath entries are on the given
403417 * project's raw classpath.
404- *
418+ *
405419 * @throws JavaModelException
406420 * @throws InterruptedException
407421 */
0 commit comments