Search in sources :

Example 6 with RefactoringStatus

use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.

the class DartExtractMethodRefactoringTest method doTest.

private void doTest(String filePath, boolean all, boolean asGetter) {
    final ServerExtractMethodRefactoring refactoring = createRefactoring(filePath);
    // check initial conditions
    final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
    assertNotNull(initialConditions);
    assertTrue(initialConditions.isOK());
    // configure
    refactoring.setName("test");
    refactoring.setExtractAll(all);
    refactoring.setCreateGetter(asGetter);
    // 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, false);
        } catch (DartSourceEditException e) {
            fail(e.getMessage());
        }
    });
    // validate
    myFixture.checkResultByFile(getTestName(false) + ".after.dart");
}
Also used : ServerExtractMethodRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerExtractMethodRefactoring) RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) DartSourceEditException(com.jetbrains.lang.dart.assists.DartSourceEditException)

Example 7 with RefactoringStatus

use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.

the class DartInlineMethodRefactoringTest method doTest.

private void doTest(String filePath, boolean all) {
    final ServerInlineMethodRefactoring refactoring = createRefactoring(filePath);
    // check initial conditions
    final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
    assertNotNull(initialConditions);
    assertTrue(initialConditions.isOK());
    // all
    if (all) {
        refactoring.setInlineAll(true);
        refactoring.setDeleteSource(true);
    }
    // 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, false);
        } catch (DartSourceEditException e) {
            fail(e.getMessage());
        }
    });
    // validate
    myFixture.checkResultByFile(getTestName(false) + ".after.dart");
}
Also used : RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) ServerInlineMethodRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerInlineMethodRefactoring) DartSourceEditException(com.jetbrains.lang.dart.assists.DartSourceEditException)

Example 8 with RefactoringStatus

use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.

the class DartServerRenameTest method testCheckInitialConditionsCannotCreate.

public void testCheckInitialConditionsCannotCreate() throws Throwable {
    final ServerRenameRefactoring refactoring = createRenameRefactoring();
    final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
    assertNotNull(initialConditions);
    assertTrue(initialConditions.hasFatalError());
}
Also used : RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus) ServerRenameRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerRenameRefactoring)

Example 9 with RefactoringStatus

use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.

the class DartServerRenameTest method doTest.

private void doTest(@NotNull final ServerRenameRefactoring refactoring, @NotNull final String newName) {
    // check initial conditions
    final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
    assertNotNull(initialConditions);
    assertTrue(initialConditions.isOK());
    // check final conditions
    refactoring.setNewName(newName);
    final RefactoringStatus finalConditions = refactoring.checkFinalConditions();
    assertNotNull(finalConditions);
    assertTrue(finalConditions.isOK());
    // apply the SourceChange
    final SourceChange change = refactoring.getChange();
    assertNotNull(change);
    ApplicationManager.getApplication().runWriteAction(() -> {
        final Set<String> excludedIds = refactoring.getPotentialEdits();
        try {
            AssistUtils.applySourceChange(myFixture.getProject(), change, false, excludedIds);
        } catch (DartSourceEditException e) {
            fail(e.getMessage());
        }
    });
    // validate
    myFixture.checkResultByFile(getTestName(false) + ".after.dart");
}
Also used : RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) DartSourceEditException(com.jetbrains.lang.dart.assists.DartSourceEditException)

Example 10 with RefactoringStatus

use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.

the class InlineMethodDialog method inlineElement.

@Override
public void inlineElement(@NotNull final Project project, @Nullable final Editor editor, PsiElement element) {
    final InlineRefactoringContext context = findContext(editor);
    if (context == null) {
        return;
    }
    // create refactoring
    final ServerRefactoring refactoring;
    if (ElementKind.LOCAL_VARIABLE.equals(context.kind)) {
        refactoring = new ServerInlineLocalRefactoring(project, context.virtualFile, context.offset, 0);
    } else {
        refactoring = new ServerInlineMethodRefactoring(project, context.virtualFile, context.offset, 0);
    }
    // validate initial status
    {
        final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
        if (showMessageIfError(editor, initialConditions)) {
            return;
        }
    }
    // configure using dialog
    if (refactoring instanceof ServerInlineMethodRefactoring) {
        boolean dialogOK = new InlineMethodDialog(project, element, (ServerInlineMethodRefactoring) refactoring).showAndGet();
        if (!dialogOK) {
            return;
        }
    }
    // validate final status
    {
        final RefactoringStatus finalConditions = refactoring.checkFinalConditions();
        if (showMessageIfError(editor, finalConditions)) {
            return;
        }
    }
    // Apply the change.
    ApplicationManager.getApplication().runWriteAction(() -> {
        final SourceChange change = refactoring.getChange();
        assert change != null;
        try {
            AssistUtils.applySourceChange(project, change, false);
        } catch (DartSourceEditException e) {
            CommonRefactoringUtil.showErrorHint(project, editor, e.getMessage(), CommonBundle.getErrorTitle(), null);
        }
    });
}
Also used : 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