private void refactor(String currentStepText, String newStepText, TransactionId contextTransaction, CompileContext context, RefactorStatusCallback refactorStatusCallback) { refactorStatusCallback.onStatusChange("Refactoring..."); Module module = GaugeUtil.moduleForPsiElement(file); TransactionGuard.getInstance().submitTransaction(() -> { }, contextTransaction, () -> { Api.PerformRefactoringResponse response = null; FileDocumentManager.getInstance().saveAllDocuments(); FileDocumentManager.getInstance().saveDocumentAsIs(editor.getDocument()); GaugeService gaugeService = Gauge.getGaugeService(module, true); try { response = gaugeService.getGaugeConnection().sendPerformRefactoringRequest(currentStepText, newStepText); } catch (Exception e) { refactorStatusCallback.onFinish(new RefactoringStatus(false, String.format("Could not execute refactor command: %s", e.toString()))); return; } new UndoHandler(response.getFilesChangedList(), module.getProject(), "Refactoring").handle(); if (!response.getSuccess()) { showMessage(response, context, refactorStatusCallback); return; } refactorStatusCallback.onFinish(new RefactoringStatus(true)); }); }
protected void restartAnalysis(final Project project, final AnalysisScope scope) { TransactionGuard guard = TransactionGuard.getInstance(); TransactionId id = guard.getContextTransaction(); DumbService.getInstance(project).smartInvokeLater(() -> TransactionGuard.getInstance().submitTransaction(project, id, () -> { if(DumbService.isDumb(project)) { restartAnalysis(project, scope); } else { analyze(project, scope); } })); }
void compileAndRefactor(String currentStepText, String newStepText, @Nullable RefactorStatusCallback refactorStatusCallback) { refactorStatusCallback.onStatusChange("Compiling..."); TransactionId contextTransaction = TransactionGuard.getInstance().getContextTransaction(); CompilerManager.getInstance(project).make((aborted, errors, warnings, context) -> { if (errors > 0) { refactorStatusCallback.onFinish(new RefactoringStatus(false, "Please fix all errors before refactoring.")); return; } refactor(currentStepText, newStepText, contextTransaction, context, refactorStatusCallback); }); }
public static void runTransactionWithEverythingCommitted(@Nonnull final Project project, @Nonnull final Runnable runnable) { TransactionGuard guard = TransactionGuard.getInstance(); TransactionId id = guard.getContextTransaction(); final PsiDocumentManager pdm = PsiDocumentManager.getInstance(project); pdm.performLaterWhenAllCommitted(() -> guard.submitTransaction(project, id, () -> { if (pdm.hasUncommitedDocuments()) { // no luck, will try later runTransactionWithEverythingCommitted(project, runnable); } else { runnable.run(); } })); }
void commitAsynchronously(@Nonnull final Project project, @Nonnull final Document document, @NonNls @Nonnull Object reason, @Nullable TransactionId context);
@Override public void commitAsynchronously(@Nonnull Project project, @Nonnull Document document, @NonNls @Nonnull Object reason, @Nonnull TransactionId context) { }