Search in sources :

Example 1 with CachedValuesManager

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

the class GetInvocation method invoke.

@Override
public Object invoke(final DomInvocationHandler<?, ?> handler, final Object[] args) throws Throwable {
    if (myConverter == Converter.EMPTY_CONVERTER) {
        return getValueInner(handler, myConverter);
    }
    CachedValue<List<Pair<Converter, Object>>> value = handler.getUserData(DOM_VALUE_KEY);
    if (value == null) {
        final DomManagerImpl domManager = handler.getManager();
        final Project project = domManager.getProject();
        final CachedValuesManager cachedValuesManager = CachedValuesManager.getManager(project);
        handler.putUserData(DOM_VALUE_KEY, value = cachedValuesManager.createCachedValue(() -> {
            List<Pair<Converter, Object>> list = ContainerUtil.createLockFreeCopyOnWriteList();
            return CachedValueProvider.Result.create(list, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, domManager, ProjectRootManager.getInstance(project));
        }, false));
    }
    return getOrCalcValue(handler, value.getValue());
}
Also used : Project(com.intellij.openapi.project.Project) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) List(java.util.List) Pair(com.intellij.openapi.util.Pair)

Example 2 with CachedValuesManager

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

the class MavenGroovyPomScriptType method doPatchResolveScope.

public GlobalSearchScope doPatchResolveScope(@NotNull GroovyFile file, @NotNull GlobalSearchScope baseScope) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null) {
        return baseScope;
    }
    Project project = module.getProject();
    GlobalSearchScope result = baseScope;
    CachedValuesManager cachedValuesManager = CachedValuesManager.getManager(file.getProject());
    Boolean hasGroovyModuleLib = cachedValuesManager.getCachedValue(file.getProject(), () -> CachedValueProvider.Result.createSingleDependency(hasModuleWithGroovyLibrary(project), ProjectRootManagerEx.getInstanceEx(project)));
    if (hasGroovyModuleLib) {
        final Collection<VirtualFile> files = additionalScopeFiles();
        result = result.uniteWith(new NonClasspathDirectoriesScope(files));
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonClasspathDirectoriesScope(com.intellij.psi.search.NonClasspathDirectoriesScope) Project(com.intellij.openapi.project.Project) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module)

Example 3 with CachedValuesManager

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

the class DefinitionResolver method getAllVariants.

@Nullable
public static Map<String, Set<Define>> getAllVariants(Grammar scope) {
    final PsiElement psiElement = scope.getPsiElement();
    if (psiElement == null || !psiElement.isValid())
        return null;
    final CachedValuesManager manager = CachedValuesManager.getManager(psiElement.getProject());
    CachedValue<Map<String, Set<Define>>> data = psiElement.getUserData(KEY);
    if (data == null || !((DefinitionResolver) data.getValueProvider()).isValid()) {
        final DefinitionResolver resolver = new DefinitionResolver(scope);
        data = manager.createCachedValue(resolver, false);
        psiElement.putUserData(KEY, data);
    }
    return data.getValue();
}
Also used : CachedValuesManager(com.intellij.psi.util.CachedValuesManager) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with CachedValuesManager

use of com.intellij.psi.util.CachedValuesManager in project android by JetBrains.

the class AndroidXmlSchemaProvider method getSchema.

@Override
public XmlFile getSchema(@NotNull @NonNls String url, @Nullable final Module module, @NotNull PsiFile baseFile) {
    if (module == null || AndroidFacet.getInstance(module) == null)
        return null;
    Map<String, CachedValue<XmlFile>> descriptors = module.getUserData(DESCRIPTORS_MAP_IN_MODULE);
    if (descriptors == null) {
        descriptors = new THashMap<String, CachedValue<XmlFile>>();
        module.putUserData(DESCRIPTORS_MAP_IN_MODULE, descriptors);
    }
    CachedValue<XmlFile> reference = descriptors.get(url);
    if (reference != null) {
        return reference.getValue();
    }
    CachedValuesManager manager = CachedValuesManager.getManager(module.getProject());
    reference = manager.createCachedValue(new CachedValueProvider<XmlFile>() {

        @Override
        public Result<XmlFile> compute() {
            final URL resource = AndroidXmlSchemaProvider.class.getResource("android.xsd");
            final VirtualFile fileByURL = VfsUtil.findFileByURL(resource);
            XmlFile result = (XmlFile) PsiManager.getInstance(module.getProject()).findFile(fileByURL).copy();
            return new Result<XmlFile>(result, PsiModificationTracker.MODIFICATION_COUNT);
        }
    }, false);
    descriptors.put(url, reference);
    return reference.getValue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) XmlFile(com.intellij.psi.xml.XmlFile) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) CachedValue(com.intellij.psi.util.CachedValue) URL(java.net.URL)

Example 5 with CachedValuesManager

use of com.intellij.psi.util.CachedValuesManager 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)

Aggregations

CachedValuesManager (com.intellij.psi.util.CachedValuesManager)7 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 CachedValue (com.intellij.psi.util.CachedValue)2 Nullable (org.jetbrains.annotations.Nullable)2 Module (com.intellij.openapi.module.Module)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 NonClasspathDirectoriesScope (com.intellij.psi.search.NonClasspathDirectoriesScope)1 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)1 CachedValueProvider (com.intellij.psi.util.CachedValueProvider)1 XmlFile (com.intellij.psi.xml.XmlFile)1 Schema (com.thaiopensource.validate.Schema)1 URL (java.net.URL)1 List (java.util.List)1 Map (java.util.Map)1 NotNull (org.jetbrains.annotations.NotNull)1 BuildException (org.kohsuke.rngom.ast.builder.BuildException)1 IllegalSchemaException (org.kohsuke.rngom.parse.IllegalSchemaException)1