Search in sources :

Example 1 with RenameRefactoring

use of com.intellij.refactoring.RenameRefactoring 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 RenameRefactoring

use of com.intellij.refactoring.RenameRefactoring 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 RenameRefactoring

use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.

the class JavaFXRenameTest method testStaticPropertyMethod.

public void testStaticPropertyMethod() throws Exception {
    final String className = "container.MyCustomContainer";
    final String methodName = "setStaticProp";
    final String newName = "setNewMethodName";
    myFixture.configureByFiles(getTestName(true) + ".fxml", className.replace('.', '/') + ".java");
    final PsiClass psiClass = myFixture.findClass(className);
    assertNotNull(psiClass);
    final PsiMethod[] methods = psiClass.findMethodsByName(methodName, false);
    assertEquals(1, methods.length);
    final PsiMethod method = methods[0];
    final RenameRefactoring rename = new JavaRenameRefactoringImpl(getProject(), method, newName, false, false);
    rename.run();
    myFixture.checkResultByFile(getTestName(true) + "_after.fxml");
    assertMethodExists(psiClass, newName);
}
Also used : JavaRenameRefactoringImpl(com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl) PsiMethod(com.intellij.psi.PsiMethod) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiClass(com.intellij.psi.PsiClass)

Example 4 with RenameRefactoring

use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.

the class JavaFxPropertyRenameHandler method doRename.

private static void doRename(JavaFxPropertyReference reference, String newName, final boolean searchInComments, boolean isPreview) {
    final PsiElement psiElement = JavaFxPropertyElement.fromReference(reference);
    if (psiElement == null)
        return;
    final RenameRefactoring rename = new JavaRenameRefactoringImpl(psiElement.getProject(), psiElement, newName, searchInComments, false);
    rename.setPreviewUsages(isPreview);
    final Map<PsiElement, String> elementsToRename = getElementsToRename(reference, newName);
    elementsToRename.forEach(rename::addElement);
    rename.run();
}
Also used : JavaRenameRefactoringImpl(com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl) RenameRefactoring(com.intellij.refactoring.RenameRefactoring)

Example 5 with RenameRefactoring

use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.

the class RncRenameTest method testRenameIncludedFile.

public void testRenameIncludedFile() throws Throwable {
    myTestFixture.copyFileToProject("rename-in-include-ref.rnc");
    final Project project = myTestFixture.getProject();
    final RefactoringFactory factory = RefactoringFactory.getInstance(project);
    String fullPath = myTestFixture.getTempDirPath() + "/" + "rename-in-include-ref.rnc";
    final VirtualFile copy = LocalFileSystem.getInstance().refreshAndFindFileByPath(fullPath.replace(File.separatorChar, '/'));
    assert copy != null : "file " + fullPath + " not found";
    final PsiFile file = PsiManager.getInstance(project).findFile(copy);
    assertNotNull(file);
    myTestFixture.configureByFile("rename-in-include.rnc");
    final RenameRefactoring refactoring = factory.createRename(file, "rename-after.rnc");
    refactoring.setPreviewUsages(false);
    refactoring.setSearchInComments(false);
    refactoring.setSearchInNonJavaFiles(true);
    refactoring.run();
    myTestFixture.checkResultByFile("rename-in-include_after.rnc");
    assertEquals("rename-after.rnc", file.getName());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiFile(com.intellij.psi.PsiFile) RefactoringFactory(com.intellij.refactoring.RefactoringFactory)

Aggregations

RenameRefactoring (com.intellij.refactoring.RenameRefactoring)11 Project (com.intellij.openapi.project.Project)4 JavaRenameRefactoringImpl (com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3 PsiMethod (com.intellij.psi.PsiMethod)3 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 PsiElement (com.intellij.psi.PsiElement)2 PsiNamedElement (com.intellij.psi.PsiNamedElement)2 RefactoringFactory (com.intellij.refactoring.RefactoringFactory)2 Test (org.testng.annotations.Test)2 PsiFile (com.intellij.psi.PsiFile)1 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)1 PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)1