use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class JavaModulePresentationProvider method getPresentation.
@Override
public ItemPresentation getPresentation(@NotNull final PsiJavaModule item) {
return new ItemPresentation() {
@Override
public String getPresentableText() {
return item.getName();
}
@Nullable
@Override
public String getLocationString() {
VirtualFile file = PsiImplUtil.getModuleVirtualFile(item);
FileIndexFacade index = FileIndexFacade.getInstance(item.getProject());
if (index.isInLibraryClasses(file)) {
Matcher matcher = JAR_NAME.matcher(file.getPath());
if (matcher.find()) {
return matcher.group(1);
}
} else if (index.isInSource(file)) {
Module module = index.getModuleForFile(file);
if (module != null) {
return '[' + module.getName() + ']';
}
}
return null;
}
@Nullable
@Override
public Icon getIcon(boolean unused) {
return AllIcons.Nodes.JavaModule;
}
};
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class PsiClassFavoriteNodeProvider method checkClassUnderSources.
private boolean checkClassUnderSources(final PsiElement element, final Project project) {
final PsiFile file = element.getContainingFile();
if (file != null && file.getVirtualFile() != null) {
final FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
final VirtualFile vf = file.getVirtualFile();
return indexFacade.isInSource(vf) || indexFacade.isInSourceContent(vf);
}
return false;
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class PsiUtilCore method getPsiFile.
/**
* Tries to find PSI file for a virtual file and throws assertion error with debug info if it is null.
*/
@NotNull
public static PsiFile getPsiFile(@NotNull Project project, @NotNull VirtualFile file) {
PsiManager psiManager = PsiManager.getInstance(project);
PsiFile psi = psiManager.findFile(file);
if (psi != null)
return psi;
FileType fileType = file.getFileType();
FileViewProvider viewProvider = psiManager.findViewProvider(file);
Document document = FileDocumentManager.getInstance().getDocument(file);
boolean ignored = !(file instanceof LightVirtualFile) && FileTypeRegistry.getInstance().isFileIgnored(file);
VirtualFile vDir = file.getParent();
PsiDirectory psiDir = vDir == null ? null : PsiManager.getInstance(project).findDirectory(vDir);
FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
StringBuilder sb = new StringBuilder();
sb.append("valid=").append(file.isValid()).append(" isDirectory=").append(file.isDirectory()).append(" hasDocument=").append(document != null).append(" length=").append(file.getLength());
sb.append("\nproject=").append(project.getName()).append(" default=").append(project.isDefault()).append(" open=").append(project.isOpen());
sb.append("\nfileType=").append(fileType.getName()).append("/").append(fileType.getClass().getName());
sb.append("\nisIgnored=").append(ignored);
sb.append(" underIgnored=").append(indexFacade.isUnderIgnored(file));
sb.append(" inLibrary=").append(indexFacade.isInLibrarySource(file) || indexFacade.isInLibraryClasses(file));
sb.append(" parentDir=").append(vDir == null ? "no-vfs" : vDir.isDirectory() ? "has-vfs-dir" : "has-vfs-file").append("/").append(psiDir == null ? "no-psi" : "has-psi");
sb.append("\nviewProvider=").append(viewProvider == null ? "null" : viewProvider.getClass().getName());
if (viewProvider != null) {
List<PsiFile> files = viewProvider.getAllFiles();
sb.append(" language=").append(viewProvider.getBaseLanguage().getID());
sb.append(" physical=").append(viewProvider.isPhysical());
sb.append(" rootCount=").append(files.size());
for (PsiFile o : files) {
sb.append("\n root=").append(o.getLanguage().getID()).append("/").append(o.getClass().getName());
}
}
LOG.error("no PSI for file '" + file.getName() + "'", new Attachment(file.getPresentableUrl(), sb.toString()));
throw new AssertionError();
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class ModuleDefaultVcsRootPolicy method getVcsRootFor.
@Override
@Nullable
public VirtualFile getVcsRootFor(@NotNull VirtualFile file) {
FileIndexFacade indexFacade = PeriodicalTasksCloser.getInstance().safeGetService(myProject, FileIndexFacade.class);
if (myBaseDir != null && indexFacade.isValidAncestor(myBaseDir, file)) {
LOG.debug("File " + file + " is under project base dir " + myBaseDir);
return myBaseDir;
}
VirtualFile contentRoot = ProjectRootManager.getInstance(myProject).getFileIndex().getContentRootForFile(file, Registry.is("ide.hide.excluded.files"));
if (contentRoot != null) {
LOG.debug("Content root for file " + file + " is " + contentRoot);
if (contentRoot.isDirectory()) {
return contentRoot;
}
VirtualFile parent = contentRoot.getParent();
LOG.debug("Content root is not a directory, using its parent " + parent);
return parent;
}
if (ProjectKt.isDirectoryBased(myProject)) {
VirtualFile ideaDir = ProjectKt.getStateStore(myProject).getDirectoryStoreFile();
if (ideaDir != null && VfsUtilCore.isAncestor(ideaDir, file, false)) {
LOG.debug("File " + file + " is under .idea");
return ideaDir;
}
}
LOG.debug("Couldn't find proper root for " + file);
return null;
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class MappingsToRoots method getDetailedVcsMappings.
// not only set mappings, but include all modules inside: modules might have different settings
public List<VirtualFile> getDetailedVcsMappings(final AbstractVcs vcs) {
// same as above, but no compression
final List<VirtualFile> result = myMappings.getMappingsAsFilesUnderVcs(vcs);
boolean addInnerModules = true;
final String vcsName = vcs.getName();
final List<VcsDirectoryMapping> directoryMappings = myMappings.getDirectoryMappings(vcsName);
for (VcsDirectoryMapping directoryMapping : directoryMappings) {
if (directoryMapping.isDefaultMapping()) {
addInnerModules = false;
break;
}
}
Collections.sort(result, FilePathComparator.getInstance());
if (addInnerModules) {
final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(myProject, FileIndexFacade.class);
final Collection<VirtualFile> modules = DefaultVcsRootPolicy.getInstance(myProject).getDefaultVcsRoots(myMappings, vcsName);
ApplicationManager.getApplication().runReadAction(() -> {
Iterator<VirtualFile> iterator = modules.iterator();
while (iterator.hasNext()) {
final VirtualFile module = iterator.next();
boolean included = false;
for (VirtualFile root : result) {
if (facade.isValidAncestor(root, module)) {
included = true;
break;
}
}
if (!included) {
iterator.remove();
}
}
});
result.addAll(modules);
}
result.removeIf(file -> !file.isDirectory());
return result;
}
Aggregations