Search in sources :

Example 11 with RenameRefactoring

use of com.intellij.refactoring.RenameRefactoring in project Perl5-IDEA by Camelcade.

the class PerlMoveFileHandler method updateMovedFile.

@Override
public void updateMovedFile(PsiFile file) throws IncorrectOperationException {
    String originalPackageName = file.getUserData(ORIGINAL_PACKAGE_NAME);
    Project project = file.getProject();
    VirtualFile virtualFile = file.getVirtualFile();
    VirtualFile newInnermostRoot = PerlUtil.getFileClassRoot(project, virtualFile);
    if (newInnermostRoot != null && originalPackageName != null) {
        String newRelativePath = VfsUtil.getRelativePath(virtualFile, newInnermostRoot);
        String newPackageName = PerlPackageUtil.getPackageNameByPath(newRelativePath);
        final RenameRefactoring[] refactoring = { null };
        for (PerlNamespaceDefinitionElement namespaceDefinition : PsiTreeUtil.findChildrenOfType(file, PerlNamespaceDefinitionElement.class)) {
            if (originalPackageName.equals(namespaceDefinition.getPackageName())) {
                if (refactoring[0] == null) {
                    refactoring[0] = RefactoringFactory.getInstance(file.getProject()).createRename(namespaceDefinition, newPackageName);
                } else {
                    refactoring[0].addElement(namespaceDefinition, newPackageName);
                }
            }
        }
        if (refactoring[0] != null) {
            ApplicationManager.getApplication().invokeLater(refactoring[0]::run);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) RenameRefactoring(com.intellij.refactoring.RenameRefactoring)

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