Search in sources :

Example 1 with ServerExtractLocalVariableRefactoring

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

Example 2 with ServerExtractLocalVariableRefactoring

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

the class DartExtractLocalVariableRefactoringTest method createRefactoring.

@NotNull
private ServerExtractLocalVariableRefactoring createRefactoring(String filePath) {
    ((CodeInsightTestFixtureImpl) myFixture).canChangeDocumentDuringHighlighting(true);
    final PsiFile psiFile = myFixture.configureByFile(filePath);
    ApplicationManager.getApplication().runWriteAction(() -> {
        try {
            VfsUtil.saveText(psiFile.getVirtualFile(), StringUtil.convertLineSeparators(psiFile.getText(), "\r\n"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    // make sure server is warmed up
    myFixture.doHighlighting();
    // find the Element to rename
    final SelectionModel selectionModel = getEditor().getSelectionModel();
    int offset = selectionModel.getSelectionStart();
    final int length = selectionModel.getSelectionEnd() - offset;
    return new ServerExtractLocalVariableRefactoring(getProject(), psiFile.getVirtualFile(), offset, length);
}
Also used : ServerExtractLocalVariableRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerExtractLocalVariableRefactoring) CodeInsightTestFixtureImpl(com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl) SelectionModel(com.intellij.openapi.editor.SelectionModel) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ServerExtractLocalVariableRefactoring

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

the class DartServerExtractLocalVariableDialog method createRefactoring.

private void createRefactoring(int offset, int length) {
    refactoring = new ServerExtractLocalVariableRefactoring(project, file.getVirtualFile(), offset, length);
    final RefactoringStatus initialStatus = refactoring.checkInitialConditions();
    if (showMessageIfError(initialStatus)) {
        refactoring = null;
    }
}
Also used : ServerExtractLocalVariableRefactoring(com.jetbrains.lang.dart.ide.refactoring.ServerExtractLocalVariableRefactoring) RefactoringStatus(com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus)

Aggregations

ServerExtractLocalVariableRefactoring (com.jetbrains.lang.dart.ide.refactoring.ServerExtractLocalVariableRefactoring)3 RefactoringStatus (com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus)2 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 PsiFile (com.intellij.psi.PsiFile)1 CodeInsightTestFixtureImpl (com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl)1 DartSourceEditException (com.jetbrains.lang.dart.assists.DartSourceEditException)1 IOException (java.io.IOException)1 SourceChange (org.dartlang.analysis.server.protocol.SourceChange)1 NotNull (org.jetbrains.annotations.NotNull)1