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