Search in sources :

Example 1 with ServerInlineLocalRefactoring

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

the class DartInlineLocalRefactoringTest method createInlineLocalRefactoring.

@NotNull
private ServerInlineLocalRefactoring createInlineLocalRefactoring(String filePath) {
    ((CodeInsightTestFixtureImpl) myFixture).canChangeDocumentDuringHighlighting(true);
    final PsiFile psiFile = myFixture.configureByFile(filePath);
    // make sure server is warmed up
    myFixture.doHighlighting();
    // find the Element to rename
    final int offset = getEditor().getCaretModel().getOffset();
    return new ServerInlineLocalRefactoring(getProject(), psiFile.getVirtualFile(), offset, 0);
}
Also used : CodeInsightTestFixtureImpl(com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl) ServerInlineLocalRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerInlineLocalRefactoring) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ServerInlineLocalRefactoring

use of com.jetbrains.lang.dart.ide.refactoring.ServerInlineLocalRefactoring 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

ServerInlineLocalRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerInlineLocalRefactoring)2 PsiFile (com.intellij.psi.PsiFile)1 CodeInsightTestFixtureImpl (com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl)1 DartSourceEditException (com.jetbrains.lang.dart.assists.DartSourceEditException)1 RefactoringStatus (com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus)1 SourceChange (org.dartlang.analysis.server.protocol.SourceChange)1 NotNull (org.jetbrains.annotations.NotNull)1