Search in sources :

Example 6 with DartSourceEditException

use of com.jetbrains.lang.dart.assists.DartSourceEditException 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 7 with DartSourceEditException

use of com.jetbrains.lang.dart.assists.DartSourceEditException 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)

Example 8 with DartSourceEditException

use of com.jetbrains.lang.dart.assists.DartSourceEditException in project intellij-plugins by JetBrains.

the class DartServerExtractLocalVariableDialog method performInPlace.

private void performInPlace() {
    final String[] names = refactoring.getNames();
    if (names.length != 0) {
        refactoring.setName(names[0]);
    }
    // validate final status
    {
        final RefactoringStatus finalConditions = refactoring.checkFinalConditions();
        if (showMessageIfError(finalConditions)) {
            return;
        }
    }
    // Apply the change.
    ApplicationManager.getApplication().runWriteAction(() -> {
        final SourceChange change = refactoring.getChange();
        assert change != null;
        try {
            AssistUtils.applySourceChange(project, change, true);
        } 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)

Example 9 with DartSourceEditException

use of com.jetbrains.lang.dart.assists.DartSourceEditException in project intellij-plugins by JetBrains.

the class DartInlineLocalRefactoringTest method doTest.

private void doTest(String filePath) {
    final ServerInlineLocalRefactoring refactoring = createInlineLocalRefactoring(filePath);
    // check initial conditions
    final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
    assertNotNull(initialConditions);
    assertTrue(initialConditions.isOK());
    // 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 : ServerInlineLocalRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerInlineLocalRefactoring) RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) DartSourceEditException(com.jetbrains.lang.dart.assists.DartSourceEditException)

Aggregations

DartSourceEditException (com.jetbrains.lang.dart.assists.DartSourceEditException)9 SourceChange (org.dartlang.analysis.server.protocol.SourceChange)8 RefactoringStatus (com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus)7 Document (com.intellij.openapi.editor.Document)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)1 ServerExtractLocalVariableRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerExtractLocalVariableRefactoring)1 ServerExtractMethodRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerExtractMethodRefactoring)1 ServerInlineLocalRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerInlineLocalRefactoring)1 ServerInlineMethodRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerInlineMethodRefactoring)1 IOException (java.io.IOException)1 Position (org.dartlang.analysis.server.protocol.Position)1 SourceFileEdit (org.dartlang.analysis.server.protocol.SourceFileEdit)1