use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.
the class ConfigurationsTest method testRenameMethod.
@Test
public void testRenameMethod() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final String className = psiClass.getName();
final TestNGConfiguration configuration = createConfiguration(project);
final PsiMethod method = findTestMethod(psiClass);
configuration.beMethodConfiguration(new PsiLocation<>(project, method));
final String newMethodName = "renamedTest";
final RenameRefactoring renameMethod = RefactoringFactory.getInstance(project).createRename(method, newMethodName);
renameMethod.setSearchInComments(false);
renameMethod.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameMethod.run();
}
}.execute();
Assert.assertEquals(className, configuration.getPersistantData().getMainClassName());
Assert.assertEquals(newMethodName, configuration.getPersistantData().getMethodName());
final PsiMethod notATestMethod = findNotATestMethod(psiClass);
final RenameRefactoring renameNotATestMethod1 = RefactoringFactory.getInstance(project).createRename(notATestMethod, "bbbbb");
renameNotATestMethod1.setSearchInComments(false);
renameNotATestMethod1.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameNotATestMethod1.run();
}
}.execute();
Assert.assertEquals(className, configuration.getPersistantData().getMainClassName());
Assert.assertEquals(newMethodName, configuration.getPersistantData().getMethodName());
}
use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.
the class ConfigurationsTest method testClassRename.
@Test
public void testClassRename() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final TestNGConfiguration configuration = createConfiguration(project);
configuration.beClassConfiguration(psiClass);
final String newName = "Testt1";
final RenameRefactoring renameClass = RefactoringFactory.getInstance(project).createRename(psiClass, newName);
renameClass.setSearchInComments(false);
renameClass.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameClass.run();
}
}.execute();
Assert.assertEquals(newName, configuration.getPersistantData().getMainClassName());
final PsiMethod notATestMethod = findNotATestMethod(psiClass);
final RenameRefactoring renameNotATestMethod = RefactoringFactory.getInstance(project).createRename(notATestMethod, "aaaa");
renameNotATestMethod.setSearchInComments(false);
renameNotATestMethod.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameNotATestMethod.run();
}
}.execute();
Assert.assertEquals(configuration.getPersistantData().getMainClassName(), newName);
Assert.assertEquals(configuration.getPersistantData().getMethodName(), "");
Assert.assertEquals(configuration.getPersistantData().TEST_OBJECT, TestType.CLASS.getType());
}
use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.
the class ArrayTableCellEditor method cancelEditing.
public void cancelEditing() {
new WriteCommandAction(null) {
protected void run(@NotNull Result result) throws Throwable {
if (myEditor.getEditor() != null) {
myEditor.getEditor().getDocument().setText(myLastValue.toString());
}
}
}.execute();
myEditor.getComponent().repaint();
stopCellEditing();
}
use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.
the class XmlNamespacesTest method doOptimizeImportsTest.
private void doOptimizeImportsTest(String after) {
myFixture.testHighlighting();
new WriteCommandAction(getProject(), getFile()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
new OptimizeImportsProcessor(getProject(), getFile()).runWithoutProgress();
}
}.execute();
myFixture.checkResult(after);
}
use of com.intellij.openapi.application.Result in project kotlin by JetBrains.
the class KotlinInplaceVariableIntroducer method runWriteActionAndRestartRefactoring.
protected final void runWriteActionAndRestartRefactoring(final Runnable runnable) {
final Ref<Boolean> greedyToRight = new Ref<Boolean>();
new WriteCommandAction(myProject, getCommandName(), getCommandName()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
ASTNode identifier = myDeclaration.getNode().findChildByType(KtTokens.IDENTIFIER);
if (identifier != null) {
TextRange range = identifier.getTextRange();
RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
for (RangeHighlighter highlighter : highlighters) {
if (highlighter.getStartOffset() == range.getStartOffset()) {
if (highlighter.getEndOffset() == range.getEndOffset()) {
greedyToRight.set(highlighter.isGreedyToRight());
highlighter.setGreedyToRight(false);
}
}
}
}
runnable.run();
TemplateState templateState = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor));
if (templateState != null) {
myEditor.putUserData(INTRODUCE_RESTART, true);
templateState.cancelTemplate();
}
}
}.execute();
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
ASTNode identifier = myDeclaration.getNode().findChildByType(KtTokens.IDENTIFIER);
if (identifier != null) {
TextRange range = identifier.getTextRange();
RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
for (RangeHighlighter highlighter : highlighters) {
if (highlighter.getStartOffset() == range.getStartOffset()) {
if (highlighter.getEndOffset() == range.getEndOffset()) {
highlighter.setGreedyToRight(greedyToRight.get());
}
}
}
}
}
});
if (myEditor.getUserData(INTRODUCE_RESTART) == Boolean.TRUE) {
myInitialName = myDeclaration.getName();
performInplaceRefactoring(getSuggestionsForNextRun());
}
}
Aggregations