Search in sources :

Example 1 with RefactoringStatus

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();
}
Also used : ServerExtractMethodRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerExtractMethodRefactoring) SelectionModel(com.intellij.openapi.editor.SelectionModel) RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus)

Example 2 with RefactoringStatus

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;
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with RefactoringStatus

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);
    }
}
Also used : RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus)

Example 4 with RefactoringStatus

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;
}
Also used : RefactoringStatusSeverity(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatusSeverity) RefactoringStatusEntry(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatusEntry) RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus)

Example 5 with RefactoringStatus

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");
}
Also used : ServerExtractLocalVariableRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerExtractLocalVariableRefactoring) RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) DartSourceEditException(com.jetbrains.lang.dart.assists.DartSourceEditException)

Aggregations

RefactoringStatus (com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus)15 DartSourceEditException (com.jetbrains.lang.dart.assists.DartSourceEditException)7 SourceChange (org.dartlang.analysis.server.protocol.SourceChange)7 ServerExtractLocalVariableRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerExtractLocalVariableRefactoring)2 ServerExtractMethodRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerExtractMethodRefactoring)2 ServerRenameRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerRenameRefactoring)2 Caret (com.intellij.openapi.editor.Caret)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 ServerInlineLocalRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerInlineLocalRefactoring)1 ServerInlineMethodRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerInlineMethodRefactoring)1 RefactoringStatusEntry (com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatusEntry)1 RefactoringStatusSeverity (com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatusSeverity)1 Nullable (org.jetbrains.annotations.Nullable)1