use of com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceUsageInfo in project intellij-community by JetBrains.
the class SafeDeleteProcessor method preprocessUsages.
@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
UsageInfo[] usages = refUsages.get();
ArrayList<String> conflicts = new ArrayList<>();
for (PsiElement element : myElements) {
for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
if (delegate.handlesElement(element)) {
Collection<String> foundConflicts = delegate instanceof SafeDeleteProcessorDelegateBase ? ((SafeDeleteProcessorDelegateBase) delegate).findConflicts(element, myElements, usages) : delegate.findConflicts(element, myElements);
if (foundConflicts != null) {
conflicts.addAll(foundConflicts);
}
break;
}
}
}
final HashMap<PsiElement, UsageHolder> elementsToUsageHolders = sortUsages(usages);
final Collection<UsageHolder> usageHolders = elementsToUsageHolders.values();
for (UsageHolder usageHolder : usageHolders) {
if (usageHolder.hasUnsafeUsagesInCode()) {
conflicts.add(usageHolder.getDescription());
}
}
if (!conflicts.isEmpty()) {
final RefactoringEventData conflictData = new RefactoringEventData();
conflictData.putUserData(RefactoringEventData.CONFLICTS_KEY, conflicts);
myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).conflictsDetected("refactoring.safeDelete", conflictData);
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (!ConflictsInTestsException.isTestIgnore())
throw new ConflictsInTestsException(conflicts);
} else {
UnsafeUsagesDialog dialog = new UnsafeUsagesDialog(ArrayUtil.toStringArray(conflicts), myProject);
if (!dialog.showAndGet()) {
final int exitCode = dialog.getExitCode();
// dialog is always dismissed;
prepareSuccessful();
if (exitCode == UnsafeUsagesDialog.VIEW_USAGES_EXIT_CODE) {
showUsages(Arrays.stream(usages).filter(usage -> usage instanceof SafeDeleteReferenceUsageInfo && !((SafeDeleteReferenceUsageInfo) usage).isSafeDelete()).toArray(UsageInfo[]::new), usages);
}
return false;
} else {
myPreviewNonCodeUsages = false;
}
}
}
UsageInfo[] preprocessedUsages = usages;
for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
preprocessedUsages = delegate.preprocessUsages(myProject, preprocessedUsages);
if (preprocessedUsages == null)
return false;
}
final UsageInfo[] filteredUsages = UsageViewUtil.removeDuplicatedUsages(preprocessedUsages);
// dialog is always dismissed
prepareSuccessful();
if (filteredUsages == null) {
return false;
}
refUsages.set(filteredUsages);
return true;
}
Aggregations