Search in sources :

Example 81 with ProjectFileIndex

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

the class ExcludedFromCompileFilesUtil method getExcludedFilesScope.

static GlobalSearchScope getExcludedFilesScope(@NotNull ExcludeEntryDescription[] descriptions, @NotNull Set<FileType> fileTypes, @NotNull Project project, @NotNull ProjectFileIndex fileIndex) {
    ManagingFS fs = ManagingFS.getInstance();
    final Collection<VirtualFile> excludedFiles = Stream.of(descriptions).flatMap(description -> {
        final VirtualFile file = description.getVirtualFile();
        if (file == null)
            return Stream.empty();
        if (description.isFile()) {
            return Stream.of(file);
        } else if (description.isIncludeSubdirectories()) {
            final Stream.Builder<VirtualFile> builder = Stream.builder();
            VfsUtilCore.iterateChildrenRecursively(file, f -> !f.isDirectory() || fs.areChildrenLoaded(f), f -> {
                builder.accept(f);
                return true;
            });
            return builder.build();
        } else {
            return fs.areChildrenLoaded(file) ? Stream.of(file.getChildren()) : Stream.empty();
        }
    }).filter(f -> !f.isDirectory() && fileTypes.contains(f.getFileType()) && fileIndex.isInSourceContent(f)).collect(Collectors.toList());
    return GlobalSearchScope.filesWithoutLibrariesScope(project, excludedFiles);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Collection(java.util.Collection) ExcludeEntryDescription(com.intellij.openapi.compiler.options.ExcludeEntryDescription) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) FileType(com.intellij.openapi.fileTypes.FileType) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) ManagingFS(com.intellij.openapi.vfs.newvfs.ManagingFS) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) ManagingFS(com.intellij.openapi.vfs.newvfs.ManagingFS)

Example 82 with ProjectFileIndex

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

the class InspectionValidatorUtil method expandCompileScopeIfNeeded.

public static Collection<VirtualFile> expandCompileScopeIfNeeded(final Collection<VirtualFile> result, final CompileContext context) {
    final ProjectFileIndex index = ProjectRootManager.getInstance(context.getProject()).getFileIndex();
    final THashSet<VirtualFile> set = new THashSet<>();
    final THashSet<Module> modules = new THashSet<>();
    for (VirtualFile file : result) {
        if (index.getSourceRootForFile(file) == null) {
            set.add(file);
            ContainerUtil.addIfNotNull(modules, index.getModuleForFile(file));
        }
    }
    if (!set.isEmpty()) {
        ((CompileContextEx) context).addScope(new FileSetCompileScope(set, modules.toArray(new Module[modules.size()])));
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) CompileContextEx(com.intellij.openapi.compiler.ex.CompileContextEx) Module(com.intellij.openapi.module.Module) THashSet(gnu.trove.THashSet) FileSetCompileScope(com.intellij.compiler.impl.FileSetCompileScope)

Example 83 with ProjectFileIndex

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

the class CompilerEncodingServiceImpl method computeModuleCharsetMap.

@NotNull
private Map<Module, Set<Charset>> computeModuleCharsetMap() {
    final Map<Module, Set<Charset>> map = new THashMap<>();
    final Map<VirtualFile, Charset> mappings = ((EncodingProjectManagerImpl) EncodingProjectManager.getInstance(myProject)).getAllMappings();
    ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
    final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
    for (Map.Entry<VirtualFile, Charset> entry : mappings.entrySet()) {
        final VirtualFile file = entry.getKey();
        final Charset charset = entry.getValue();
        if (file == null || charset == null || (!file.isDirectory() && !compilerManager.isCompilableFileType(file.getFileType())) || !index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES))
            continue;
        final Module module = index.getModuleForFile(file);
        if (module == null)
            continue;
        Set<Charset> set = map.get(module);
        if (set == null) {
            set = new LinkedHashSet<>();
            map.put(module, set);
            final VirtualFile sourceRoot = index.getSourceRootForFile(file);
            VirtualFile current = file.getParent();
            Charset parentCharset = null;
            while (current != null) {
                final Charset currentCharset = mappings.get(current);
                if (currentCharset != null) {
                    parentCharset = currentCharset;
                }
                if (current.equals(sourceRoot)) {
                    break;
                }
                current = current.getParent();
            }
            if (parentCharset != null) {
                set.add(parentCharset);
            }
        }
        set.add(charset);
    }
    //todo[nik,jeka] perhaps we should take into account encodings of source roots only not individual files
    for (Module module : ModuleManager.getInstance(myProject).getModules()) {
        for (VirtualFile file : ModuleRootManager.getInstance(module).getSourceRoots(true)) {
            Charset encoding = EncodingProjectManager.getInstance(myProject).getEncoding(file, true);
            if (encoding != null) {
                Set<Charset> charsets = map.get(module);
                if (charsets == null) {
                    charsets = new LinkedHashSet<>();
                    map.put(module, charsets);
                }
                charsets.add(encoding);
            }
        }
    }
    return map;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) CompilerManager(com.intellij.openapi.compiler.CompilerManager) Charset(java.nio.charset.Charset) THashMap(gnu.trove.THashMap) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) EncodingProjectManagerImpl(com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl) Module(com.intellij.openapi.module.Module) THashMap(gnu.trove.THashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with ProjectFileIndex

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

the class PackageFileAction method getFilesToPackage.

@NotNull
private static List<VirtualFile> getFilesToPackage(@NotNull AnActionEvent e, @NotNull Project project) {
    final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (files == null)
        return Collections.emptyList();
    List<VirtualFile> result = new ArrayList<>();
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    for (VirtualFile file : files) {
        if (file == null || file.isDirectory() || fileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) && compilerManager.isCompilableFileType(file.getFileType())) {
            return Collections.emptyList();
        }
        final Collection<? extends Artifact> artifacts = ArtifactBySourceFileFinder.getInstance(project).findArtifacts(file);
        for (Artifact artifact : artifacts) {
            if (!StringUtil.isEmpty(artifact.getOutputPath())) {
                result.add(file);
                break;
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) CompilerManager(com.intellij.openapi.compiler.CompilerManager) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with ProjectFileIndex

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

the class AbstractProjectStructureAction method getSelectedGradleModule.

@Nullable
protected static Module getSelectedGradleModule(@NotNull AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Module module = MODULE_CONTEXT.getData(dataContext);
    if (isGradleModule(module)) {
        return module;
    }
    Project project = e.getProject();
    if (project != null) {
        VirtualFile file = VIRTUAL_FILE.getData(dataContext);
        if (file != null) {
            ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
            module = fileIndex.getModuleForFile(file);
            if (isGradleModule(module)) {
                return module;
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

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