/** * Initializes {@link #cacheMap} and {@link VirtualFileManager}. * * @param project current project */ protected FilesIndexCacheProjectComponent(@NotNull final Project project) { super(project); cacheMap = ContainerUtil.newConcurrentMap(); virtualFileManager = VirtualFileManager.getInstance(); projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); }
Project project = editor.getProject(); if (project != null) { VirtualFile root = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(vf); if (root != null) { msg.append(vf.getPath().substring(root.getPath().length() + 1));
@NotNull @Override public ProjectFileIndex getProjectFileIndex(@NotNull Project project) { return ProjectRootManager.getInstance(project).getFileIndex(); }
public static boolean isInDLanguageSdkOrDLanguagePackagesFolder(final @NotNull Project project, final @NotNull VirtualFile file) { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); if (fileIndex.isInLibraryClasses(file)) { return true; // file in SDK or in custom package root } // if (fileIndex.isExcluded(file) || (fileIndex.isInContent(file) && isInDartPackagesFolder(fileIndex, file))) { // return true; // symlinked child of 'packages' folder. Real location is in user cache folder for Dart packages, not in project // } return false; }
private boolean isFileInRoots(@NotNull final VirtualFile file) { Validate.notNull(file); final ProjectFileIndex index = ProjectRootManager.getInstance(this.project).getFileIndex(); return index.isInSource(file) || index.isInLibraryClasses(file); }
@Override public void fileOpenedSync(@NotNull FileEditorManager source, @NotNull VirtualFile file, @NotNull Pair<FileEditor[], FileEditorProvider[]> editors) { if (file.getName().endsWith(ProtoFileType.INSTANCE.getDefaultExtension())) { Project project = source.getProject(); Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(file); if (module == null) { return; } addLibrary(module); } } });
private static Collection<VirtualFile> getAllFiles(Project project) { List<VirtualFile> fileList = new ArrayList<>(); ProjectFileIndex fileIndex = SonarLintUtils.get(project, ProjectRootManager.class).getFileIndex(); fileIndex.iterateContent(vFile -> { if (!vFile.isDirectory() && !ProjectCoreUtil.isProjectOrWorkspaceFile(vFile, vFile.getFileType())) { fileList.add(vFile); } return true; }); return fileList; }
public static VirtualFile getContentRoot(Project project, VirtualFile vfile) { VirtualFile root = ProjectRootManager.getInstance(project) .getFileIndex().getContentRootForFile(vfile); if ( root!=null ) return root; return vfile.getParent(); }
@Before public void before() { when(projectRootManager.getFileIndex()).thenReturn(projectFileIndex); }
@CheckReturnValue @VisibleForTesting @SuppressWarnings("WeakerAccess") static boolean isAvailable(@Nonnull AnActionEvent event) { final Project project = event.getProject(); if (project == null) { return false; } final IdeView view = event.getData(LangDataKeys.IDE_VIEW); if (view == null) { return false; } final ProjectRootManager rootManager = ProjectRootManager.getInstance(project); final ProjectFileIndex fileIndex = rootManager.getFileIndex(); final Optional<PsiDirectory> sourceDirectory = Stream.of(view.getDirectories()) .filter(directory -> { final VirtualFile virtualFile = directory.getVirtualFile(); return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES); }) .findFirst(); return sourceDirectory.isPresent(); } }
private boolean isPsiFileInProject(Project project, PsiFile psiFile) { boolean inProject = ProjectRootManager.getInstance(project) .getFileIndex().isInContent(psiFile.getVirtualFile()); if (!inProject) { LOGGER.info("File " + psiFile + " not in current project " + project); } return inProject; }
package_ = ProjectRootManager.getInstance(project).getFileIndex().getPackageNameByDirectory(vfile.getParent()); if ( Strings.isNullOrEmpty(package_)) { package_ = MISSING;
@Nullable public static VirtualFile getRunnableDFileFromContext(final @NotNull ConfigurationContext context) { final PsiElement psiLocation = context.getPsiLocation(); final PsiFile psiFile = psiLocation == null ? null : psiLocation.getContainingFile(); final VirtualFile virtualFile = getRealVirtualFile(psiFile); if ((psiFile instanceof DlangFile) && virtualFile != null && ProjectRootManager.getInstance(context.getProject()).getFileIndex().isInContent(virtualFile) && !DlangWritingAccessProvider.isInDLanguageSdkOrDLanguagePackagesFolder(psiFile.getProject(), virtualFile)) { // dont try to run this producer if is a test file if (isDunitTestFile(psiFile)) { return null; } else { return virtualFile; } } return null; }
@Nullable public static VirtualFile getRunnableDFileFromContext(final @NotNull ConfigurationContext context) { final PsiElement psiLocation = context.getPsiLocation(); final PsiFile psiFile = psiLocation == null ? null : psiLocation.getContainingFile(); final VirtualFile virtualFile = getRealVirtualFile(psiFile); if ((psiFile instanceof DlangFile) && virtualFile != null && ProjectRootManager.getInstance(context.getProject()).getFileIndex().isInContent(virtualFile) && !DlangWritingAccessProvider.isInDLanguageSdkOrDLanguagePackagesFolder(psiFile.getProject(), virtualFile)) { // only run this producer if is test file if (DUtil.isDunitTestFile(psiFile)) { return virtualFile; } else { return null; } } return null; }
public static GlobalSearchScope moduleScope(PsiFile file) { VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { return GlobalSearchScope.EMPTY_SCOPE; } Module module = ProjectRootManager.getInstance(file.getProject()).getFileIndex().getModuleForFile(virtualFile); if (module == null) { return GlobalSearchScope.fileScope(file); } //the module scope returned by getModuleScope() just contains the files in the configured source and test source directories, //module content scope includes all files in the module directory return module.getModuleContentScope(); }
private List<String> getCompilerSourcePaths(final PsiFile file) { Module module = ProjectRootManager.getInstance(file.getProject()).getFileIndex().getModuleForFile(file.getVirtualFile()); final ArrayList<String> compilerSourcePaths = new ArrayList<>(); final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); final Sdk sdk = moduleRootManager.getSdk(); if (sdk != null && (sdk.getSdkType() instanceof DlangSdkType)) { for (VirtualFile f: sdk.getSdkModificator().getRoots(OrderRootType.SOURCES)) { if (f.exists() && f.isDirectory()) { compilerSourcePaths.add(f.getPath()); } } } return compilerSourcePaths; }
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>(); file.accept(
return; final Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vf); if (module == null) { return;
private Result checkFileInSourceFolders(VirtualFile file, Module module) { ProjectFileIndex fileIndex = projectRootManager.getFileIndex(); if (fileIndex.isExcluded(file)) { return Result.excluded("file is excluded or ignored in IntelliJ's project structure"); } SourceFolder sourceFolder = SonarLintUtils.getSourceFolder(fileIndex.getSourceRootForFile(file), module); if (sourceFolder != null) { if (SonarLintUtils.isGeneratedSource(sourceFolder)) { return Result.excluded("file is classified as generated in IntelliJ's project structure"); } if (SonarLintUtils.isJavaResource(sourceFolder)) { return Result.excluded("file is classified as resource in IntelliJ's project structure"); } } // the fact that the file doesn't explicitly belong to sources doesn't mean it's not sources. // In WebStorm, for example, everything is considered to be sources unless it is explicitly marked otherwise. return Result.notExcluded(); }
Project project = event.getData(PlatformDataKeys.PROJECT); VirtualFile file = event.getData(PlatformDataKeys.VIRTUAL_FILE); final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); Module moduleForFile = index.getModuleForFile(file); String modulePath = moduleForFile.getModuleFilePath();