use of com.intellij.openapi.command.WriteCommandAction 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.command.WriteCommandAction 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.command.WriteCommandAction 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.command.WriteCommandAction 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.command.WriteCommandAction in project intellij-community by JetBrains.
the class GrCreateSubclassAction method createSubclassGroovy.
@Nullable
public static PsiClass createSubclassGroovy(final GrTypeDefinition psiClass, final PsiDirectory targetDirectory, final String className) {
final Project project = psiClass.getProject();
final Ref<GrTypeDefinition> targetClass = new Ref<>();
new WriteCommandAction(project, getTitle(psiClass), getTitle(psiClass)) {
@Override
protected void run(@NotNull Result result) throws Throwable {
IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
final GrTypeParameterList oldTypeParameterList = psiClass.getTypeParameterList();
try {
targetClass.set(CreateClassActionBase.createClassByType(targetDirectory, className, PsiManager.getInstance(project), psiClass, GroovyTemplates.GROOVY_CLASS, true));
} catch (final IncorrectOperationException e) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(project, CodeInsightBundle.message("intention.error.cannot.create.class.message", className) + "\n" + e.getLocalizedMessage(), CodeInsightBundle.message("intention.error.cannot.create.class.title")));
return;
}
startTemplate(oldTypeParameterList, project, psiClass, targetClass.get(), false);
}
}.execute();
if (targetClass.get() == null)
return null;
if (!ApplicationManager.getApplication().isUnitTestMode() && !psiClass.hasTypeParameters()) {
final Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, targetClass.get().getContainingFile(), targetClass.get());
if (editor == null)
return targetClass.get();
chooseAndImplement(psiClass, project, targetClass.get(), editor);
}
return targetClass.get();
}
Aggregations