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 80603 Details for
Bug 206685
Advanced Source Navigation via Hyperlinks
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]
Demo Patch
interface_hyperlinking_patch.txt (text/plain), 6.00 KB, created by
Nobody - feel free to take it
on 2007-10-17 15:20:58 EDT
(
hide
)
Description:
Demo Patch
Filename:
MIME Type:
Creator:
Nobody - feel free to take it
Created:
2007-10-17 15:20:58 EDT
Size:
6.00 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/ui/actions/OpenAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OpenAction.java,v >retrieving revision 1.54 >diff -u -r1.54 OpenAction.java >--- ui/org/eclipse/jdt/ui/actions/OpenAction.java 12 Sep 2007 14:10:01 -0000 1.54 >+++ ui/org/eclipse/jdt/ui/actions/OpenAction.java 17 Oct 2007 18:32:18 -0000 >@@ -12,8 +12,10 @@ > > import java.lang.reflect.InvocationTargetException; > import java.util.ArrayList; >+import java.util.HashMap; > import java.util.Iterator; > import java.util.List; >+import java.util.Map; > > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IStatus; >@@ -25,6 +27,7 @@ > import org.eclipse.jface.dialogs.ErrorDialog; > import org.eclipse.jface.util.OpenStrategy; > import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.window.Window; > > import org.eclipse.jface.text.ITextSelection; > >@@ -32,16 +35,22 @@ > import org.eclipse.ui.IWorkbenchSite; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.dialogs.ElementListSelectionDialog; > import org.eclipse.ui.texteditor.IEditorStatusLine; > >+import org.eclipse.jdt.core.Flags; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.ISourceReference; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.ITypeHierarchy; > import org.eclipse.jdt.core.JavaModelException; > > import org.eclipse.jdt.internal.corext.util.JavaModelUtil; > import org.eclipse.jdt.internal.corext.util.Messages; > >+import org.eclipse.jdt.ui.JavaElementLabelProvider; > import org.eclipse.jdt.ui.JavaUI; > > import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; >@@ -150,7 +159,94 @@ > if (element == null) > return; > } >+ >+ try { >+ >+ switch(element.getElementType()) { > >+ case IJavaElement.METHOD : >+ >+ // Check parent is interface >+ if(element.getParent().getElementType() == IJavaElement.TYPE && >+ ((IType) element.getParent()).isInterface()) { >+ >+ // Grab method & interface >+ IMethod method = (IMethod) element; >+ IType iface = (IType) element.getParent(); >+ >+ // Create hierarchy & map to store implementing types >+ ITypeHierarchy hierarchy = iface.newTypeHierarchy(null); >+ Map impTypes = new HashMap(); >+ >+ // Get *all* sub types >+ IType[] subTypes = hierarchy.getAllSubtypes(iface); >+ >+ for (int i = 0; i < subTypes.length; i++) { >+ >+ // Attempt to get method (TODO: Is this utility method accurate enough?) >+ IMethod currentMethod = JavaModelUtil.findMethod(method.getElementName(), >+ method.getParameterTypes(), >+ false, >+ subTypes[i]); >+ // Additionally, check the return types are the same... >+ if(currentMethod != null && >+ currentMethod.getReturnType().equals(method.getReturnType())) { >+ >+ // Check it's not been overriden in a sub interface or >+ // redeclared as abstract somewhere >+ if(!subTypes[i].isInterface() && >+ !Flags.isAbstract(currentMethod.getFlags()) && >+ !impTypes.containsKey(subTypes[i])) { >+ >+ impTypes.put(subTypes[i], currentMethod); >+ } >+ } >+ } >+ >+ // Prompt user for choice >+ IType[] types = (IType[]) impTypes.keySet().toArray(new IType[impTypes.size()-1]); >+ IType selectedImpl = selectImplementingType(types, method.getElementName()); >+ >+ // Set type to open >+ if(selectedImpl != null) { >+ element = (IJavaElement) impTypes.get(selectedImpl); >+ } >+ } >+ break; >+ >+ case IJavaElement.TYPE : >+ >+ // Check its an interface >+ if(((IType) element).isInterface()) { >+ >+ IType iface = (IType) element; >+ >+ // Create hierarchy & list for implementing classes >+ ITypeHierarchy hierarchy = iface.newTypeHierarchy(null); // TODO : Should use ProgressMonitor >+ List implTypes = new ArrayList(); >+ >+ // Add only direct subtypes which are classes (no extending interfaces) >+ IType[] subTypes = hierarchy.getSubtypes(iface); >+ for (int i= 0; i < subTypes.length; i++) { >+ if(subTypes[i].isClass()) { >+ implTypes.add(subTypes[i]); >+ } >+ } >+ >+ // Prompt user for selection >+ IType[] types = (IType[]) implTypes.toArray(new IType[implTypes.size()-1]); >+ IType selectedImpl = selectImplementingType(types, >+ iface.getElementName()); >+ >+ // Set type to open >+ if(selectedImpl != null) { >+ element = selectedImpl; >+ } >+ } >+ break; >+ } >+ } catch(JavaModelException jme) { /*...*/ } >+ > run(new Object[] {element} ); > } catch (InvocationTargetException e) { > ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.OpenAction_error_message); >@@ -158,7 +254,27 @@ > // ignore > } > } >+ >+ private IType selectImplementingType(IType[] types, String elementName) { > >+ // Check basic >+ if(types.length == 0) return null; >+ if(types.length == 1) return types[0]; >+ >+ // Prompt user to choose >+ int flags = JavaElementLabelProvider.SHOW_DEFAULT | JavaElementLabelProvider.SHOW_POST_QUALIFIED; >+ ElementListSelectionDialog dialog= new ElementListSelectionDialog(fEditor.getSite().getShell(), >+ new JavaElementLabelProvider(flags)); >+ dialog.setTitle("Open Implementation"); //$NON-NLS-1$ >+ dialog.setMessage("Choose an implementation of: " + elementName); //$NON-NLS-1$ >+ dialog.setElements(types); >+ >+ // Prompt user to select type >+ if (dialog.open() == Window.OK) { >+ return (IType) dialog.getFirstResult(); >+ } >+ return null; >+ } > /** > * Selects the openable elements out of the given ones. > *
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
Actions:
View
|
Diff
Attachments on
bug 206685
: 80603