Search in sources :

Example 6 with CachedValuesManager

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

the class DomModelCache method getCachedValue.

@Nullable
public T getCachedValue(@NotNull final H dataHolder) {
    CachedValue<T> cachedValue = dataHolder.getUserData(myKey);
    if (cachedValue == null) {
        final CachedValueProvider<T> myProvider = () -> computeValue(dataHolder);
        final CachedValuesManager manager = CachedValuesManager.getManager(myProject);
        cachedValue = manager.createCachedValue(myProvider, false);
        dataHolder.putUserData(myKey, cachedValue);
    }
    return cachedValue.getValue();
}
Also used : CachedValuesManager(com.intellij.psi.util.CachedValuesManager) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with CachedValuesManager

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

the class RngParser method getCachedSchema.

public static Schema getCachedSchema(final XmlFile descriptorFile) {
    CachedValue<Schema> value = descriptorFile.getUserData(SCHEMA_KEY);
    if (value == null) {
        final CachedValueProvider<Schema> provider = () -> {
            final InputSource inputSource = makeInputSource(descriptorFile);
            try {
                final Schema schema = new MySchemaReader(descriptorFile).createSchema(inputSource, EMPTY_PROPS);
                final PsiElementProcessor.CollectElements<XmlFile> processor = new PsiElementProcessor.CollectElements<>();
                RelaxIncludeIndex.processForwardDependencies(descriptorFile, processor);
                if (processor.getCollection().size() > 0) {
                    return CachedValueProvider.Result.create(schema, processor.toArray(), descriptorFile);
                } else {
                    return CachedValueProvider.Result.createSingleDependency(schema, descriptorFile);
                }
            } catch (Exception e) {
                LOG.info(e);
                return CachedValueProvider.Result.createSingleDependency(null, descriptorFile);
            }
        };
        final CachedValuesManager mgr = CachedValuesManager.getManager(descriptorFile.getProject());
        value = mgr.createCachedValue(provider, false);
        descriptorFile.putUserData(SCHEMA_KEY, value);
    }
    return value.getValue();
}
Also used : InputSource(org.xml.sax.InputSource) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) Schema(com.thaiopensource.validate.Schema) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) SAXException(org.xml.sax.SAXException) IllegalSchemaException(org.kohsuke.rngom.parse.IllegalSchemaException) SAXParseException(org.xml.sax.SAXParseException) BuildException(org.kohsuke.rngom.ast.builder.BuildException)

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