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