Search in sources :

Example 1 with MoveDirectoryWithClassesProcessor

use of com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor in project intellij-community by JetBrains.

the class RenamePsiPackageProcessor method createRenameMoveProcessor.

public static MoveDirectoryWithClassesProcessor createRenameMoveProcessor(final String newName, final PsiPackage psiPackage, final boolean searchInComments, final boolean searchInNonJavaFiles) {
    final Project project = psiPackage.getProject();
    final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    final PsiDirectory[] directories = psiPackage.getDirectories();
    return new MoveDirectoryWithClassesProcessor(project, directories, null, searchInComments, searchInNonJavaFiles, false, null) {

        @Override
        public TargetDirectoryWrapper getTargetDirectory(final PsiDirectory dir) {
            final VirtualFile vFile = dir.getVirtualFile();
            final VirtualFile sourceRoot = index.getSourceRootForFile(vFile);
            LOG.assertTrue(sourceRoot != null, vFile.getPath());
            return new TargetDirectoryWrapper(dir.getManager().findDirectory(sourceRoot), newName.replaceAll("\\.", "\\/"));
        }

        @Override
        protected String getTargetName() {
            return newName;
        }

        @Override
        protected String getCommandName() {
            return "Rename package";
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) MoveDirectoryWithClassesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Aggregations

Project (com.intellij.openapi.project.Project)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 MoveDirectoryWithClassesProcessor (com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor)1