Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 152469 Details for
Bug 288464
[navigation] Open Implementation hyperlink does not show multiple implementations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Updated Patch
patch9_288464.txt (text/plain), 11.95 KB, created by
Raksha Vasisht
on 2009-11-18 08:59:23 EST
(
hide
)
Description:
Updated Patch
Filename:
MIME Type:
Creator:
Raksha Vasisht
Created:
2009-11-18 08:59:23 EST
Size:
11.95 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkImplementationDetector.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkImplementationDetector.java,v >retrieving revision 1.3 >diff -u -r1.3 JavaElementHyperlinkImplementationDetector.java >--- ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkImplementationDetector.java 20 Mar 2009 07:48:17 -0000 1.3 >+++ ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkImplementationDetector.java 18 Nov 2009 13:59:15 -0000 >@@ -40,7 +40,7 @@ > */ > protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, ITextEditor editor) { > if (element.getElementType() == IJavaElement.METHOD && canBeOverridden((IMethod)element)) { >- return new JavaElementImplementationHyperlink(wordRegion, openAction, element, qualify, editor); >+ return new JavaElementImplementationHyperlink(wordRegion, openAction, (IMethod)element, qualify, editor); > } > return null; > } >Index: ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementImplementationHyperlink.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementImplementationHyperlink.java,v >retrieving revision 1.9 >diff -u -r1.9 JavaElementImplementationHyperlink.java >--- ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementImplementationHyperlink.java 5 Aug 2009 07:19:30 -0000 1.9 >+++ ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementImplementationHyperlink.java 18 Nov 2009 13:59:15 -0000 >@@ -36,10 +36,11 @@ > > import org.eclipse.ui.texteditor.ITextEditor; > >-import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.ITypeHierarchy; > import org.eclipse.jdt.core.ITypeRoot; >+import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.dom.ASTNode; > import org.eclipse.jdt.core.dom.CompilationUnit; > import org.eclipse.jdt.core.dom.Expression; >@@ -50,6 +51,7 @@ > import org.eclipse.jdt.core.dom.SimpleName; > import org.eclipse.jdt.core.dom.SuperMethodInvocation; > import org.eclipse.jdt.core.search.IJavaSearchConstants; >+import org.eclipse.jdt.core.search.IJavaSearchScope; > import org.eclipse.jdt.core.search.SearchEngine; > import org.eclipse.jdt.core.search.SearchMatch; > import org.eclipse.jdt.core.search.SearchParticipant; >@@ -59,6 +61,7 @@ > import org.eclipse.jdt.internal.corext.dom.Bindings; > import org.eclipse.jdt.internal.corext.util.JdtFlags; > import org.eclipse.jdt.internal.corext.util.Messages; >+import org.eclipse.jdt.internal.corext.util.MethodOverrideTester; > > import org.eclipse.jdt.ui.JavaElementLabels; > import org.eclipse.jdt.ui.SharedASTProvider; >@@ -74,9 +77,15 @@ > */ > public class JavaElementImplementationHyperlink implements IHyperlink { > >+ /** >+ * Indicates whether the search scope needs to be restricted to sub types in the hierarchy. >+ * >+ * @since 3.6 >+ */ >+ private static boolean fCreateSubtypeHierarchyScope; > private final IRegion fRegion; > private final SelectionDispatchAction fOpenAction; >- private final IJavaElement fElement; >+ private final IMethod fMethod; > private final boolean fQualify; > > /** >@@ -89,21 +98,22 @@ > * > * @param region the region of the link > * @param openAction the action to use to open the java elements >- * @param element the java element to open >+ * @param method the method to open > * @param qualify <code>true</code> if the hyperlink text should show a qualified name for > * element. > * @param editor the active java editor > */ >- public JavaElementImplementationHyperlink(IRegion region, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, ITextEditor editor) { >+ public JavaElementImplementationHyperlink(IRegion region, SelectionDispatchAction openAction, IMethod method, boolean qualify, ITextEditor editor) { > Assert.isNotNull(openAction); > Assert.isNotNull(region); >- Assert.isNotNull(element); >+ Assert.isNotNull(method); > > fRegion= region; > fOpenAction= openAction; >- fElement= element; >+ fMethod= method; > fQualify= qualify; > fEditor= editor; >+ fCreateSubtypeHierarchyScope= true; > } > > /* >@@ -118,8 +128,8 @@ > */ > public String getHyperlinkText() { > if (fQualify) { >- String elementLabel= JavaElementLabels.getElementLabel(fElement, JavaElementLabels.ALL_FULLY_QUALIFIED); >- return Messages.format(JavaEditorMessages.JavaElementImplementationHyperlink_hyperlinkText_qualified, new Object[] { elementLabel }); >+ String methodLabel= JavaElementLabels.getElementLabel(fMethod, JavaElementLabels.ALL_FULLY_QUALIFIED); >+ return Messages.format(JavaEditorMessages.JavaElementImplementationHyperlink_hyperlinkText_qualified, new Object[] { methodLabel }); > } else { > return JavaEditorMessages.JavaElementImplementationHyperlink_hyperlinkText; > } >@@ -140,23 +150,23 @@ > * </p> > */ > public void open() { >- openImplementations(fEditor, fRegion, fElement, fOpenAction); >+ openImplementations(fEditor, fRegion, fMethod, fOpenAction); > } > > /** > * Finds the implementations for the method. > * <p> >- * If there's only one implementor that java element is opened in the editor, otherwise the >- * Quick Hierarchy is opened. >+ * If there's only one implementor that method is opened in the editor, otherwise the Quick >+ * Hierarchy is opened. > * </p> > * >- * @param openAction the action to use to open the java elements >- * @param javaElement the java element >+ * @param openAction the action to use to open the methods >+ * @param method the method > * @param region the region of the selection > * @param editor the active java editor > * @since 3.6 > */ >- public static void openImplementations(IEditorPart editor, IRegion region, final IJavaElement javaElement, SelectionDispatchAction openAction) { >+ public static void openImplementations(IEditorPart editor, IRegion region, final IMethod method, SelectionDispatchAction openAction) { > ITypeRoot editorInput= EditorUtility.getEditorInputJavaElement(editor, false); > > CompilationUnit ast= SharedASTProvider.getAST(editorInput, SharedASTProvider.WAIT_ACTIVE_ONLY, null); >@@ -178,14 +188,14 @@ > } > } else if (parent instanceof SuperMethodInvocation) { > // Directly go to the super method definition >- openAction.run(new StructuredSelection(javaElement)); >+ openAction.run(new StructuredSelection(method)); > return; > } else if (parent instanceof MethodDeclaration) { > parentTypeBinding= Bindings.getBindingOfParentType(node); > } > } >- final IType type= parentTypeBinding != null ? (IType) parentTypeBinding.getJavaElement() : null; >- if (type == null) { >+ final IType receiverType= parentTypeBinding != null ? (IType)parentTypeBinding.getJavaElement() : null; >+ if (receiverType == null) { > openQuickHierarchy(editor); > return; > } >@@ -199,28 +209,40 @@ > monitor= new NullProgressMonitor(); > } > try { >- String methodLabel= JavaElementLabels.getElementLabel(javaElement, JavaElementLabels.DEFAULT_QUALIFIED); >- monitor.beginTask(Messages.format(JavaEditorMessages.JavaElementImplementationHyperlink_search_method_implementors, methodLabel), 100); >+ String methodLabel= JavaElementLabels.getElementLabel(method, JavaElementLabels.DEFAULT_QUALIFIED); >+ monitor.beginTask(Messages.format(JavaEditorMessages.JavaElementImplementationHyperlink_search_method_implementors, methodLabel), 10); >+ ITypeHierarchy superTypeHierarchy= receiverType.newSupertypeHierarchy(new SubProgressMonitor(monitor, 3)); >+ IType type; >+ type= findTypeDefiningSearchScope(superTypeHierarchy, method, receiverType, links); >+ > SearchRequestor requestor= new SearchRequestor() { > public void acceptSearchMatch(SearchMatch match) throws CoreException { > if (match.getAccuracy() == SearchMatch.A_ACCURATE) { >- IJavaElement element= (IJavaElement)match.getElement(); >- if (element instanceof IMethod && !JdtFlags.isAbstract((IMethod)element)) { >- links.add(element); >- if (links.size() > 1) { >- throw new OperationCanceledException(dummyString); >+ Object element= match.getElement(); >+ if (element instanceof IMethod) { >+ IMethod methodFound= (IMethod)element; >+ if (!JdtFlags.isAbstract(methodFound) && !links.contains(methodFound)) { >+ links.add(element); >+ if (links.size() > 1) { >+ throw new OperationCanceledException(dummyString); >+ } > } > } > } > } > }; > int limitTo= IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE; >- SearchPattern pattern= SearchPattern.createPattern(javaElement, limitTo); >+ SearchPattern pattern= SearchPattern.createPattern(method, limitTo); > Assert.isNotNull(pattern); > SearchParticipant[] participants= new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; > SearchEngine engine= new SearchEngine(); >- engine.search(pattern, participants, SearchEngine.createHierarchyScope(type), requestor, new SubProgressMonitor(monitor, 100)); >- >+ IJavaSearchScope hierarchyScope; >+ if (fCreateSubtypeHierarchyScope) { >+ hierarchyScope= SearchEngine.createHierarchyScope(null, type, true, false, null); >+ } else { >+ hierarchyScope= SearchEngine.createHierarchyScope(type); >+ } >+ engine.search(pattern, participants, hierarchyScope, requestor, new SubProgressMonitor(monitor, 7)); > if (monitor.isCanceled()) { > throw new OperationCanceledException(); > } >@@ -237,7 +259,7 @@ > context.run(true, true, runnable); > } catch (InvocationTargetException e) { > IStatus status= new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, >- Messages.format(JavaEditorMessages.JavaElementImplementationHyperlink_error_status_message, javaElement.getElementName()), e.getCause()); >+ Messages.format(JavaEditorMessages.JavaElementImplementationHyperlink_error_status_message, method.getElementName()), e.getCause()); > JavaPlugin.log(status); > ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), > JavaEditorMessages.JavaElementImplementationHyperlink_hyperlinkText, >@@ -256,6 +278,33 @@ > } > > /** >+ * Finds the type which defines the scope to search for implementors. Returns the receiver type >+ * if its a class, else return the declaring type of the method. >+ * >+ * @param superTypeHierarchy the type hierarchy >+ * @param method the method >+ * @param receiverType the receiver type >+ * @param links the list of implementors >+ * @return the receiver type if its a class, else the declaring type of the method. >+ * @throws JavaModelException if the java element does not exist or if an exception occurs while >+ * accessing its corresponding resource >+ * @since 3.6 >+ */ >+ private static IType findTypeDefiningSearchScope(ITypeHierarchy superTypeHierarchy, IMethod method, IType receiverType, ArrayList links) throws JavaModelException { >+ if (receiverType.isClass()) { >+ MethodOverrideTester methodOverrideTester= new MethodOverrideTester(receiverType, superTypeHierarchy); >+ IMethod methodInReceiver= methodOverrideTester.findOverriddenMethodInType(receiverType, method); >+ if (methodInReceiver == null || JdtFlags.isAbstract(methodInReceiver)) { >+ fCreateSubtypeHierarchyScope= false; >+ } else { >+ links.add(methodInReceiver); >+ } >+ return receiverType; >+ } >+ return method.getDeclaringType(); >+ } >+ >+ /** > * Opens the quick type hierarchy for the given editor. > * > * @param editor the editor for which to open the quick hierarchy
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
daniel_megert
:
review-
Actions:
View
|
Diff
Attachments on
bug 288464
:
149619
|
150467
|
151587
|
152156
|
152163
|
152464
|
152469
|
152565