1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.ui.actions;
13 import org.eclipse.swt.widgets.Shell;
15 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.text.ITextSelection;
19 import org.eclipse.ui.IWorkbenchSite;
20 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.jdt.core.ICompilationUnit;
23 import org.eclipse.jdt.core.JavaModelException;
24 import org.eclipse.jdt.core.dom.CompilationUnit;
26 import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;
27 import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
29 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
30 import org.eclipse.jdt.internal.ui.actions.ActionUtil;
31 import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
32 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
33 import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection;
34 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
37 * Inlines the value of a local variable at all places where a read reference
41 * This class may be instantiated; it is not intended to be subclassed.
46 * @noextend This class is not intended to be subclassed by clients.
48 public class InlineTempAction extends SelectionDispatchAction {
50 private JavaEditor fEditor;
53 * Note: This constructor is for internal use only. Clients should not call this constructor.
55 * @param editor the java editor
57 * @noreference This constructor is not intended to be referenced by clients.
59 public InlineTempAction(JavaEditor editor) {
60 this(editor.getEditorSite());
62 setEnabled(SelectionConverter.canOperateOn(fEditor));
65 /* package */ InlineTempAction(IWorkbenchSite site) {
67 setText(RefactoringMessages.InlineTempAction_label);
68 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INLINE_ACTION);
71 //---- text selection ----------------------------------------------------------
74 * Method declared on SelectionDispatchAction
77 public void selectionChanged(ITextSelection selection) {
82 * Note: This method is for internal use only. Clients should not call this method.
84 * @param selection the Java text selection
85 * @noreference This method is not intended to be referenced by clients.
88 public void selectionChanged(JavaTextSelection selection) {
90 setEnabled(RefactoringAvailabilityTester.isInlineTempAvailable(selection));
91 } catch (JavaModelException e) {
97 * Method declared on SelectionDispatchAction
100 public void run(ITextSelection selection) {
101 ICompilationUnit input= SelectionConverter.getInputAsCompilationUnit(fEditor);
102 if (!ActionUtil.isEditable(fEditor))
104 RefactoringExecutionStarter.startInlineTempRefactoring(input, null, selection, getShell());
108 * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection)
111 public void run(IStructuredSelection selection) {
116 * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
119 public void selectionChanged(IStructuredSelection selection) {
123 /* package */ boolean tryInlineTemp(ICompilationUnit unit, CompilationUnit node, ITextSelection selection, Shell shell) {
124 return RefactoringExecutionStarter.startInlineTempRefactoring(unit, node, selection, shell);