use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.
the class ResolveScopeManagerImpl method getUseScope.
@Override
@NotNull
public GlobalSearchScope getUseScope(@NotNull PsiElement element) {
VirtualFile vDirectory;
final VirtualFile virtualFile;
final PsiFile containingFile;
final GlobalSearchScope allScope = GlobalSearchScope.allScope(myManager.getProject());
if (element instanceof PsiDirectory) {
vDirectory = ((PsiDirectory) element).getVirtualFile();
virtualFile = null;
containingFile = null;
} else {
containingFile = element.getContainingFile();
if (containingFile == null)
return allScope;
virtualFile = containingFile.getVirtualFile();
if (virtualFile == null)
return allScope;
if (virtualFile instanceof VirtualFileWindow) {
return GlobalSearchScope.fileScope(myProject, ((VirtualFileWindow) virtualFile).getDelegate());
}
vDirectory = virtualFile.getParent();
}
if (vDirectory == null)
return allScope;
final ProjectFileIndex projectFileIndex = myProjectRootManager.getFileIndex();
final Module module = projectFileIndex.getModuleForFile(vDirectory);
if (module == null) {
VirtualFile notNullVFile = virtualFile != null ? virtualFile : vDirectory;
final List<OrderEntry> entries = projectFileIndex.getOrderEntriesForFile(notNullVFile);
if (entries.isEmpty() && (myAdditionalIndexableFileSet.isInSet(notNullVFile) || isFromAdditionalLibraries(notNullVFile))) {
return allScope;
}
GlobalSearchScope result = LibraryScopeCache.getInstance(myProject).getLibraryUseScope(entries);
return containingFile == null || virtualFile.isDirectory() || result.contains(virtualFile) ? result : GlobalSearchScope.fileScope(containingFile).uniteWith(result);
}
boolean isTest = TestSourcesFilter.isTestSources(vDirectory, myProject);
GlobalSearchScope scope = isTest ? GlobalSearchScope.moduleTestsWithDependentsScope(module) : GlobalSearchScope.moduleWithDependentsScope(module);
RefResolveService resolveService;
if (virtualFile instanceof VirtualFileWithId && RefResolveService.ENABLED && (resolveService = RefResolveService.getInstance(myProject)).isUpToDate()) {
return resolveService.restrictByBackwardIds(virtualFile, scope);
}
return scope;
}
use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.
the class LightDirectoryIndex method getInfoForFile.
@NotNull
public T getInfoForFile(@Nullable VirtualFile file) {
if (!(file instanceof VirtualFileWithId))
return myDefValue;
VirtualFile dir;
if (!file.isDirectory()) {
T info = getCachedInfo(file);
if (info != null) {
return info;
}
dir = file.getParent();
} else {
dir = file;
}
int count = 0;
for (VirtualFile root = dir; root != null; root = root.getParent()) {
if (++count > 1000) {
throw new IllegalStateException("Possible loop in tree, started at " + dir.getName());
}
T info = getCachedInfo(root);
if (info != null) {
if (!dir.equals(root)) {
cacheInfos(dir, root, info);
}
return info;
}
}
return cacheInfos(dir, null, myDefValue);
}
use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.
the class Win32FsCache method getAttributes.
@Nullable
FileAttributes getAttributes(@NotNull VirtualFile file) {
VirtualFile parent = file.getParent();
int parentId = parent instanceof VirtualFileWithId ? ((VirtualFileWithId) parent).getId() : -((VirtualFileWithId) file).getId();
TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
THashMap<String, FileAttributes> nestedMap = map.get(parentId);
String name = file.getName();
FileAttributes attributes = nestedMap != null ? nestedMap.get(name) : null;
if (attributes == null) {
if (nestedMap != null && !(nestedMap instanceof IncompleteChildrenMap)) {
// our info from parent doesn't mention the child in this refresh session
return null;
}
FileInfo info = myKernel.getInfo(file.getPath());
if (info == null) {
return null;
}
attributes = info.toFileAttributes();
if (nestedMap == null) {
nestedMap = new IncompleteChildrenMap<>(FileUtil.PATH_HASHING_STRATEGY);
map.put(parentId, nestedMap);
}
nestedMap.put(name, attributes);
}
return attributes;
}
use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.
the class Win32FsCache method list.
@NotNull
String[] list(@NotNull VirtualFile file) {
String path = file.getPath();
FileInfo[] fileInfo = myKernel.listChildren(path);
if (fileInfo == null || fileInfo.length == 0) {
return ArrayUtil.EMPTY_STRING_ARRAY;
}
String[] names = new String[fileInfo.length];
TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
int parentId = ((VirtualFileWithId) file).getId();
THashMap<String, FileAttributes> nestedMap = map.get(parentId);
if (nestedMap == null) {
nestedMap = new THashMap<>(fileInfo.length, FileUtil.PATH_HASHING_STRATEGY);
map.put(parentId, nestedMap);
}
for (int i = 0, length = fileInfo.length; i < length; i++) {
FileInfo info = fileInfo[i];
String name = info.getName();
nestedMap.put(name, info.toFileAttributes());
names[i] = name;
}
return names;
}
use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.
the class VirtualFileGistImpl method getFileData.
@Override
public Data getFileData(@NotNull Project project, @NotNull VirtualFile file) {
ApplicationManager.getApplication().assertReadAccessAllowed();
ProgressManager.checkCanceled();
if (!(file instanceof VirtualFileWithId))
return myCalculator.calcData(project, file);
int stamp = PersistentFS.getInstance().getModificationCount(file) + ((GistManagerImpl) GistManager.getInstance()).getReindexCount();
try (DataInputStream stream = getFileAttribute(project).readAttribute(file)) {
if (stream != null && DataInputOutputUtil.readINT(stream) == stamp) {
return stream.readBoolean() ? myExternalizer.read(stream) : null;
}
} catch (IOException e) {
LOG.error(e);
}
Data result = myCalculator.calcData(project, file);
cacheResult(stamp, result, project, file);
return result;
}
Aggregations