Backported fix for bug 291716 to 3.5 maintenance.
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/JavaWorkingSetPageContentProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/JavaWorkingSetPageContentProvider.java
index dae4fc0..6bc98f3 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/JavaWorkingSetPageContentProvider.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/JavaWorkingSetPageContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -31,8 +31,10 @@
if (element instanceof IPackageFragment) {
IPackageFragment pkg= (IPackageFragment)element;
try {
- if (pkg.getKind() == IPackageFragmentRoot.K_BINARY)
+ if (pkg.getKind() == IPackageFragmentRoot.K_BINARY) {
+ // Don't show IJarEntryResource
return pkg.getChildren().length > 0;
+ }
} catch (JavaModelException ex) {
// use super behavior
}
@@ -58,6 +60,15 @@
}
}
+ protected Object[] getPackageFragmentRootContent(IPackageFragmentRoot root) throws JavaModelException {
+ if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
+ // Don't show IJarEntryResource
+ return root.getChildren();
+ }
+
+ return super.getPackageFragmentRootContent(root);
+ }
+
private Object[] getNonJavaProjects(IJavaModel model) throws JavaModelException {
return model.getNonJavaResources();
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetFilter.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetFilter.java
index 2055991..a6778a4 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetFilter.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetFilter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,6 +19,7 @@
import org.eclipse.ui.IWorkingSet;
+import org.eclipse.jdt.core.IJarEntryResource;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
@@ -34,10 +35,17 @@
*/
public class WorkingSetFilter extends JavaViewerFilter {
+
private static class WorkingSetCompareEntry {
+
+ /**
+ * Denotes an {@link IJarEntryResource} if it is
+ * <code>null && fJavaElement != null.</code>
+ */
private IPath fResourcePath;
private IJavaElement fJavaElement;
+
public WorkingSetCompareEntry(IAdaptable a) {
if (a instanceof IJavaElement) {
init((IJavaElement) a);
@@ -50,6 +58,8 @@
// that means it will only appear if the parent container project is in the working set
IResource fakeInternal= proj.getProject().getFile(wrapper.getProject().getElementName() + "-fake-jar.jar"); //$NON-NLS-1$
init(proj.getPackageFragmentRoot(fakeInternal));
+ } else if (a instanceof IJarEntryResource) {
+ init((IJarEntryResource)a);
} else {
IJavaElement je= (IJavaElement) a.getAdapter(IJavaElement.class);
if (je != null) {
@@ -76,6 +86,14 @@
fResourcePath= curr.getPath();
}
+ private void init(IJarEntryResource jarEntryResource) {
+ Object parent= jarEntryResource.getParent();
+ while (parent instanceof IJarEntryResource)
+ parent= ((IJarEntryResource)parent).getParent();
+ fJavaElement= (IJavaElement)parent;
+ fResourcePath= null;
+ }
+
public boolean contains(WorkingSetCompareEntry element) {
if (fJavaElement != null && element.fJavaElement != null) {
IJavaElement other= element.fJavaElement;
@@ -88,7 +106,8 @@
}
}
- if (isAncestor(other, fJavaElement) || isAncestor(fJavaElement, other)) {
+ // Check relationship in both directions except for IJarFileEntryResource which cannot be part of a working set
+ if (isAncestor(other, fJavaElement) || isAncestor(fJavaElement, other) && element.fResourcePath != null) {
return true;
}
return false;
@@ -101,6 +120,14 @@
return false;
}
+ /**
+ * Check whether the given parent is an ancestor of the given element
+ * or the same as the element.
+ *
+ * @param elem the element
+ * @param parent the anchestor
+ * @return <code>true</code> if it is an ancestor
+ */
private boolean isAncestor(IJavaElement elem, IJavaElement parent) {
IJavaElement anc= elem.getAncestor(parent.getElementType());
if (parent.equals(anc)) {