Java Code Examples for com.intellij.openapi.roots.ProjectFileIndex#isInSource()
The following examples show how to use
com.intellij.openapi.roots.ProjectFileIndex#isInSource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VFSUtils.java From SmartIM4IntelliJ with Apache License 2.0 | 5 votes |
public static String getPath(VirtualFile file) { String result = null; Document document = FileDocumentManager.getInstance().getDocument(file); Project[] openProjects = VFSUtils.getOpenProjects(); for (int i = 0; i < openProjects.length && result == null; i++) { Project openProject = openProjects[i]; if (!openProject.isInitialized() && !ApplicationManager.getApplication().isUnitTestMode()) continue; if (document != null) { PsiFile psiFile = PsiDocumentManager.getInstance(openProject).getPsiFile(document); result = PsiFileTypeFactory.create(psiFile).getQualifiedName(psiFile); } ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(openProject).getFileIndex(); if (projectFileIndex.isInSource(file)) { VirtualFile sourceRoot = projectFileIndex.getSourceRootForFile(file); result = (getRelativePath(file, sourceRoot)); } if (projectFileIndex.isInContent(file)) { VirtualFile contentRoot = projectFileIndex.getContentRootForFile(file); result = (getRelativePath(file, contentRoot)); } } return result; }
Example 2
Source File: ProjectRootsUtil.java From consulo with Apache License 2.0 | 5 votes |
public static boolean isOutsideSourceRoot(@Nullable PsiFile psiFile) { if (psiFile == null) return false; if (psiFile instanceof PsiCodeFragment) return false; final VirtualFile file = psiFile.getVirtualFile(); if (file == null) return false; final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex(); return !projectFileIndex.isInSource(file) && !projectFileIndex.isInLibraryClasses(file); }
Example 3
Source File: SourcesScope.java From consulo with Apache License 2.0 | 5 votes |
public SourcesScope() { super(NAME, new AbstractPackageSet("src:*..*") { @Override public boolean contains(VirtualFile file, NamedScopesHolder holder) { final ProjectFileIndex index = ProjectRootManager.getInstance(holder.getProject()).getFileIndex(); return file != null && index.isInSource(file); } }); }
Example 4
Source File: CheckinHandlerUtil.java From consulo with Apache License 2.0 | 5 votes |
private static boolean isFileUnderSourceRoot(@Nonnull Project project, @Nonnull VirtualFile file) { ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); if (InternalStdFileTypes.JAVA == file.getFileType()) { return index.isInSource(file) && !index.isInLibrarySource(file); } else { return index.isInContent(file) && !index.isInLibrarySource(file) ; } }
Example 5
Source File: ProjectRootsUtil.java From consulo with Apache License 2.0 | 4 votes |
public static boolean isSourceOrTestRoot(@Nonnull VirtualFile virtualFile, final Project project) { final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); return projectFileIndex.isInSource(virtualFile); }