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