Search in sources :

Example 6 with CachedValue

use of com.intellij.psi.util.CachedValue in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoIdFilter method createIdFilter.

private static IdFilter createIdFilter(@NotNull Project project, @NotNull Key<CachedValue<IdFilter>> cacheKey, @NotNull Condition<VirtualFile> filterCondition) {
    return CachedValuesManager.getManager(project).getCachedValue(project, cacheKey, () -> {
        BitSet bitSet = new BitSet();
        ContentIterator iterator = fileOrDir -> {
            if (filterCondition.value(fileOrDir)) {
                addToBitSet(bitSet, fileOrDir);
            }
            ProgressManager.checkCanceled();
            return true;
        };
        FileBasedIndex.getInstance().iterateIndexableFiles(iterator, project, null);
        return CachedValueProvider.Result.create(new GoIdFilter(bitSet), ProjectRootManager.getInstance(project), VirtualFileManager.VFS_STRUCTURE_MODIFICATIONS);
    }, false);
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) GoTestFinder(com.goide.runconfig.testing.GoTestFinder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) Key(com.intellij.openapi.util.Key) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IdFilter(com.intellij.util.indexing.IdFilter) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) Nullable(org.jetbrains.annotations.Nullable) CachedValue(com.intellij.psi.util.CachedValue) Project(com.intellij.openapi.project.Project) BitSet(java.util.BitSet) Logger(com.intellij.openapi.diagnostic.Logger) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) Condition(com.intellij.openapi.util.Condition) ContentIterator(com.intellij.openapi.roots.ContentIterator) BitSet(java.util.BitSet)

Example 7 with CachedValue

use of com.intellij.psi.util.CachedValue in project intellij-community by JetBrains.

the class PsiJavaModuleReference method multiResolve.

@NotNull
public static Collection<PsiJavaModule> multiResolve(@NotNull final PsiElement refOwner, final String refText, final boolean incompleteCode) {
    if (StringUtil.isEmpty(refText))
        return Collections.emptyList();
    CachedValuesManager manager = CachedValuesManager.getManager(refOwner.getProject());
    Key<CachedValue<Collection<PsiJavaModule>>> key = incompleteCode ? K_INCOMPLETE : K_COMPLETE;
    return manager.getCachedValue(refOwner, key, () -> {
        Collection<PsiJavaModule> modules = Resolver.findModules(refOwner.getContainingFile(), refText, incompleteCode);
        return CachedValueProvider.Result.create(modules, OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
    }, false);
}
Also used : CachedValuesManager(com.intellij.psi.util.CachedValuesManager) CachedValue(com.intellij.psi.util.CachedValue) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with CachedValue

use of com.intellij.psi.util.CachedValue in project intellij-community by JetBrains.

the class GradleConsoleFilterProvider method getDefaultFilters.

@NotNull
@Override
public Filter[] getDefaultFilters(@NotNull Project project) {
    return new Filter[] { new GradleConsoleFilter(project), new RegexpFilter(project, RegexpFilter.FILE_PATH_MACROS + ":" + RegexpFilter.LINE_MACROS) {

        private CachedValue<Boolean> myIsGradleProject = new CachedValueImpl<>(() -> CachedValueProvider.Result.create(isGradleProject(), ProjectRootModificationTracker.getInstance(project)));

        @Override
        public Result applyFilter(String line, int entireLength) {
            if (line == null || !FileUtil.isAbsolutePlatformIndependent(line))
                return null;
            if (Boolean.FALSE.equals(myIsGradleProject.getValue()))
                return null;
            Result result = super.applyFilter(line, entireLength);
            if (result == null)
                return null;
            Pattern pattern = getPattern();
            Matcher matcher = pattern.matcher(StringUtil.newBombedCharSequence(line, 100));
            if (!matcher.lookingAt())
                return result;
            int lineStart = entireLength - line.length();
            int start = lineStart + matcher.start();
            int end = lineStart + matcher.end();
            return new Result(start, end, result.getFirstHyperlinkInfo());
        }

        private boolean isGradleProject() {
            return !GradleSettings.getInstance(project).getLinkedProjectsSettings().isEmpty();
        }
    } };
}
Also used : Pattern(java.util.regex.Pattern) RegexpFilter(com.intellij.execution.filters.RegexpFilter) Filter(com.intellij.execution.filters.Filter) RegexpFilter(com.intellij.execution.filters.RegexpFilter) Matcher(java.util.regex.Matcher) CachedValue(com.intellij.psi.util.CachedValue) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with CachedValue

use of com.intellij.psi.util.CachedValue in project intellij-community by JetBrains.

the class XmlDocumentImpl method updateSelfDependentDtdDescriptors.

private void updateSelfDependentDtdDescriptors(XmlDocumentImpl copy, HashMap<String, CachedValue<XmlNSDescriptor>> cacheStrict, HashMap<String, CachedValue<XmlNSDescriptor>> cacheNotStrict) {
    copy.myDefaultDescriptorsCacheNotStrict = ContainerUtil.newConcurrentMap();
    copy.myDefaultDescriptorsCacheStrict = ContainerUtil.newConcurrentMap();
    for (Map.Entry<String, CachedValue<XmlNSDescriptor>> e : cacheStrict.entrySet()) {
        if (e.getValue().hasUpToDateValue()) {
            final XmlNSDescriptor nsDescriptor = e.getValue().getValue();
            if (!isGeneratedFromDtd(nsDescriptor))
                copy.myDefaultDescriptorsCacheStrict.put(e.getKey(), e.getValue());
        }
    }
    for (Map.Entry<String, CachedValue<XmlNSDescriptor>> e : cacheNotStrict.entrySet()) {
        if (e.getValue().hasUpToDateValue()) {
            final XmlNSDescriptor nsDescriptor = e.getValue().getValue();
            if (!isGeneratedFromDtd(nsDescriptor))
                copy.myDefaultDescriptorsCacheNotStrict.put(e.getKey(), e.getValue());
        }
    }
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) CachedValue(com.intellij.psi.util.CachedValue) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

CachedValue (com.intellij.psi.util.CachedValue)9 NotNull (org.jetbrains.annotations.NotNull)4 CachedValueProvider (com.intellij.psi.util.CachedValueProvider)3 CachedValuesManager (com.intellij.psi.util.CachedValuesManager)3 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 XmlDocument (com.intellij.psi.xml.XmlDocument)2 XmlTag (com.intellij.psi.xml.XmlTag)2 Nullable (org.jetbrains.annotations.Nullable)2 GoBuildTargetSettings (com.goide.project.GoBuildTargetSettings)1 GoTestFinder (com.goide.runconfig.testing.GoTestFinder)1 Filter (com.intellij.execution.filters.Filter)1 RegexpFilter (com.intellij.execution.filters.RegexpFilter)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Module (com.intellij.openapi.module.Module)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Project (com.intellij.openapi.project.Project)1 ContentIterator (com.intellij.openapi.roots.ContentIterator)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1