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 33451 Details for
Bug 123198
add parameterized commands to open/show java elements
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]
new patch - doesn't use handle identifiers
java-commands-patch3.txt (text/plain), 18.06 KB, created by
Christopher Daly
on 2006-01-23 04:40:25 EST
(
hide
)
Description:
new patch - doesn't use handle identifiers
Filename:
MIME Type:
Creator:
Christopher Daly
Created:
2006-01-23 04:40:25 EST
Size:
18.06 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/plugin.properties,v >retrieving revision 1.374 >diff -u -r1.374 plugin.properties >--- plugin.properties 17 Jan 2006 12:24:41 -0000 1.374 >+++ plugin.properties 23 Jan 2006 09:23:52 -0000 >@@ -951,6 +951,17 @@ > ViewCommand.callHierarchy.name= Java Call Hierarchy > ViewCommand.callHierarchy.description= Show the Call Hierarchy view > >+#--- Commands for surfacing java elements >+command.openElementInEditor.name= Open Java Element >+command.openElementInEditor.desc= Open a Java element in its editor >+commandParameter.openElementInEditor.elementRef.name= Java element reference >+command.showElementInPackageView.name= Show Java Element in Package Explorer >+command.showElementInPackageView.desc= Select Java element in the Package Explorer view >+commandParameter.showElementInPackageView.elementRef.name= Java element reference >+command.showElementInTypeHierarchyView.name= Show Java Element Type Hierarchy >+command.showElementInTypeHierarchyView.desc= Show a Java element in the Type Hierarchy view >+commandParameter.showElementInTypeHierarchyView.elementRef.name= Java element reference >+ > #--- Call Hierarchy > callHierarchyViewName=Call Hierarchy > >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/plugin.xml,v >retrieving revision 1.603 >diff -u -r1.603 plugin.xml >--- plugin.xml 18 Jan 2006 15:20:03 -0000 1.603 >+++ plugin.xml 23 Jan 2006 09:23:57 -0000 >@@ -314,6 +314,51 @@ > </command> > </extension> > >+ <!-- commands to surface java elements given handle id encoded parameter --> >+ <extension >+ point="org.eclipse.ui.commands"> >+ <commandParameterType >+ converter="org.eclipse.jdt.internal.ui.commands.JavaElementReferenceConverter" >+ id="org.eclipse.jdt.ui.commands.javaElementReference" >+ type="org.eclipse.jdt.core.IJavaElement"/> >+ <command >+ categoryId="org.eclipse.ui.category.navigate" >+ defaultHandler="org.eclipse.jdt.internal.ui.commands.OpenElementInEditorHandler" >+ description="%command.openElementInEditor.desc" >+ id="org.eclipse.jdt.ui.commands.openElementInEditor" >+ name="%command.openElementInEditor.name"> >+ <commandParameter >+ id="elementRef" >+ name="%commandParameter.openElementInEditor.elementRef.name" >+ optional="false" >+ typeId="org.eclipse.jdt.ui.commands.javaElementReference"/> >+ </command> >+ <command >+ categoryId="org.eclipse.ui.category.navigate" >+ defaultHandler="org.eclipse.jdt.internal.ui.commands.ShowElementInPackageViewHandler" >+ description="%command.showElementInPackageView.desc" >+ id="org.eclipse.jdt.ui.commands.showElementInPackageView" >+ name="%command.showElementInPackageView.name"> >+ <commandParameter >+ id="elementRef" >+ name="%commandParameter.showElementInPackageView.elementRef.name" >+ optional="false" >+ typeId="org.eclipse.jdt.ui.commands.javaElementReference"/> >+ </command> >+ <command >+ categoryId="org.eclipse.ui.category.navigate" >+ defaultHandler="org.eclipse.jdt.internal.ui.commands.ShowElementInTypeHierarchyViewHandler" >+ description="%command.showElementInTypeHierarchyView.desc" >+ id="org.eclipse.jdt.ui.commands.showElementInTypeHierarchyView" >+ name="%command.showElementInTypeHierarchyView.name"> >+ <commandParameter >+ id="elementRef" >+ name="%commandParameter.showElementInTypeHierarchyView.elementRef.name" >+ optional="false" >+ typeId="org.eclipse.jdt.ui.commands.javaElementReference"/> >+ </command> >+ </extension> >+ > <!-- Note: Do not change the sequence of those hover contributions --> > <extension > point="org.eclipse.jdt.ui.javaEditorTextHovers"> >Index: ui/org/eclipse/jdt/internal/ui/commands/ShowElementInPackageViewHandler.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/commands/ShowElementInPackageViewHandler.java >diff -N ui/org/eclipse/jdt/internal/ui/commands/ShowElementInPackageViewHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/commands/ShowElementInPackageViewHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 2005 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.jdt.internal.ui.commands; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+ >+import org.eclipse.jdt.core.IJavaElement; >+ >+import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart; >+ >+/** >+ * A command handler to show a java element in the package view. >+ * >+ * @since 3.2 >+ */ >+public class ShowElementInPackageViewHandler extends AbstractHandler { >+ >+ private static final String PARAM_ID_ELEMENT_REF = "elementRef"; //$NON-NLS-1$ >+ >+ public Object execute(ExecutionEvent event) throws ExecutionException { >+ >+ IJavaElement javaElement = (IJavaElement) event >+ .getObjectParameterForExecution(PARAM_ID_ELEMENT_REF); >+ >+ PackageExplorerPart view = PackageExplorerPart >+ .openInActivePerspective(); >+ view.tryToReveal(javaElement); >+ >+ return null; >+ } >+ >+} >Index: ui/org/eclipse/jdt/internal/ui/commands/JavaElementReferenceConverter.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/commands/JavaElementReferenceConverter.java >diff -N ui/org/eclipse/jdt/internal/ui/commands/JavaElementReferenceConverter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/commands/JavaElementReferenceConverter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,211 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.jdt.internal.ui.commands; >+ >+import org.eclipse.core.commands.AbstractParameterValueConverter; >+import org.eclipse.core.commands.ParameterValueConversionException; >+ >+import org.eclipse.core.resources.ResourcesPlugin; >+ >+import org.eclipse.jdt.core.IField; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaModel; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IMethod; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.Signature; >+ >+/** >+ * A command parameter value converter to convert between Java elements and >+ * String references that identify them. >+ * <p> >+ * References can be made to Java types, methods and fields. The reference >+ * identifies the project to use as a search scope as well as the java element >+ * information. Note that non-source elements may be referenced (such as >+ * java.lang.Object), but they must be resolved within the scope of some >+ * project. >+ * </p> >+ * <p> >+ * References take the form: >+ * >+ * <pre> >+ * elementRef := typeRef | fieldRef | methodRef >+ * typeRef := projectName '/' fullyQualifiedTypeName >+ * fieldRef := typeRef '#' fieldName >+ * methodRef := typeRef '#' methodName '(' parameterSignatures ')' >+ * </pre> >+ * >+ * where <code>parameterSignatures</code> uses the signature format documented >+ * in the {@link org.eclipse.jdt.core.Signature Signature} class. >+ * </p> >+ * >+ * @since 3.2 >+ */ >+public class JavaElementReferenceConverter extends >+ AbstractParameterValueConverter { >+ >+ private static final char PROJECT_END_CHAR = '/'; >+ >+ private static final char TYPE_END_CHAR = '#'; >+ >+ private static final char PARAM_START_CHAR = Signature.C_PARAM_START; >+ >+ private static final char PARAM_END_CHAR = Signature.C_PARAM_END; >+ >+ public Object convertToObject(String parameterValue) >+ throws ParameterValueConversionException { >+ >+ assertWellFormed(parameterValue != null); >+ >+ final int projectEndPosition = parameterValue.indexOf(PROJECT_END_CHAR); >+ assertWellFormed(projectEndPosition != -1); >+ >+ String projectName = parameterValue.substring(0, projectEndPosition); >+ String javaElementRef = parameterValue >+ .substring(projectEndPosition + 1); >+ >+ IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace() >+ .getRoot()); >+ assertExists(javaModel); >+ >+ IJavaProject javaProject = javaModel.getJavaProject(projectName); >+ assertExists(javaProject); >+ >+ final int typeEndPosition = javaElementRef.indexOf(TYPE_END_CHAR); >+ String typeName; >+ if (typeEndPosition == -1) { >+ typeName = javaElementRef; >+ } else { >+ typeName = javaElementRef.substring(0, typeEndPosition); >+ } >+ >+ IType type = null; >+ try { >+ type = javaProject.findType(typeName); >+ } catch (JavaModelException ex) { >+ // type == null >+ } >+ assertExists(type); >+ >+ if (typeEndPosition == -1) { >+ return type; >+ } >+ >+ String memberRef = javaElementRef.substring(typeEndPosition + 1); >+ >+ final int paramStartPosition = memberRef.indexOf(PARAM_START_CHAR); >+ if (paramStartPosition == -1) { >+ IField field = type.getField(memberRef); >+ assertExists(field); >+ return field; >+ } >+ String methodName = memberRef.substring(0, paramStartPosition); >+ String signature = memberRef.substring(paramStartPosition); >+ String[] parameterTypes = null; >+ try { >+ parameterTypes = Signature.getParameterTypes(signature); >+ } catch (IllegalArgumentException ex) { >+ // parameterTypes == null >+ } >+ assertWellFormed(parameterTypes != null); >+ IMethod method = type.getMethod(methodName, parameterTypes); >+ assertExists(method); >+ return method; >+ } >+ >+ /** >+ * Throws a <code>ParameterValueConversionException</code> if the java >+ * element reference string does not meet some well-formedness condition. >+ * >+ * @param assertion >+ * a boolean check for well-formedness >+ * @throws ParameterValueConversionException >+ */ >+ private void assertWellFormed(boolean assertion) >+ throws ParameterValueConversionException { >+ if (!assertion) { >+ throw new ParameterValueConversionException( >+ "Malformed parameterValue"); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * Throws a <code>ParameterValueConversionException</code> if the java >+ * element reference string identifes an element that does not exist. >+ * >+ * @param javaElement >+ * an element to check for existence >+ * @throws ParameterValueConversionException >+ */ >+ private void assertExists(IJavaElement javaElement) >+ throws ParameterValueConversionException { >+ if ((javaElement == null) || (!javaElement.exists())) { >+ throw new ParameterValueConversionException( >+ "parameterValue must reference an existing IJavaElement"); //$NON-NLS-1$ >+ } >+ } >+ >+ public String convertToString(Object parameterValue) >+ throws ParameterValueConversionException { >+ >+ if (!(parameterValue instanceof IJavaElement)) { >+ throw new ParameterValueConversionException( >+ "parameterValue must be an IJavaElement"); //$NON-NLS-1$ >+ } >+ >+ IJavaElement javaElement = (IJavaElement) parameterValue; >+ >+ IJavaProject javaProject = javaElement.getJavaProject(); >+ if (javaProject == null) { >+ throw new ParameterValueConversionException( >+ "Could not get IJavaProject for element"); //$NON-NLS-1$ >+ } >+ >+ StringBuffer buffer; >+ >+ if (javaElement instanceof IType) { >+ IType type = (IType) javaElement; >+ buffer = composeTypeReference(type); >+ } else if (javaElement instanceof IMethod) { >+ IMethod method = (IMethod) javaElement; >+ buffer = composeTypeReference(method.getDeclaringType()); >+ buffer.append(TYPE_END_CHAR); >+ buffer.append(method.getElementName()); >+ String[] parameterTypes = method.getParameterTypes(); >+ buffer.append(PARAM_START_CHAR); >+ for (int i = 0; i < parameterTypes.length; i++) { >+ buffer.append(parameterTypes[i]); >+ } >+ buffer.append(PARAM_END_CHAR); >+ } else if (javaElement instanceof IField) { >+ IField field = (IField) javaElement; >+ buffer = composeTypeReference(field.getDeclaringType()); >+ buffer.append(TYPE_END_CHAR); >+ buffer.append(field.getElementName()); >+ } else { >+ throw new ParameterValueConversionException( >+ "Unsupported IJavaElement type"); //$NON-NLS-1$ >+ } >+ >+ return buffer.toString(); >+ } >+ >+ private StringBuffer composeTypeReference(IType type) { >+ StringBuffer buffer = new StringBuffer(); >+ buffer.append(type.getJavaProject().getElementName()); >+ buffer.append(PROJECT_END_CHAR); >+ buffer.append(type.getFullyQualifiedName()); >+ return buffer; >+ } >+ >+} >Index: ui/org/eclipse/jdt/internal/ui/commands/OpenElementInEditorHandler.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/commands/OpenElementInEditorHandler.java >diff -N ui/org/eclipse/jdt/internal/ui/commands/OpenElementInEditorHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/commands/OpenElementInEditorHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,53 @@ >+/******************************************************************************* >+ * Copyright (c) 2005 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.jdt.internal.ui.commands; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+ >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.PartInitException; >+ >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.JavaModelException; >+ >+import org.eclipse.jdt.ui.JavaUI; >+ >+/** >+ * A command handler to open a java element in its editor. >+ * >+ * @since 3.2 >+ */ >+public class OpenElementInEditorHandler extends AbstractHandler { >+ >+ private static final String PARAM_ID_ELEMENT_REF = "elementRef"; //$NON-NLS-1$ >+ >+ public Object execute(ExecutionEvent event) throws ExecutionException { >+ >+ IJavaElement javaElement = (IJavaElement) event >+ .getObjectParameterForExecution(PARAM_ID_ELEMENT_REF); >+ >+ try { >+ IEditorPart editorPart = JavaUI.openInEditor(javaElement); >+ JavaUI.revealInEditor(editorPart, javaElement); >+ } catch (JavaModelException ex) { >+ throw new ExecutionException( >+ "Error opening java element in editor", ex); //$NON-NLS-1$ >+ } catch (PartInitException ex) { >+ throw new ExecutionException( >+ "Error opening java element in editor", ex); //$NON-NLS-1$ >+ } >+ >+ return null; >+ } >+ >+} >Index: ui/org/eclipse/jdt/internal/ui/commands/ShowElementInTypeHierarchyViewHandler.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/commands/ShowElementInTypeHierarchyViewHandler.java >diff -N ui/org/eclipse/jdt/internal/ui/commands/ShowElementInTypeHierarchyViewHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/commands/ShowElementInTypeHierarchyViewHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,54 @@ >+/******************************************************************************* >+ * Copyright (c) 2005 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.jdt.internal.ui.commands; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+ >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+ >+import org.eclipse.jdt.core.IJavaElement; >+ >+import org.eclipse.jdt.internal.ui.util.OpenTypeHierarchyUtil; >+ >+/** >+ * A command handler to show a java element in the type hierarchy view. >+ * >+ * @since 3.2 >+ */ >+public class ShowElementInTypeHierarchyViewHandler extends AbstractHandler { >+ >+ private static final String PARAM_ID_ELEMENT_REF = "elementRef"; //$NON-NLS-1$ >+ >+ public Object execute(ExecutionEvent event) throws ExecutionException { >+ >+ IWorkbenchWindow window = getWorkbenchWindow(); >+ if (window == null) >+ return null; >+ >+ IJavaElement javaElement = (IJavaElement) event >+ .getObjectParameterForExecution(PARAM_ID_ELEMENT_REF); >+ >+ OpenTypeHierarchyUtil.open(javaElement, window); >+ >+ return null; >+ } >+ >+ private IWorkbenchWindow getWorkbenchWindow() { >+ IWorkbench workbench = PlatformUI.getWorkbench(); >+ IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow(); >+ return activeWindow; >+ } >+ >+}
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 123198
:
32742
|
32802
| 33451