issue_id
int64
2.03k
426k
title
stringlengths
9
251
body
stringlengths
1
32.8k
status
stringclasses
6 values
after_fix_sha
stringlengths
7
7
project_name
stringclasses
6 values
repo_url
stringclasses
6 values
repo_name
stringclasses
6 values
language
stringclasses
1 value
issue_url
null
before_fix_sha
null
pull_url
null
commit_datetime
timestamp[us, tz=UTC]
report_datetime
timestamp[us, tz=UTC]
updated_file
stringlengths
2
187
file_content
stringlengths
0
368k
48,360
Bug 48360 ArrayIndexOutOfBoundsException when using escape key [reorg]
Using 1209, I got the following stack trace when trying to use Ctrl + C for copying and then cancelling it with the escape key. STEPS TO REPRODUCE: 1) Select a folder 2) Copy it in a folder that already contains a folder with the same name 3) You get a dialog asking if you want to override the existing file 4) Cancel it using the Esc key. 5) You get the exception. If you use the cancel button, it works fine. java.lang.reflect.InvocationTargetException at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:313) at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:252) at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:394) at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:131) at org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgCopyStarter.run(ReorgCopyStarter.java:70) at org.eclipse.jdt.internal.ui.refactoring.reorg.PasteAction$JavaElementAndResourcePaster.paste(PasteAction.java:404) at org.eclipse.jdt.internal.ui.refactoring.reorg.PasteAction.run(PasteAction.java:189) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:194) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:172) at org.eclipse.jface.action.Action.runWithEvent(Action.java:842) at org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetAction.java:212) at org.eclipse.ui.internal.commands.ActionHandler.execute(ActionHandler.java:40) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:341) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:673) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:711) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:410) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$0(WorkbenchKeyboard.java:372) at org.eclipse.ui.internal.keys.WorkbenchKeyboard$1.handleEvent(WorkbenchKeyboard.java:205) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Display.filterEvent(Display.java:692) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:846) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:871) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:856) at org.eclipse.swt.widgets.Control.sendKeyEvent(Control.java:1716) at org.eclipse.swt.widgets.Control.sendKeyEvent(Control.java:1712) at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3036) at org.eclipse.swt.widgets.Tree.WM_CHAR(Tree.java:1292) at org.eclipse.swt.widgets.Control.windowProc(Control.java:2939) at org.eclipse.swt.widgets.Display.windowProc(Display.java:2819) at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1368) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1973) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1537) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1513) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:242) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:139) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:47) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:242) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.internal.boot.OSGiBootLoader.basicRun(OSGiBootLoader.java:239) at org.eclipse.core.internal.boot.OSGiBootLoader.run(OSGiBootLoader.java:665) at org.eclipse.core.internal.boot.OSGiBootLoader.run(OSGiBootLoader.java:652) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:299) at org.eclipse.core.launcher.Main.run(Main.java:767) at org.eclipse.core.launcher.Main.main(Main.java:601) Caused by: java.lang.ArrayIndexOutOfBoundsException: -1 at org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgQueries$1.run(ReorgQueries.java:129) at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:131) at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:25) at org.eclipse.swt.widgets.Display.syncExec(Display.java:2611) at org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgQueries$YesYesToAllNoNoToAllQuery.confirm(ReorgQueries.java:96) at org.eclipse.jdt.internal.corext.refactoring.reorg.OverwriteHelper.overwrite(OverwriteHelper.java:206) at org.eclipse.jdt.internal.corext.refactoring.reorg.OverwriteHelper.overwrite(OverwriteHelper.java:197) at org.eclipse.jdt.internal.corext.refactoring.reorg.OverwriteHelper.confirmFolderOverwritting(OverwriteHelper.java:131) at org.eclipse.jdt.internal.corext.refactoring.reorg.OverwriteHelper.confirmOverwritting(OverwriteHelper.java:99) at org.eclipse.jdt.internal.corext.refactoring.reorg.OverwriteHelper.confirmOverwritting(OverwriteHelper.java:93) at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$FilesFoldersAndCusReorgPolicy.confirmOverwritting(ReorgPolicyFactory.java:470) at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$FilesFoldersAndCusReorgPolicy.checkInput(ReorgPolicyFactory.java:455) at org.eclipse.jdt.internal.corext.refactoring.reorg.CopyRefactoring.checkInput(CopyRefactoring.java:101) at org.eclipse.jdt.internal.corext.refactoring.base.Refactoring.checkPreconditions(Refactoring.java:79) at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.run(RefactoringExecutionHelper.java:69) at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:302) ... 52 more
resolved fixed
ba138ba
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-10T10:37:30Z
2003-12-09T20:00:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/ReorgQueries.java
48,431
Bug 48431 Incorrect order for modifiers in generated testcases [JUnit]
null
resolved fixed
148ecc1
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T00:42:26Z
2003-12-10T18:13:20Z
org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/NewTestCaseCreationWizardPage.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Sebastian Davids - bug 38507 *******************************************************************************/ package org.eclipse.jdt.internal.junit.wizards; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.ListIterator; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.ITypeHierarchy; import org.eclipse.jdt.core.JavaConventions; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.SearchEngine; import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.junit.ui.IJUnitHelpContextIds; import org.eclipse.jdt.internal.junit.ui.JUnitPlugin; import org.eclipse.jdt.internal.junit.util.JUnitStatus; import org.eclipse.jdt.internal.junit.util.JUnitStubUtility; import org.eclipse.jdt.internal.junit.util.LayoutUtil; import org.eclipse.jdt.internal.junit.util.TestSearchEngine; import org.eclipse.jdt.internal.junit.util.JUnitStubUtility.GenStubSettings; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.util.SWTUtil; import org.eclipse.jdt.ui.IJavaElementSearchConstants; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.wizards.NewTypeWizardPage; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.SelectionDialog; import org.eclipse.ui.help.WorkbenchHelp; /** * The first page of the TestCase creation wizard. */ public class NewTestCaseCreationWizardPage extends NewTypeWizardPage { private final static String PAGE_NAME= "NewTestCaseCreationWizardPage"; //$NON-NLS-1$ private final static String CLASS_TO_TEST= PAGE_NAME + ".classtotest"; //$NON-NLS-1$ private final static String TEST_SUFFIX= "Test"; //$NON-NLS-1$ private final static String SETUP= "setUp"; //$NON-NLS-1$ private final static String TEARDOWN= "tearDown"; //$NON-NLS-1$ private final static String STORE_GENERATE_MAIN= PAGE_NAME + ".GENERATE_MAIN"; //$NON-NLS-1$ private final static String STORE_USE_TESTRUNNER= PAGE_NAME + ".USE_TESTRUNNER"; //$NON-NLS-1$ private final static String STORE_TESTRUNNER_TYPE= PAGE_NAME + ".TESTRUNNER_TYPE"; //$NON-NLS-1$ private String fDefaultClassToTest; private NewTestCaseCreationWizardPage2 fPage2; private MethodStubsSelectionButtonGroup fMethodStubsButtons; private IType fClassToTest; private IStatus fClassToTestStatus; private IStatus fTestClassStatus; private int fIndexOfFirstTestMethod; private Label fClassToTestLabel; private Text fClassToTestText; private Button fClassToTestButton; private boolean fFirstTime; public NewTestCaseCreationWizardPage() { super(true, PAGE_NAME); fFirstTime= true; setTitle(WizardMessages.getString("NewTestClassWizPage.title")); //$NON-NLS-1$ setDescription(WizardMessages.getString("NewTestClassWizPage.description")); //$NON-NLS-1$ String[] buttonNames= new String[] { "public static void main(Strin&g[] args)", //$NON-NLS-1$ /* Add testrunner statement to main Method */ WizardMessages.getString("NewTestClassWizPage.methodStub.testRunner"), //$NON-NLS-1$ WizardMessages.getString("NewTestClassWizPage.methodStub.setUp"), //$NON-NLS-1$ WizardMessages.getString("NewTestClassWizPage.methodStub.tearDown"), //$NON-NLS-1$ WizardMessages.getString("NewTestClassWizPage.methodStub.constructor") //$NON-NLS-1$ }; fMethodStubsButtons= new MethodStubsSelectionButtonGroup(SWT.CHECK, buttonNames, 1); fMethodStubsButtons.setLabelText(WizardMessages.getString("NewTestClassWizPage.method.Stub.label")); //$NON-NLS-1$ fClassToTestStatus= new JUnitStatus(); fTestClassStatus= new JUnitStatus(); fDefaultClassToTest= ""; //$NON-NLS-1$ } // -------- Initialization --------- /** * Should be called from the wizard with the initial selection and the 2nd page of the wizard.. */ public void init(IStructuredSelection selection, NewTestCaseCreationWizardPage2 page2) { fPage2= page2; IJavaElement element= getInitialJavaElement(selection); initContainerPage(element); initTypePage(element); doStatusUpdate(); // put default class to test if (element != null) { IType classToTest= null; // evaluate the enclosing type IType typeInCompUnit= (IType) element.getAncestor(IJavaElement.TYPE); if (typeInCompUnit != null) { if (typeInCompUnit.getCompilationUnit() != null) { classToTest= typeInCompUnit; } } else { ICompilationUnit cu= (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) classToTest= cu.findPrimaryType(); else { if (element instanceof IClassFile) { try { IClassFile cf= (IClassFile) element; if (cf.isStructureKnown()) classToTest= cf.getType(); } catch(JavaModelException e) { JUnitPlugin.log(e); } } } } if (classToTest != null) { try { if (!TestSearchEngine.isTestImplementor(classToTest)) { fDefaultClassToTest= classToTest.getFullyQualifiedName(); } } catch (JavaModelException e) { JUnitPlugin.log(e); } } } fMethodStubsButtons.setSelection(0, false); //main fMethodStubsButtons.setSelection(1, false); //add textrunner fMethodStubsButtons.setEnabled(1, false); //add text fMethodStubsButtons.setSelection(2, false); //setUp fMethodStubsButtons.setSelection(3, false); //tearDown fMethodStubsButtons.setSelection(4, false); //constructor } /** * @see NewContainerWizardPage#handleFieldChanged */ protected void handleFieldChanged(String fieldName) { super.handleFieldChanged(fieldName); if (fieldName.equals(CLASS_TO_TEST)) { fClassToTestStatus= classToTestClassChanged(); } else if (fieldName.equals(SUPER)) { validateSuperClass(); if (!fFirstTime) fTestClassStatus= typeNameChanged(); } else if (fieldName.equals(TYPENAME)) { fTestClassStatus= typeNameChanged(); } else if (fieldName.equals(PACKAGE) || fieldName.equals(CONTAINER) || fieldName.equals(SUPER)) { if (fieldName.equals(PACKAGE)) fPackageStatus= packageChanged(); if (!fFirstTime) { validateSuperClass(); fClassToTestStatus= classToTestClassChanged(); fTestClassStatus= typeNameChanged(); } if (fieldName.equals(CONTAINER)) { validateJUnitOnBuildPath(); } } doStatusUpdate(); } // ------ validation -------- private void doStatusUpdate() { // status of all used components IStatus[] status= new IStatus[] { fContainerStatus, fPackageStatus, fTestClassStatus, fClassToTestStatus, fModifierStatus, fSuperClassStatus }; // the mode severe status will be displayed and the ok button enabled/disabled. updateStatus(status); } /* * @see IDialogPage#createControl(Composite) */ public void createControl(Composite parent) { initializeDialogUnits(parent); Composite composite= new Composite(parent, SWT.NONE); int nColumns= 4; GridLayout layout= new GridLayout(); layout.numColumns= nColumns; composite.setLayout(layout); createContainerControls(composite, nColumns); createPackageControls(composite, nColumns); createSeparator(composite, nColumns); createClassToTestControls(composite, nColumns); createSeparator(composite, nColumns); createTypeNameControls(composite, nColumns); createSuperClassControls(composite, nColumns); createMethodStubSelectionControls(composite, nColumns); setSuperClass(JUnitPlugin.TEST_SUPERCLASS_NAME, true); setControl(composite); //set default and focus if (fDefaultClassToTest.length() > 0) { fClassToTestText.setText(fDefaultClassToTest); setTypeName(Signature.getSimpleName(fDefaultClassToTest)+TEST_SUFFIX, true); } restoreWidgetValues(); Dialog.applyDialogFont(composite); WorkbenchHelp.setHelp(composite, IJUnitHelpContextIds.NEW_TESTCASE_WIZARD_PAGE); } private void createMethodStubSelectionControls(Composite composite, int nColumns) { LayoutUtil.setHorizontalSpan(fMethodStubsButtons.getLabelControl(composite), nColumns); LayoutUtil.createEmptySpace(composite,1); LayoutUtil.setHorizontalSpan(fMethodStubsButtons.getSelectionButtonsGroup(composite), nColumns - 1); } private void createClassToTestControls(Composite composite, int nColumns) { fClassToTestLabel= new Label(composite, SWT.LEFT | SWT.WRAP); fClassToTestLabel.setFont(composite.getFont()); fClassToTestLabel.setText(WizardMessages.getString("NewTestClassWizPage.class_to_test.label")); //$NON-NLS-1$ GridData gd= new GridData(); gd.horizontalSpan= 1; fClassToTestLabel.setLayoutData(gd); fClassToTestText= new Text(composite, SWT.SINGLE | SWT.BORDER); fClassToTestText.setEnabled(true); fClassToTestText.setFont(composite.getFont()); fClassToTestText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { handleFieldChanged(CLASS_TO_TEST); } }); gd= new GridData(); gd.horizontalAlignment= GridData.FILL; gd.grabExcessHorizontalSpace= true; gd.horizontalSpan= nColumns - 2; fClassToTestText.setLayoutData(gd); fClassToTestButton= new Button(composite, SWT.PUSH); fClassToTestButton.setText(WizardMessages.getString("NewTestClassWizPage.class_to_test.browse")); //$NON-NLS-1$ fClassToTestButton.setEnabled(true); fClassToTestButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { classToTestButtonPressed(); } public void widgetSelected(SelectionEvent e) { classToTestButtonPressed(); } }); gd= new GridData(); gd.horizontalAlignment= GridData.FILL; gd.grabExcessHorizontalSpace= false; gd.horizontalSpan= 1; gd.heightHint = SWTUtil.getButtonHeightHint(fClassToTestButton); gd.widthHint = SWTUtil.getButtonWidthHint(fClassToTestButton); fClassToTestButton.setLayoutData(gd); } private void classToTestButtonPressed() { IType type= chooseClassToTestType(); if (type != null) { fClassToTestText.setText(JavaModelUtil.getFullyQualifiedName(type)); handleFieldChanged(CLASS_TO_TEST); } } private IType chooseClassToTestType() { IPackageFragmentRoot root= getPackageFragmentRoot(); if (root == null) return null; IJavaElement[] elements= new IJavaElement[] { root.getJavaProject() }; IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements); IType type= null; try { SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), getWizard().getContainer(), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, getClassToTestText()); dialog.setTitle(WizardMessages.getString("NewTestClassWizPage.class_to_test.dialog.title")); //$NON-NLS-1$ dialog.setMessage(WizardMessages.getString("NewTestClassWizPage.class_to_test.dialog.message")); //$NON-NLS-1$ dialog.open(); if (dialog.getReturnCode() != Window.OK) return type; else { Object[] resultArray= dialog.getResult(); if (resultArray != null && resultArray.length > 0) type= (IType) resultArray[0]; } } catch (JavaModelException e) { JUnitPlugin.log(e); } return type; } private IStatus classToTestClassChanged() { fClassToTestButton.setEnabled(getPackageFragmentRoot() != null); // sets the test class field? IStatus status= validateClassToTest(); return status; } /** * Returns the content of the class to test text field. */ public String getClassToTestText() { return fClassToTestText.getText(); } /** * Returns the class to be tested. */ public IType getClassToTest() { return fClassToTest; } /** * Sets the name of the class to test. */ public void setClassToTest(String name) { fClassToTestText.setText(name); } /** * @see NewTypeWizardPage#createTypeMembers */ protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException { fIndexOfFirstTestMethod= 0; if (fMethodStubsButtons.isSelected(0)) createMain(type); if (fMethodStubsButtons.isSelected(2)) { createSetUp(type, imports); } if (fMethodStubsButtons.isSelected(3)) { createTearDown(type, imports); } if (fMethodStubsButtons.isSelected(4)) createConstructor(type, imports); if (isNextPageValid()) { createTestMethodStubs(type); } } private void createConstructor(IType type, ImportsManager imports) throws JavaModelException { ITypeHierarchy typeHierarchy= null; IType[] superTypes= null; String constr= ""; //$NON-NLS-1$ IMethod methodTemplate= null; if (type.exists()) { typeHierarchy= type.newSupertypeHierarchy(null); superTypes= typeHierarchy.getAllSuperclasses(type); for (int i= 0; i < superTypes.length; i++) { if (superTypes[i].exists()) { IMethod constrMethod= superTypes[i].getMethod(superTypes[i].getElementName(), new String[] {"Ljava.lang.String;"}); //$NON-NLS-1$ if (constrMethod.exists() && constrMethod.isConstructor()) { methodTemplate= constrMethod; break; } } } } CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(); if (methodTemplate != null) { GenStubSettings genStubSettings= new GenStubSettings(settings); genStubSettings.fCallSuper= true; genStubSettings.fMethodOverwrites= true; constr= JUnitStubUtility.genStub(getTypeName(), methodTemplate, genStubSettings, imports); } else { constr += "public "+getTypeName()+"(String name) {" + //$NON-NLS-1$ //$NON-NLS-2$ getLineDelimiter() + "super(name);" + //$NON-NLS-1$ getLineDelimiter() + "}" + //$NON-NLS-1$ getLineDelimiter() + getLineDelimiter(); } type.createMethod(constr, null, true, null); fIndexOfFirstTestMethod++; } private void createMain(IType type) throws JavaModelException { type.createMethod(fMethodStubsButtons.getMainMethod(getTypeName()), null, false, null); fIndexOfFirstTestMethod++; } private void createSetUp(IType type, ImportsManager imports) throws JavaModelException { ITypeHierarchy typeHierarchy= null; IType[] superTypes= null; String setUp= ""; //$NON-NLS-1$ IMethod methodTemplate= null; if (type.exists()) { typeHierarchy= type.newSupertypeHierarchy(null); superTypes= typeHierarchy.getAllSuperclasses(type); for (int i= 0; i < superTypes.length; i++) { if (superTypes[i].exists()) { IMethod testMethod= superTypes[i].getMethod(SETUP, new String[] {}); if (testMethod.exists()) { methodTemplate= testMethod; break; } } } } CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(); if (methodTemplate != null) { GenStubSettings genStubSettings= new GenStubSettings(settings); genStubSettings.fCallSuper= true; genStubSettings.fMethodOverwrites= true; setUp= JUnitStubUtility.genStub(getTypeName(), methodTemplate, genStubSettings, imports); } else { if (settings.createComments) setUp= "/**" + //$NON-NLS-1$ getLineDelimiter() + " * Sets up the fixture, for example, open a network connection." + //$NON-NLS-1$ getLineDelimiter() + " * This method is called before a test is executed." + //$NON-NLS-1$ getLineDelimiter() + " * @throws Exception" + //$NON-NLS-1$ getLineDelimiter() + " */" + //$NON-NLS-1$ getLineDelimiter(); setUp+= "protected void "+SETUP+"() throws Exception {}" + //$NON-NLS-1$ //$NON-NLS-2$ getLineDelimiter() + getLineDelimiter(); } type.createMethod(setUp, null, false, null); fIndexOfFirstTestMethod++; } private void createTearDown(IType type, ImportsManager imports) throws JavaModelException { ITypeHierarchy typeHierarchy= null; IType[] superTypes= null; String tearDown= ""; //$NON-NLS-1$ IMethod methodTemplate= null; if (type.exists()) { if (typeHierarchy == null) { typeHierarchy= type.newSupertypeHierarchy(null); superTypes= typeHierarchy.getAllSuperclasses(type); } for (int i= 0; i < superTypes.length; i++) { if (superTypes[i].exists()) { IMethod testM= superTypes[i].getMethod(TEARDOWN, new String[] {}); if (testM.exists()) { methodTemplate= testM; break; } } } } CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(); if (methodTemplate != null) { GenStubSettings genStubSettings= new GenStubSettings(settings); genStubSettings.fCallSuper= true; genStubSettings.fMethodOverwrites= true; tearDown= JUnitStubUtility.genStub(getTypeName(), methodTemplate, genStubSettings, imports); type.createMethod(tearDown, null, false, null); fIndexOfFirstTestMethod++; } } private void createTestMethodStubs(IType type) throws JavaModelException { IMethod[] methods= fPage2.getCheckedMethods(); if (methods.length == 0) return; /* find overloaded methods */ IMethod[] allMethodsArray= fPage2.getAllMethods(); List allMethods= new ArrayList(); allMethods.addAll(Arrays.asList(allMethodsArray)); List overloadedMethods= getOveloadedMethods(allMethods); /* used when for example both sum and Sum methods are present. Then * sum -> testSum * Sum -> testSum1 */ List newMethodsNames= new ArrayList(); for (int i = 0; i < methods.length; i++) { IMethod testedMethod= methods[i]; String elementName= testedMethod.getElementName(); StringBuffer methodName= new StringBuffer(NewTestCaseCreationWizardPage2.PREFIX+Character.toUpperCase(elementName.charAt(0))+elementName.substring(1)); StringBuffer newMethod= new StringBuffer(); if (overloadedMethods.contains(testedMethod)) { appendMethodComment(newMethod, testedMethod); String[] params= testedMethod.getParameterTypes(); appendParameterNamesToMethodName(methodName, params); } /* Should I for examples have methods * void foo(java.lang.StringBuffer sb) {} * void foo(mypackage1.StringBuffer sb) {} * void foo(mypackage2.StringBuffer sb) {} * I will get in the test class: * testFooStringBuffer() * testFooStringBuffer1() * testFooStringBuffer2() */ if (newMethodsNames.contains(methodName.toString())) { int suffix= 1; while (newMethodsNames.contains(methodName.toString() + Integer.toString(suffix))) suffix++; methodName.append(Integer.toString(suffix)); } newMethodsNames.add(methodName.toString()); if (fPage2.getCreateFinalMethodStubsButtonSelection()) newMethod.append("final "); //$NON-NLS-1$ newMethod.append("public void ");//$NON-NLS-1$ newMethod.append(methodName.toString()); newMethod.append("()");//$NON-NLS-1$ appendTestMethodBody(newMethod, testedMethod); type.createMethod(newMethod.toString(), null, false, null); } } private String getLineDelimiter(){ IType classToTest= getClassToTest(); if (classToTest != null && classToTest.exists()) return JUnitStubUtility.getLineDelimiterUsed(classToTest); else return JUnitStubUtility.getLineDelimiterUsed(getPackageFragment()); } private void appendTestMethodBody(StringBuffer newMethod, IMethod testedMethod) { newMethod.append("{"); //$NON-NLS-1$ if (createTasks()){ newMethod.append(getLineDelimiter()); newMethod.append("//"); //$NON-NLS-1$ newMethod.append(JUnitStubUtility.getTodoTaskTag(getPackageFragment().getJavaProject())); newMethod.append(WizardMessages.getFormattedString("NewTestClassWizPage.marker.message", testedMethod.getElementName())); //$NON-NLS-1$ newMethod.append(getLineDelimiter()); } newMethod.append("}").append(getLineDelimiter()).append(getLineDelimiter()); //$NON-NLS-1$ } public void appendParameterNamesToMethodName(StringBuffer methodName, String[] params) { for (int i= 0; i < params.length; i++) { String param= params[i]; methodName.append(Signature.getSimpleName(Signature.toString(Signature.getElementType(param)))); for (int j= 0, arrayCount= Signature.getArrayCount(param); j < arrayCount; j++) { methodName.append("Array"); //$NON-NLS-1$ } } } private void appendMethodComment(StringBuffer newMethod, IMethod method) throws JavaModelException { String returnType= Signature.toString(method.getReturnType()); String body= WizardMessages.getFormattedString("NewTestClassWizPage.comment.class_to_test", new String[]{returnType, method.getElementName()}); //$NON-NLS-1$ newMethod.append("/*");//$NON-NLS-1$ newMethod.append(getLineDelimiter()); newMethod.append(" * ");//$NON-NLS-1$ newMethod.append(body); newMethod.append("(");//$NON-NLS-1$ String[] paramTypes= method.getParameterTypes(); if (paramTypes.length > 0) { if (paramTypes.length > 1) { for (int j= 0; j < paramTypes.length-1; j++) { newMethod.append(Signature.toString(paramTypes[j])+", "); //$NON-NLS-1$ } } newMethod.append(Signature.toString(paramTypes[paramTypes.length-1])); } newMethod.append(")");//$NON-NLS-1$ newMethod.append(getLineDelimiter()); newMethod.append(" */");//$NON-NLS-1$ newMethod.append(getLineDelimiter()); } private List getOveloadedMethods(List allMethods) { List overloadedMethods= new ArrayList(); for (int i= 0; i < allMethods.size(); i++) { IMethod current= (IMethod) allMethods.get(i); String currentName= current.getElementName(); boolean currentAdded= false; for (ListIterator iter= allMethods.listIterator(i+1); iter.hasNext(); ) { IMethod iterMethod= (IMethod) iter.next(); if (iterMethod.getElementName().equals(currentName)) { //method is overloaded if (!currentAdded) { overloadedMethods.add(current); currentAdded= true; } overloadedMethods.add(iterMethod); iter.remove(); } } } return overloadedMethods; } /** * @see DialogPage#setVisible(boolean) */ public void setVisible(boolean visible) { super.setVisible(visible); if (visible && fFirstTime) { if (getClassToTestText().equals("")) //$NON-NLS-1$ setPageComplete(false); else handleFieldChanged(CLASS_TO_TEST); //creates error message when wizard is opened if TestCase already exists fFirstTime= false; } if (visible) setFocus(); } private void validateJUnitOnBuildPath() { IPackageFragmentRoot root= getPackageFragmentRoot(); if (root == null) return; IJavaProject jp= root.getJavaProject(); try { if (jp.findType(JUnitPlugin.TEST_SUPERCLASS_NAME) != null) return; } catch (JavaModelException e) { } if (MessageDialog.openQuestion(getShell(), WizardMessages.getString("NewTestClassWizPage.not_on_buildpath.title"), WizardMessages.getString("NewTestClassWizPage.not_on_buildpath.message"))) { //$NON-NLS-1$ //$NON-NLS-2$ try { addJUnitToBuildPath(jp); return; } catch(JavaModelException e) { ErrorDialog.openError(getShell(), WizardMessages.getString("NewTestClassWizPage.cannot_add.title"), WizardMessages.getString("NewTestClassWizPage.cannot_add.message"), e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$ } } JUnitStatus status= new JUnitStatus(); status.setWarning(WizardMessages.getString("NewTestClassWizPage.error.junitNotOnbuildpath")); //$NON-NLS-1$ fContainerStatus= status; } public static void addJUnitToBuildPath(IJavaProject project) throws JavaModelException { IPath junitHome= new Path(JUnitPlugin.JUNIT_HOME); IClasspathEntry entry= JavaCore.newVariableEntry( junitHome.append("junit.jar"), //$NON-NLS-1$ junitHome.append("junitsrc.zip"), //$NON-NLS-1$ null ); addToClasspath(project, entry); } private static void addToClasspath(IJavaProject project, IClasspathEntry entry) throws JavaModelException { IClasspathEntry[] oldEntries= project.getRawClasspath(); for (int i= 0; i < oldEntries.length; i++) { if (oldEntries[i].equals(entry)) { return; } } int nEntries= oldEntries.length; IClasspathEntry[] newEntries= new IClasspathEntry[nEntries + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, nEntries); newEntries[nEntries]= entry; project.setRawClasspath(newEntries, null); } /** * Returns the index of the first method that is a test method, i.e. excluding main, setUp() and tearDown(). * If none of the aforementioned method stubs is created, then 0 is returned. As such method stubs are created, * this counter is incremented. */ public int getIndexOfFirstMethod() { return fIndexOfFirstTestMethod; } private boolean createTasks() { return fPage2.getCreateTasksButtonSelection(); } private void validateSuperClass() { fMethodStubsButtons.setEnabled(2, true);//enable setUp() checkbox fMethodStubsButtons.setEnabled(3, true);//enable tearDown() checkbox String superClassName= getSuperClass(); if (superClassName == null || superClassName.trim().equals("")) { //$NON-NLS-1$ fSuperClassStatus= new JUnitStatus(); ((JUnitStatus)fSuperClassStatus).setError(WizardMessages.getString("NewTestClassWizPage.error.superclass.empty")); //$NON-NLS-1$ return; } if (getPackageFragmentRoot() != null) { //$NON-NLS-1$ try { IType type= resolveClassNameToType(getPackageFragmentRoot().getJavaProject(), getPackageFragment(), superClassName); JUnitStatus status = new JUnitStatus(); if (type == null) { /* TODO: is this a warning or error? */ status.setWarning(WizardMessages.getString("NewTestClassWizPage.error.superclass.not_exist")); //$NON-NLS-1$ fSuperClassStatus= status; } else { if (type.isInterface()) { status.setError(WizardMessages.getString("NewTestClassWizPage.error.superclass.is_interface")); //$NON-NLS-1$ fSuperClassStatus= status; } if (!TestSearchEngine.isTestImplementor(type)) { status.setError(WizardMessages.getFormattedString("NewTestClassWizPage.error.superclass.not_implementing_test_interface", JUnitPlugin.TEST_INTERFACE_NAME)); //$NON-NLS-1$ fSuperClassStatus= status; } else { IMethod setupMethod= type.getMethod(SETUP, new String[] {}); IMethod teardownMethod= type.getMethod(TEARDOWN, new String[] {}); if (setupMethod.exists()) fMethodStubsButtons.setEnabled(2, !Flags.isFinal(setupMethod.getFlags())); if (teardownMethod.exists()) fMethodStubsButtons.setEnabled(3, !Flags.isFinal(teardownMethod.getFlags())); } } } catch (JavaModelException e) { JUnitPlugin.log(e); } } } /** * @see IWizardPage#canFlipToNextPage */ public boolean canFlipToNextPage() { return isPageComplete() && getNextPage() != null && isNextPageValid(); } protected boolean isNextPageValid() { return !getClassToTestText().equals(""); //$NON-NLS-1$ } private JUnitStatus validateClassToTest() { IPackageFragmentRoot root= getPackageFragmentRoot(); IPackageFragment pack= getPackageFragment(); String classToTestName= getClassToTestText(); JUnitStatus status= new JUnitStatus(); fClassToTest= null; if (classToTestName.length() == 0) { return status; } IStatus val= JavaConventions.validateJavaTypeName(classToTestName); // if (!val.isOK()) { if (val.getSeverity() == IStatus.ERROR) { status.setError(WizardMessages.getString("NewTestClassWizPage.error.class_to_test.not_valid")); //$NON-NLS-1$ return status; } if (root != null) { try { IType type= resolveClassNameToType(root.getJavaProject(), pack, classToTestName); if (type == null) { //status.setWarning("Warning: "+typeLabel+" does not exist in current project."); status.setError(WizardMessages.getString("NewTestClassWizPage.error.class_to_test.not_exist")); //$NON-NLS-1$ return status; } else { if (type.isInterface()) { status.setWarning(WizardMessages.getFormattedString("NewTestClassWizPage.warning.class_to_test.is_interface",classToTestName)); //$NON-NLS-1$ } if (pack != null && !JavaModelUtil.isVisible(type, pack)) { status.setWarning(WizardMessages.getFormattedString("NewTestClassWizPage.warning.class_to_test.not_visible", new String[] {(type.isInterface())?WizardMessages.getString("Interface"):WizardMessages.getString("Class") , classToTestName})); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } fClassToTest= type; } catch (JavaModelException e) { status.setError(WizardMessages.getString("NewTestClassWizPage.error.class_to_test.not_valid")); //$NON-NLS-1$ } } else { status.setError(""); //$NON-NLS-1$ } return status; } private IType resolveClassNameToType(IJavaProject jproject, IPackageFragment pack, String classToTestName) throws JavaModelException { IType type= null; if (type == null && pack != null) { String packName= pack.getElementName(); // search in own package if (!pack.isDefaultPackage()) { type= jproject.findType(packName, classToTestName); } // search in java.lang if (type == null && !"java.lang".equals(packName)) { //$NON-NLS-1$ type= jproject.findType("java.lang", classToTestName); //$NON-NLS-1$ } } // search fully qualified if (type == null) { type= jproject.findType(classToTestName); } return type; } /** * Use the dialog store to restore widget values to the values that they held * last time this wizard was used to completion */ private void restoreWidgetValues() { IDialogSettings settings= getDialogSettings(); if (settings != null) { boolean generateMain= settings.getBoolean(STORE_GENERATE_MAIN); fMethodStubsButtons.setSelection(0, generateMain); fMethodStubsButtons.setEnabled(1, generateMain); fMethodStubsButtons.setSelection(1,settings.getBoolean(STORE_USE_TESTRUNNER)); try { fMethodStubsButtons.setComboSelection(settings.getInt(STORE_TESTRUNNER_TYPE)); } catch(NumberFormatException e) {} } } /** * Since Finish was pressed, write widget values to the dialog store so that they * will persist into the next invocation of this wizard page */ void saveWidgetValues() { IDialogSettings settings= getDialogSettings(); if (settings != null) { settings.put(STORE_GENERATE_MAIN, fMethodStubsButtons.isSelected(0)); settings.put(STORE_USE_TESTRUNNER, fMethodStubsButtons.isSelected(1)); settings.put(STORE_TESTRUNNER_TYPE, fMethodStubsButtons.getComboSelection()); } } }
46,941
Bug 46941 Change method signature: Edit dialog: Window dialog to long [refactoring]
20031119 In the 'Refactoring > Change Method Signature' dialog, press edit. The window dialog says 'Modify Declaration of Parameter myParameter' This is too long. Window titles should not be a sentence anyway. Suggest to change it to 'Method Parameter' and to add a description 'Declaration of parameter 'myParameter':'
resolved fixed
4d51b31
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T09:53:16Z
2003-11-19T11:06:40Z
org.eclipse.jdt.ui/ui
46,941
Bug 46941 Change method signature: Edit dialog: Window dialog to long [refactoring]
20031119 In the 'Refactoring > Change Method Signature' dialog, press edit. The window dialog says 'Modify Declaration of Parameter myParameter' This is too long. Window titles should not be a sentence anyway. Suggest to change it to 'Method Parameter' and to add a description 'Declaration of parameter 'myParameter':'
resolved fixed
4d51b31
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T09:53:16Z
2003-11-19T11:06:40Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/ParameterEditDialog.java
10,947
Bug 10947 [Cell Editors] Clicking in white space on property sheet doesn't commit change
Make a change in a text cell editor in the property sheet. click on the table somewhere below the last table item. The change is not committed. 02-14 build
resolved fixed
782f51c
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T11:50:58Z
2002-03-07T14:06:40Z
org.eclipse.jdt.ui/ui
10,947
Bug 10947 [Cell Editors] Clicking in white space on property sheet doesn't commit change
Make a change in a text cell editor in the property sheet. click on the table somewhere below the last table item. The change is not committed. 02-14 build
resolved fixed
782f51c
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T11:50:58Z
2002-03-07T14:06:40Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/ChangeParametersControl.java
10,947
Bug 10947 [Cell Editors] Clicking in white space on property sheet doesn't commit change
Make a change in a text cell editor in the property sheet. click on the table somewhere below the last table item. The change is not committed. 02-14 build
resolved fixed
782f51c
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T11:50:58Z
2002-03-07T14:06:40Z
org.eclipse.jdt.ui/ui
10,947
Bug 10947 [Cell Editors] Clicking in white space on property sheet doesn't commit change
Make a change in a text cell editor in the property sheet. click on the table somewhere below the last table item. The change is not committed. 02-14 build
resolved fixed
782f51c
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T11:50:58Z
2002-03-07T14:06:40Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/ExternalizeWizardPage.java
44,891
Bug 44891 Search view hanging while resorting search matches
Build 3.0 M4 Search all references to type String in self-hosted workspace. Finds almost 80.000 of them. Now sort them by parent name... it will take minutes to recover, while it works UI is entirely non responsive.
resolved fixed
d79e542
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:20:05Z
2003-10-15T12:13:20Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/ElementNameSorter.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.search; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.search.ui.ISearchResultView; import org.eclipse.search.ui.ISearchResultViewEntry; import org.eclipse.search.ui.SearchUI; /** * Sorts the search result viewer by the Java Element name. */ public class ElementNameSorter extends ViewerSorter { private ILabelProvider fLabelProvider; /* * Overrides method from ViewerSorter */ public int compare(Viewer viewer, Object e1, Object e2) { String name1= null; String name2= null; if (e1 instanceof ISearchResultViewEntry) name1= fLabelProvider.getText(e1); if (e2 instanceof ISearchResultViewEntry) name2= fLabelProvider.getText(e2); if (name1 == null) name1= ""; //$NON-NLS-1$ if (name2 == null) name2= ""; //$NON-NLS-1$ return getCollator().compare(name1, name2); } /* * Overrides method from ViewerSorter */ public boolean isSorterProperty(Object element, String property) { return true; } /* * Overrides method from ViewerSorter */ public void sort(Viewer viewer, Object[] elements) { // Set label provider to show "element - path" ISearchResultView view= SearchUI.getSearchResultView(); if (view == null) return; fLabelProvider= view.getLabelProvider(); if (fLabelProvider instanceof JavaSearchResultLabelProvider) { ((JavaSearchResultLabelProvider)fLabelProvider).setOrder(JavaSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER); super.sort(viewer, elements); } } }
44,891
Bug 44891 Search view hanging while resorting search matches
Build 3.0 M4 Search all references to type String in self-hosted workspace. Finds almost 80.000 of them. Now sort them by parent name... it will take minutes to recover, while it works UI is entirely non responsive.
resolved fixed
d79e542
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:20:05Z
2003-10-15T12:13:20Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/JavaSearchSorter.java
44,891
Bug 44891 Search view hanging while resorting search matches
Build 3.0 M4 Search all references to type String in self-hosted workspace. Finds almost 80.000 of them. Now sort them by parent name... it will take minutes to recover, while it works UI is entirely non responsive.
resolved fixed
d79e542
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:20:05Z
2003-10-15T12:13:20Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/ParentNameSorter.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.search; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.search.ui.ISearchResultView; import org.eclipse.search.ui.ISearchResultViewEntry; import org.eclipse.search.ui.SearchUI; /** * Sorts the search result viewer by the Java Element parent name. */ public class ParentNameSorter extends ViewerSorter { private ILabelProvider fLabelProvider; /* * Overrides method from ViewerSorter */ public int compare(Viewer viewer, Object e1, Object e2) { String name1= null; String name2= null; if (e1 instanceof ISearchResultViewEntry) name1= fLabelProvider.getText(e1); if (e2 instanceof ISearchResultViewEntry) name2= fLabelProvider.getText(e2); if (name1 == null) name1= ""; //$NON-NLS-1$ if (name2 == null) name2= ""; //$NON-NLS-1$ return getCollator().compare(name1, name2); } /* * Overrides method from ViewerSorter */ public boolean isSorterProperty(Object element, String property) { return true; } /* * Overrides method from ViewerSorter */ public void sort(Viewer viewer, Object[] elements) { // Set label provider to show "path - resource" ISearchResultView view= SearchUI.getSearchResultView(); if (view == null) return; fLabelProvider= view.getLabelProvider(); if (fLabelProvider instanceof JavaSearchResultLabelProvider) ((JavaSearchResultLabelProvider)fLabelProvider).setOrder(JavaSearchResultLabelProvider.SHOW_CONTAINER_ELEMENT); super.sort(viewer, elements); } }
44,891
Bug 44891 Search view hanging while resorting search matches
Build 3.0 M4 Search all references to type String in self-hosted workspace. Finds almost 80.000 of them. Now sort them by parent name... it will take minutes to recover, while it works UI is entirely non responsive.
resolved fixed
d79e542
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:20:05Z
2003-10-15T12:13:20Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/PathNameSorter.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.search; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.search.ui.ISearchResultView; import org.eclipse.search.ui.ISearchResultViewEntry; import org.eclipse.search.ui.SearchUI; /** * Sorts the search result viewer by the path name. */ public class PathNameSorter extends ViewerSorter { private ILabelProvider fLabelProvider; /* * Overrides method from ViewerSorter */ public int compare(Viewer viewer, Object e1, Object e2) { String name1= null; String name2= null; ISearchResultViewEntry entry1= null; ISearchResultViewEntry entry2= null; if (e1 instanceof ISearchResultViewEntry) { entry1= (ISearchResultViewEntry)e1; name1= fLabelProvider.getText(e1); } if (e2 instanceof ISearchResultViewEntry) { entry2= (ISearchResultViewEntry)e2; name2= fLabelProvider.getText(e2); } if (name1 == null) name1= ""; //$NON-NLS-1$ if (name2 == null) name2= ""; //$NON-NLS-1$ IResource resource= null; if (entry1 != null) resource= entry1.getResource(); if (resource != null && entry2 != null && resource == entry2.getResource()) { if (resource instanceof IProject || resource.getFileExtension().equalsIgnoreCase("jar") || resource.getFileExtension().equalsIgnoreCase("zip")) //$NON-NLS-2$ //$NON-NLS-1$ // binary archives return getCollator().compare(name1, name2); // Sort by marker start position if resource is equal. int startPos1= -1; int startPos2= -1; IMarker marker1= entry1.getSelectedMarker(); IMarker marker2= entry2.getSelectedMarker(); if (marker1 != null) startPos1= marker1.getAttribute(IMarker.CHAR_START, -1); if (marker2 != null) startPos2= marker2.getAttribute(IMarker.CHAR_START, -1); return startPos1 - startPos2; } return getCollator().compare(name1, name2); } /* * Overrides method from ViewerSorter */ public boolean isSorterProperty(Object element, String property) { return true; } /* * Overrides method from ViewerSorter */ public void sort(Viewer viewer, Object[] elements) { // Set label provider to show "path - resource" ISearchResultView view= SearchUI.getSearchResultView(); if (view == null) return; fLabelProvider= view.getLabelProvider(); if (fLabelProvider instanceof JavaSearchResultLabelProvider) ((JavaSearchResultLabelProvider)fLabelProvider).setOrder(JavaSearchResultLabelProvider.SHOW_PATH); super.sort(viewer, elements); } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui.tests.refactoring/test
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
cases/org/eclipse/jdt/ui/tests/refactoring/MoveMembersTests.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui.tests.refactoring/test
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
cases/org/eclipse/jdt/ui/tests/refactoring/PullUpTests.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/Checks.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ConvertAnonymousToNestedRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractConstantRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractTempRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineMethodRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceParameterRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RenameExtensionManager.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTempRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/sef/SelfEncapsulateFieldRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/core
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ChangeTypeRefactoring.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/ChangeParametersControl.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/InlineConstantAction.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/InlineMethodAction.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/MoveInstanceMethodAction.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/MoveStaticMembersAction.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/RefactoringActions.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/RenameJavaElementAction.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/RenameTempAction.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/ReorgMoveAction.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SelectionConverter.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.actions; import java.util.Iterator; import org.eclipse.swt.widgets.Shell; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICodeAssist; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.ui.IWorkingCopyManager; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; public class SelectionConverter { private static final IJavaElement[] EMPTY_RESULT= new IJavaElement[0]; private SelectionConverter() { // no instance } /** * Converts the selection provided by the given part into a structured selection. * The following conversion rules are used: * <ul> * <li><code>part instanceof JavaEditor</code>: returns a structured selection * using code resolve to convert the editor's text selection.</li> * <li><code>part instanceof IWorkbenchPart</code>: returns the part's selection * if it is a structured selection.</li> * <li><code>default</code>: returns an empty structured selection.</li> * </ul> */ public static IStructuredSelection getStructuredSelection(IWorkbenchPart part) throws JavaModelException { if (part instanceof JavaEditor) return new StructuredSelection(codeResolve((JavaEditor)part)); ISelectionProvider provider= part.getSite().getSelectionProvider(); if (provider != null) { ISelection selection= provider.getSelection(); if (selection instanceof IStructuredSelection) return (IStructuredSelection)selection; } return StructuredSelection.EMPTY; } /** * Converts the given structured selection into an array of Java elements. * An empty array is returned if one of the elements stored in the structured * selection is not of tupe <code>IJavaElement</code> */ public static IJavaElement[] getElements(IStructuredSelection selection) { if (!selection.isEmpty()) { IJavaElement[] result= new IJavaElement[selection.size()]; int i= 0; for (Iterator iter= selection.iterator(); iter.hasNext(); i++) { Object element= iter.next(); if (!(element instanceof IJavaElement)) return EMPTY_RESULT; result[i]= (IJavaElement)element; } return result; } return EMPTY_RESULT; } public static boolean canOperateOn(JavaEditor editor) { if (editor == null) return false; return getInput(editor) != null; } /** * Converts the text selection provided by the given editor into an array of * Java elements. If the selection doesn't cover a Java element and the selection's * length is greater than 0 the methods returns the editor's input element. */ public static IJavaElement[] codeResolveOrInput(JavaEditor editor) throws JavaModelException { IJavaElement input= getInput(editor); ITextSelection selection= (ITextSelection)editor.getSelectionProvider().getSelection(); IJavaElement[] result= codeResolve(input, selection); if (result.length == 0) { result= new IJavaElement[] {input}; } return result; } public static IJavaElement[] codeResolveOrInputHandled(JavaEditor editor, Shell shell, String title) { try { return codeResolveOrInput(editor); } catch(JavaModelException e) { ExceptionHandler.handle(e, shell, title, ActionMessages.getString("SelectionConverter.codeResolve_failed")); //$NON-NLS-1$ } return null; } /** * Converts the text selection provided by the given editor a Java element by * asking the user if code reolve returned more than one result. If the selection * doesn't cover a Java element and the selection's length is greater than 0 the * methods returns the editor's input element. */ public static IJavaElement codeResolveOrInput(JavaEditor editor, Shell shell, String title, String message) throws JavaModelException { IJavaElement[] elements= codeResolveOrInput(editor); if (elements == null || elements.length == 0) return null; IJavaElement candidate= elements[0]; if (elements.length > 1) { candidate= OpenActionUtil.selectJavaElement(elements, shell, title, message); } return candidate; } public static IJavaElement codeResolveOrInputHandled(JavaEditor editor, Shell shell, String title, String message) { try { return codeResolveOrInput(editor, shell, title, message); } catch (JavaModelException e) { ExceptionHandler.handle(e, shell, title, ActionMessages.getString("SelectionConverter.codeResolveOrInput_failed")); //$NON-NLS-1$ } return null; } public static IJavaElement[] codeResolve(JavaEditor editor) throws JavaModelException { return codeResolve(getInput(editor), (ITextSelection)editor.getSelectionProvider().getSelection()); } /** * Converts the text selection provided by the given editor a Java element by * asking the user if code reolve returned more than one result. If the selection * doesn't cover a Java element <code>null</code> is returned. */ public static IJavaElement codeResolve(JavaEditor editor, Shell shell, String title, String message) throws JavaModelException { IJavaElement[] elements= codeResolve(editor); if (elements == null || elements.length == 0) return null; IJavaElement candidate= elements[0]; if (elements.length > 1) { candidate= OpenActionUtil.selectJavaElement(elements, shell, title, message); } return candidate; } public static IJavaElement[] codeResolveHandled(JavaEditor editor, Shell shell, String title) { try { return codeResolve(editor); } catch (JavaModelException e) { ExceptionHandler.handle(e, shell, title, ActionMessages.getString("SelectionConverter.codeResolve_failed")); //$NON-NLS-1$ } return null; } public static IJavaElement getElementAtOffset(JavaEditor editor) throws JavaModelException { return getElementAtOffset(getInput(editor), (ITextSelection)editor.getSelectionProvider().getSelection()); } public static IType getTypeAtOffset(JavaEditor editor) throws JavaModelException { IJavaElement element= SelectionConverter.getElementAtOffset(editor); IType type= (IType)element.getAncestor(IJavaElement.TYPE); if (type == null) { ICompilationUnit unit= SelectionConverter.getInputAsCompilationUnit(editor); if (unit != null) type= unit.findPrimaryType(); } return type; } public static IJavaElement getInput(JavaEditor editor) { if (editor == null) return null; IEditorInput input= editor.getEditorInput(); if (input instanceof IClassFileEditorInput) return ((IClassFileEditorInput)input).getClassFile(); IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager(); return manager.getWorkingCopy(input); } public static ICompilationUnit getInputAsCompilationUnit(JavaEditor editor) { Object editorInput= SelectionConverter.getInput(editor); if (editorInput instanceof ICompilationUnit) return (ICompilationUnit)editorInput; else return null; } private static IJavaElement[] codeResolve(IJavaElement input, ITextSelection selection) throws JavaModelException { if (input instanceof ICodeAssist) { if (input instanceof ICompilationUnit) { ICompilationUnit cunit= (ICompilationUnit)input; if (cunit.isWorkingCopy()) { synchronized (cunit) { cunit.reconcile(); } } } IJavaElement[] elements= ((ICodeAssist)input).codeSelect(selection.getOffset(), selection.getLength()); if (elements != null && elements.length > 0) return elements; } return EMPTY_RESULT; } public static IJavaElement getElementAtOffset(IJavaElement input, ITextSelection selection) throws JavaModelException { if (input instanceof ICompilationUnit) { ICompilationUnit cunit= (ICompilationUnit)input; if (cunit.isWorkingCopy()) { synchronized (cunit) { cunit.reconcile(); } } IJavaElement ref= cunit.getElementAt(selection.getOffset()); if (ref == null) return input; else return ref; } else if (input instanceof IClassFile) { IJavaElement ref= ((IClassFile)input).getElementAt(selection.getOffset()); if (ref == null) return input; else return ref; } return null; } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaTextSelection.java
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ChangeTypeAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IMember; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.ISourceRange; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.dom.PrimitiveType; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.internal.corext.refactoring.base.Refactoring; import org.eclipse.jdt.internal.corext.refactoring.structure.ChangeTypeRefactoring; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.refactoring.ChangeTypeWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; /** * @author tip */ public class ChangeTypeAction extends SelectionDispatchAction { private CompilationUnitEditor fEditor; private String fDialogMessageTitle; /** * Note: This constructor is for internal use only. Clients should not call * this constructor. */ public ChangeTypeAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); } /** * Creates a new <code>ChangeTypeAction</code>. The action requires that * the selection provided by the site's selection provider is of type * <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site * the site providing context information for this action */ public ChangeTypeAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("ChangeTypeAction.label")); //$NON-NLS-1$ setToolTipText(RefactoringMessages.getString("ChangeTypeAction.tooltipText")); //$NON-NLS-1$ setDescription(RefactoringMessages.getString("ChangeTypeAction.description")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.CHANGE_TYPE_ACTION); } /* * (non-Javadoc) Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; try { ChangeTypeRefactoring refactoring= createRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), fDialogMessageTitle, false); } catch (CoreException e) { ExceptionHandler.handle(e, fDialogMessageTitle, RefactoringMessages.getString("ChangeTypeAction.exception")); //$NON-NLS-1$ } } /* * (non-Javadoc) Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { setEnabled(checkEnabled(selection)); } public void selectionChanged(IStructuredSelection selection) { try { setEnabled(getMember(selection) != null); } catch (JavaModelException e) { setEnabled(false); } } public void run(IStructuredSelection selection) { try { IMember member= getMember(selection); if (member == null) return; ISourceRange range= member.getNameRange(); ICompilationUnit icu= member.getCompilationUnit(); ITextSelection textSelection= new TextSelection(range.getOffset(), range.getLength()); ChangeTypeRefactoring refactoring= createRefactoring(icu, textSelection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), fDialogMessageTitle, false); } catch (CoreException e) { ExceptionHandler.handle(e, fDialogMessageTitle, RefactoringMessages.getString("ChangeTypeAction.exception")); //$NON-NLS-1$ } } private IMember getMember(IStructuredSelection selection) throws JavaModelException { if (selection.size() != 1) return null; Object element= selection.getFirstElement(); if (!(element instanceof IMember)) return null; if (element instanceof IMethod) { IMethod method= (IMethod)element; String returnType= method.getReturnType(); if (PrimitiveType.toCode(Signature.toString(returnType)) != null) return null; return method; } else if (element instanceof IField) { return (IField)element; } return null; } private static ChangeTypeRefactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) throws CoreException { return ChangeTypeRefactoring.create(cunit, selection.getOffset(), selection.getLength()); } private RefactoringWizard createWizard(ChangeTypeRefactoring refactoring) { // String pageTitle= RefactoringMessages.getString("ChangeTypeWizard.title"); //$NON-NLS-1$ return new ChangeTypeWizard(refactoring); } private boolean checkEnabled(ITextSelection selection) { return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; } private RefactoringWizard createWizard(Refactoring refactoring) { return new ChangeTypeWizard((ChangeTypeRefactoring)refactoring); } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ConvertAnonymousToNestedAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.ISourceRange; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.refactoring.ConvertAnonymousToNestedWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.refactoring.code.ConvertAnonymousToNestedRefactoring; /** * Action to convert an anonymous inner class to a nested class. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.1 */ public class ConvertAnonymousToNestedAction extends SelectionDispatchAction { private static final String DIALOG_MESSAGE_TITLE= RefactoringMessages.getString("ConvertAnonymousToNestedAction.dialog_title"); //$NON-NLS-1$ private final CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ConvertAnonymousToNestedAction(CompilationUnitEditor editor) { super(editor.getEditorSite()); setText(RefactoringMessages.getString("ConvertAnonymousToNestedAction.Convert_Anonymous")); //$NON-NLS-1$ fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_ACTION); } private static ConvertAnonymousToNestedRefactoring createRefactoring(ICompilationUnit cunit, int offset, int length) { return ConvertAnonymousToNestedRefactoring.create(cunit, offset, length); } private static RefactoringWizard createWizard(ConvertAnonymousToNestedRefactoring refactoring) { return new ConvertAnonymousToNestedWizard(refactoring); } public ConvertAnonymousToNestedAction(IWorkbenchSite site) { super(site); fEditor= null; setText(RefactoringMessages.getString("ConvertAnonymousToNestedAction.Convert_Anonymous")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_ACTION); } //---- Structured selection ----------------------------------------------------- /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(IStructuredSelection selection) { setEnabled(getElement(selection) != null); } private IType getElement(IStructuredSelection selection) { if (selection.size() != 1) return null; Object element= selection.getFirstElement(); if (!(element instanceof IType)) return null; IType type= (IType)element; try { if (type.isAnonymous()) return type; } catch (JavaModelException e) { // fall through } return null; } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(IStructuredSelection selection) { IType type= getElement(selection); if (type == null) return; ISourceRange range; try { range= type.getNameRange(); run(type.getCompilationUnit(), range.getOffset(), range.getLength()); } catch (JavaModelException e) { ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("NewTextRefactoringAction.exception")); //$NON-NLS-1$ } } //---- Text selection ----------------------------------------------------------- /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { try{ run(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); } catch (JavaModelException e){ ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("NewTextRefactoringAction.exception")); //$NON-NLS-1$ } } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { setEnabled(checkEnabled()); } private boolean checkEnabled() { return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; } //---- helpers ------------------------------------------------------------------- private void run(ICompilationUnit unit, int offset, int length) throws JavaModelException { if (!ActionUtil.isProcessable(getShell(), unit)) return; ConvertAnonymousToNestedRefactoring refactoring= createRefactoring(unit, offset, length); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ConvertLocalToFieldAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.text.ITextSelection; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.PromoteTempWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.refactoring.code.PromoteTempToFieldRefactoring; /** * Action to convert a local variable to a field. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.1 */ public class ConvertLocalToFieldAction extends SelectionDispatchAction { private static final String DIALOG_MESSAGE_TITLE= RefactoringMessages.getString("ConvertLocalToField.title"); //$NON-NLS-1$ private final CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ConvertLocalToFieldAction(CompilationUnitEditor editor) { super(editor.getEditorSite()); setText(RefactoringMessages.getString("ConvertLocalToField.label")); //$NON-NLS-1$ fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.PROMOTE_TEMP_TO_FIELD_ACTION); } private static PromoteTempToFieldRefactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) { return PromoteTempToFieldRefactoring.create(cunit, selection.getOffset(), selection.getLength(), JavaPreferencesSettings.getCodeGenerationSettings()); } private static RefactoringWizard createWizard(PromoteTempToFieldRefactoring refactoring) { return new PromoteTempWizard(refactoring); } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; try{ PromoteTempToFieldRefactoring refactoring= createRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } catch (JavaModelException e){ ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("NewTextRefactoringAction.exception")); //$NON-NLS-1$ } } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { setEnabled(checkEnabled()); } private boolean checkEnabled() { return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ConvertNestedToTopAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.MoveInnerToTopWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.Assert; import org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring; import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; /** * Action to convert a nested class to a top level class. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.1 */ public class ConvertNestedToTopAction extends SelectionDispatchAction { private CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ConvertNestedToTopAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /** * Creates a new <code>MoveInnerToTopAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public ConvertNestedToTopAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("ConvertNestedToTopAction.Convert")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.MOVE_INNER_TO_TOP_ACTION); } /* * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.filterNotPresentException(e)) JavaPlugin.log(e); setEnabled(false);//no ui } } /* * @see SelectionDispatchAction#selectionChanged(ITextSelection) */ public void selectionChanged(ITextSelection selection) { //do nothing, this happens too often } /* * @see SelectionDispatchAction#run(IStructuredSelection) */ public void run(IStructuredSelection selection) { try { //we have to call this here - no selection changed event is sent after a refactoring but it may still invalidate enablement if (canEnable(selection)) startRefactoring(getSingleSelectedType(selection)); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } /* * @see SelectionDispatchAction#run(ITextSelection) */ public void run(ITextSelection selection) { try { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; IType type= getSingleSelectedType(); if (canRunOn(type)){ startRefactoring(type); } else { String unavailable= RefactoringMessages.getString("ConvertNestedToTopAction.To_activate"); //$NON-NLS-1$ MessageDialog.openInformation(getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.unavailable"), unavailable); //$NON-NLS-1$ } } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } private static boolean canEnable(IStructuredSelection selection) throws JavaModelException{ return canRunOn(getSingleSelectedType(selection)); } private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException{ if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; } private IType getSingleSelectedType() throws JavaModelException{ IJavaElement[] elements= resolveElements(); if (elements.length != 1) return null; if (elements[0] instanceof IType) return (IType)elements[0]; return null; } private static boolean canRunOn(IType type) throws JavaModelException{ return MoveInnerToTopRefactoring.isAvailable(type); } private IJavaElement[] resolveElements() { return SelectionConverter.codeResolveHandled(fEditor, getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring")); //$NON-NLS-1$ } private static RefactoringWizard createWizard(MoveInnerToTopRefactoring refactoring){ return new MoveInnerToTopWizard(refactoring); } private static MoveInnerToTopRefactoring createRefactoring(IType type) throws JavaModelException{ return MoveInnerToTopRefactoring.create(type, JavaPreferencesSettings.getCodeGenerationSettings()); } private void startRefactoring(IType type) throws JavaModelException { MoveInnerToTopRefactoring refactoring= createRefactoring(type); Assert.isNotNull(refactoring); // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=19104 if (!ActionUtil.isProcessable(getShell(), refactoring.getInputType())) return; Object newElementToProcess= new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), true); //$NON-NLS-1$ if (newElementToProcess == null) return; IStructuredSelection mockSelection= new StructuredSelection(newElementToProcess); selectionChanged(mockSelection); if (isEnabled()) run(mockSelection); else MessageDialog.openInformation(getShell(), RefactoringMessages.getString("ConvertNestedToTopAction.Refactoring"), RefactoringMessages.getString("ConvertNestedToTopAction.not_possible")); //$NON-NLS-1$ //$NON-NLS-2$ } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ExtractConstantAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.text.ITextSelection; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.ExtractConstantWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.refactoring.code.ExtractConstantRefactoring; /** * Extracts an expression into a new local variable and replaces all occurrences of * the expression with the local variable. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.1 */ public class ExtractConstantAction extends SelectionDispatchAction { private static final String DIALOG_MESSAGE_TITLE= RefactoringMessages.getString("ExtractConstantAction.extract_constant"); //$NON-NLS-1$ private final CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ExtractConstantAction(CompilationUnitEditor editor) { super(editor.getEditorSite()); setText(RefactoringMessages.getString("ExtractConstantAction.label")); //$NON-NLS-1$ fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.EXTRACT_CONSTANT_ACTION); } private static ExtractConstantRefactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) { return ExtractConstantRefactoring.create(cunit, selection.getOffset(), selection.getLength(), JavaPreferencesSettings.getCodeGenerationSettings()); } private static RefactoringWizard createWizard(ExtractConstantRefactoring refactoring) { return new ExtractConstantWizard(refactoring); } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; try{ ExtractConstantRefactoring refactoring= createRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } catch (JavaModelException e){ ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("NewTextRefactoringAction.exception")); //$NON-NLS-1$ } } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { setEnabled(checkEnabled()); } private boolean checkEnabled() { return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ExtractInterfaceAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.ExtractInterfaceWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.Assert; import org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceRefactoring; import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; /** * Extract a new interface from a class and tries to use the interface instead * of the concrete class where possible. * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.1 */ public class ExtractInterfaceAction extends SelectionDispatchAction { private CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ExtractInterfaceAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /** * Creates a new <code>ExtractInterfaceAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public ExtractInterfaceAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("ExtractInterfaceAction.Extract_Interface")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.EXTRACT_INTERFACE_ACTION); } /* * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.filterNotPresentException(e)) JavaPlugin.log(e); setEnabled(false);//no ui - happens on selection changes } } /* * @see SelectionDispatchAction#selectionChanged(ITextSelection) */ public void selectionChanged(ITextSelection selection) { //do nothing, this happens too often } /* * @see SelectionDispatchAction#run(IStructuredSelection) */ public void run(IStructuredSelection selection) { try { if (canEnable(selection)) startRefactoring(getSingleSelectedType(selection)); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } /* * @see SelectionDispatchAction#run(ITextSelection) */ public void run(ITextSelection selection) { try { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; IType type= getSingleSelectedType(); if (canRunOn(type)){ startRefactoring(type); } else { String unavailable= RefactoringMessages.getString("ExtractInterfaceAction.To_activate"); //$NON-NLS-1$ MessageDialog.openInformation(getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.unavailable"), unavailable); //$NON-NLS-1$ } } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } private static boolean canEnable(IStructuredSelection selection) throws JavaModelException{ return canRunOn(getSingleSelectedType(selection)); } private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException{ if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; } private IType getSingleSelectedType(){ IJavaElement[] elements= resolveElements(); if (elements.length != 1) return null; if (elements[0] instanceof IType) return (IType)elements[0]; return null; } private static boolean canRunOn(IType type) throws JavaModelException { return ExtractInterfaceRefactoring.isAvailable(type); } private IJavaElement[] resolveElements() { return SelectionConverter.codeResolveHandled(fEditor, getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring")); //$NON-NLS-1$ } private static RefactoringWizard createWizard(ExtractInterfaceRefactoring refactoring){ return new ExtractInterfaceWizard(refactoring); } private void startRefactoring(IType type) throws JavaModelException { ExtractInterfaceRefactoring refactoring= ExtractInterfaceRefactoring.create(type, JavaPreferencesSettings.getCodeGenerationSettings()); Assert.isNotNull(refactoring); // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=19104 if (!ActionUtil.isProcessable(getShell(), refactoring.getInputType())) return; Object newElementToProcess= new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), true); //$NON-NLS-1$ if (newElementToProcess == null) return; IStructuredSelection mockSelection= new StructuredSelection(newElementToProcess); selectionChanged(mockSelection); if (isEnabled()) run(mockSelection); else MessageDialog.openInformation(getShell(), RefactoringMessages.getString("ExtractInterfaceAction.Refactoring"), RefactoringMessages.getString("ExtractInterfaceAction.not_possible")); //$NON-NLS-1$ //$NON-NLS-2$ } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ExtractMethodAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jface.text.ITextSelection; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.refactoring.code.ExtractMethodWizard; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; /** * Extracts the code selected inside a compilation unit editor into a new method. * Necessary arguments, exceptions and returns values are computed and an * appropriate method signature is generated. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class ExtractMethodAction extends SelectionDispatchAction { private final CompilationUnitEditor fEditor; private static final String DIALOG_MESSAGE_TITLE= RefactoringMessages.getString("ExtractMethodAction.dialog.title");//$NON-NLS-1$ /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ExtractMethodAction(CompilationUnitEditor editor) { super(editor.getEditorSite()); setText(RefactoringMessages.getString("ExtractMethodAction.label"));//$NON-NLS-1$ fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.EXTRACT_METHOD_ACTION); } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; try{ ExtractMethodRefactoring refactoring= createRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } catch (CoreException e){ ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("NewTextRefactoringAction.exception")); //$NON-NLS-1$ } } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { setEnabled(checkEnabled(selection)); } private static ExtractMethodRefactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) throws CoreException { return ExtractMethodRefactoring.create( cunit, selection.getOffset(), selection.getLength(), JavaPreferencesSettings.getCodeGenerationSettings()); } private static RefactoringWizard createWizard(ExtractMethodRefactoring refactoring) { return new ExtractMethodWizard(refactoring); } private boolean checkEnabled(ITextSelection selection) { if (selection.getLength() == 0) return false; return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ExtractTempAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.text.ITextSelection; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.ExtractTempWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring; /** * Extracts an expression into a new local variable and replaces all occurrences of * the expression with the local variable. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class ExtractTempAction extends SelectionDispatchAction { private static final String DIALOG_MESSAGE_TITLE= RefactoringMessages.getString("ExtractTempAction.extract_temp"); //$NON-NLS-1$ private final CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ExtractTempAction(CompilationUnitEditor editor) { super(editor.getEditorSite()); setText(RefactoringMessages.getString("ExtractTempAction.label")); //$NON-NLS-1$ fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.EXTRACT_TEMP_ACTION); } private static ExtractTempRefactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) { return ExtractTempRefactoring.create(cunit, selection.getOffset(), selection.getLength(), JavaPreferencesSettings.getCodeGenerationSettings()); } private static RefactoringWizard createWizard(ExtractTempRefactoring refactoring) { return new ExtractTempWizard(refactoring); } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; try{ ExtractTempRefactoring refactoring= createRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } catch (JavaModelException e){ ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("NewTextRefactoringAction.exception")); //$NON-NLS-1$ } } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { setEnabled(checkEnabled()); } private boolean checkEnabled() { return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/InlineTempAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.refactoring.InlineTempWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.refactoring.base.Refactoring; import org.eclipse.jdt.internal.corext.refactoring.code.InlineTempRefactoring; /** * Inlines the value of a local variable at all places where a read reference * is used. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class InlineTempAction extends SelectionDispatchAction { private CompilationUnitEditor fEditor; private static final String DIALOG_MESSAGE_TITLE= RefactoringMessages.getString("InlineTempAction.inline_temp");//$NON-NLS-1$ /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public InlineTempAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /* package */ InlineTempAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("InlineTempAction.label"));//$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.INLINE_ACTION); } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { //do nothing } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { try{ ICompilationUnit input= SelectionConverter.getInputAsCompilationUnit(fEditor); if (!ActionUtil.isProcessable(getShell(), input)) return; Refactoring refactoring= createRefactoring(input, selection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } catch (JavaModelException e){ ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("NewTextRefactoringAction.exception")); //$NON-NLS-1$ } } /** * Note: this method is for internal use only. Clients should not call this method. */ protected Refactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) { return InlineTempRefactoring.create(cunit, selection.getOffset(), selection.getLength()); } /** * Note: this method is for internal use only. Clients should not call this method. */ protected RefactoringWizard createWizard(Refactoring refactoring) { RefactoringWizard result= new InlineTempWizard((InlineTempRefactoring)refactoring); result.setExpandFirstNode(true); return result; } /* * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection) */ public void run(IStructuredSelection selection) { //do nothing } /* * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { setEnabled(false); } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/IntroduceFactoryAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.ISourceRange; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.corext.refactoring.code.IntroduceFactoryRefactoring; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.IntroduceFactoryWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; /** * Action that encapsulates the IntroduceFactoryRefactoring refactoring for * association with UI entities. * @author rfuhrer */ public class IntroduceFactoryAction extends SelectionDispatchAction { private CompilationUnitEditor fEditor; private static final String DIALOG_MESSAGE_TITLE= RefactoringMessages.getString("IntroduceFactoryAction.dialog_title");//$NON-NLS-1$ /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public IntroduceFactoryAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); } /** * Creates a new <code>IntroduceFactoryAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public IntroduceFactoryAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("IntroduceFactoryAction.label")); //$NON-NLS-1$ setToolTipText(RefactoringMessages.getString("IntroduceFactoryAction.tooltipText")); //$NON-NLS-1$ setDescription(RefactoringMessages.getString("IntroduceFactoryAction.description")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.INTRODUCE_FACTORY_ACTION); } /* * @see SelectionDispatchAction#run(IStructuredSelection) */ public void run(IStructuredSelection selection) { try { //we have to call this here - no selection changed event is sent after a refactoring but it may still invalidate enablement if (canEnable(selection)) { IMethod method= getSingleSelectedMethod(selection); ICompilationUnit unit= method.getCompilationUnit(); ISourceRange nameRange= method.getNameRange(); ITextSelection textSel= new TextSelection(nameRange.getOffset(), nameRange.getLength()); IntroduceFactoryRefactoring refactoring= createRefactoring(unit, textSel); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } } catch (CoreException e) { ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("IntroduceFactoryAction.exception")); //$NON-NLS-1$ } } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; try{ IntroduceFactoryRefactoring refactoring= createRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } catch (CoreException e){ ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("IntroduceFactoryAction.exception")); //$NON-NLS-1$ } } private static boolean canEnable(IStructuredSelection selection) throws JavaModelException{ return canRunOn(getSingleSelectedMethod(selection)); } private static boolean canRunOn(IMethod method) throws JavaModelException{ return method != null && method.isConstructor(); } private static IMethod getSingleSelectedMethod(IStructuredSelection selection){ if (selection.isEmpty() || selection.size() != 1) return null; if (selection.getFirstElement() instanceof IMethod) return (IMethod)selection.getFirstElement(); return null; } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { setEnabled(checkEnabled(selection)); } /* * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { if (JavaModelUtil.filterNotPresentException(e)) JavaPlugin.log(e); setEnabled(false);//no ui here - happens on selection changes } } private static IntroduceFactoryRefactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) throws CoreException { return IntroduceFactoryRefactoring.create(cunit, selection.getOffset(), selection.getLength(), JavaPreferencesSettings.getCodeGenerationSettings()); } private RefactoringWizard createWizard(IntroduceFactoryRefactoring refactoring) { String pageTitle= RefactoringMessages.getString("IntroduceFactoryAction.use_factory"); //$NON-NLS-1$ return new IntroduceFactoryWizard(refactoring, pageTitle); } private boolean checkEnabled(ITextSelection selection) { return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/IntroduceParameterAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jface.text.ITextSelection; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.internal.corext.refactoring.code.IntroduceParameterRefactoring; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.IntroduceParameterWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; /** * Introduces a new method parameter from a selected expression. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 3.0 */ public class IntroduceParameterAction extends SelectionDispatchAction { private final CompilationUnitEditor fEditor; private static final String DIALOG_MESSAGE_TITLE= RefactoringMessages.getString("IntroduceParameterAction.dialog_title");//$NON-NLS-1$ /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public IntroduceParameterAction(CompilationUnitEditor editor) { super(editor.getEditorSite()); setText(RefactoringMessages.getString("IntroduceParameterAction.label"));//$NON-NLS-1$ fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.INTRODUCE_PARAMETER_ACTION); } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; try{ IntroduceParameterRefactoring refactoring= createRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection); if (refactoring == null) return; new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false); } catch (CoreException e){ ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.getString("NewTextRefactoringAction.exception")); //$NON-NLS-1$ } } /* (non-Javadoc) * Method declared on SelectionDispatchAction */ public void selectionChanged(ITextSelection selection) { setEnabled(checkEnabled(selection)); } private static IntroduceParameterRefactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) throws CoreException { return IntroduceParameterRefactoring.create( cunit, selection.getOffset(), selection.getLength(), JavaPreferencesSettings.getCodeGenerationSettings()); } private static RefactoringWizard createWizard(IntroduceParameterRefactoring refactoring) { return new IntroduceParameterWizard(refactoring); } private boolean checkEnabled(ITextSelection selection) { return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ModifyParametersAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionMessages; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.ChangeSignatureWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.Assert; import org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureRefactoring; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; /** * Action to start the modify parameters refactoring. The refactoring supports * swapping and renaming of arguments. * <p> * This action is applicable to selections containing a method with one or * more arguments. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class ModifyParametersAction extends SelectionDispatchAction { private CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ModifyParametersAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /** * Creates a new <code>ModifyParametersAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public ModifyParametersAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("RefactoringGroup.modify_Parameters_label"));//$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.MODIFY_PARAMETERS_ACTION); } /* * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.filterNotPresentException(e)) JavaPlugin.log(e); setEnabled(false);//no ui here - happens on selection changes } } /* * @see SelectionDispatchAction#selectionChanged(ITextSelection) */ public void selectionChanged(ITextSelection selection) { //do nothing, this happens too often } /* * @see SelectionDispatchAction#run(IStructuredSelection) */ public void run(IStructuredSelection selection) { try { //we have to call this here - no selection changed event is sent after a refactoring but it may still invalidate enablement if (canEnable(selection)) startRefactoring(getSingleSelectedMethod(selection)); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } /* * @see SelectionDispatchAction#run(ITextSelection) */ public void run(ITextSelection selection) { try { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; IMethod singleSelectedMethod= getSingleSelectedMethod(selection); if (canRunOn(singleSelectedMethod)){ startRefactoring(singleSelectedMethod); } else { String unavailable= RefactoringMessages.getString("ModifyParametersAction.unavailable"); //$NON-NLS-1$ MessageDialog.openInformation(getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.unavailable"), unavailable); //$NON-NLS-1$ } } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } private static boolean canEnable(IStructuredSelection selection) throws JavaModelException{ return canRunOn(getSingleSelectedMethod(selection)); } private static IMethod getSingleSelectedMethod(IStructuredSelection selection){ if (selection.isEmpty() || selection.size() != 1) return null; if (selection.getFirstElement() instanceof IMethod) return (IMethod)selection.getFirstElement(); return null; } private IMethod getSingleSelectedMethod(ITextSelection selection) throws JavaModelException{ IJavaElement[] elements= resolveElements(); if (elements.length != 1) return null; if (elements[0] instanceof IMethod) return (IMethod)elements[0]; IJavaElement elementAt= SelectionConverter.getInputAsCompilationUnit(fEditor).getElementAt(selection.getOffset()); if (elementAt instanceof IMethod) return (IMethod)elementAt; return null; } private static boolean canRunOn(IMethod method) throws JavaModelException{ return ChangeSignatureRefactoring.isAvailable(method); } private static ChangeSignatureRefactoring createRefactoring(IMethod method) throws JavaModelException{ return ChangeSignatureRefactoring.create(method, JavaPreferencesSettings.getCodeGenerationSettings()); } private IJavaElement[] resolveElements() { return SelectionConverter.codeResolveHandled(fEditor, getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring")); //$NON-NLS-1$ } private static RefactoringWizard createWizard(ChangeSignatureRefactoring refactoring){ return new ChangeSignatureWizard(refactoring); } private void startRefactoring(IMethod method) throws JavaModelException { ChangeSignatureRefactoring refactoring= createRefactoring(method); Assert.isNotNull(refactoring); // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=19104 if (!ActionUtil.isProcessable(getShell(), refactoring.getMethod())) return; Object newElementToProcess= new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), true); //$NON-NLS-1$ if (newElementToProcess == null) return; IStructuredSelection mockSelection= new StructuredSelection(newElementToProcess); selectionChanged(mockSelection); if (isEnabled()) run(mockSelection); else MessageDialog.openInformation(getShell(), ActionMessages.getString("ModifyParameterAction.problem.title"), ActionMessages.getString("ModifyParameterAction.problem.message")); //$NON-NLS-1$ //$NON-NLS-2$ } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OpenAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import java.util.Iterator; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.util.OpenStrategy; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.ISourceReference; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.IJavaStatusConstants; import org.eclipse.jdt.internal.ui.actions.ActionMessages; import org.eclipse.jdt.internal.ui.actions.OpenActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; /** * This action opens a Java editor on a Java element or file. * <p> * The action is applicable to selections containing elements of * type <code>ICompilationUnit</code>, <code>IMember</code> * or <code>IFile</code>. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class OpenAction extends SelectionDispatchAction { private JavaEditor fEditor; /** * Creates a new <code>OpenAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public OpenAction(IWorkbenchSite site) { super(site); setText(ActionMessages.getString("OpenAction.label")); //$NON-NLS-1$ setToolTipText(ActionMessages.getString("OpenAction.tooltip")); //$NON-NLS-1$ setDescription(ActionMessages.getString("OpenAction.description")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public OpenAction(JavaEditor editor) { this(editor.getEditorSite()); fEditor= editor; setText(ActionMessages.getString("OpenAction.declaration.label")); //$NON-NLS-1$ setEnabled(SelectionConverter.canOperateOn(fEditor)); } /* (non-Javadoc) * Method declared on SelectionDispatchAction. */ protected void selectionChanged(ITextSelection selection) { } /* (non-Javadoc) * Method declared on SelectionDispatchAction. */ public void selectionChanged(IStructuredSelection selection) { setEnabled(checkEnabled(selection)); } private boolean checkEnabled(IStructuredSelection selection) { if (selection.isEmpty()) return false; for (Iterator iter= selection.iterator(); iter.hasNext();) { Object element= iter.next(); if (element instanceof ISourceReference) continue; if (element instanceof IFile) continue; if (element instanceof IStorage) continue; return false; } return true; } /* (non-Javadoc) * Method declared on SelectionDispatchAction. */ public void run(ITextSelection selection) { try { IJavaElement element= SelectionConverter.codeResolve(fEditor, getShell(), getDialogTitle(), ActionMessages.getString("OpenAction.select_element")); //$NON-NLS-1$ if (element == null) { IEditorStatusLine statusLine= (IEditorStatusLine) fEditor.getAdapter(IEditorStatusLine.class); if (statusLine != null) statusLine.setMessage(true, ActionMessages.getString("OpenAction.error.messageBadSelection"), null); //$NON-NLS-1$ getShell().getDisplay().beep(); return; } IJavaElement input= SelectionConverter.getInput(fEditor); int type= element.getElementType(); if (type == IJavaElement.JAVA_PROJECT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT || type == IJavaElement.PACKAGE_FRAGMENT) element= input; run(new Object[] {element} ); } catch (JavaModelException e) { showError(e); } } /* (non-Javadoc) * Method declared on SelectionDispatchAction. */ public void run(IStructuredSelection selection) { if (!checkEnabled(selection)) return; run(selection.toArray()); } public void run(Object[] elements) { if (elements == null) return; for (int i= 0; i < elements.length; i++) { Object element= elements[i]; try { element= getElementToOpen(element); boolean activateOnOpen= fEditor != null ? true : OpenStrategy.activateOnOpen(); OpenActionUtil.open(element, activateOnOpen); } catch (JavaModelException e) { JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, ActionMessages.getString("OpenAction.error.message"), e)); //$NON-NLS-1$ ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.getString("OpenAction.error.messageProblems"), //$NON-NLS-1$ e.getStatus()); } catch (PartInitException x) { String name= null; if (element instanceof IJavaElement) { name= ((IJavaElement) element).getElementName(); } else if (element instanceof IStorage) { name= ((IStorage) element).getName(); } else if (element instanceof IResource) { name= ((IResource) element).getName(); } if (name != null) { MessageDialog.openError(getShell(), ActionMessages.getString("OpenAction.error.messageProblems"), //$NON-NLS-1$ ActionMessages.getFormattedString("OpenAction.error.messageArgs", //$NON-NLS-1$ new String[] { name, x.getMessage() } )); } } } } /** * Note: this method is for internal use only. Clients should not call this method. */ public Object getElementToOpen(Object object) throws JavaModelException { return object; } private String getDialogTitle() { return ActionMessages.getString("OpenAction.error.title"); //$NON-NLS-1$ } private void showError(CoreException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.getString("OpenAction.error.message")); //$NON-NLS-1$ } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/PullUpAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMember; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionMessages; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.PullUpWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.Assert; import org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoring; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; /** * Action to pull up method and fields into a superclass. * <p> * Action is applicable to selections containing elements of * type <code>IField</code> and <code>IMethod</code> * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class PullUpAction extends SelectionDispatchAction{ private CompilationUnitEditor fEditor; /** * Creates a new <code>PullUpAction</code>. The action requires that the selection * provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public PullUpAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("RefactoringGroup.pull_Up_label"));//$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.PULL_UP_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public PullUpAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /* * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(getSelectedMembers(selection))); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.filterNotPresentException(e)) JavaPlugin.log(e); setEnabled(false);//no ui } } /* * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(ITextSelection) */ public void selectionChanged(ITextSelection selection) { //do nothing, this happens too often } /* * @see SelectionDispatchAction#run(IStructuredSelection) */ public void run(IStructuredSelection selection) { try { IMember[] members= getSelectedMembers(selection); if (canEnable(members)) startRefactoring(members); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } /* * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#run(ITextSelection) */ public void run(ITextSelection selection) { try { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; IMember member= getSelectedMember(); IMember[] array= new IMember[]{member}; if (member != null && canEnable(array)){ startRefactoring(array); } else { String unavailable= RefactoringMessages.getString("PullUpAction.unavailable"); //$NON-NLS-1$ MessageDialog.openInformation(getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.unavailable"), unavailable); //$NON-NLS-1$ } } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } private static IMember[] getSelectedMembers(IStructuredSelection selection){ if (selection.isEmpty()) return null; for (Iterator iter= selection.iterator(); iter.hasNext(); ) { if (! (iter.next() instanceof IMember)) return null; } return convertToMemberArray(selection.toArray()); } private static boolean canEnable(IMember[] members) throws JavaModelException { return PullUpRefactoring.isAvailable(members); } private IMember getSelectedMember() throws JavaModelException{ IJavaElement element= SelectionConverter.getElementAtOffset(fEditor); if (element == null || ! (element instanceof IMember)) return null; return (IMember)element; } private static PullUpRefactoring createNewRefactoringInstance(IMember[] members) throws JavaModelException{ return PullUpRefactoring.create(members, JavaPreferencesSettings.getCodeGenerationSettings()); } private static IMember[] convertToMemberArray(Object[] obj) { if (obj == null) return null; Set memberSet= new HashSet(); memberSet.addAll(Arrays.asList(obj)); return (IMember[]) memberSet.toArray(new IMember[memberSet.size()]); } private static RefactoringWizard createWizard(PullUpRefactoring refactoring){ return new PullUpWizard(refactoring); } private void startRefactoring(IMember[] members) throws JavaModelException { PullUpRefactoring refactoring= createNewRefactoringInstance(members); Assert.isNotNull(refactoring); // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=19104 if (!ActionUtil.isProcessable(getShell(), refactoring.getDeclaringType())) return; Object newElementToProcess= new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), true); //$NON-NLS-1$ if (newElementToProcess == null) return; IStructuredSelection mockSelection= new StructuredSelection(newElementToProcess); selectionChanged(mockSelection); if (isEnabled()) run(mockSelection); else MessageDialog.openInformation(getShell(), ActionMessages.getString("PullUpAction.problem.title"), ActionMessages.getString("PullUpAction.problem.message")); //$NON-NLS-1$ //$NON-NLS-2$ } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/PushDownAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMember; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.PushDownWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.Assert; import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoring; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; /** * Action to push down methods and fields into subclasses. * <p> * Action is applicable to selections containing elements of * type <code>IField</code> and <code>IMethod</code> * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.1 */ public class PushDownAction extends SelectionDispatchAction{ private CompilationUnitEditor fEditor; /** * Creates a new <code>PushDownAction</code>. The action requires that the selection * provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public PushDownAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("PushDownAction.Push_Down")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.PUSH_DOWN_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public PushDownAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /* * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(getSelectedMembers(selection))); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.filterNotPresentException(e)) JavaPlugin.log(e); setEnabled(false);//no ui } } /* * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(ITextSelection) */ public void selectionChanged(ITextSelection selection) { //do nothing, this happens too often } /* * @see SelectionDispatchAction#run(IStructuredSelection) */ public void run(IStructuredSelection selection) { try { IMember[] members= getSelectedMembers(selection); if (canEnable(members)) startRefactoring(members); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } /* * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#run(ITextSelection) */ public void run(ITextSelection selection) { try { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; IMember member= getSelectedMember(); IMember[] array= new IMember[]{member}; if (member != null && canEnable(array)){ startRefactoring(array); } else { String unavailable= RefactoringMessages.getString("PushDownAction.To_activate"); //$NON-NLS-1$ MessageDialog.openInformation(getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.unavailable"), unavailable); //$NON-NLS-1$ } } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } private static IMember[] getSelectedMembers(IStructuredSelection selection){ if (selection.isEmpty()) return null; for (Iterator iter= selection.iterator(); iter.hasNext(); ) { if (! (iter.next() instanceof IMember)) return null; } return convertToMemberArray(selection.toArray()); } private static boolean canEnable(IMember[] members) throws JavaModelException { return PushDownRefactoring.isAvailable(members); } private IMember getSelectedMember() throws JavaModelException{ IJavaElement element= SelectionConverter.getElementAtOffset(fEditor); if (element == null || ! (element instanceof IMember)) return null; return (IMember)element; } private static PushDownRefactoring createNewRefactoringInstance(IMember[] members) throws JavaModelException{ return PushDownRefactoring.create(members, JavaPreferencesSettings.getCodeGenerationSettings()); } private static IMember[] convertToMemberArray(Object[] obj) { if (obj == null) return null; Set memberSet= new HashSet(); memberSet.addAll(Arrays.asList(obj)); return (IMember[]) memberSet.toArray(new IMember[memberSet.size()]); } private static RefactoringWizard createWizard(PushDownRefactoring refactoring){ return new PushDownWizard(refactoring); } private void startRefactoring(IMember[] members) throws JavaModelException { PushDownRefactoring refactoring= createNewRefactoringInstance(members); Assert.isNotNull(refactoring); // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=19104 if (!ActionUtil.isProcessable(getShell(), refactoring.getDeclaringClass())) return; Object newElementToProcess= new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), true); //$NON-NLS-1$ if (newElementToProcess == null) return; IStructuredSelection mockSelection= new StructuredSelection(newElementToProcess); selectionChanged(mockSelection); if (isEnabled()) run(mockSelection); else MessageDialog.openInformation(getShell(), RefactoringMessages.getString("PushDownAction.Refactoring"), RefactoringMessages.getString("PushDownAction.not_possible")); //$NON-NLS-1$ //$NON-NLS-2$ } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/RefactorActionGroup.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.part.Page; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionMessages; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.refactoring.reorg.RenameRefactoringAction; import org.eclipse.jdt.ui.IContextMenuConstants; /** * Action group that adds refactor actions (for example Rename..., Move..., etc) * to a context menu and the global menu bar. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class RefactorActionGroup extends ActionGroup { /** * Pop-up menu: id of the refactor sub menu (value <code>org.eclipse.jdt.ui.refactoring.menu</code>). * * @since 2.1 */ public static final String MENU_ID= "org.eclipse.jdt.ui.refactoring.menu"; //$NON-NLS-1$ /** * Pop-up menu: id of the reorg group of the refactor sub menu (value * <code>reorgGroup</code>). * * @since 2.1 */ public static final String GROUP_REORG= "reorgGroup"; //$NON-NLS-1$ /** * Pop-up menu: id of the type group of the refactor sub menu (value * <code>typeGroup</code>). * * @since 2.1 */ public static final String GROUP_TYPE= "typeGroup"; //$NON-NLS-1$ /** * Pop-up menu: id of the coding group of the refactor sub menu (value * <code>codingGroup</code>). * * @since 2.1 */ public static final String GROUP_CODING= "codingGroup"; //$NON-NLS-1$ private IWorkbenchSite fSite; private String fGroupName= IContextMenuConstants.GROUP_REORGANIZE; private SelectionDispatchAction fMoveAction; private SelectionDispatchAction fRenameAction; private SelectionDispatchAction fModifyParametersAction; private SelectionDispatchAction fConvertAnonymousToNestedAction; private SelectionDispatchAction fConvertNestedToTopAction; private SelectionDispatchAction fPullUpAction; private SelectionDispatchAction fPushDownAction; private SelectionDispatchAction fExtractInterfaceAction; private SelectionDispatchAction fChangeTypeAction; private SelectionDispatchAction fUseSupertypeAction; private SelectionDispatchAction fInlineAction; private SelectionDispatchAction fExtractMethodAction; private SelectionDispatchAction fExtractTempAction; private SelectionDispatchAction fExtractConstantAction; private SelectionDispatchAction fIntroduceParameterAction; private SelectionDispatchAction fIntroduceFactoryAction; private SelectionDispatchAction fConvertLocalToFieldAction; private SelectionDispatchAction fSelfEncapsulateField; private SelectionDispatchAction fRenameRefactoringAction; /** * Creates a new <code>RefactorActionGroup</code>. The group requires * that the selection provided by the part's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param part the view part that owns this action group */ public RefactorActionGroup(IViewPart part) { this(part.getSite()); } /** * Creates a new <code>RefactorActionGroup</code>. The action requires * that the selection provided by the page's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param page the page that owns this action group */ public RefactorActionGroup(Page page) { this(page.getSite()); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public RefactorActionGroup(CompilationUnitEditor editor, String groupName) { fSite= editor.getEditorSite(); fGroupName= groupName; ISelectionProvider provider= editor.getSelectionProvider(); ISelection selection= provider.getSelection(); fRenameAction= new RenameAction(editor); fRenameAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.RENAME_ELEMENT); fRenameAction.update(selection); editor.setAction("RenameElement", fRenameAction); //$NON-NLS-1$ fSelfEncapsulateField= new SelfEncapsulateFieldAction(editor); fSelfEncapsulateField.setActionDefinitionId(IJavaEditorActionDefinitionIds.SELF_ENCAPSULATE_FIELD); fSelfEncapsulateField.update(selection); editor.setAction("SelfEncapsulateField", fSelfEncapsulateField); //$NON-NLS-1$ fModifyParametersAction= new ModifyParametersAction(editor); fModifyParametersAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.MODIFY_METHOD_PARAMETERS); fModifyParametersAction.update(selection); editor.setAction("ModifyParameters", fModifyParametersAction); //$NON-NLS-1$ fPullUpAction= new PullUpAction(editor); fPullUpAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.PULL_UP); fPullUpAction.update(selection); editor.setAction("PullUp", fPullUpAction); //$NON-NLS-1$ fPushDownAction= new PushDownAction(editor); fPushDownAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.PUSH_DOWN); fPushDownAction.update(selection); editor.setAction("PushDown", fPushDownAction); //$NON-NLS-1$ fMoveAction= new MoveAction(editor); fMoveAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.MOVE_ELEMENT); fMoveAction.update(selection); editor.setAction("MoveElement", fMoveAction); //$NON-NLS-1$ fExtractTempAction= new ExtractTempAction(editor); fExtractTempAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTRACT_LOCAL_VARIABLE); initAction(fExtractTempAction, provider, selection); editor.setAction("ExtractLocalVariable", fExtractTempAction); //$NON-NLS-1$ fIntroduceParameterAction= new IntroduceParameterAction(editor); fIntroduceParameterAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.INTRODUCE_PARAMETER); initAction(fIntroduceParameterAction, provider, selection); editor.setAction("IntroduceParameter", fIntroduceParameterAction); //$NON-NLS-1$ fIntroduceFactoryAction= new IntroduceFactoryAction(editor); fIntroduceFactoryAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.INTRODUCE_FACTORY); initAction(fIntroduceFactoryAction, provider, selection); editor.setAction("IntroduceFactory", fIntroduceFactoryAction); //$NON-NLS-1$ fExtractConstantAction= new ExtractConstantAction(editor); fExtractConstantAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTRACT_CONSTANT); initAction(fExtractConstantAction, provider, selection); editor.setAction("ExtractConstant", fExtractConstantAction); //$NON-NLS-1$ fInlineAction= new InlineAction(editor); fInlineAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.INLINE); fInlineAction.update(selection); editor.setAction("Inline", fInlineAction); //$NON-NLS-1$ fExtractMethodAction= new ExtractMethodAction(editor); fExtractMethodAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTRACT_METHOD); initAction(fExtractMethodAction, provider, selection); editor.setAction("ExtractMethod", fExtractMethodAction); //$NON-NLS-1$ fConvertLocalToFieldAction= new ConvertLocalToFieldAction(editor); fConvertLocalToFieldAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.PROMOTE_LOCAL_VARIABLE); initAction(fConvertLocalToFieldAction, provider, selection); editor.setAction("PromoteTemp", fConvertLocalToFieldAction); //$NON-NLS-1$ fConvertAnonymousToNestedAction= new ConvertAnonymousToNestedAction(editor); fConvertAnonymousToNestedAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.CONVERT_ANONYMOUS_TO_NESTED); initAction(fConvertAnonymousToNestedAction, provider, selection); editor.setAction("ConvertAnonymousToNested", fConvertAnonymousToNestedAction); //$NON-NLS-1$ fExtractInterfaceAction= new ExtractInterfaceAction(editor); fExtractInterfaceAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTRACT_INTERFACE); fExtractInterfaceAction.update(selection); editor.setAction("ExtractInterface", fExtractInterfaceAction); //$NON-NLS-1$ fChangeTypeAction= new ChangeTypeAction(editor); fChangeTypeAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.CHANGE_TYPE); initAction(fChangeTypeAction, provider, selection); editor.setAction("ChangeType", fChangeTypeAction); //$NON-NLS-1$ fConvertNestedToTopAction= new ConvertNestedToTopAction(editor); fConvertNestedToTopAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.MOVE_INNER_TO_TOP); fConvertNestedToTopAction.update(selection); editor.setAction("MoveInnerToTop", fConvertNestedToTopAction); //$NON-NLS-1$ fUseSupertypeAction= new UseSupertypeAction(editor); fUseSupertypeAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.USE_SUPERTYPE); fUseSupertypeAction.update(selection); editor.setAction("UseSupertype", fUseSupertypeAction); //$NON-NLS-1$ } private RefactorActionGroup(IWorkbenchSite site) { fSite= site; ISelectionProvider provider= fSite.getSelectionProvider(); ISelection selection= provider.getSelection(); fMoveAction= new MoveAction(site); initAction(fMoveAction, provider, selection); fRenameAction= new RenameAction(site); initAction(fRenameAction, provider, selection); fModifyParametersAction= new ModifyParametersAction(fSite); initAction(fModifyParametersAction, provider, selection); fPullUpAction= new PullUpAction(fSite); initAction(fPullUpAction, provider, selection); fPushDownAction= new PushDownAction(fSite); initAction(fPushDownAction, provider, selection); fSelfEncapsulateField= new SelfEncapsulateFieldAction(fSite); initAction(fSelfEncapsulateField, provider, selection); fExtractInterfaceAction= new ExtractInterfaceAction(fSite); initAction(fExtractInterfaceAction, provider, selection); fChangeTypeAction= new ChangeTypeAction(fSite); initAction(fChangeTypeAction, provider, selection); fConvertNestedToTopAction= new ConvertNestedToTopAction(fSite); initAction(fConvertNestedToTopAction, provider, selection); fUseSupertypeAction= new UseSupertypeAction(fSite); initAction(fUseSupertypeAction, provider, selection); fInlineAction= new InlineAction(fSite); initAction(fInlineAction, provider, selection); fRenameRefactoringAction= new RenameRefactoringAction(fSite); initAction(fRenameRefactoringAction, provider, selection); fIntroduceFactoryAction= new IntroduceFactoryAction(fSite); initAction(fIntroduceFactoryAction, provider, selection); fConvertAnonymousToNestedAction= new ConvertAnonymousToNestedAction(fSite); initAction(fConvertAnonymousToNestedAction, provider, selection); } private static void initAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection){ action.update(selection); provider.addSelectionChangedListener(action); } /* (non-Javadoc) * Method declared in ActionGroup */ public void fillActionBars(IActionBars actionBars) { super.fillActionBars(actionBars); actionBars.setGlobalActionHandler(JdtActionConstants.SELF_ENCAPSULATE_FIELD, fSelfEncapsulateField); actionBars.setGlobalActionHandler(JdtActionConstants.MOVE, fMoveAction); actionBars.setGlobalActionHandler(JdtActionConstants.RENAME, fRenameAction); actionBars.setGlobalActionHandler(JdtActionConstants.MODIFY_PARAMETERS, fModifyParametersAction); actionBars.setGlobalActionHandler(JdtActionConstants.PULL_UP, fPullUpAction); actionBars.setGlobalActionHandler(JdtActionConstants.PUSH_DOWN, fPushDownAction); actionBars.setGlobalActionHandler(JdtActionConstants.EXTRACT_TEMP, fExtractTempAction); actionBars.setGlobalActionHandler(JdtActionConstants.EXTRACT_CONSTANT, fExtractConstantAction); actionBars.setGlobalActionHandler(JdtActionConstants.INTRODUCE_PARAMETER, fIntroduceParameterAction); actionBars.setGlobalActionHandler(JdtActionConstants.INTRODUCE_FACTORY, fIntroduceFactoryAction); actionBars.setGlobalActionHandler(JdtActionConstants.EXTRACT_METHOD, fExtractMethodAction); actionBars.setGlobalActionHandler(JdtActionConstants.INLINE, fInlineAction); actionBars.setGlobalActionHandler(JdtActionConstants.EXTRACT_INTERFACE, fExtractInterfaceAction); actionBars.setGlobalActionHandler(JdtActionConstants.CHANGE_TYPE, fChangeTypeAction); actionBars.setGlobalActionHandler(JdtActionConstants.CONVERT_NESTED_TO_TOP, fConvertNestedToTopAction); actionBars.setGlobalActionHandler(JdtActionConstants.USE_SUPERTYPE, fUseSupertypeAction); actionBars.setGlobalActionHandler(JdtActionConstants.CONVERT_LOCAL_TO_FIELD, fConvertLocalToFieldAction); actionBars.setGlobalActionHandler(JdtActionConstants.CONVERT_ANONYMOUS_TO_NESTED, fConvertAnonymousToNestedAction); } /* (non-Javadoc) * Method declared in ActionGroup */ public void fillContextMenu(IMenuManager menu) { super.fillContextMenu(menu); addRefactorSubmenu(menu); } /* * @see ActionGroup#dispose() */ public void dispose() { ISelectionProvider provider= fSite.getSelectionProvider(); disposeAction(fSelfEncapsulateField, provider); disposeAction(fMoveAction, provider); disposeAction(fRenameAction, provider); disposeAction(fModifyParametersAction, provider); disposeAction(fPullUpAction, provider); disposeAction(fPushDownAction, provider); disposeAction(fExtractTempAction, provider); disposeAction(fExtractConstantAction, provider); disposeAction(fIntroduceParameterAction, provider); disposeAction(fIntroduceFactoryAction, provider); disposeAction(fExtractMethodAction, provider); disposeAction(fInlineAction, provider); disposeAction(fExtractInterfaceAction, provider); disposeAction(fChangeTypeAction, provider); disposeAction(fConvertNestedToTopAction, provider); disposeAction(fUseSupertypeAction, provider); disposeAction(fConvertLocalToFieldAction, provider); disposeAction(fConvertAnonymousToNestedAction, provider); super.dispose(); } private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { if (action != null) provider.removeSelectionChangedListener(action); } private void addRefactorSubmenu(IMenuManager menu) { IMenuManager refactorSubmenu= new MenuManager(ActionMessages.getString("RefactorMenu.label"), MENU_ID); //$NON-NLS-1$ int added= 0; refactorSubmenu.add(new Separator(GROUP_REORG)); added+= addAction(refactorSubmenu, fRenameAction); added+= addAction(refactorSubmenu, fMoveAction); added+= addAction(refactorSubmenu, fModifyParametersAction); added+= addAction(refactorSubmenu, fConvertAnonymousToNestedAction); added+= addAction(refactorSubmenu, fConvertNestedToTopAction); refactorSubmenu.add(new Separator(GROUP_TYPE)); added+= addAction(refactorSubmenu, fPullUpAction); added+= addAction(refactorSubmenu, fPushDownAction); added+= addAction(refactorSubmenu, fExtractInterfaceAction); added+= addAction(refactorSubmenu, fChangeTypeAction); added+= addAction(refactorSubmenu, fUseSupertypeAction); refactorSubmenu.add(new Separator(GROUP_CODING)); added+= addAction(refactorSubmenu, fInlineAction); added+= addAction(refactorSubmenu, fExtractMethodAction); added+= addAction(refactorSubmenu, fExtractTempAction); added+= addAction(refactorSubmenu, fExtractConstantAction); added+= addAction(refactorSubmenu, fIntroduceParameterAction); added+= addAction(refactorSubmenu, fIntroduceFactoryAction); added+= addAction(refactorSubmenu, fConvertLocalToFieldAction); added+= addAction(refactorSubmenu, fSelfEncapsulateField); if (JavaPlugin.getDefault().getPreferenceStore().getBoolean("org.eclipse.jdt.refactoring.participants")) { //$NON-NLS-1$ refactorSubmenu.add(new Separator()); added+= addAction(refactorSubmenu, fRenameRefactoringAction); } if (added > 0) menu.appendToGroup(fGroupName, refactorSubmenu); } private int addAction(IMenuManager menu, IAction action) { if (action != null && action.isEnabled()) { menu.add(action); return 1; } return 0; } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/SelectionDispatchAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.swt.widgets.Shell; import org.eclipse.jface.action.Action; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.util.Assert; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.ui.IWorkbenchSite; /** * Action that dispatches the <code>IAction#run()</code> and the * <code>ISelectionChangedListener#selectionChanged</code> * according to the type of the selection. * * <ul> * <li>if selection is of type <code>ITextSelection</code> then * <code>run(ITextSelection)</code> and <code>selectionChanged(ITextSelection)</code> * is called.</li> * <li>if selection is of type <code>IStructuredSelection</code> then * <code>run(IStructuredSelection)</code> and <code> * selectionChanged(IStructuredSelection)</code> is called.</li> * <li>default is to call <code>run(ISelection)</code> and <code> * selectionChanged(ISelection)</code>.</li> * </ul> * * <p> * Note: This class is not intended to be subclassed outside the JDT UI plugin. * </p> * * @since 2.0 */ public abstract class SelectionDispatchAction extends Action implements ISelectionChangedListener { private IWorkbenchSite fSite; /** * Creates a new action with no text and no image. * <p> * Configure the action later using the set methods. * </p> * * @param site the site this action is working on */ protected SelectionDispatchAction(IWorkbenchSite site) { Assert.isNotNull(site); fSite= site; } /** * Returns the site owning this action. * * @return the site owning this action */ public IWorkbenchSite getSite() { return fSite; } /** * Returns the selection provided by the site owning this action. * * @return the site's selection */ public ISelection getSelection() { if (getSelectionProvider() != null) return getSelectionProvider().getSelection(); else return null; } /** * Returns the shell provided by the site owning this action. * * @return the site's shell */ public Shell getShell() { return fSite.getShell(); } /** * Returns the selection provider managed by the site owning this action. * * @return the site's selection provider */ public ISelectionProvider getSelectionProvider() { return fSite.getSelectionProvider(); } /** * Updates the action's enablement state according to the given selection. This * default implementation calls one of the <code>selectionChanged</code> * methods depending on the type of the passed selection. * * @param selection the selection this action is working on */ public void update(ISelection selection) { dispatchSelectionChanged(selection); } /** * Notifies this action that the given structured selection has changed. This default * implementation calls <code>selectionChanged(ISelection selection)</code>. * * @param selection the new selection */ public void selectionChanged(IStructuredSelection selection) { selectionChanged((ISelection)selection); } /** * Executes this actions with the given structured selection. This default implementation * calls <code>run(ISelection selection)</code>. */ public void run(IStructuredSelection selection) { run((ISelection)selection); } /** * Notifies this action that the given text selection has changed. This default * implementation calls <code>selectionChanged(ISelection selection)</code>. * * @param selection the new selection */ protected void selectionChanged(ITextSelection selection) { selectionChanged((ISelection)selection); } /** * Executes this actions with the given text selection. This default implementation * calls <code>run(ISelection selection)</code>. */ public void run(ITextSelection selection) { run((ISelection)selection); } /** * Notifies this action that the given selection has changed. This default * implementation sets the action's enablement state to <code>false</code>. * * @param selection the new selection */ public void selectionChanged(ISelection selection) { setEnabled(false); } /** * Executes this actions with the given selection. This default implementation * does nothing. */ public void run(ISelection selection) { } /* (non-Javadoc) * Method declared on IAction. */ public void run() { dispatchRun(getSelection()); } /* (non-Javadoc) * Method declared on ISelectionChangedListener. */ public void selectionChanged(SelectionChangedEvent event) { dispatchSelectionChanged(event.getSelection()); } private void dispatchSelectionChanged(ISelection selection) { if (selection instanceof IStructuredSelection) { selectionChanged((IStructuredSelection)selection); } else if (selection instanceof ITextSelection) { selectionChanged((ITextSelection)selection); } else { selectionChanged(selection); } } private void dispatchRun(ISelection selection) { if (selection instanceof IStructuredSelection) { run((IStructuredSelection)selection); } else if (selection instanceof ITextSelection) { run((ITextSelection)selection); } else { run(selection); } } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/SelfEncapsulateFieldAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.actions.ActionMessages; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.refactoring.sef.SelfEncapsulateFieldWizard; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.refactoring.sef.SelfEncapsulateFieldRefactoring; import org.eclipse.jdt.internal.corext.util.WorkingCopyUtil; /** * Action to run the self encapsulate field refactoring. * <p> * Action is applicable to selections containing elements of type * <code>IField</code>. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class SelfEncapsulateFieldAction extends SelectionDispatchAction { private CompilationUnitEditor fEditor; /** * Creates a new <code>SelfEncapsulateFieldAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public SelfEncapsulateFieldAction(IWorkbenchSite site) { super(site); setText(ActionMessages.getString("SelfEncapsulateFieldAction.label")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.SELF_ENCAPSULATE_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public SelfEncapsulateFieldAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /* (non-Javadoc) * Method declared on SelectionDispatchAction. */ public void selectionChanged(ITextSelection selection) { } /* (non-Javadoc) * Method declared on SelectionDispatchAction. */ public void selectionChanged(IStructuredSelection selection) { setEnabled(checkEnabled(selection)); } private boolean checkEnabled(IStructuredSelection selection) { if (selection.size() != 1) return false; Object element= selection.getFirstElement(); if (!(element instanceof IField)) return false; return !((IField)element).isBinary(); } /* (non-Javadoc) * Method declared on SelectionDispatchAction. */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; IJavaElement[] elements= SelectionConverter.codeResolveHandled(fEditor, getShell(), getDialogTitle()); if (elements.length != 1 || !(elements[0] instanceof IField)) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.getString("SelfEncapsulateFieldAction.dialog.unavailable")); //$NON-NLS-1$ return; } IField field= (IField)elements[0]; if (field.isBinary()) return; run(field); } /* (non-Javadoc) * Method declared on SelectionDispatchAction. */ public void run(IStructuredSelection selection) { if (!checkEnabled(selection)) return; run((IField)selection.getFirstElement()); } public void run(IField selectedField) { if (!ActionUtil.isProcessable(getShell(), selectedField)) return; IField field= null; try { field= (IField)WorkingCopyUtil.getWorkingCopyIfExists(selectedField); } catch (JavaModelException e) { } if (field == null) { MessageDialog.openInformation( getShell(), getDialogTitle(), ActionMessages.getFormattedString("SelfEncapsulateFieldAction.dialog.field_doesnot_exit", selectedField.getElementName())); //$NON-NLS-1$ return; } try { SelfEncapsulateFieldRefactoring refactoring= createRefactoring(field); if (refactoring == null) return; new RefactoringStarter().activate( refactoring, new SelfEncapsulateFieldWizard(refactoring), getShell(), getDialogTitle(), true); } catch (JavaModelException e) { ExceptionHandler.handle(e, getDialogTitle(), ActionMessages.getString("SelfEncapsulateFieldAction.dialog.cannot_perform")); //$NON-NLS-1$ } } private SelfEncapsulateFieldRefactoring createRefactoring(IField field) throws JavaModelException { return SelfEncapsulateFieldRefactoring.create(field); } private String getDialogTitle() { return ActionMessages.getString("SelfEncapsulateFieldAction.dialog.title"); //$NON-NLS-1$ } }
47,838
Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
verified fixed
d4785a8
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T13:22:10Z
2003-12-01T20:20:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/UseSupertypeAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.UseSupertypeWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.Assert; import org.eclipse.jdt.internal.corext.refactoring.structure.UseSupertypeWherePossibleRefactoring; import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; /** * Tries to use a super type of a class where possible. * * @since 2.1 */ public class UseSupertypeAction extends SelectionDispatchAction{ private CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public UseSupertypeAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /** * Creates a new <code>UseSupertypeAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public UseSupertypeAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("UseSupertypeAction.use_Supertype")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.USE_SUPERTYPE_ACTION); } /* * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.filterNotPresentException(e)) JavaPlugin.log(e); setEnabled(false);//no ui - happens on selection changes } } /* * @see SelectionDispatchAction#selectionChanged(ITextSelection) */ public void selectionChanged(ITextSelection selection) { //do nothing, this happens too often } /* * @see SelectionDispatchAction#run(IStructuredSelection) */ public void run(IStructuredSelection selection) { try { if (canEnable(selection)) startRefactoring(getSingleSelectedType(selection)); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } /* * @see SelectionDispatchAction#run(ITextSelection) */ public void run(ITextSelection selection) { try { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; IType type= getSingleSelectedType(); if (canRunOn(type)){ startRefactoring(type); } else { String unavailable= RefactoringMessages.getString("UseSupertypeAction.to_activate"); //$NON-NLS-1$ MessageDialog.openInformation(getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.unavailable"), unavailable); //$NON-NLS-1$ } } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } private static boolean canEnable(IStructuredSelection selection) throws JavaModelException{ return canRunOn(getSingleSelectedType(selection)); } private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException{ if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; } private IType getSingleSelectedType(){ IJavaElement[] elements= resolveElements(); if (elements.length != 1) return null; if (elements[0] instanceof IType) return (IType)elements[0]; return null; } private static boolean canRunOn(IType type) throws JavaModelException{ return UseSupertypeWherePossibleRefactoring.isAvailable(type); } private IJavaElement[] resolveElements() { return SelectionConverter.codeResolveHandled(fEditor, getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring")); //$NON-NLS-1$ } private static RefactoringWizard createWizard(UseSupertypeWherePossibleRefactoring refactoring){ return new UseSupertypeWizard(refactoring); } private void startRefactoring(IType type) throws JavaModelException { UseSupertypeWherePossibleRefactoring refactoring= UseSupertypeWherePossibleRefactoring.create(type, JavaPreferencesSettings.getCodeGenerationSettings()); Assert.isNotNull(refactoring); // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=19104 if (!ActionUtil.isProcessable(getShell(), refactoring.getInputType())) return; Object newElementToProcess= new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), true); //$NON-NLS-1$ if (newElementToProcess == null) return; IStructuredSelection mockSelection= new StructuredSelection(newElementToProcess); selectionChanged(mockSelection); if (isEnabled()) run(mockSelection); else MessageDialog.openInformation(getShell(), RefactoringMessages.getString("UseSupertypeAction.Refactoring"), RefactoringMessages.getString("UseSupertypeAction.not_possible")); //$NON-NLS-1$ //$NON-NLS-2$ } }
47,874
Bug 47874 Change Method Signature: enable if cursor is in signature [refactoring]
M5 Currently the user has to select the method name. Would be better if the refactoring will work if the cursor is inside the method's signature.
resolved fixed
18d4077
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T17:19:36Z
2003-12-02T10:13:20Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ModifyParametersAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionMessages; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.refactoring.ChangeSignatureWizard; import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; import org.eclipse.jdt.internal.corext.Assert; import org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureRefactoring; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; /** * Action to start the modify parameters refactoring. The refactoring supports * swapping and renaming of arguments. * <p> * This action is applicable to selections containing a method with one or * more arguments. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class ModifyParametersAction extends SelectionDispatchAction { private CompilationUnitEditor fEditor; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public ModifyParametersAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } /** * Creates a new <code>ModifyParametersAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public ModifyParametersAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("RefactoringGroup.modify_Parameters_label"));//$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.MODIFY_PARAMETERS_ACTION); } /* * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) */ public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.filterNotPresentException(e)) JavaPlugin.log(e); setEnabled(false);//no ui here - happens on selection changes } } /* * @see SelectionDispatchAction#selectionChanged(ITextSelection) */ public void selectionChanged(ITextSelection selection) { setEnabled(true); } /** * Note: This method is for internal use only. Clients should not call this method. */ public void selectionChanged(JavaTextSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { setEnabled(false); } } private boolean canEnable(JavaTextSelection selection) throws JavaModelException { IJavaElement[] elements= selection.resolveElementAtOffset(); if (elements.length != 1) return false; if (! (elements[0] instanceof IMethod)) return false; return ChangeSignatureRefactoring.isAvailable((IMethod)elements[0]); } /* * @see SelectionDispatchAction#run(IStructuredSelection) */ public void run(IStructuredSelection selection) { try { //we have to call this here - no selection changed event is sent after a refactoring but it may still invalidate enablement if (canEnable(selection)) startRefactoring(getSingleSelectedMethod(selection)); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } /* * @see SelectionDispatchAction#run(ITextSelection) */ public void run(ITextSelection selection) { try { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; IMethod singleSelectedMethod= getSingleSelectedMethod(selection); if (canRunOn(singleSelectedMethod)){ startRefactoring(singleSelectedMethod); } else { String unavailable= RefactoringMessages.getString("ModifyParametersAction.unavailable"); //$NON-NLS-1$ MessageDialog.openInformation(getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.unavailable"), unavailable); //$NON-NLS-1$ } } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), RefactoringMessages.getString("OpenRefactoringWizardAction.exception")); //$NON-NLS-1$ //$NON-NLS-2$ } } private static boolean canEnable(IStructuredSelection selection) throws JavaModelException{ return canRunOn(getSingleSelectedMethod(selection)); } private static IMethod getSingleSelectedMethod(IStructuredSelection selection){ if (selection.isEmpty() || selection.size() != 1) return null; if (selection.getFirstElement() instanceof IMethod) return (IMethod)selection.getFirstElement(); return null; } private IMethod getSingleSelectedMethod(ITextSelection selection) throws JavaModelException{ IJavaElement[] elements= resolveElements(); if (elements.length != 1) return null; if (elements[0] instanceof IMethod) return (IMethod)elements[0]; IJavaElement elementAt= SelectionConverter.getInputAsCompilationUnit(fEditor).getElementAt(selection.getOffset()); if (elementAt instanceof IMethod) return (IMethod)elementAt; return null; } private static boolean canRunOn(IMethod method) throws JavaModelException{ return ChangeSignatureRefactoring.isAvailable(method); } private static ChangeSignatureRefactoring createRefactoring(IMethod method) throws JavaModelException{ return ChangeSignatureRefactoring.create(method, JavaPreferencesSettings.getCodeGenerationSettings()); } private IJavaElement[] resolveElements() { return SelectionConverter.codeResolveHandled(fEditor, getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring")); //$NON-NLS-1$ } private static RefactoringWizard createWizard(ChangeSignatureRefactoring refactoring){ return new ChangeSignatureWizard(refactoring); } private void startRefactoring(IMethod method) throws JavaModelException { ChangeSignatureRefactoring refactoring= createRefactoring(method); Assert.isNotNull(refactoring); // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=19104 if (!ActionUtil.isProcessable(getShell(), refactoring.getMethod())) return; Object newElementToProcess= new RefactoringStarter().activate(refactoring, createWizard(refactoring), getShell(), RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), true); //$NON-NLS-1$ if (newElementToProcess == null) return; IStructuredSelection mockSelection= new StructuredSelection(newElementToProcess); selectionChanged(mockSelection); if (isEnabled()) run(mockSelection); else MessageDialog.openInformation(getShell(), ActionMessages.getString("ModifyParameterAction.problem.title"), ActionMessages.getString("ModifyParameterAction.problem.message")); //$NON-NLS-1$ //$NON-NLS-2$ } }
48,473
Bug 48473 code and comments preference section is blank
I will atach a screen shot to demonstrate
verified fixed
4ad3a82
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-11T19:46:49Z
2003-12-11T10:53:20Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/NameConventionConfigurationBlock.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.preferences; import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.IStatus; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ColumnLayoutData; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaConventions; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ui.JavaElementImageDescriptor; import org.eclipse.jdt.ui.PreferenceConstants; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.dialogs.StatusDialog; import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; import org.eclipse.jdt.internal.ui.util.SWTUtil; import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry; import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter; import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField; import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField; /* * The page to configure name conventions */ public class NameConventionConfigurationBlock extends OptionsConfigurationBlock { private final static int FIELD= 1; private final static int STATIC= 2; private final static int ARGUMENT= 3; private final static int LOCAL= 4; // Preference store keys, see JavaCore.getOptions private static final String PREF_FIELD_PREFIXES= JavaCore.CODEASSIST_FIELD_PREFIXES; private static final String PREF_FIELD_SUFFIXES= JavaCore.CODEASSIST_FIELD_SUFFIXES; private static final String PREF_STATIC_FIELD_PREFIXES= JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES; private static final String PREF_STATIC_FIELD_SUFFIXES= JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES; private static final String PREF_ARGUMENT_PREFIXES= JavaCore.CODEASSIST_ARGUMENT_PREFIXES; private static final String PREF_ARGUMENT_SUFFIXES= JavaCore.CODEASSIST_ARGUMENT_SUFFIXES; private static final String PREF_LOCAL_PREFIXES= JavaCore.CODEASSIST_LOCAL_PREFIXES; private static final String PREF_LOCAL_SUFFIXES= JavaCore.CODEASSIST_LOCAL_SUFFIXES; private static class NameConventionEntry { public int kind; public String prefix; public String suffix; public String prefixkey; public String suffixkey; } private class NameConventionInputDialog extends StatusDialog implements IDialogFieldListener { private StringDialogField fPrefixField; private StringDialogField fSuffixField; private NameConventionEntry fEntry; private DialogField fMessageField; public NameConventionInputDialog(Shell parent, String title, String message, NameConventionEntry entry) { super(parent); fEntry= entry; setTitle(title); fMessageField= new DialogField(); fMessageField.setLabelText(message); fPrefixField= new StringDialogField(); fPrefixField.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.dialog.prefix")); //$NON-NLS-1$ fPrefixField.setDialogFieldListener(this); fSuffixField= new StringDialogField(); fSuffixField.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.dialog.suffix")); //$NON-NLS-1$ fSuffixField.setDialogFieldListener(this); fPrefixField.setText(entry.prefix); fSuffixField.setText(entry.suffix); } public NameConventionEntry getResult() { NameConventionEntry res= new NameConventionEntry(); res.prefix= fPrefixField.getText(); res.suffix= fSuffixField.getText(); res.prefixkey= fEntry.prefixkey; res.suffixkey= fEntry.suffixkey; res.kind= fEntry.kind; return res; } protected Control createDialogArea(Composite parent) { Composite composite= (Composite) super.createDialogArea(parent); Composite inner= new Composite(composite, SWT.NONE); GridLayout layout= new GridLayout(); layout.marginHeight= 0; layout.marginWidth= 0; layout.numColumns= 2; inner.setLayout(layout); fMessageField.doFillIntoGrid(inner, 2); fPrefixField.doFillIntoGrid(inner, 2); fSuffixField.doFillIntoGrid(inner, 2); LayoutUtil.setHorizontalGrabbing(fPrefixField.getTextControl(null)); LayoutUtil.setWidthHint(fPrefixField.getTextControl(null), convertWidthInCharsToPixels(45)); LayoutUtil.setWidthHint(fSuffixField.getTextControl(null), convertWidthInCharsToPixels(45)); fPrefixField.postSetFocusOnDialogField(parent.getDisplay()); applyDialogFont(composite); return composite; } /* (non-Javadoc) * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) */ public void dialogFieldChanged(DialogField field) { // validate IStatus prefixStatus= validateIdentifiers(getTokens(fPrefixField.getText(), ","), true); //$NON-NLS-1$ IStatus suffixStatus= validateIdentifiers(getTokens(fSuffixField.getText(), ","), false); //$NON-NLS-1$ updateStatus(StatusUtil.getMoreSevere(suffixStatus, prefixStatus)); } private IStatus validateIdentifiers(String[] values, boolean prefix) { for (int i= 0; i < values.length; i++) { String val= values[i]; if (val.length() == 0) { if (prefix) { return new StatusInfo(IStatus.ERROR, PreferencesMessages.getString("NameConventionConfigurationBlock.error.emptyprefix")); //$NON-NLS-1$ } else { return new StatusInfo(IStatus.ERROR, PreferencesMessages.getString("NameConventionConfigurationBlock.error.emptysuffix")); //$NON-NLS-1$ } } String name= prefix ? val + "x" : "x" + val; //$NON-NLS-2$ //$NON-NLS-1$ IStatus status= JavaConventions.validateFieldName(name); if (status.matches(IStatus.ERROR)) { if (prefix) { return new StatusInfo(IStatus.ERROR, PreferencesMessages.getFormattedString("NameConventionConfigurationBlock.error.invalidprefix", val)); //$NON-NLS-1$ } else { return new StatusInfo(IStatus.ERROR, PreferencesMessages.getFormattedString("NameConventionConfigurationBlock.error.invalidsuffix", val)); //$NON-NLS-1$ } } } return new StatusInfo(); } /* * @see org.eclipse.jface.window.Window#configureShell(Shell) */ protected void configureShell(Shell newShell) { super.configureShell(newShell); //WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.IMPORT_ORGANIZE_INPUT_DIALOG); } } private static class NameConventionLabelProvider extends LabelProvider implements ITableLabelProvider { /* (non-Javadoc) * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) */ public Image getImage(Object element) { return getColumnImage(element, 0); } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) */ public String getText(Object element) { return getColumnText(element, 0); } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) */ public Image getColumnImage(Object element, int columnIndex) { if (columnIndex != 0) { return null; } NameConventionEntry entry= (NameConventionEntry) element; ImageDescriptorRegistry registry= JavaPlugin.getImageDescriptorRegistry(); switch (entry.kind) { case FIELD: return registry.get(JavaPluginImages.DESC_FIELD_PUBLIC); case STATIC: return registry.get(new JavaElementImageDescriptor(JavaPluginImages.DESC_FIELD_PUBLIC, JavaElementImageDescriptor.STATIC, JavaElementImageProvider.SMALL_SIZE)); case ARGUMENT: return registry.get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE); default: return registry.get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE); } } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) */ public String getColumnText(Object element, int columnIndex) { NameConventionEntry entry= (NameConventionEntry) element; if (columnIndex == 0) { switch (entry.kind) { case FIELD: return PreferencesMessages.getString("NameConventionConfigurationBlock.field.label"); //$NON-NLS-1$ case STATIC: return PreferencesMessages.getString("NameConventionConfigurationBlock.static.label"); //$NON-NLS-1$ case ARGUMENT: return PreferencesMessages.getString("NameConventionConfigurationBlock.arg.label"); //$NON-NLS-1$ default: return PreferencesMessages.getString("NameConventionConfigurationBlock.local.label"); //$NON-NLS-1$ } } else if (columnIndex == 1) { return entry.prefix; } else { return entry.suffix; } } } private class NameConventionAdapter implements IListAdapter, IDialogFieldListener { private boolean canEdit(ListDialogField field) { return field.getSelectedElements().size() == 1; } public void customButtonPressed(ListDialogField field, int index) { doEditButtonPressed(); } public void selectionChanged(ListDialogField field) { field.enableButton(0, canEdit(field)); } public void doubleClicked(ListDialogField field) { if (canEdit(field)) { doEditButtonPressed(); } } public void dialogFieldChanged(DialogField field) { validateSettings(null, null); } } private ListDialogField fNameConventionList; private SelectionButtonDialogField fUseKeywordThisBox; private SelectionButtonDialogField fUseIsForBooleanGettersBox; private static final String PREF_KEYWORD_THIS= PreferenceConstants.CODEGEN_KEYWORD_THIS; private static final String PREF_IS_FOR_GETTERS= PreferenceConstants.CODEGEN_IS_FOR_GETTERS; private static final String PREF_EXCEPTION_NAME= PreferenceConstants.CODEGEN_EXCEPTION_VAR_NAME; private StringDialogField fExceptionName; public NameConventionConfigurationBlock(IStatusChangeListener context, IJavaProject project) { super(context, project); NameConventionAdapter adapter= new NameConventionAdapter(); String[] buttons= new String[] { /* 0 */ PreferencesMessages.getString("NameConventionConfigurationBlock.list.edit.button") //$NON-NLS-1$ }; fNameConventionList= new ListDialogField(adapter, buttons, new NameConventionLabelProvider()); fNameConventionList.setDialogFieldListener(adapter); fNameConventionList.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.list.label")); //$NON-NLS-1$ String[] columnsHeaders= new String[] { PreferencesMessages.getString("NameConventionConfigurationBlock.list.name.column"), //$NON-NLS-1$ PreferencesMessages.getString("NameConventionConfigurationBlock.list.prefix.column"), //$NON-NLS-1$ PreferencesMessages.getString("NameConventionConfigurationBlock.list.suffix.column"), //$NON-NLS-1$ }; ColumnLayoutData[] data= new ColumnLayoutData[] { new ColumnWeightData(3), new ColumnWeightData(2), new ColumnWeightData(2) }; fNameConventionList.setTableColumns(new ListDialogField.ColumnsDescription(data, columnsHeaders, true)); unpackEntries(); if (fNameConventionList.getSize() > 0) { fNameConventionList.selectFirstElement(); } else { fNameConventionList.enableButton(0, false); } IPreferenceStore preferenceStore= PreferenceConstants.getPreferenceStore(); fExceptionName= new StringDialogField(); fExceptionName.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.exceptionname.label")); //$NON-NLS-1$ fExceptionName.setText(preferenceStore.getString(PREF_EXCEPTION_NAME)); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=38879 fUseKeywordThisBox= new SelectionButtonDialogField(SWT.CHECK | SWT.WRAP); fUseKeywordThisBox.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.keywordthis.label")); //$NON-NLS-1$ fUseKeywordThisBox.setSelection(preferenceStore.getBoolean(PREF_KEYWORD_THIS)); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=39044 fUseIsForBooleanGettersBox= new SelectionButtonDialogField(SWT.CHECK | SWT.WRAP); fUseIsForBooleanGettersBox.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.isforbooleangetters.label")); //$NON-NLS-1$ fUseIsForBooleanGettersBox.setSelection(preferenceStore.getBoolean(PREF_IS_FOR_GETTERS)); } protected String[] getAllKeys() { return new String[] { PREF_FIELD_PREFIXES, PREF_FIELD_SUFFIXES, PREF_STATIC_FIELD_PREFIXES, PREF_STATIC_FIELD_SUFFIXES, PREF_ARGUMENT_PREFIXES, PREF_ARGUMENT_SUFFIXES, PREF_LOCAL_PREFIXES, PREF_LOCAL_SUFFIXES }; } protected Control createContents(Composite parent) { setShell(parent.getShell()); GridLayout layout= new GridLayout(); layout.numColumns= 3; Composite composite= new Composite(parent, SWT.NONE); composite.setLayout(layout); fNameConventionList.doFillIntoGrid(composite, 4); LayoutUtil.setHorizontalSpan(fNameConventionList.getLabelControl(null), 2); Table table= fNameConventionList.getTableViewer().getTable(); GridData data= (GridData)fNameConventionList.getListControl(null).getLayoutData(); data.heightHint= SWTUtil.getTableHeightHint(table, 5); data.grabExcessHorizontalSpace= true; data.verticalAlignment= GridData.BEGINNING; data.grabExcessVerticalSpace= false; data= (GridData)fNameConventionList.getButtonBox(null).getLayoutData(); data.grabExcessVerticalSpace= false; data.verticalAlignment= GridData.BEGINNING; fUseKeywordThisBox.doFillIntoGrid(composite, 3); fUseIsForBooleanGettersBox.doFillIntoGrid(composite, 3); fExceptionName.doFillIntoGrid(composite, 2); DialogField.createEmptySpace(parent); return composite; } /* (non-Javadoc) * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(java.lang.String, java.lang.String) */ protected void validateSettings(String changedKey, String newValue) { // no validation } /* (non-Javadoc) * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#updateControls() */ protected void updateControls() { unpackEntries(); } /* (non-Javadoc) * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean) */ protected String[] getFullBuildDialogStrings(boolean workspaceSettings) { return null; // no build required } private void createEntry(List list, String prefixKey, String suffixKey, int kind) { NameConventionEntry entry= new NameConventionEntry(); entry.kind= kind; entry.suffixkey= suffixKey; entry.prefixkey= prefixKey; entry.suffix= (String) fWorkingValues.get(suffixKey); entry.prefix= (String) fWorkingValues.get(prefixKey); list.add(entry); } private void unpackEntries() { ArrayList list= new ArrayList(4); createEntry(list, PREF_FIELD_PREFIXES, PREF_FIELD_SUFFIXES, FIELD); createEntry(list, PREF_STATIC_FIELD_PREFIXES, PREF_STATIC_FIELD_SUFFIXES, STATIC); createEntry(list, PREF_ARGUMENT_PREFIXES, PREF_ARGUMENT_SUFFIXES, ARGUMENT); createEntry(list, PREF_LOCAL_PREFIXES, PREF_LOCAL_SUFFIXES, LOCAL); fNameConventionList.setElements(list); } private void packEntries() { for (int i= 0; i < fNameConventionList.getSize(); i++) { NameConventionEntry entry= (NameConventionEntry) fNameConventionList.getElement(i); fWorkingValues.put(entry.suffixkey, entry.suffix); fWorkingValues.put(entry.prefixkey, entry.prefix); } } private void doEditButtonPressed() { NameConventionEntry entry= (NameConventionEntry) fNameConventionList.getSelectedElements().get(0); String title; String message; switch (entry.kind) { case FIELD: title= PreferencesMessages.getString("NameConventionConfigurationBlock.field.dialog.title"); //$NON-NLS-1$ message= PreferencesMessages.getString("NameConventionConfigurationBlock.field.dialog.message"); //$NON-NLS-1$ break; case STATIC: title= PreferencesMessages.getString("NameConventionConfigurationBlock.static.dialog.title"); //$NON-NLS-1$ message= PreferencesMessages.getString("NameConventionConfigurationBlock.static.dialog.message"); //$NON-NLS-1$ break; case ARGUMENT: title= PreferencesMessages.getString("NameConventionConfigurationBlock.arg.dialog.title"); //$NON-NLS-1$ message= PreferencesMessages.getString("NameConventionConfigurationBlock.arg.dialog.message"); //$NON-NLS-1$ break; default: title= PreferencesMessages.getString("NameConventionConfigurationBlock.local.dialog.title"); //$NON-NLS-1$ message= PreferencesMessages.getString("NameConventionConfigurationBlock.local.dialog.message"); //$NON-NLS-1$ } NameConventionInputDialog dialog= new NameConventionInputDialog(getShell(), title, message, entry); if (dialog.open() == Window.OK) { fNameConventionList.replaceElement(entry, dialog.getResult()); } } /* (non-Javadoc) * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performDefaults() */ public void performDefaults() { super.performDefaults(); IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); fExceptionName.setText(prefs.getDefaultString(PREF_EXCEPTION_NAME)); fUseKeywordThisBox.setSelection(prefs.getDefaultBoolean(PREF_KEYWORD_THIS)); fUseIsForBooleanGettersBox.setSelection(prefs.getDefaultBoolean(PREF_IS_FOR_GETTERS)); } /* (non-Javadoc) * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performOk(boolean) */ public boolean performOk(boolean enabled) { IPreferenceStore prefs= PreferenceConstants.getPreferenceStore(); prefs.setValue(PREF_EXCEPTION_NAME, fExceptionName.getText()); prefs.setValue(PREF_KEYWORD_THIS, fUseKeywordThisBox.isSelected()); prefs.setValue(PREF_IS_FOR_GETTERS, fUseIsForBooleanGettersBox.isSelected()); JavaPlugin.getDefault().savePluginPreferences(); packEntries(); return super.performOk(enabled); } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/JavaSearchResultLabelProvider.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.search; import org.eclipse.core.resources.IMarker; import org.eclipse.swt.graphics.Image; import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.ui.PlatformUI; import org.eclipse.search.ui.ISearchResultViewEntry; import org.eclipse.search.ui.SearchUI; import org.eclipse.jdt.core.IImportDeclaration; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.ui.ProblemsLabelDecorator; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels; public class JavaSearchResultLabelProvider extends LabelProvider { public static final int SHOW_ELEMENT_CONTAINER= 1; // default public static final int SHOW_CONTAINER_ELEMENT= 2; public static final int SHOW_PATH= 3; public static final String POTENTIAL_MATCH= SearchMessages.getString("JavaSearchResultLabelProvider.potentialMatch"); //$NON-NLS-1$ private AppearanceAwareLabelProvider fLabelProvider; private ILabelDecorator fDecorator; // Cache private IMarker fLastMarker; private IJavaElement fLastJavaElement; public JavaSearchResultLabelProvider() { fDecorator= PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(); fLabelProvider= new AppearanceAwareLabelProvider( AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.P_COMPRESSED, AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS); fLabelProvider.addLabelDecorator(new ProblemsLabelDecorator(null)); } public String getText(Object o) { fLastMarker= null; // reset cache IJavaElement javaElement= getJavaElement(o); // sets fLastMarker as side effect boolean isPotentialMatch= fLastMarker != null && fLastMarker.getAttribute(SearchUI.POTENTIAL_MATCH, false); if (javaElement == null) { if (fLastMarker != null) { if (isPotentialMatch) return super.getText(fLastMarker.getResource()) + POTENTIAL_MATCH; else return super.getText(fLastMarker.getResource()); } else return ""; //$NON-NLS-1$ } if (javaElement instanceof IImportDeclaration) javaElement= ((IImportDeclaration)javaElement).getParent().getParent(); String text= ""; //$NON-NLS-1$ if (isPotentialMatch) text= fLabelProvider.getText(javaElement) + POTENTIAL_MATCH; else text= fLabelProvider.getText(javaElement); if (fDecorator != null) { String decoratedText= fDecorator.decorateText(text, javaElement); if (decoratedText != null) return decoratedText; } return text; } public Image getImage(Object o) { IJavaElement javaElement= getJavaElement(o); if (javaElement == null) return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_UNKNOWN); Image image= fLabelProvider.getImage(javaElement); if (image == null) return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_UNKNOWN); if (fDecorator != null) { Image decoratedImage= fDecorator.decorateImage(image, javaElement); if (decoratedImage != null) return decoratedImage; } return image; } public void setOrder(int orderFlag) { int flags= AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.P_COMPRESSED; if (orderFlag == SHOW_ELEMENT_CONTAINER) flags |= JavaElementLabels.F_POST_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.I_POST_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.T_POST_QUALIFIED | JavaElementLabels.D_POST_QUALIFIED | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED; else if (orderFlag == SHOW_CONTAINER_ELEMENT) flags |= JavaElementLabels.F_FULLY_QUALIFIED | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.I_FULLY_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.D_QUALIFIED | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED; else if (orderFlag == SHOW_PATH) { flags |= JavaElementLabels.F_FULLY_QUALIFIED | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.I_FULLY_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.D_QUALIFIED | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED; flags |= JavaElementLabels.PREPEND_ROOT_PATH; } fLabelProvider.setTextFlags(flags); } private IJavaElement getJavaElement(Object o) { if (o instanceof IJavaElement) return (IJavaElement)o; IMarker marker= getMarker(o); if (marker == null) return null; return getJavaElement(marker, (ISearchResultViewEntry)o); } protected IMarker getMarker(Object o) { if (!(o instanceof ISearchResultViewEntry)) return null; return ((ISearchResultViewEntry)o).getSelectedMarker(); } private IJavaElement getJavaElement(IMarker marker, ISearchResultViewEntry entry) { if (fLastMarker != marker) { boolean canUseGroupByKey= !marker.getAttribute(SearchUI.POTENTIAL_MATCH, false) && !marker.getAttribute(IJavaSearchUIConstants.ATT_IS_WORKING_COPY, false) && !marker.getAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID_CHANGED, false); if (canUseGroupByKey && entry.getGroupByKey() instanceof IJavaElement) fLastJavaElement= (IJavaElement)entry.getGroupByKey(); else fLastJavaElement= SearchUtil.getJavaElement(marker); fLastMarker= marker; } return fLastJavaElement; } public void addListener(ILabelProviderListener listener) { super.addListener(listener); fLabelProvider.addListener(listener); } public void dispose() { super.dispose(); fLabelProvider.dispose(); } public boolean isLabelProperty(Object element, String property) { return fLabelProvider.isLabelProperty(element, property); } public void removeListener(ILabelProviderListener listener) { super.removeListener(listener); fLabelProvider.removeListener(listener); } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import java.lang.reflect.InvocationTargetException; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IWorkspaceDescription; import org.eclipse.core.runtime.CoreException; import org.eclipse.swt.widgets.Shell; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.search.ui.SearchUI; import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMember; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.SearchEngine; import org.eclipse.jdt.ui.JavaElementLabelProvider; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.actions.SelectionConverter; import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.JavaSearchOperation; import org.eclipse.jdt.internal.ui.search.JavaSearchResultCollector; import org.eclipse.jdt.internal.ui.search.SearchMessages; import org.eclipse.jdt.internal.ui.search.SearchUtil; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; /** * Abstract class for Java search actions. * <p> * Note: This class is for internal use only. Clients should not use this class. * </p> * * @since 2.0 */ public abstract class FindAction extends SelectionDispatchAction { // A dummy which can't be selected in the UI private static final IJavaElement RETURN_WITHOUT_BEEP= JavaCore.create(JavaPlugin.getWorkspace().getRoot()); private Class[] fValidTypes; private JavaEditor fEditor; FindAction(IWorkbenchSite site, String label, Class[] validTypes) { super(site); setText(label); fValidTypes= validTypes; } FindAction(JavaEditor editor, String label, Class[] validTypes) { this (editor.getEditorSite(), label, validTypes); fEditor= editor; setEnabled(SelectionConverter.canOperateOn(fEditor)); } private boolean canOperateOn(IStructuredSelection sel) { return sel != null && !sel.isEmpty() && canOperateOn(getJavaElement(sel, true)); } boolean canOperateOn(IJavaElement element) { if (fValidTypes == null || fValidTypes.length == 0) return false; if (element != null) { for (int i= 0; i < fValidTypes.length; i++) { if (fValidTypes[i].isInstance(element)) { if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) return hasChildren((IPackageFragment)element); else return true; } } } return false; } private boolean hasChildren(IPackageFragment packageFragment) { try { return packageFragment.hasChildren(); } catch (JavaModelException ex) { return false; } } private IJavaElement getJavaElement(IJavaElement o, boolean silent) { if (o == null) return null; switch (o.getElementType()) { case IJavaElement.COMPILATION_UNIT: if (silent) return (ICompilationUnit)o; else return findType((ICompilationUnit)o, silent); case IJavaElement.CLASS_FILE: return findType((IClassFile)o); default: return o; } } private IJavaElement getJavaElement(IMarker marker, boolean silent) { return getJavaElement(SearchUtil.getJavaElement(marker), silent); } private IJavaElement getJavaElement(Object o, boolean silent) { if (o instanceof IJavaElement) return getJavaElement((IJavaElement)o, silent); else if (o instanceof IMarker) return getJavaElement((IMarker)o, silent); else if (o instanceof ISelection) return getJavaElement((IStructuredSelection)o, silent); else if (SearchUtil.isISearchResultViewEntry(o)) return getJavaElement(SearchUtil.getJavaElement(o), silent); return null; } IJavaElement getJavaElement(IStructuredSelection selection, boolean silent) { if (selection.size() == 1) // Selection only enabled if one element selected. return getJavaElement(selection.getFirstElement(), silent); return null; } private void showOperationUnavailableDialog() { MessageDialog.openInformation(getShell(), SearchMessages.getString("JavaElementAction.operationUnavailable.title"), getOperationUnavailableMessage()); //$NON-NLS-1$ } String getOperationUnavailableMessage() { return SearchMessages.getString("JavaElementAction.operationUnavailable.generic"); //$NON-NLS-1$ } private IJavaElement findType(ICompilationUnit cu, boolean silent) { IType[] types= null; try { types= cu.getAllTypes(); } catch (JavaModelException ex) { // silent mode ExceptionHandler.log(ex, SearchMessages.getString("JavaElementAction.error.open.message")); //$NON-NLS-1$ if (silent) return RETURN_WITHOUT_BEEP; else return null; } if (types.length == 1 || (silent && types.length > 0)) return types[0]; if (silent) return RETURN_WITHOUT_BEEP; if (types.length == 0) return null; String title= SearchMessages.getString("JavaElementAction.typeSelectionDialog.title"); //$NON-NLS-1$ String message = SearchMessages.getString("JavaElementAction.typeSelectionDialog.message"); //$NON-NLS-1$ int flags= (JavaElementLabelProvider.SHOW_DEFAULT); ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(flags)); dialog.setTitle(title); dialog.setMessage(message); dialog.setElements(types); if (dialog.open() == Window.OK) return (IType)dialog.getFirstResult(); else return RETURN_WITHOUT_BEEP; } private IType findType(IClassFile cf) { IType mainType; try { mainType= cf.getType(); } catch (JavaModelException ex) { ExceptionHandler.log(ex, SearchMessages.getString("JavaElementAction.error.open.message")); //$NON-NLS-1$ return null; } return mainType; } /* * Method declared on SelectionChangedAction. */ public void run(IStructuredSelection selection) { IJavaElement element= getJavaElement(selection, false); if (element == null || !element.exists()) { showOperationUnavailableDialog(); return; } else if (element == RETURN_WITHOUT_BEEP) return; run(element); } /* * Method declared on SelectionChangedAction. */ public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(getShell(), fEditor)) return; try { String title= SearchMessages.getString("SearchElementSelectionDialog.title"); //$NON-NLS-1$ String message= SearchMessages.getString("SearchElementSelectionDialog.message"); //$NON-NLS-1$ IJavaElement[] elements= SelectionConverter.codeResolve(fEditor); if (elements.length > 0 && canOperateOn(elements[0])) { IJavaElement element= elements[0]; if (elements.length > 1) element= SelectionConverter.codeResolve(fEditor, getShell(), title, message); run(element); } else showOperationUnavailableDialog(); } catch (JavaModelException ex) { JavaPlugin.log(ex); String title= SearchMessages.getString("Search.Error.search.title"); //$NON-NLS-1$ String message= SearchMessages.getString("Search.Error.codeResolve"); //$NON-NLS-1$ ErrorDialog.openError(getShell(), title, message, ex.getStatus()); } } /* * Method declared on SelectionChangedAction. */ public void selectionChanged(IStructuredSelection selection) { setEnabled(canOperateOn(selection)); } /* * Method declared on SelectionChangedAction. */ public void selectionChanged(ITextSelection selection) { } public void run(IJavaElement element) { if (!ActionUtil.isProcessable(getShell(), element)) return; SearchUI.activateSearchResultView(); Shell shell= JavaPlugin.getActiveWorkbenchShell(); JavaSearchOperation op= null; try { op= makeOperation(element); if (op == null) return; } catch (JavaModelException ex) { ExceptionHandler.handle(ex, shell, SearchMessages.getString("Search.Error.search.title"), SearchMessages.getString("Search.Error.search.message")); //$NON-NLS-1$ //$NON-NLS-2$ return; } IWorkspaceDescription workspaceDesc= JavaPlugin.getWorkspace().getDescription(); boolean isAutoBuilding= workspaceDesc.isAutoBuilding(); if (isAutoBuilding) { // disable auto-build during search operation workspaceDesc.setAutoBuilding(false); try { JavaPlugin.getWorkspace().setDescription(workspaceDesc); } catch (CoreException ex) { ExceptionHandler.handle(ex, shell, SearchMessages.getString("Search.Error.setDescription.title"), SearchMessages.getString("Search.Error.setDescription.message")); //$NON-NLS-1$ //$NON-NLS-2$ } } try { new ProgressMonitorDialog(shell).run(true, true, op); } catch (InvocationTargetException ex) { ExceptionHandler.handle(ex, shell, SearchMessages.getString("Search.Error.search.title"), SearchMessages.getString("Search.Error.search.message")); //$NON-NLS-1$ //$NON-NLS-2$ } catch(InterruptedException e) { } finally { if (isAutoBuilding) { // enable auto-building again workspaceDesc= JavaPlugin.getWorkspace().getDescription(); workspaceDesc.setAutoBuilding(true); try { JavaPlugin.getWorkspace().setDescription(workspaceDesc); } catch (CoreException ex) { ExceptionHandler.handle(ex, shell, SearchMessages.getString("Search.Error.setDescription.title"), SearchMessages.getString("Search.Error.setDescription.message")); //$NON-NLS-1$ //$NON-NLS-2$ } } } } JavaSearchOperation makeOperation(IJavaElement element) throws JavaModelException { IType type= getType(element); return new JavaSearchOperation(JavaPlugin.getWorkspace(), element, getLimitTo(), getScope(type), getScopeDescription(type), getCollector()); } abstract int getLimitTo(); IJavaSearchScope getScope(IType element) throws JavaModelException { return SearchEngine.createWorkspaceScope(); } JavaSearchResultCollector getCollector() { return new JavaSearchResultCollector(); } String getScopeDescription(IType type) { return SearchMessages.getString("WorkspaceScope"); //$NON-NLS-1$ } IType getType(IJavaElement element) { if (element == null) return null; IType type= null; if (element.getElementType() == IJavaElement.TYPE) type= (IType)element; else if (element instanceof IMember) type= ((IMember)element).getDeclaringType(); if (type != null) { ICompilationUnit cu= type.getCompilationUnit(); if (cu == null) return type; IType wcType= (IType)getWorkingCopy(type); if (wcType != null) return wcType; else return type; } return null; } /** * Tries to find the given element in a working copy. */ private IJavaElement getWorkingCopy(IJavaElement input) { try { if (input instanceof ICompilationUnit) return EditorUtility.getWorkingCopy((ICompilationUnit)input); else return EditorUtility.getWorkingCopy(input, true); } catch (JavaModelException ex) { } return null; } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindDeclarationsAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IImportDeclaration; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IPackageDeclaration; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.JavaSearchOperation; import org.eclipse.jdt.internal.ui.search.PrettySignature; import org.eclipse.jdt.internal.ui.search.SearchMessages; /** * Finds declarations of the selected element in the workspace. * The action is applicable to selections representing a Java element. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindDeclarationsAction extends FindAction { /** * Creates a new <code>FindDeclarationsAction</code>. The action requires * that the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindDeclarationsAction(IWorkbenchSite site) { this(site, SearchMessages.getString("Search.FindDeclarationAction.label"), new Class[] {IField.class, IMethod.class, IType.class, ICompilationUnit.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindDeclarationAction.tooltip")); //$NON-NLS-1$ } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindDeclarationsAction(JavaEditor editor) { this(editor, SearchMessages.getString("Search.FindDeclarationAction.label"), new Class[] {IField.class, IMethod.class, IType.class, ICompilationUnit.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindDeclarationAction.tooltip")); //$NON-NLS-1$ } FindDeclarationsAction(IWorkbenchSite site, String label, Class[] validTypes) { super(site, label, validTypes); setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_WORKSPACE_ACTION); } FindDeclarationsAction(JavaEditor editor, String label, Class[] validTypes) { super(editor, label, validTypes); setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_WORKSPACE_ACTION); } JavaSearchOperation makeOperation(IJavaElement element) throws JavaModelException { if (element.getElementType() == IJavaElement.METHOD) { IMethod method= (IMethod)element; int searchFor= IJavaSearchConstants.METHOD; if (method.isConstructor()) searchFor= IJavaSearchConstants.CONSTRUCTOR; IType type= getType(element); String pattern= PrettySignature.getUnqualifiedMethodSignature(method); return new JavaSearchOperation(JavaPlugin.getWorkspace(), pattern, true, searchFor, getLimitTo(), getScope(type), getScopeDescription(type), getCollector()); } else return super.makeOperation(element); } int getLimitTo() { return IJavaSearchConstants.DECLARATIONS; } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindDeclarationsInHierarchyAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.SearchEngine; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.SearchMessages; /** * Finds declarations of the selected element in its hierarchy. * The action is applicable to selections representing a Java element. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindDeclarationsInHierarchyAction extends FindDeclarationsAction { /** * Creates a new <code>FindDeclarationsInHierarchyAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindDeclarationsInHierarchyAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindHierarchyDeclarationsAction.label"), new Class[] {IField.class, IMethod.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindHierarchyDeclarationsAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_HIERARCHY_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindDeclarationsInHierarchyAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindHierarchyDeclarationsAction.label"), new Class[] {IField.class, IMethod.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindHierarchyDeclarationsAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_HIERARCHY_ACTION); } IJavaSearchScope getScope(IType type) throws JavaModelException { if (type != null) return SearchEngine.createHierarchyScope(type); else return super.getScope(type); } String getScopeDescription(IType type) { String typeName= ""; //$NON-NLS-1$ if (type != null) typeName= type.getElementName(); return SearchMessages.getFormattedString("HierarchyScope", new String[] {typeName}); //$NON-NLS-1$ } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindDeclarationsInProjectAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.core.resources.IResource; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IImportDeclaration; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IPackageDeclaration; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.JavaSearchOperation; import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; import org.eclipse.jdt.internal.ui.search.SearchMessages; import org.eclipse.jdt.internal.ui.search.SearchUtil; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; /** * Finds declarations of the selected element in the enclosing project * of the selected element. * The action is applicable to selections representing a Java element. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 3.0 */ public class FindDeclarationsInProjectAction extends FindDeclarationsAction { /** * Creates a new <code>FindDeclarationsInProjectAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindDeclarationsInProjectAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindDeclarationsInProjectAction.label"), new Class[] {IField.class, IMethod.class, IType.class, ICompilationUnit.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindDeclarationsInProjectAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_PROJECT_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindDeclarationsInProjectAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindDeclarationsInProjectAction.label"), new Class[] {IField.class, IMethod.class, IType.class, ICompilationUnit.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindDeclarationsInProjectAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_PROJECT_ACTION); } IJavaSearchScope getScope(IJavaElement element) throws JavaModelException { return JavaSearchScopeFactory.getInstance().createJavaSearchScope(new IResource[] { element.getJavaProject().getProject() }); } String getScopeDescription(IJavaElement element) { return SearchUtil.getProjectScopeDescription(element); } JavaSearchOperation makeOperation(IJavaElement element) throws JavaModelException { return new JavaSearchOperation(JavaPlugin.getWorkspace(), element, getLimitTo(), getScope(element), getScopeDescription(element), getCollector()); } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReadReferencesAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.SearchMessages; /** * Finds field read accesses of the selected element in the workspace. * The action is applicable to selections representing a Java interface field. * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindReadReferencesAction extends FindReferencesAction { /** * Creates a new <code>FindReadReferencesAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindReadReferencesAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindReadReferencesAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReadReferencesAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_WORKSPACE_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindReadReferencesAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindReadReferencesAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReadReferencesAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_WORKSPACE_ACTION); } int getLimitTo() { return IJavaSearchConstants.READ_ACCESSES; } String getOperationUnavailableMessage() { return SearchMessages.getString("JavaElementAction.operationUnavailable.field"); //$NON-NLS-1$ } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReadReferencesInHierarchyAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.SearchMessages; /** * Finds field read accesses of the selected element in its hierarchy. * The action is applicable to selections representing a Java field. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindReadReferencesInHierarchyAction extends FindReferencesInHierarchyAction { /** * Creates a new <code>FindReadReferencesInHierarchyAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindReadReferencesInHierarchyAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindReadReferencesInHierarchyAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReadReferencesInHierarchyAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_HIERARCHY_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindReadReferencesInHierarchyAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindReadReferencesInHierarchyAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReadReferencesInHierarchyAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_HIERARCHY_ACTION); } int getLimitTo() { return IJavaSearchConstants.READ_ACCESSES; } String getOperationUnavailableMessage() { return SearchMessages.getString("JavaElementAction.operationUnavailable.field"); //$NON-NLS-1$ } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReadReferencesInWorkingSetAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.SearchMessages; /** * Finds field read accesses of the selected element in working sets. * The action is applicable to selections representing a Java field. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindReadReferencesInWorkingSetAction extends FindReferencesInWorkingSetAction { /** * Creates a new <code>FindReadReferencesInWorkingSetAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be * prompted to select the working sets. * * @param site the site providing context information for this action */ public FindReadReferencesInWorkingSetAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindReadReferencesInWorkingSetAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReadReferencesInWorkingSetAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_WORKING_SET_ACTION); } /** * Creates a new <code>FindReadReferencesInWorkingSetAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action * @param workingSets the working sets to be used in the search */ public FindReadReferencesInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) { super(site, workingSets, new Class[] {IField.class}); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_WORKING_SET_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindReadReferencesInWorkingSetAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindReadReferencesInWorkingSetAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReadReferencesInWorkingSetAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_WORKING_SET_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindReadReferencesInWorkingSetAction(JavaEditor editor, IWorkingSet[] workingSets) { super(editor, workingSets, new Class[] {IField.class}); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_WORKING_SET_ACTION); } int getLimitTo() { return IJavaSearchConstants.READ_ACCESSES; } String getOperationUnavailableMessage() { return SearchMessages.getString("JavaElementAction.operationUnavailable.field"); //$NON-NLS-1$ } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IImportDeclaration; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IPackageDeclaration; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.SearchMessages; import org.eclipse.jdt.internal.ui.search.SearchUtil; /** * Finds references of the selected element in the workspace. * The action is applicable to selections representing a Java element. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindReferencesAction extends FindAction { /** * Creates a new <code>FindReferencesAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindReferencesAction(IWorkbenchSite site) { this(site, SearchMessages.getString("Search.FindReferencesAction.label"), new Class[] {ICompilationUnit.class, IType.class, IMethod.class, IField.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReferencesAction.tooltip")); //$NON-NLS-1$ } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindReferencesAction(JavaEditor editor) { this(editor, SearchMessages.getString("Search.FindReferencesAction.label"), new Class[] {ICompilationUnit.class, IType.class, IMethod.class, IField.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReferencesAction.tooltip")); //$NON-NLS-1$ } FindReferencesAction(IWorkbenchSite site, String label, Class[] validTypes) { super(site, label, validTypes); setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_WORKSPACE_ACTION); } FindReferencesAction(JavaEditor editor, String label, Class[] validTypes) { super(editor, label, validTypes); setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_WORKSPACE_ACTION); } int getLimitTo() { return IJavaSearchConstants.REFERENCES; } public void run(IJavaElement element) { SearchUtil.warnIfBinaryConstant(element, getShell()); super.run(element); } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInHierarchyAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.SearchEngine; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.SearchMessages; /** * Finds references of the selected element in its hierarchy. * The action is applicable to selections representing a Java element. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindReferencesInHierarchyAction extends FindReferencesAction { /** * Creates a new <code>FindReferencesInHierarchyAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindReferencesInHierarchyAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindHierarchyReferencesAction.label"), new Class[] {ICompilationUnit.class, IType.class, IMethod.class, IField.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindHierarchyReferencesAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_HIERARCHY_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindReferencesInHierarchyAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindHierarchyReferencesAction.label"), new Class[] {ICompilationUnit.class, IType.class, IMethod.class, IField.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindHierarchyReferencesAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_HIERARCHY_ACTION); } FindReferencesInHierarchyAction(IWorkbenchSite site, String label, Class[] validTypes) { super(site, label, validTypes); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_HIERARCHY_ACTION); } FindReferencesInHierarchyAction(JavaEditor editor, String label, Class[] validTypes) { super(editor, label, validTypes); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_HIERARCHY_ACTION); } IJavaSearchScope getScope(IType type) throws JavaModelException { if (type == null) return super.getScope(type); return SearchEngine.createHierarchyScope(type); } String getScopeDescription(IType type) { String typeName= ""; //$NON-NLS-1$ if (type != null) typeName= type.getElementName(); return SearchMessages.getFormattedString("HierarchyScope", new String[] {typeName}); //$NON-NLS-1$ } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInProjectAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.core.resources.IResource; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IImportDeclaration; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IPackageDeclaration; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.search.JavaSearchOperation; import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; import org.eclipse.jdt.internal.ui.search.SearchMessages; import org.eclipse.jdt.internal.ui.search.SearchUtil; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; /** * Finds references to the selected element in the enclosing project * of the selected element. * The action is applicable to selections representing a Java element. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 3.0 */ public class FindReferencesInProjectAction extends FindReferencesAction { /** * Creates a new <code>FindReferencesInProjectAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindReferencesInProjectAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindReferencesInProjectAction.label"), new Class[] {IField.class, IMethod.class, IType.class, ICompilationUnit.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReferencesInProjectAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_PROJECT_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindReferencesInProjectAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindReferencesInProjectAction.label"), new Class[] {IField.class, IMethod.class, IType.class, ICompilationUnit.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class}); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindReferencesInProjectAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_PROJECT_ACTION); } IJavaSearchScope getScope(IJavaElement element) throws JavaModelException { return JavaSearchScopeFactory.getInstance().createJavaSearchScope(new IResource[] { element.getJavaProject().getProject() }); } String getScopeDescription(IJavaElement element) { return SearchUtil.getProjectScopeDescription(element); } JavaSearchOperation makeOperation(IJavaElement element) throws JavaModelException { return new JavaSearchOperation(JavaPlugin.getWorkspace(), element, getLimitTo(), getScope(element), getScopeDescription(element), getCollector()); } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindWriteReferencesAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.internal.ui.search.SearchMessages; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; /** * Finds field write accesses of the selected element in the workspace. * The action is applicable to selections representing a Java element. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindWriteReferencesAction extends FindReferencesAction { /** * Creates a new <code>FindWriteReferencesAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindWriteReferencesAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindWriteReferencesAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindWriteReferencesAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_WRITE_REFERENCES_IN_WORKSPACE_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindWriteReferencesAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindWriteReferencesAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindWriteReferencesAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_WRITE_REFERENCES_IN_WORKSPACE_ACTION); } int getLimitTo() { return IJavaSearchConstants.WRITE_ACCESSES; } String getOperationUnavailableMessage() { return SearchMessages.getString("JavaElementAction.operationUnavailable.field"); //$NON-NLS-1$ } }
45,448
Bug 45448 Operation unavailable attempting to search a local variable [search]
Build 20031023 Selecting a local variable declaration in a Java editor and attempting to search for references to this local variable brings up a dialog saying the the operation is unavailable for the selected element.
verified fixed
a6ada08
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
2003-12-12T10:44:16Z
2003-10-23T14:40:00Z
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindWriteReferencesInHierarchyAction.java
/******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.internal.ui.search.SearchMessages; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; /** * Finds field write accesses of the selected element in its hierarchy. * The action is applicable to selections representing a Java field. * * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> * * @since 2.0 */ public class FindWriteReferencesInHierarchyAction extends FindReferencesInHierarchyAction { /** * Creates a new <code>FindWriteReferencesInHierarchyAction</code>. The action * requires that the selection provided by the site's selection provider is of type * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site the site providing context information for this action */ public FindWriteReferencesInHierarchyAction(IWorkbenchSite site) { super(site, SearchMessages.getString("Search.FindWriteReferencesInHierarchyAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindWriteReferencesInHierarchyAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_WRITE_REFERENCES_IN_HIERARCHY_ACTION); } /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ public FindWriteReferencesInHierarchyAction(JavaEditor editor) { super(editor, SearchMessages.getString("Search.FindWriteReferencesInHierarchyAction.label"), new Class[] {IField.class} ); //$NON-NLS-1$ setToolTipText(SearchMessages.getString("Search.FindWriteReferencesInHierarchyAction.tooltip")); //$NON-NLS-1$ WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_WRITE_REFERENCES_IN_HIERARCHY_ACTION); } int getLimitTo() { return IJavaSearchConstants.WRITE_ACCESSES; } String getOperationUnavailableMessage() { return SearchMessages.getString("JavaElementAction.operationUnavailable.field"); //$NON-NLS-1$ } }