Search in sources :

Example 1 with Result

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());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiClass(com.intellij.psi.PsiClass) Result(com.intellij.openapi.application.Result) Test(org.testng.annotations.Test)

Example 2 with Result

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());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiClass(com.intellij.psi.PsiClass) Result(com.intellij.openapi.application.Result) Test(org.testng.annotations.Test)

Example 3 with Result

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();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Result(com.intellij.openapi.application.Result)

Example 4 with Result

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);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) OptimizeImportsProcessor(com.intellij.codeInsight.actions.OptimizeImportsProcessor) Result(com.intellij.openapi.application.Result)

Example 5 with Result

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());
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) ASTNode(com.intellij.lang.ASTNode) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)298 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)186 NotNull (org.jetbrains.annotations.NotNull)116 WriteAction (com.intellij.openapi.application.WriteAction)93 VirtualFile (com.intellij.openapi.vfs.VirtualFile)83 Project (com.intellij.openapi.project.Project)58 Module (com.intellij.openapi.module.Module)32 File (java.io.File)32 PsiFile (com.intellij.psi.PsiFile)31 Document (com.intellij.openapi.editor.Document)28 XmlFile (com.intellij.psi.xml.XmlFile)28 IOException (java.io.IOException)28 XmlTag (com.intellij.psi.xml.XmlTag)24 Nullable (org.jetbrains.annotations.Nullable)17 ReadAction (com.intellij.openapi.application.ReadAction)16 ArrayList (java.util.ArrayList)15 Editor (com.intellij.openapi.editor.Editor)13 PsiElement (com.intellij.psi.PsiElement)13 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)10