Search in sources :

Example 21 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class CompilerReferenceReader method getWholeHierarchy.

@Nullable("return null if the class hierarchy contains ambiguous qualified names")
private LightRef.NamedLightRef[] getWholeHierarchy(LightRef.LightClassHierarchyElementDef hierarchyElement, boolean checkBaseClassAmbiguity) throws StorageException {
    Set<LightRef.NamedLightRef> result = new THashSet<>();
    Queue<LightRef.NamedLightRef> q = new Queue<>(10);
    q.addLast(hierarchyElement);
    while (!q.isEmpty()) {
        LightRef.NamedLightRef curClass = q.pullFirst();
        if (result.add(curClass)) {
            if (checkBaseClassAmbiguity || curClass != hierarchyElement) {
                DefCount count = getDefinitionCount(curClass);
                if (count == DefCount.NONE) {
                    //diagnostic
                    String baseHierarchyElement = getNameEnumerator().getName(hierarchyElement.getName());
                    String curHierarchyElement = getNameEnumerator().getName(curClass.getName());
                    LOG.error("Can't get definition files for: " + curHierarchyElement + " base class: " + baseHierarchyElement);
                }
                if (count != DefCount.ONE) {
                    return null;
                }
            }
            myIndex.get(CompilerIndices.BACK_HIERARCHY).getData(curClass).forEach((id, children) -> {
                for (LightRef child : children) {
                    if (child instanceof LightRef.LightClassHierarchyElementDef) {
                        q.addLast((LightRef.LightClassHierarchyElementDef) child);
                    }
                }
                return true;
            });
        }
    }
    return result.toArray(new LightRef.NamedLightRef[result.size()]);
}
Also used : LightRef(org.jetbrains.jps.backwardRefs.LightRef) Queue(com.intellij.util.containers.Queue) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class DirtyScopeHolder method getAllDirtyModules.

@NotNull
Set<Module> getAllDirtyModules() {
    final Set<Module> dirtyModules = new THashSet<>(myVFSChangedModules);
    for (Document document : myFileDocManager.getUnsavedDocuments()) {
        final VirtualFile file = myFileDocManager.getFile(document);
        if (file == null)
            continue;
        final Module m = getModuleForSourceContentFile(file);
        if (m != null)
            dirtyModules.add(m);
    }
    for (Document document : myPsiDocManager.getUncommittedDocuments()) {
        final PsiFile psiFile = myPsiDocManager.getPsiFile(document);
        if (psiFile == null)
            continue;
        final VirtualFile file = psiFile.getVirtualFile();
        if (file == null)
            continue;
        final Module m = getModuleForSourceContentFile(file);
        if (m != null)
            dirtyModules.add(m);
    }
    return dirtyModules;
}
Also used : PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with THashSet

use of gnu.trove.THashSet in project kotlin by JetBrains.

the class SourceNavigationHelper method getOriginalClass.

