rename: check overriden for getters/setters (IDEA-22871)
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / extractInterface / ExtractClassUtil.java
blobb0624f97c4e5f93b932d3ce79da16e8b07f5f493
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.extractInterface;
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.application.ApplicationNamesInfo;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.psi.PsiClass;
22 import com.intellij.psi.PsiElement;
23 import com.intellij.psi.SmartPointerManager;
24 import com.intellij.psi.SmartPsiElementPointer;
25 import com.intellij.refactoring.RefactoringBundle;
26 import com.intellij.refactoring.JavaRefactoringSettings;
27 import com.intellij.refactoring.turnRefsToSuper.TurnRefsToSuperProcessor;
28 import com.intellij.refactoring.ui.YesNoPreviewUsagesDialog;
30 /**
31 * @author dsl
33 public class ExtractClassUtil {
34 public static void askAndTurnRefsToSuper(final Project project, PsiClass aClass, final PsiClass aSuperClass) {
35 final SmartPsiElementPointer classPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(aClass);
36 final SmartPsiElementPointer interfacePointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(aSuperClass);
37 ApplicationManager.getApplication().invokeLater(new Runnable() {
38 public void run() {
39 final PsiElement classElement = classPointer.getElement();
40 final PsiElement interfaceElement = interfacePointer.getElement();
41 if (classElement instanceof PsiClass && interfaceElement instanceof PsiClass) {
42 final PsiClass superClass = (PsiClass) interfaceElement;
43 String superClassName = superClass.getName();
44 String className = ((PsiClass) classElement).getName();
45 String createdString = superClass.isInterface() ?
46 RefactoringBundle.message("interface.has.been.successfully.created", superClassName) :
47 RefactoringBundle.message("class.has.been.successfully.created", superClassName);
48 String message = createdString + "\n" +
49 RefactoringBundle.message("use.super.references.prompt",
50 ApplicationNamesInfo.getInstance().getProductName(), className, superClassName);
51 YesNoPreviewUsagesDialog dialog = new YesNoPreviewUsagesDialog(
52 RefactoringBundle.message("analyze.and.replace.usages"),
53 message,
54 JavaRefactoringSettings.getInstance().EXTRACT_INTERFACE_PREVIEW_USAGES,
55 /*HelpID.TURN_REFS_TO_SUPER*/null, project);
56 dialog.show();
57 if (dialog.isOK()) {
58 final boolean isPreviewUsages = dialog.isPreviewUsages();
59 JavaRefactoringSettings.getInstance().EXTRACT_INTERFACE_PREVIEW_USAGES = isPreviewUsages;
60 TurnRefsToSuperProcessor processor =
61 new TurnRefsToSuperProcessor(project, (PsiClass) classElement, (PsiClass) interfaceElement, true);
62 processor.setPreviewUsages(isPreviewUsages);
63 processor.run();
67 });