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);
}
}
}
Aggregations