Search in sources :

Example 6 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.

the class ProjectScopeBuilderImpl method buildAllScope.

@NotNull
@Override
public GlobalSearchScope buildAllScope() {
    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
    if (projectRootManager == null)
        return new EverythingGlobalScope(myProject);
    boolean searchOutsideRootModel = false;
    for (SearchScopeEnlarger each : Extensions.getExtensions(SearchScopeEnlarger.EXTENSION)) {
        searchOutsideRootModel = each.allScopeSearchesOutsideRootModel(myProject);
        if (searchOutsideRootModel)
            break;
    }
    return new ProjectAndLibrariesScope(myProject, searchOutsideRootModel);
}
Also used : ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.

the class NavBarModel method updateModel.

protected void updateModel(final PsiElement psiElement) {
    final Set<VirtualFile> roots = new HashSet<>();
    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
    final ProjectFileIndex projectFileIndex = projectRootManager.getFileIndex();
    for (VirtualFile root : projectRootManager.getContentRoots()) {
        VirtualFile parent = root.getParent();
        if (parent == null || !projectFileIndex.isInContent(parent)) {
            roots.add(root);
        }
    }
    for (final NavBarModelExtension modelExtension : Extensions.getExtensions(NavBarModelExtension.EP_NAME)) {
        for (VirtualFile root : modelExtension.additionalRoots(psiElement.getProject())) {
            VirtualFile parent = root.getParent();
            if (parent == null || !projectFileIndex.isInContent(parent)) {
                roots.add(root);
            }
        }
    }
    final List<Object> updatedModel = new ArrayList<>();
    ApplicationManager.getApplication().runReadAction(() -> traverseToRoot(psiElement, roots, updatedModel));
    setModel(ContainerUtil.reverse(updatedModel));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager)

Example 8 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.

the class SaveProjectAsTemplateAction method collectStructure.

@NotNull
private static List<LocalArchivedTemplate.RootDescription> collectStructure(Project project, Module moduleToSave) {
    List<LocalArchivedTemplate.RootDescription> result = new ArrayList<>();
    if (moduleToSave != null) {
        PathMacroManager macroManager = PathMacroManager.getInstance(moduleToSave);
        ModuleRootManager rootManager = ModuleRootManager.getInstance(moduleToSave);
        int i = 0;
        for (VirtualFile file : rootManager.getContentRoots()) {
            result.add(i, describeRoot(file, i, macroManager));
            i++;
        }
    } else {
        PathMacroManager macroManager = PathMacroManager.getInstance(project);
        ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
        int i = 0;
        for (VirtualFile file : rootManager.getContentRoots()) {
            result.add(i, describeRoot(file, i, macroManager));
            i++;
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) PathMacroManager(com.intellij.openapi.components.PathMacroManager) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.

the class TestOnlyInspection method isUnderTestSources.

private static boolean isUnderTestSources(PsiElement e) {
    ProjectRootManager rm = ProjectRootManager.getInstance(e.getProject());
    VirtualFile f = e.getContainingFile().getVirtualFile();
    return f != null && rm.getFileIndex().isInTestSourceContent(f);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager)

Example 10 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.

the class MoveInnerDialog method getTargetContainer.

@Nullable
private PsiElement getTargetContainer() {
    if (myTargetContainer instanceof PsiDirectory) {
        final PsiDirectory psiDirectory = (PsiDirectory) myTargetContainer;
        PsiPackage oldPackage = getTargetPackage();
        String name = oldPackage == null ? "" : oldPackage.getQualifiedName();
        final String targetName = myPackageNameField.getText();
        if (!Comparing.equal(name, targetName)) {
            final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
            final List<VirtualFile> contentSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject);
            final PackageWrapper newPackage = new PackageWrapper(PsiManager.getInstance(myProject), targetName);
            final VirtualFile targetSourceRoot;
            if (contentSourceRoots.size() > 1) {
                PsiPackage targetPackage = JavaPsiFacade.getInstance(myProject).findPackage(targetName);
                PsiDirectory initialDir = null;
                if (targetPackage != null) {
                    final PsiDirectory[] directories = targetPackage.getDirectories();
                    final VirtualFile root = projectRootManager.getFileIndex().getSourceRootForFile(psiDirectory.getVirtualFile());
                    for (PsiDirectory dir : directories) {
                        if (Comparing.equal(projectRootManager.getFileIndex().getSourceRootForFile(dir.getVirtualFile()), root)) {
                            initialDir = dir;
                            break;
                        }
                    }
                }
                final VirtualFile sourceRoot = MoveClassesOrPackagesUtil.chooseSourceRoot(newPackage, contentSourceRoots, initialDir);
                if (sourceRoot == null)
                    return null;
                targetSourceRoot = sourceRoot;
            } else {
                targetSourceRoot = contentSourceRoots.get(0);
            }
            PsiDirectory dir = RefactoringUtil.findPackageDirectoryInSourceRoot(newPackage, targetSourceRoot);
            if (dir == null) {
                dir = ApplicationManager.getApplication().runWriteAction(new NullableComputable<PsiDirectory>() {

                    public PsiDirectory compute() {
                        try {
                            return RefactoringUtil.createPackageDirectoryInSourceRoot(newPackage, targetSourceRoot);
                        } catch (IncorrectOperationException e) {
                            return null;
                        }
                    }
                });
            }
            return dir;
        }
    }
    return myTargetContainer;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NullableComputable(com.intellij.openapi.util.NullableComputable) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) PackageWrapper(com.intellij.refactoring.PackageWrapper) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 Project (com.intellij.openapi.project.Project)8 Module (com.intellij.openapi.module.Module)7 Sdk (com.intellij.openapi.projectRoots.Sdk)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)4 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)4 File (java.io.File)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 NullableComputable (com.intellij.openapi.util.NullableComputable)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiManager (com.intellij.psi.PsiManager)2 PackageWrapper (com.intellij.refactoring.PackageWrapper)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CheckStylePlugin (org.infernus.idea.checkstyle.CheckStylePlugin)2 ScanScope (org.infernus.idea.checkstyle.model.ScanScope)2