use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class ChangeClassSignatureProcessor method getBeforeData.
@Nullable
@Override
protected RefactoringEventData getBeforeData() {
RefactoringEventData data = new RefactoringEventData();
data.addElement(myClass);
return data;
}
use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class EncapsulateFieldsProcessor method getAfterData.
@Nullable
@Override
protected RefactoringEventData getAfterData(@NotNull UsageInfo[] usages) {
RefactoringEventData data = new RefactoringEventData();
List<PsiElement> elements = new ArrayList<>();
if (myNameToGetter != null) {
elements.addAll(myNameToGetter.values());
}
if (myNameToSetter != null) {
elements.addAll(myNameToSetter.values());
}
data.addElements(elements);
return data;
}
use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class BaseRefactoringProcessor method doRefactoring.
private void doRefactoring(@NotNull final Collection<UsageInfo> usageInfoSet) {
for (Iterator<UsageInfo> iterator = usageInfoSet.iterator(); iterator.hasNext(); ) {
UsageInfo usageInfo = iterator.next();
final PsiElement element = usageInfo.getElement();
if (element == null || !isToBeChanged(usageInfo)) {
iterator.remove();
}
}
LocalHistoryAction action = LocalHistory.getInstance().startAction(getCommandName());
final UsageInfo[] writableUsageInfos = usageInfoSet.toArray(new UsageInfo[usageInfoSet.size()]);
try {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
RefactoringListenerManagerImpl listenerManager = (RefactoringListenerManagerImpl) RefactoringListenerManager.getInstance(myProject);
myTransaction = listenerManager.startTransaction();
final Map<RefactoringHelper, Object> preparedData = new LinkedHashMap<>();
final Runnable prepareHelpersRunnable = new Runnable() {
@Override
public void run() {
for (final RefactoringHelper helper : Extensions.getExtensions(RefactoringHelper.EP_NAME)) {
Object operation = ApplicationManager.getApplication().runReadAction(new Computable<Object>() {
@Override
public Object compute() {
return helper.prepareOperation(writableUsageInfos);
}
});
preparedData.put(helper, operation);
}
}
};
ProgressManager.getInstance().runProcessWithProgressSynchronously(prepareHelpersRunnable, "Prepare ...", false, myProject);
Runnable performRefactoringRunnable = () -> {
final String refactoringId = getRefactoringId();
if (refactoringId != null) {
RefactoringEventData data = getBeforeData();
if (data != null) {
data.addUsages(usageInfoSet);
}
myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, data);
}
try {
if (refactoringId != null) {
UndoableAction action1 = new UndoRefactoringAction(myProject, refactoringId);
UndoManager.getInstance(myProject).undoableActionPerformed(action1);
}
performRefactoring(writableUsageInfos);
} finally {
if (refactoringId != null) {
myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, getAfterData(writableUsageInfos));
}
}
};
ApplicationImpl app = (ApplicationImpl) ApplicationManagerEx.getApplicationEx();
if (Registry.is("run.refactorings.under.progress")) {
app.runWriteActionWithProgressInDispatchThread(getCommandName(), myProject, null, null, indicator -> performRefactoringRunnable.run());
} else {
app.runWriteAction(performRefactoringRunnable);
}
DumbService.getInstance(myProject).completeJustSubmittedTasks();
for (Map.Entry<RefactoringHelper, Object> e : preparedData.entrySet()) {
//noinspection unchecked
e.getKey().performOperation(myProject, e.getValue());
}
myTransaction.commit();
app.runWriteAction(() -> performPsiSpoilingRefactoring());
} finally {
action.finish();
}
int count = writableUsageInfos.length;
if (count > 0) {
StatusBarUtil.setStatusBarInfo(myProject, RefactoringBundle.message("statusBar.refactoring.result", count));
} else {
if (!isPreviewUsages(writableUsageInfos)) {
StatusBarUtil.setStatusBarInfo(myProject, RefactoringBundle.message("statusBar.noUsages"));
}
}
}
use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class BaseRefactoringProcessor method showConflicts.
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, @Nullable final UsageInfo[] usages) {
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
if (!ConflictsInTestsException.isTestIgnore())
throw new ConflictsInTestsException(conflicts.values());
return true;
}
if (myPrepareSuccessfulSwingThreadCallback != null && !conflicts.isEmpty()) {
final String refactoringId = getRefactoringId();
if (refactoringId != null) {
RefactoringEventData conflictUsages = new RefactoringEventData();
conflictUsages.putUserData(RefactoringEventData.CONFLICTS_KEY, conflicts.values());
myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).conflictsDetected(refactoringId, conflictUsages);
}
final ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, usages);
if (!conflictsDialog.showAndGet()) {
if (conflictsDialog.isShowConflicts())
prepareSuccessful();
return false;
}
}
prepareSuccessful();
return true;
}
use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class ChangeSignatureProcessorBase method getAfterData.
@Nullable
@Override
protected RefactoringEventData getAfterData(@NotNull UsageInfo[] usages) {
RefactoringEventData data = new RefactoringEventData();
data.addElement(getChangeInfo().getMethod());
return data;
}
Aggregations