use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus 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.status.RefactoringStatus in project intellij-plugins by JetBrains.
the class DartInlineMethodRefactoringTest method doTest.
private void doTest(String filePath, boolean all) {
final ServerInlineMethodRefactoring refactoring = createRefactoring(filePath);
// check initial conditions
final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
assertNotNull(initialConditions);
assertTrue(initialConditions.isOK());
// all
if (all) {
refactoring.setInlineAll(true);
refactoring.setDeleteSource(true);
}
// 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 testCheckInitialConditionsCannotCreate.
public void testCheckInitialConditionsCannotCreate() throws Throwable {
final ServerRenameRefactoring refactoring = createRenameRefactoring();
final RefactoringStatus initialConditions = refactoring.checkInitialConditions();
assertNotNull(initialConditions);
assertTrue(initialConditions.hasFatalError());
}
use of com.jetbrains.lang.dart.ide.refactoring.status.RefactoringStatus 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.ide.refactoring.status.RefactoringStatus 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);
}
});
}
Aggregations