use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.
the class DartServerExtractMethodDialog method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection())
selectionModel.selectLineAtCaret();
final int offset = selectionModel.getSelectionStart();
final int length = selectionModel.getSelectionEnd() - offset;
final ServerExtractMethodRefactoring refactoring = new ServerExtractMethodRefactoring(project, file.getVirtualFile(), offset, length);
// Validate initial status.
{
final RefactoringStatus initialStatus = refactoring.checkInitialConditions();
if (initialStatus == null) {
return;
}
if (initialStatus.hasError()) {
final String title = DartBundle.message("dart.refactoring.extract.method.error");
CommonRefactoringUtil.showErrorHint(project, editor, initialStatus.getMessage(), title, null);
return;
}
}
new DartServerExtractMethodDialog(project, editor, refactoring).show();
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.
the class ServerRefactoring method checkFinalConditions.
@Nullable
public RefactoringStatus checkFinalConditions() {
ProgressManager.getInstance().run(new Task.Modal(null, refactoringName, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText("Validating the specified parameters.");
indicator.setIndeterminate(true);
setOptions(false, indicator);
}
});
if (serverErrorStatus != null) {
return serverErrorStatus;
}
if (finalStatus == null) {
return null;
}
RefactoringStatus result = new RefactoringStatus();
result.merge(optionsStatus);
result.merge(finalStatus);
return result;
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.
the class ServerRefactoring method notifyListener.
private void notifyListener() {
if (listener != null) {
boolean hasPendingRequests = !pendingRequestIds.isEmpty();
RefactoringStatus status = optionsStatus != null ? optionsStatus : new RefactoringStatus();
listener.requestStateChanged(hasPendingRequests, status);
}
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.
the class ServerRefactoring method toRefactoringStatus.
private static RefactoringStatus toRefactoringStatus(@NotNull List<RefactoringProblem> problems) {
RefactoringStatus status = new RefactoringStatus();
for (RefactoringProblem problem : problems) {
final String serverSeverity = problem.getSeverity();
final RefactoringStatusSeverity problemSeverity = toProblemSeverity(serverSeverity);
final String message = problem.getMessage();
status.addEntry(new RefactoringStatusEntry(problemSeverity, message));
}
return status;
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.
the class DartExtractLocalVariableRefactoringTest method doTest.
private void doTest(String filePath, boolean all) {
final ServerExtractLocalVariableRefactoring refactoring = createRefactoring(filePath);
// check initial conditions
final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
assertNotNull(initialConditions);
assertTrue(initialConditions.isOK());
// configure
//refactoring.setName("test");
refactoring.setExtractAll(all);
// check final conditions
final RefactoringStatus finalConditions = refactoring.checkFinalConditions();
assertNotNull(finalConditions);
assertTrue(finalConditions.isOK());
// apply the SourceChange
final SourceChange change = refactoring.getChange();
assertNotNull(change);
ApplicationManager.getApplication().runWriteAction(() -> {
try {
AssistUtils.applySourceChange(myFixture.getProject(), change, true);
} catch (DartSourceEditException e) {
fail(e.getMessage());
}
});
// validate
myFixture.checkResultByFile(getTestName(false) + ".after.dart");
}
Aggregations