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();
}
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();
}
Aggregations