use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.
the class ChangeSignatureProcessor method preprocessUsages.
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
for (ChangeSignatureUsageProcessor processor : ChangeSignatureUsageProcessor.EP_NAME.getExtensions()) {
if (!processor.setupDefaultValues(myChangeInfo, refUsages, myProject))
return false;
}
MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<>();
collectConflictsFromExtensions(refUsages, conflictDescriptions, myChangeInfo);
final UsageInfo[] usagesIn = refUsages.get();
RenameUtil.addConflictDescriptions(usagesIn, conflictDescriptions);
Set<UsageInfo> usagesSet = new HashSet<>(Arrays.asList(usagesIn));
RenameUtil.removeConflictUsages(usagesSet);
if (!conflictDescriptions.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (ConflictsInTestsException.isTestIgnore())
return true;
throw new ConflictsInTestsException(conflictDescriptions.values());
}
if (myPrepareSuccessfulSwingThreadCallback != null) {
ConflictsDialog dialog = prepareConflictsDialog(conflictDescriptions, usagesIn);
if (!dialog.showAndGet()) {
if (dialog.isShowConflicts())
prepareSuccessful();
return false;
}
}
}
if (myChangeInfo.isReturnTypeChanged()) {
askToRemoveCovariantOverriders(usagesSet);
}
refUsages.set(usagesSet.toArray(new UsageInfo[usagesSet.size()]));
prepareSuccessful();
return true;
}
use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.
the class ExtractSuperClassUtil method showConflicts.
public static boolean showConflicts(DialogWrapper dialog, MultiMap<PsiElement, String> conflicts, final Project project) {
if (!conflicts.isEmpty()) {
fireConflictsEvent(conflicts, project);
ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
conflictsDialog.show();
final boolean ok = conflictsDialog.isOK();
if (!ok && conflictsDialog.isShowConflicts())
dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
return ok;
}
return true;
}
use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.
the class InheritanceToDelegationProcessor method preprocessUsages.
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
final UsageInfo[] usagesIn = refUsages.get();
ArrayList<UsageInfo> oldUsages = new ArrayList<>();
Collections.addAll(oldUsages, usagesIn);
final ObjectUpcastedUsageInfo[] objectUpcastedUsageInfos = objectUpcastedUsages(usagesIn);
if (myPrepareSuccessfulSwingThreadCallback != null) {
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
if (objectUpcastedUsageInfos.length > 0) {
final String message = RefactoringBundle.message("instances.of.0.upcasted.to.1.were.found", RefactoringUIUtil.getDescription(myClass, true), CommonRefactoringUtil.htmlEmphasize(CommonClassNames.JAVA_LANG_OBJECT));
conflicts.putValue(myClass, message);
}
analyzeConflicts(usagesIn, conflicts);
if (!conflicts.isEmpty()) {
ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, usagesIn);
if (!conflictsDialog.showAndGet()) {
if (conflictsDialog.isShowConflicts())
prepareSuccessful();
return false;
}
}
if (objectUpcastedUsageInfos.length > 0) {
showObjectUpcastedUsageView(objectUpcastedUsageInfos);
setPreviewUsages(true);
}
}
ArrayList<UsageInfo> filteredUsages = filterUsages(oldUsages);
refUsages.set(filteredUsages.toArray(new UsageInfo[filteredUsages.size()]));
prepareSuccessful();
return true;
}
use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.
the class MoveClassesOrPackagesImpl method doRearrangePackage.
public static void doRearrangePackage(final Project project, final PsiDirectory[] directories) {
if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(directories), true)) {
return;
}
List<PsiDirectory> sourceRootDirectories = buildRearrangeTargetsList(project, directories);
DirectoryChooser chooser = new DirectoryChooser(project);
chooser.setTitle(RefactoringBundle.message("select.source.root.chooser.title"));
chooser.fillList(sourceRootDirectories.toArray(new PsiDirectory[sourceRootDirectories.size()]), null, project, "");
if (!chooser.showAndGet()) {
return;
}
final PsiDirectory selectedTarget = chooser.getSelectedDirectory();
if (selectedTarget == null)
return;
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final Runnable analyzeConflicts = () -> ApplicationManager.getApplication().runReadAction(() -> RefactoringConflictsUtil.analyzeModuleConflicts(project, Arrays.asList(directories), UsageInfo.EMPTY_ARRAY, selectedTarget, conflicts));
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(analyzeConflicts, "Analyze Module Conflicts...", true, project)) {
return;
}
if (!conflicts.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values());
} else {
final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
if (!conflictsDialog.showAndGet()) {
return;
}
}
}
final Ref<IncorrectOperationException> ex = Ref.create(null);
final String commandDescription = RefactoringBundle.message("moving.directories.command");
Runnable runnable = () -> ApplicationManager.getApplication().runWriteAction(() -> {
LocalHistoryAction a = LocalHistory.getInstance().startAction(commandDescription);
try {
rearrangeDirectoriesToTarget(directories, selectedTarget);
} catch (IncorrectOperationException e) {
ex.set(e);
} finally {
a.finish();
}
});
CommandProcessor.getInstance().executeCommand(project, runnable, commandDescription, null);
if (ex.get() != null) {
RefactoringUIUtil.processIncorrectOperation(project, ex.get());
}
}
use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.
the class MakeMethodOrClassStaticProcessor method preprocessUsages.
protected final boolean preprocessUsages(@NotNull final Ref<UsageInfo[]> refUsages) {
UsageInfo[] usagesIn = refUsages.get();
if (myPrepareSuccessfulSwingThreadCallback != null) {
MultiMap<PsiElement, String> conflicts = getConflictDescriptions(usagesIn);
if (conflicts.size() > 0) {
ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, refUsages.get());
if (!conflictsDialog.showAndGet()) {
if (conflictsDialog.isShowConflicts())
prepareSuccessful();
return false;
}
}
if (!mySettings.isChangeSignature()) {
refUsages.set(filterInternalUsages(usagesIn));
}
}
final Set<UsageInfo> toMakeStatic = new LinkedHashSet<>();
refUsages.set(filterOverriding(usagesIn, toMakeStatic));
if (!findAdditionalMembers(toMakeStatic))
return false;
prepareSuccessful();
return true;
}
Aggregations