Search in sources :

Example 11 with VirtualFileWithId

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) Module(com.intellij.openapi.module.Module) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with VirtualFileWithId

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with VirtualFileWithId

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) FileInfo(com.intellij.openapi.util.io.win32.FileInfo) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with VirtualFileWithId

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;
}
Also used : FileInfo(com.intellij.openapi.util.io.win32.FileInfo) THashMap(gnu.trove.THashMap) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) FileAttributes(com.intellij.openapi.util.io.FileAttributes) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with VirtualFileWithId

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;
}
Also used : IOException(java.io.IOException) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) DataInputStream(java.io.DataInputStream)

Aggregations

VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)2 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 FileInfo (com.intellij.openapi.util.io.win32.FileInfo)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 THashMap (gnu.trove.THashMap)2 DuplicatesProfile (com.intellij.dupLocator.DuplicatesProfile)1 DuplocatorState (com.intellij.dupLocator.DuplocatorState)1 LightDuplicateProfile (com.intellij.dupLocator.LightDuplicateProfile)1 FragmentsCollector (com.intellij.dupLocator.treeHash.FragmentsCollector)1 PsiFragment (com.intellij.dupLocator.util.PsiFragment)1 StubBasedPsiElementBase (com.intellij.extapi.psi.StubBasedPsiElementBase)1 DomSupportEnabled (com.intellij.ide.highlighter.DomSupportEnabled)1 PsiNavigationSupport (com.intellij.ide.util.PsiNavigationSupport)1 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1