mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
(no message)
This commit is contained in:
@@ -45,7 +45,7 @@ public class RenamePublicClassFix implements IntentionAction {
|
||||
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
String newName = vFile.getNameWithoutExtension();
|
||||
RenameProcessor processor = new RenameProcessor(project, myClass, newName, false, false, false);
|
||||
RenameProcessor processor = new RenameProcessor(project, myClass, newName, false, false);
|
||||
processor.run((Object)null);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class RenameRefactoringImpl extends RefactoringImpl<RenameProcessor> impl
|
||||
String newName,
|
||||
boolean toSearchInComments,
|
||||
boolean toSearchInNonJavaFiles) {
|
||||
super(new RenameProcessor(project, element, newName, toSearchInComments, toSearchInNonJavaFiles, true));
|
||||
super(new RenameProcessor(project, element, newName, toSearchInComments, toSearchInNonJavaFiles));
|
||||
}
|
||||
|
||||
public void addElement(PsiElement element, String newName) {
|
||||
|
||||
@@ -158,9 +158,7 @@ public class PsiElementRenameHandler implements RenameHandler {
|
||||
}
|
||||
String helpID = HelpID.getRenameHelpID(elementToRename);
|
||||
final RenameDialog dialog =
|
||||
new RenameDialog(project, elementToRename, nameSuggestionContext, helpID,
|
||||
new RenameProcessor(project, elementToRename)
|
||||
);
|
||||
new RenameDialog(project, elementToRename, nameSuggestionContext, helpID);
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@@ -43,10 +43,6 @@ public class RenameDialog extends RefactoringDialog {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameDialog");
|
||||
private SuggestedNameInfo mySuggestedNameInfo;
|
||||
|
||||
public static interface Callback {
|
||||
void run(RenameDialog dialog);
|
||||
}
|
||||
|
||||
private JLabel myNameLabel;
|
||||
private NameSuggestionsField myNameSuggestionsField;
|
||||
private JCheckBox myCbSearchInComments;
|
||||
@@ -61,16 +57,15 @@ public class RenameDialog extends RefactoringDialog {
|
||||
private Project myProject;
|
||||
private PsiElement myPsiElement;
|
||||
private final PsiElement myNameSuggestionContext;
|
||||
private Callback myCallback;
|
||||
|
||||
|
||||
public RenameDialog(Project project, PsiElement psiElement,
|
||||
PsiElement nameSuggestionContext, String helpID, Callback callback) {
|
||||
public RenameDialog(Project project,
|
||||
PsiElement psiElement,
|
||||
PsiElement nameSuggestionContext,
|
||||
String helpID) {
|
||||
super(project, true);
|
||||
myProject = project;
|
||||
myPsiElement = psiElement;
|
||||
myNameSuggestionContext = nameSuggestionContext;
|
||||
myCallback = callback;
|
||||
setTitle("Rename");
|
||||
|
||||
createNewNameComponent();
|
||||
@@ -195,7 +190,7 @@ public class RenameDialog extends RefactoringDialog {
|
||||
list.add(parameterName);
|
||||
}
|
||||
ContainerUtil.removeDuplicates(list);
|
||||
return (String[])list.toArray(new String[list.size()]);
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
private String suggestProperlyCasedName(PsiElement psiElement) {
|
||||
@@ -416,8 +411,13 @@ public class RenameDialog extends RefactoringDialog {
|
||||
if (mySuggestedNameInfo != null) {
|
||||
mySuggestedNameInfo.nameChoosen(getNewName());
|
||||
}
|
||||
final RenameProcessor processor = new RenameProcessor(getProject(), myPsiElement, getNewName(), isSearchInComments(),
|
||||
isSearchInNonJavaFiles());
|
||||
processor.setShouldRenameInheritors(shouldRenameInheritors());
|
||||
processor.setShouldRenameVariables(shouldRenameVariables());
|
||||
processor.setShouldRenameForms(shouldRenameForms());
|
||||
|
||||
myCallback.run(this);
|
||||
invokeRefactoring(processor);
|
||||
}
|
||||
|
||||
private boolean checkNameConflicts() {
|
||||
@@ -495,7 +495,6 @@ public class RenameDialog extends RefactoringDialog {
|
||||
|
||||
protected boolean areButtonsValid() {
|
||||
final String newName = getNewName();
|
||||
final boolean enabled;
|
||||
if (newName == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,11 +9,9 @@ import com.intellij.j2ee.ejb.role.EjbMethodRole;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
@@ -39,35 +37,35 @@ import com.intellij.util.containers.HashSet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class RenameProcessor extends BaseRefactoringProcessor implements RenameDialog.Callback {
|
||||
public class RenameProcessor extends BaseRefactoringProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameProcessor");
|
||||
|
||||
protected ArrayList<PsiElement> myElements = new ArrayList<PsiElement>();
|
||||
protected ArrayList<String> myNames = new ArrayList<String>();
|
||||
|
||||
private RenameDialog myDialog;
|
||||
private PsiElement myElement;
|
||||
private String myNewName = null;
|
||||
|
||||
boolean mySearchInComments;
|
||||
private boolean mySearchInNonJavaFiles;
|
||||
private boolean myPreviewUsages;
|
||||
private String myCommandName;
|
||||
private boolean myShouldRenameVariables;
|
||||
private boolean myShouldRenameInheritors;
|
||||
|
||||
private boolean myShouldRenameForms;
|
||||
private UsageInfo[] myUsagesForNonCodeRenaming;
|
||||
private List<AutomaticRenamer<? extends PsiNamedElement>> myRenamers = new ArrayList<AutomaticRenamer<? extends PsiNamedElement>>();
|
||||
|
||||
public RenameProcessor(Project project, PsiElement element, String newName,
|
||||
boolean isSearchInComments, boolean toSearchInNonJavaFiles, boolean isPreviewUsages) {
|
||||
public RenameProcessor(Project project,
|
||||
PsiElement element,
|
||||
String newName,
|
||||
boolean isSearchInComments,
|
||||
boolean toSearchInNonJavaFiles) {
|
||||
super(project);
|
||||
myDialog = null;
|
||||
myElement = element;
|
||||
|
||||
mySearchInComments = isSearchInComments;
|
||||
mySearchInNonJavaFiles = toSearchInNonJavaFiles;
|
||||
myPreviewUsages = isPreviewUsages;
|
||||
|
||||
setNewName(newName);
|
||||
}
|
||||
@@ -85,7 +83,9 @@ public class RenameProcessor extends BaseRefactoringProcessor implements RenameD
|
||||
myShouldRenameInheritors = shouldRenameInheritors;
|
||||
}
|
||||
|
||||
|
||||
public void setShouldRenameForms(final boolean shouldRenameForms) {
|
||||
myShouldRenameForms = shouldRenameForms;
|
||||
}
|
||||
|
||||
public RenameProcessor(Project project, PsiElement element) {
|
||||
super(project);
|
||||
@@ -142,29 +142,13 @@ public class RenameProcessor extends BaseRefactoringProcessor implements RenameD
|
||||
return HelpID.getRenameHelpID(myElement);
|
||||
}
|
||||
|
||||
public void run(RenameDialog dialog) {
|
||||
myDialog = dialog;
|
||||
setNewName(dialog.getNewName());
|
||||
|
||||
mySearchInComments = dialog.isSearchInComments();
|
||||
mySearchInNonJavaFiles = dialog.isSearchInNonJavaFiles();
|
||||
myPreviewUsages = dialog.isPreviewUsages();
|
||||
myShouldRenameVariables = dialog.shouldRenameVariables();
|
||||
myShouldRenameInheritors = dialog.shouldRenameInheritors();
|
||||
myShouldRenameForms = dialog.shouldRenameForms();
|
||||
|
||||
run((Object) null);
|
||||
}
|
||||
|
||||
protected boolean preprocessUsages(UsageInfo[][] usages) {
|
||||
if (myDialog != null) {
|
||||
String[] conflicts = RenameUtil.getConflictDescriptions(usages[0]);
|
||||
if (conflicts.length > 0) {
|
||||
ConflictsDialog conflictsDialog = new ConflictsDialog(conflicts, myProject);
|
||||
conflictsDialog.show();
|
||||
if (!conflictsDialog.isOK()) {
|
||||
return false;
|
||||
}
|
||||
String[] conflicts = RenameUtil.getConflictDescriptions(usages[0]);
|
||||
if (conflicts.length > 0) {
|
||||
ConflictsDialog conflictsDialog = new ConflictsDialog(conflicts, myProject);
|
||||
conflictsDialog.show();
|
||||
if (!conflictsDialog.isOK()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Set<UsageInfo> usagesSet = new HashSet<UsageInfo>(Arrays.asList(usages[0]));
|
||||
@@ -172,9 +156,7 @@ public class RenameProcessor extends BaseRefactoringProcessor implements RenameD
|
||||
|
||||
final List<UsageInfo> variableUsages = new ArrayList<UsageInfo>();
|
||||
if (!myRenamers.isEmpty()) {
|
||||
boolean isOK = findRenamedVariables(variableUsages);
|
||||
|
||||
if (!isOK) return false;
|
||||
if (!findRenamedVariables(variableUsages)) return false;
|
||||
}
|
||||
|
||||
if (!variableUsages.isEmpty()) {
|
||||
@@ -182,14 +164,7 @@ public class RenameProcessor extends BaseRefactoringProcessor implements RenameD
|
||||
usages[0] = usagesSet.toArray(new UsageInfo[usagesSet.size()]);
|
||||
}
|
||||
|
||||
if (myDialog != null) {
|
||||
// make sure that dialog is closed in swing thread
|
||||
ToolWindowManager.getInstance(myProject).invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
myDialog.close(DialogWrapper.CANCEL_EXIT_CODE);
|
||||
}
|
||||
});
|
||||
}
|
||||
prepareSuccessful();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -399,15 +374,15 @@ public class RenameProcessor extends BaseRefactoringProcessor implements RenameD
|
||||
}
|
||||
|
||||
protected boolean isPreviewUsages(UsageInfo[] usages) {
|
||||
boolean toPreview = myPreviewUsages;
|
||||
if (super.isPreviewUsages(usages)) return true;
|
||||
if (!isNonCodeElements() && UsageViewUtil.hasNonCodeUsages(usages)) {
|
||||
toPreview = true;
|
||||
WindowManager.getInstance().getStatusBar(myProject).setInfo("Occurrences found in comments, strings and non-java files");
|
||||
return true;
|
||||
} else if (UsageViewUtil.hasReadOnlyUsages(usages)) {
|
||||
toPreview = true;
|
||||
WindowManager.getInstance().getStatusBar(myProject).setInfo("Occurrences found in read-only files");
|
||||
return true;
|
||||
}
|
||||
return toPreview;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isNonCodeElements() {
|
||||
|
||||
@@ -117,7 +117,7 @@ public final class BindingProperty extends Property {
|
||||
myGuiEditor.refreshAndSave(false);
|
||||
PsiDocumentManager.getInstance(myGuiEditor.getProject()).commitAllDocuments();
|
||||
|
||||
final RenameProcessor processor = new RenameProcessor(project, oldField, newBinding, true, true, false);
|
||||
final RenameProcessor processor = new RenameProcessor(project, oldField, newBinding, true, true);
|
||||
processor.run((Object)null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class ArrayIndexOutOfBoundsTest extends PsiTestCase {
|
||||
assertNotNull("Package bla not found", aPackage);
|
||||
|
||||
PsiDirectory dir = aPackage.getDirectories()[0];
|
||||
new RenameProcessor(myProject, dir, "anotherBla", true, true, false).testRun();
|
||||
new RenameProcessor(myProject, dir, "anotherBla", true, true).testRun();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ public class RenameClassTest extends MultiFileTestCase {
|
||||
PsiClass aClass = myPsiManager.findClass(qClassName);
|
||||
assertNotNull("Class " + qClassName + " not found", aClass);
|
||||
|
||||
new RenameProcessor(myProject, aClass, newName, true, true, false).testRun();
|
||||
new RenameProcessor(myProject, aClass, newName, true, true).testRun();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,6 @@ public class RenameFieldsTest extends CodeInsightTestCase {
|
||||
PsiElement element = TargetElementUtil.findTargetElement(myEditor,
|
||||
TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
|
||||
|
||||
new RenameProcessor(myProject, element, newName, false, false, false).testRun();
|
||||
new RenameProcessor(myProject, element, newName, false, false).testRun();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class RenameMethodMultiTest extends MultiFileTestCase {
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(
|
||||
methodSignature + "{}", null), false);
|
||||
assertNotNull(methodBySignature);
|
||||
final RenameProcessor renameProcessor = new RenameProcessor(myProject, methodBySignature, newName, false, false, false);
|
||||
final RenameProcessor renameProcessor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
|
||||
renameProcessor.testRun();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user