use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus 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;
}
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus 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);
}
});
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.
the class DartServerRenameHandler method showRenameDialog.
private static void showRenameDialog(@NotNull Project project, @NotNull Editor editor, DataContext context) {
final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(context);
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(context);
if (psiFile == null || virtualFile == null) {
return;
}
// Prepare the offset in the editor or of the selected element.
final int offset;
{
final Caret caret = CommonDataKeys.CARET.getData(context);
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
if (caret != null) {
offset = caret.getOffset();
} else if (element != null) {
offset = element.getTextOffset();
} else {
return;
}
}
// Create the refactoring.
final ServerRenameRefactoring refactoring = new ServerRenameRefactoring(project, virtualFile, offset, 0);
// Validate initial status.
{
final RefactoringStatus initialStatus = refactoring.checkInitialConditions();
if (initialStatus == null) {
return;
}
if (initialStatus.hasError()) {
final String message = initialStatus.getMessage();
assert message != null;
CommonRefactoringUtil.showErrorHint(project, editor, message, CommonBundle.getErrorTitle(), null);
return;
}
}
// Show the rename dialog.
new DartRenameDialog(project, editor, refactoring).show();
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus 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");
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus in project intellij-plugins by JetBrains.
the class DartServerRenameTest method testCheckFinalConditionsNameFatalError.
public void testCheckFinalConditionsNameFatalError() throws Throwable {
final ServerRenameRefactoring refactoring = createRenameRefactoring();
// initial status OK
final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
assertNotNull(initialConditions);
assertTrue(initialConditions.isOK());
// final (actually options) status has a fatal error
refactoring.setNewName("bad name");
final RefactoringStatus finalConditions = refactoring.checkFinalConditions();
assertNotNull(finalConditions);
assertTrue(finalConditions.hasFatalError());
}
Aggregations