Search in sources :

Example 76 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project kotlin by JetBrains.

the class SourceNavigationHelper method filterByOrderEntries.

@NotNull
private static List<KtNamedDeclaration> filterByOrderEntries(@NotNull KtNamedDeclaration declaration, @NotNull Collection<KtNamedDeclaration> candidates) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(declaration.getProject()).getFileIndex();
    final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(declaration.getContainingFile().getVirtualFile());
    return CollectionsKt.filter(candidates, new Function1<KtNamedDeclaration, Boolean>() {

        @Override
        public Boolean invoke(KtNamedDeclaration candidate) {
            List<OrderEntry> candidateOrderEntries = fileIndex.getOrderEntriesForFile(candidate.getContainingFile().getVirtualFile());
            return ContainerUtil.intersects(orderEntries, candidateOrderEntries);
        }
    });
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project android by JetBrains.

the class AndroidAddLibraryDependencyAction method getGradleBuildModel.

@Nullable
private static GradleBuildModel getGradleBuildModel(@NotNull Project project, @NotNull PsiFile file) {
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    Module module = index.getModuleForFile(file.getVirtualFile());
    if (module == null) {
        return null;
    }
    return GradleBuildModel.get(module);
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 78 with ProjectFileIndex

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

the class IfsUtil method getReferencePath.

public static String getReferencePath(Project project, VirtualFile file) {
    final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(file);
    if (logicalRoot != null) {
        return getRelativePath(file, logicalRoot.getVirtualFile());
    }
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    VirtualFile sourceRoot = fileIndex.getSourceRootForFile(file);
    if (sourceRoot != null) {
        return getRelativePath(file, sourceRoot);
    }
    VirtualFile root = fileIndex.getContentRootForFile(file);
    if (root != null) {
        return getRelativePath(file, root);
    }
    return file.getPath();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalRoot(com.intellij.util.LogicalRoot) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 79 with ProjectFileIndex

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

the class CompileModuleChunkTarget method createCopyTask.

private static Generator createCopyTask(final Project project, ModuleChunk chunk, VirtualFile[] sourceRoots, String toDir, File baseDir, final GenerationOptions genOptions) {
    //noinspection HardCodedStringLiteral
    final Tag filesSelector = new Tag("type", Couple.of("type", "file"));
    final PatternSetRef excludes = CompilerExcludes.isAvailable(project) ? new PatternSetRef(BuildProperties.getExcludedFromCompilationProperty(chunk.getName())) : null;
    final PatternSetRef resourcePatternsPatternSet = new PatternSetRef(BuildProperties.PROPERTY_COMPILER_RESOURCE_PATTERNS);
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final CompositeGenerator composite = new CompositeGenerator();
    final Map<String, Copy> outputDirToTaskMap = new HashMap<>();
    for (final VirtualFile root : sourceRoots) {
        final String packagePrefix = fileIndex.getPackageNameByDirectory(root);
        final String targetDir = packagePrefix != null && packagePrefix.length() > 0 ? toDir + "/" + packagePrefix.replace('.', '/') : toDir;
        Copy copy = outputDirToTaskMap.get(targetDir);
        if (copy == null) {
            copy = new Copy(targetDir);
            outputDirToTaskMap.put(targetDir, copy);
            composite.add(copy);
        }
        final FileSet fileSet = new FileSet(GenerationUtils.toRelativePath(root, baseDir, BuildProperties.getModuleChunkBasedirProperty(chunk), genOptions));
        fileSet.add(resourcePatternsPatternSet);
        fileSet.add(filesSelector);
        if (excludes != null) {
            fileSet.add(excludes);
        }
        copy.add(fileSet);
    }
    return composite;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) HashMap(java.util.HashMap)

Example 80 with ProjectFileIndex

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

the class CompileAction method getCompilableFiles.

private static VirtualFile[] getCompilableFiles(Project project, VirtualFile[] files) {
    if (files == null || files.length == 0) {
        return VirtualFile.EMPTY_ARRAY;
    }
    final PsiManager psiManager = PsiManager.getInstance(project);
    final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(project);
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    final List<VirtualFile> filesToCompile = new ArrayList<>();
    for (final VirtualFile file : files) {
        if (!fileIndex.isInSourceContent(file)) {
            continue;
        }
        if (!file.isInLocalFileSystem()) {
            continue;
        }
        if (file.isDirectory()) {
            final PsiDirectory directory = psiManager.findDirectory(file);
            if (directory == null || JavaDirectoryService.getInstance().getPackage(directory) == null) {
                continue;
            }
        } else {
            FileType fileType = file.getFileType();
            if (!(compilerManager.isCompilableFileType(fileType) || compilerConfiguration.isCompilableResourceFile(project, file))) {
                continue;
            }
        }
        filesToCompile.add(file);
    }
    return VfsUtilCore.toVirtualFileArray(filesToCompile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FileType(com.intellij.openapi.fileTypes.FileType) CompilerManager(com.intellij.openapi.compiler.CompilerManager) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration) ArrayList(java.util.ArrayList)

Aggregations

ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)157 VirtualFile (com.intellij.openapi.vfs.VirtualFile)119 Module (com.intellij.openapi.module.Module)52 Project (com.intellij.openapi.project.Project)49 Nullable (org.jetbrains.annotations.Nullable)37 NotNull (org.jetbrains.annotations.NotNull)24 PsiDirectory (com.intellij.psi.PsiDirectory)23 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 PsiFile (com.intellij.psi.PsiFile)14 ArrayList (java.util.ArrayList)13 IdeView (com.intellij.ide.IdeView)10 OrderEntry (com.intellij.openapi.roots.OrderEntry)9 THashSet (gnu.trove.THashSet)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)5 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 File (java.io.File)4 List (java.util.List)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 Presentation (com.intellij.openapi.actionSystem.Presentation)3