Search in sources :

Example 1 with RefactoringFactory

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

Example 2 with RefactoringFactory

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

the class RenameFix method doFix.

@Override
public void doFix(Project project, ProblemDescriptor descriptor) {
    if (m_targetName == null) {
        super.doFix(project, descriptor);
    } else {
        final PsiElement nameIdentifier = descriptor.getPsiElement();
        final PsiElement elementToRename = nameIdentifier.getParent();
        final RefactoringFactory factory = RefactoringFactory.getInstance(project);
        final RenameRefactoring renameRefactoring = factory.createRename(elementToRename, m_targetName, m_searchInStrings, m_searchInNonJavaFiles);
        renameRefactoring.run();
    }
}
Also used : RenameRefactoring(com.intellij.refactoring.RenameRefactoring) RefactoringFactory(com.intellij.refactoring.RefactoringFactory) PsiElement(com.intellij.psi.PsiElement)

Aggregations

RefactoringFactory (com.intellij.refactoring.RefactoringFactory)2 RenameRefactoring (com.intellij.refactoring.RenameRefactoring)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1