mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
abort rename when unexpected exception occurs (check didn't detect e.g. rename file which is used by another app: IDEA-71413)
This commit is contained in:
+19
-5
@@ -16,6 +16,7 @@
|
||||
package com.intellij.refactoring.invertBoolean;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightServicesUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
@@ -24,9 +25,12 @@ import com.intellij.psi.search.searches.MethodReferencesSearch;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.RenamePsiElementProcessor;
|
||||
import com.intellij.refactoring.rename.RenameUtil;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.MoveRenameUsageInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
@@ -222,14 +226,24 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
|
||||
protected void performRefactoring(UsageInfo[] usages) {
|
||||
for (PsiElement element : myRenameProcessor.getElements()) {
|
||||
RenameUtil.doRename(element, myNewName, extractUsagesForElement(element, usages), myProject, new RefactoringElementListener() {
|
||||
public void elementMoved(@NotNull PsiElement newElement) {}
|
||||
|
||||
public void elementRenamed(@NotNull PsiElement newElement) {}
|
||||
});
|
||||
for (final PsiElement element : myRenameProcessor.getElements()) {
|
||||
try {
|
||||
RenameUtil.doRename(element, myNewName, extractUsagesForElement(element, usages), myProject, new RefactoringElementListener() {
|
||||
public void elementMoved(@NotNull PsiElement newElement) {
|
||||
}
|
||||
|
||||
public void elementRenamed(@NotNull PsiElement newElement) {
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (final IncorrectOperationException e) {
|
||||
RenameUtil.showErrorMessage(e, element, myProject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (UsageInfo usage : usages) {
|
||||
final SmartPsiElementPointer pointerToInvert = myToInvert.get(usage);
|
||||
if (pointerToInvert != null) {
|
||||
|
||||
@@ -318,13 +318,20 @@ public class RenameProcessor extends BaseRefactoringProcessor {
|
||||
List<Runnable> postRenameCallbacks = new ArrayList<Runnable>();
|
||||
|
||||
final MultiMap<PsiElement, UsageInfo> classified = classifyUsages(myAllRenames.keySet(), usages);
|
||||
for (PsiElement element : myAllRenames.keySet()) {
|
||||
for (final PsiElement element : myAllRenames.keySet()) {
|
||||
String newName = myAllRenames.get(element);
|
||||
|
||||
final RefactoringElementListener elementListener = getTransaction().getElementListener(element);
|
||||
Runnable postRenameCallback = RenamePsiElementProcessor.forElement(element).getPostRenameCallback(element, newName, elementListener);
|
||||
final RenamePsiElementProcessor renamePsiElementProcessor = RenamePsiElementProcessor.forElement(element);
|
||||
Runnable postRenameCallback = renamePsiElementProcessor.getPostRenameCallback(element, newName, elementListener);
|
||||
final Collection<UsageInfo> infos = classified.get(element);
|
||||
RenameUtil.doRename(element, newName, infos.toArray(new UsageInfo[infos.size()]), myProject, elementListener);
|
||||
try {
|
||||
RenameUtil.doRename(element, newName, infos.toArray(new UsageInfo[infos.size()]), myProject, elementListener);
|
||||
}
|
||||
catch (final IncorrectOperationException e) {
|
||||
RenameUtil.showErrorMessage(e, element, myProject);
|
||||
return;
|
||||
}
|
||||
if (postRenameCallback != null) {
|
||||
postRenameCallbacks.add(postRenameCallback);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class RenameUtil {
|
||||
}
|
||||
|
||||
public static void doRename(final PsiElement element, String newName, UsageInfo[] usages, final Project project,
|
||||
final RefactoringElementListener listener) {
|
||||
final RefactoringElementListener listener) throws IncorrectOperationException{
|
||||
final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
|
||||
final String fqn = element instanceof PsiFile ? ((PsiFile)element).getVirtualFile().getPath() : CopyReferenceAction.elementToFqn(element);
|
||||
if (fqn != null) {
|
||||
@@ -189,22 +189,22 @@ public class RenameUtil {
|
||||
};
|
||||
UndoManager.getInstance(project).undoableActionPerformed(action);
|
||||
}
|
||||
try {
|
||||
processor.renameElement(element, newName, usages, listener);
|
||||
processor.renameElement(element, newName, usages, listener);
|
||||
}
|
||||
|
||||
public static void showErrorMessage(final IncorrectOperationException e, final PsiElement element, final Project project) {
|
||||
// may happen if the file or package cannot be renamed. e.g. locked by another application
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(e);
|
||||
//LOG.error(e);
|
||||
//return;
|
||||
}
|
||||
catch (final IncorrectOperationException e) {
|
||||
// may happen if the file or package cannot be renamed. e.g. locked by another application
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(e);
|
||||
//LOG.error(e);
|
||||
//return;
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
final String helpID = RenamePsiElementProcessor.forElement(element).getHelpID(element);
|
||||
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("rename.title"), e.getMessage(), helpID, project);
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("rename.title"), e.getMessage(), processor.getHelpID(element), project);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void doRenameGenericNamedElement(PsiElement namedElement, String newName, UsageInfo[] usages,
|
||||
|
||||
Reference in New Issue
Block a user