@Nullable
public static PsiClass getOriginalClass(@NotNull KtClassOrObject classOrObject) {
    // Copied from JavaPsiImplementationHelperImpl:getOriginalClass()
    FqName fqName = classOrObject.getFqName();
    if (fqName == null) {
        return null;
    }
    KtFile file = classOrObject.getContainingKtFile();
    VirtualFile vFile = file.getVirtualFile();
    Project project = file.getProject();
    final ProjectFileIndex idx = ProjectRootManager.getInstance(project).getFileIndex();
    if (vFile == null || !idx.isInLibrarySource(vFile))
        return null;
    final Set<OrderEntry> orderEntries = new THashSet<OrderEntry>(idx.getOrderEntriesForFile(vFile));
    return JavaPsiFacade.getInstance(project).findClass(fqName.asString(), new GlobalSearchScope(project) {

        @Override
        public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
            return 0;
        }

        @Override
        public boolean contains(@NotNull VirtualFile file) {
            List<OrderEntry> entries = idx.getOrderEntriesForFile(file);
            for (OrderEntry entry : entries) {
                if (orderEntries.contains(entry))
                    return true;
            }
            return false;
        }

        @Override
        public boolean isSearchInModuleContent(@NotNull Module aModule) {
            return false;
        }

        @Override
        public boolean isSearchInLibraries() {
            return true;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FqName(org.jetbrains.kotlin.name.FqName) List(java.util.List) Module(com.intellij.openapi.module.Module) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class PsiSearchHelperImpl method processVirtualFile.

private void processVirtualFile(@NotNull final VirtualFile vfile, @NotNull final ProgressIndicator progress, @NotNull final Processor<? super PsiFile> localProcessor, @NotNull final AtomicBoolean canceled) throws ApplicationUtil.CannotRunReadActionException {
    final PsiFile file = ApplicationUtil.tryRunReadAction(() -> vfile.isValid() ? myManager.findFile(vfile) : null);
    if (file != null && !(file instanceof PsiBinaryFile)) {
        // load contents outside read action
        if (FileDocumentManager.getInstance().getCachedDocument(vfile) == null) {
            // cache bytes in vfs
            try {
                vfile.contentsToByteArray();
            } catch (IOException ignored) {
            }
        }
        ApplicationUtil.tryRunReadAction(() -> {
            final Project project = myManager.getProject();
            if (project.isDisposed())
                throw new ProcessCanceledException();
            if (DumbService.isDumb(project))
                throw new ApplicationUtil.CannotRunReadActionException();
            List<PsiFile> psiRoots = file.getViewProvider().getAllFiles();
            Set<PsiFile> processed = new THashSet<>(psiRoots.size() * 2, (float) 0.5);
            for (final PsiFile psiRoot : psiRoots) {
                progress.checkCanceled();
                assert psiRoot != null : "One of the roots of file " + file + " is null. All roots: " + psiRoots + "; ViewProvider: " + file.getViewProvider() + "; Virtual file: " + file.getViewProvider().getVirtualFile();
                if (!processed.add(psiRoot))
                    continue;
                if (!psiRoot.isValid()) {
                    continue;
                }
                if (!localProcessor.process(psiRoot)) {
                    canceled.set(true);
                    break;
                }
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 25 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class AdditionalIndexableFileSet method collectFilesAndDirectories.

private THashSet<VirtualFile> collectFilesAndDirectories() {
    THashSet<VirtualFile> files = new THashSet<>();
    THashSet<VirtualFile> directories = new THashSet<>();
    if (myExtensions == null) {
        myExtensions = Extensions.getExtensions(IndexableSetContributor.EP_NAME);
    }
    for (IndexableSetContributor contributor : myExtensions) {
        for (VirtualFile root : IndexableSetContributor.getRootsToIndex(contributor)) {
            (root.isDirectory() ? directories : files).add(root);
        }
        if (myProject != null) {
            Set<VirtualFile> projectRoots = IndexableSetContributor.getProjectRootsToIndex(contributor, myProject);
            for (VirtualFile root : projectRoots) {
                (root.isDirectory() ? directories : files).add(root);
            }
        }
    }
    cachedFiles = files;
    cachedDirectories = directories;
    return directories;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet)

Aggregations

THashSet (gnu.trove.THashSet)239 NotNull (org.jetbrains.annotations.NotNull)65 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 Project (com.intellij.openapi.project.Project)35 File (java.io.File)35 THashMap (gnu.trove.THashMap)31 Nullable (org.jetbrains.annotations.Nullable)31 Module (com.intellij.openapi.module.Module)29 IOException (java.io.IOException)24 PsiElement (com.intellij.psi.PsiElement)21 PsiFile (com.intellij.psi.PsiFile)18 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 java.util (java.util)16 Element (org.jdom.Element)14 Pair (com.intellij.openapi.util.Pair)13 Logger (com.intellij.openapi.diagnostic.Logger)12 ContainerUtil (com.intellij.util.containers.ContainerUtil)12 Document (com.intellij.openapi.editor.Document)11 Library (com.intellij.openapi.roots.libraries.Library)11 StringUtil (com.intellij.openapi.util.text.StringUtil)10