use of com.jetbrains.lang.dart.ide.refactoring.ServerExtractMethodRefactoring 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();
}
use of com.jetbrains.lang.dart.ide.refactoring.ServerExtractMethodRefactoring 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");
}
use of com.jetbrains.lang.dart.ide.refactoring.ServerExtractMethodRefactoring in project intellij-plugins by JetBrains.
the class DartExtractMethodRefactoringTest method createRefactoring.
@NotNull
private ServerExtractMethodRefactoring createRefactoring(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 SelectionModel selectionModel = getEditor().getSelectionModel();
int offset = selectionModel.getSelectionStart();
final int length = selectionModel.getSelectionEnd() - offset;
return new ServerExtractMethodRefactoring(getProject(), psiFile.getVirtualFile(), offset, length);
}
Aggregations