### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.ui Index: core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java,v retrieving revision 1.150 diff -u -r1.150 JavaModelUtil.java --- core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java 7 Sep 2009 10:41:29 -0000 1.150 +++ core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java 8 Mar 2010 19:35:25 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -589,6 +589,33 @@ } /** + * Returns the classpath entry of the given package fragment root. This is the raw entry, except + * if the root is a referenced library, in which case it's the resolved entry. + * + * @param root a package fragment root + * @return the corresponding classpath entry + * @throws JavaModelException if accessing the entry failed + * @since 3.6 + */ + public static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException { + IClasspathEntry rawEntry= root.getRawClasspathEntry(); + int rawEntryKind= rawEntry.getEntryKind(); + switch (rawEntryKind) { + case IClasspathEntry.CPE_LIBRARY: + case IClasspathEntry.CPE_VARIABLE: + case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037 + if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) { + IClasspathEntry resolvedEntry= root.getResolvedClasspathEntry(); + if (resolvedEntry.getReferencingEntry() != null) + return resolvedEntry; + else + return rawEntry; + } + } + return rawEntry; + } + + /** * Get all compilation units of a selection. * * @param javaElements the selected java elements Index: ui/org/eclipse/jdt/internal/ui/JavaUIMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaUIMessages.java,v retrieving revision 1.55 diff -u -r1.55 JavaUIMessages.java --- ui/org/eclipse/jdt/internal/ui/JavaUIMessages.java 14 Jan 2010 17:04:52 -0000 1.55 +++ ui/org/eclipse/jdt/internal/ui/JavaUIMessages.java 8 Mar 2010 19:35:25 -0000 @@ -179,6 +179,7 @@ public static String JavaElementLabels_comma_string; public static String JavaElementLabels_declseparator_string; public static String JavaElementLabels_category_separator_string; + public static String JavaElementLabels_onClassPathOf; public static String StatusBarUpdater_num_elements_selected; Index: ui/org/eclipse/jdt/internal/ui/JavaUIMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaUIMessages.properties,v retrieving revision 1.289 diff -u -r1.289 JavaUIMessages.properties --- ui/org/eclipse/jdt/internal/ui/JavaUIMessages.properties 14 Jan 2010 17:04:52 -0000 1.289 +++ ui/org/eclipse/jdt/internal/ui/JavaUIMessages.properties 8 Mar 2010 19:35:25 -0000 @@ -183,6 +183,7 @@ JavaElementLabels_default_package=(default package) JavaElementLabels_import_container=import declarations JavaElementLabels_initializer={...} +JavaElementLabels_onClassPathOf=\ (from {0} of {1}) StatusBarUpdater_num_elements_selected={0} items selected Index: ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java,v retrieving revision 1.7 diff -u -r1.7 JavaElementLabelComposer.java --- ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java 24 Feb 2010 14:04:32 -0000 1.7 +++ ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java 8 Mar 2010 19:35:25 -0000 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.jdt.internal.ui.viewsupport; +import java.util.jar.Attributes.Name; + import org.eclipse.core.runtime.IPath; import org.eclipse.core.resources.IProject; @@ -1050,7 +1052,11 @@ private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try { IClasspathEntry rawEntry= root.getRawClasspathEntry(); - if (rawEntry != null && rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { + if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { + IClasspathEntry entry= JavaModelUtil.getClasspathEntry(root); + if (entry.getReferencingEntry() != null) { + return false; // not the variable entry itself, but a referenced entry + } IPath path= rawEntry.getPath().makeRelative(); if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { @@ -1092,10 +1098,11 @@ private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path; + IClasspathEntry classpathEntry= null; try { - IClasspathEntry rawClasspathEntry= root.getRawClasspathEntry(); - IPath rawPath= rawClasspathEntry.getPath(); - if (rawClasspathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute()) + classpathEntry= JavaModelUtil.getClasspathEntry(root); + IPath rawPath= classpathEntry.getPath(); + if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute()) path= rawPath; else path= root.getPath(); @@ -1111,6 +1118,12 @@ fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } + if (classpathEntry != null) { + IClasspathEntry referencingEntry= classpathEntry.getReferencingEntry(); + if (referencingEntry != null) { + fBuffer.append(Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() })); + } + } if (getFlag(flags, JavaElementLabels.COLORIZE)) { fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); } @@ -1125,20 +1138,28 @@ private void appendInternalArchiveLabel(IPackageFragmentRoot root, long flags) { IResource resource= root.getResource(); boolean rootQualified= getFlag(flags, JavaElementLabels.ROOT_QUALIFIED); - boolean referencedQualified= getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root); if (rootQualified) { fBuffer.append(root.getPath().makeRelative().toString()); } else { fBuffer.append(root.getElementName()); int offset= fBuffer.length(); - if (referencedQualified) { + boolean referencedPostQualified= getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED); + if (referencedPostQualified && isReferenced(root)) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(resource.getParent().getFullPath().makeRelative().toString()); } else if (getFlag(flags, JavaElementLabels.ROOT_POST_QUALIFIED)) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(root.getParent().getPath().makeRelative().toString()); - } else { - return; + } + if (referencedPostQualified) { + try { + IClasspathEntry referencingEntry= JavaModelUtil.getClasspathEntry(root).getReferencingEntry(); + if (referencingEntry != null) { + fBuffer.append(Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() })); + } + } catch (JavaModelException e) { + // ignore + } } if (getFlag(flags, JavaElementLabels.COLORIZE)) { fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); @@ -1184,7 +1205,7 @@ /** * Returns true if the given package fragment root is - * referenced. This means it is own by a different project but is referenced + * referenced. This means it is a descendant of a different project but is referenced * by the root's parent. Returns false if the given root * doesn't have an underlying resource. *