update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / inline / InlineMethodDialog.java
blobc8389c7f51b077e8fe236aa5d490e52ed2a6533c
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.refactoring.inline;
18 import com.intellij.openapi.editor.Editor;
19 import com.intellij.openapi.help.HelpManager;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.psi.PsiJavaCodeReferenceElement;
22 import com.intellij.psi.PsiMethod;
23 import com.intellij.psi.PsiSubstitutor;
24 import com.intellij.psi.util.PsiFormatUtil;
25 import com.intellij.refactoring.HelpID;
26 import com.intellij.refactoring.RefactoringBundle;
27 import com.intellij.refactoring.JavaRefactoringSettings;
29 public class InlineMethodDialog extends InlineOptionsDialog {
30 public static final String REFACTORING_NAME = RefactoringBundle.message("inline.method.title");
31 private final PsiJavaCodeReferenceElement myReferenceElement;
32 private final Editor myEditor;
33 private final boolean myAllowInlineThisOnly;
35 private final PsiMethod myMethod;
37 public InlineMethodDialog(Project project, PsiMethod method, PsiJavaCodeReferenceElement ref, Editor editor,
38 final boolean allowInlineThisOnly) {
39 super(project, true, method);
40 myMethod = method;
41 myReferenceElement = ref;
42 myEditor = editor;
43 myAllowInlineThisOnly = allowInlineThisOnly;
44 myInvokedOnReference = ref != null;
46 setTitle(REFACTORING_NAME);
48 init();
51 protected String getNameLabelText() {
52 String methodText = PsiFormatUtil.formatMethod(myMethod,
53 PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE);
54 return RefactoringBundle.message("inline.method.method.label", methodText);
57 protected String getBorderTitle() {
58 return RefactoringBundle.message("inline.method.border.title");
61 protected String getInlineThisText() {
62 return RefactoringBundle.message("this.invocation.only.and.keep.the.method");
65 protected String getInlineAllText() {
66 return myMethod.isWritable()
67 ? RefactoringBundle.message("all.invocations.and.remove.the.method")
68 : RefactoringBundle.message("all.invocations.in.project");
71 protected void doAction() {
72 invokeRefactoring(new InlineMethodProcessor(getProject(), myMethod, myReferenceElement, myEditor, isInlineThisOnly()));
73 JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
74 if(myRbInlineThisOnly.isEnabled() && myRbInlineAll.isEnabled()) {
75 settings.INLINE_METHOD_THIS = isInlineThisOnly();
79 protected void doHelpAction() {
80 if (myMethod.isConstructor()) HelpManager.getInstance().invokeHelp(HelpID.INLINE_CONSTRUCTOR);
81 else HelpManager.getInstance().invokeHelp(HelpID.INLINE_METHOD);
84 protected boolean canInlineThisOnly() {
85 return InlineMethodHandler.checkRecursive(myMethod) || myAllowInlineThisOnly;
88 protected boolean isInlineThis() {
89 return JavaRefactoringSettings.getInstance().INLINE_METHOD_THIS;