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");
}
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);
}
});
}
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);
}
});
}
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");
}
Aggregations