public ProjectFacetManagerImpl(Project project) { myProject = project; myCachedValueProvider = new ParameterizedCachedValueProvider<Boolean, FacetTypeId<?>>() { @Override public CachedValueProvider.Result<Boolean> compute(FacetTypeId<?> param) { boolean result = false; for (Module module : ModuleManager.getInstance(myProject).getModules()) { if (!FacetManager.getInstance(module).getFacetsByType(param).isEmpty()) { result = true; break; } } return CachedValueProvider.Result.create(result, FacetFinder.getInstance(myProject).getAllFacetsOfTypeModificationTracker(param)); } }; }
private XmlElementDescriptor findRootDescriptor(final XmlTag tag) { return CachedValuesManager.getManager(tag.getProject()) .getParameterizedCachedValue(tag, ROOT_KEY, new ParameterizedCachedValueProvider<XmlElementDescriptor, RngNsDescriptor>() { @Override public CachedValueProvider.Result<XmlElementDescriptor> compute(RngNsDescriptor o) { final XmlElementDescriptor descr = o.findRootDescriptorInner(tag); if (descr != null) { return CachedValueProvider.Result.create(descr, tag, descr.getDependences(), o.getDependences()); } else { return CachedValueProvider.Result.create(null, tag, o.getDependences()); } } }, false, this); }
@Override public final XmlElementDescriptor getElementDescriptor(final XmlTag childTag, XmlTag contextTag) { final XmlElementDescriptor value = getCachedValue(childTag, this, DESCR_KEY, new ParameterizedCachedValueProvider<XmlElementDescriptor, RngElementDescriptor>() { @Override public CachedValueProvider.Result<XmlElementDescriptor> compute(RngElementDescriptor p) { final XmlElementDescriptor descriptor = p.findElementDescriptor(childTag); return CachedValueProvider.Result.create(descriptor, p.getDependences(), childTag); } }); return value == NULL ? null : value; }
@Override public final XmlAttributeDescriptor[] getAttributesDescriptors(@Nullable final XmlTag context) { if (context != null) { return getCachedValue(context, this, ATTRS_KEY, new ParameterizedCachedValueProvider<XmlAttributeDescriptor[], RngElementDescriptor>() { @Override public CachedValueProvider.Result<XmlAttributeDescriptor[]> compute(RngElementDescriptor p) { final XmlAttributeDescriptor[] value = p.collectAttributeDescriptors(context); return CachedValueProvider.Result.create(value, p.getDependences(), context); } }); } else { return collectAttributeDescriptors(null); } }
@Override protected ParameterizedCachedValue<List<JSClass>, Object> compute(final JSClassBase jsClassBase, final Object p) { return CachedValuesManager.getManager(jsClassBase.getProject()).createParameterizedCachedValue(new ParameterizedCachedValueProvider<List<JSClass>, Object>() { @Override public CachedValueProvider.Result<List<JSClass>> compute(Object list) { return new CachedValueProvider.Result<List<JSClass>>(doCompute(list), PsiModificationTracker.MODIFICATION_COUNT); } }, false); }
public PsiParameterizedCachedValue(@NotNull PsiManager manager, @NotNull ParameterizedCachedValueProvider<T, P> provider) { super(manager); myProvider = provider; }
@Override public ParameterizedCachedValueProvider<T,P> getValueProvider() { return myProvider; }
public ParameterizedCachedValueImpl(@NotNull ParameterizedCachedValueProvider<T,P> provider) { myProvider = provider; }
public PsiParameterizedCachedValue(@Nonnull PsiManager manager, @Nonnull ParameterizedCachedValueProvider<T, P> provider) { super(manager); myProvider = provider; }
public ParameterizedCachedValueImpl(@Nonnull ParameterizedCachedValueProvider<T,P> provider) { myProvider = provider; }
private static <D extends PsiElement, T, P> T getCachedValue(D context, P p, Key<ParameterizedCachedValue<T, P>> key, ParameterizedCachedValueProvider<T, P> provider) { final CachedValuesManager mgr = CachedValuesManager.getManager(context.getProject()); return mgr.getParameterizedCachedValue(context, key, provider, false, p); }
@Override protected ParameterizedCachedValue<Set<String>, JSElement> compute(JSElement jsElement, Object p) { return CachedValuesManager.getManager(jsElement.getProject()).createParameterizedCachedValue(new ParameterizedCachedValueProvider<Set<String>, JSElement>() { @Override public CachedValueProvider.Result<Set<String>> compute(JSElement context) { class MyProcessor extends ResolveProcessor implements Processor<PsiNamedElement> { Set<String> openedNses; public MyProcessor() { super(null); putUserData(ResolveProcessor.LOOKING_FOR_USE_NAMESPACES, true); } @Override public boolean process(PsiNamedElement psiNamedElement) { if(psiNamedElement instanceof JSElement) { processDeclarationsInScope((JSElement) psiNamedElement, this, ResolveState.initial(), psiNamedElement, psiNamedElement); } else { // TODO: XmlFile ? } return true; } @Override public boolean execute(PsiElement element, ResolveState state) { if(!(element instanceof JSUseNamespaceDirective)) { return true; } if(openedNses == null) { openedNses = new THashSet<String>(); } openedNses.add(((JSUseNamespaceDirective) element).getNamespaceToBeUsed()); return true; } } MyProcessor processor = new MyProcessor(); walkOverStructure(context, processor); return new CachedValueProvider.Result<Set<String>>(processor.openedNses, PsiModificationTracker.EVER_CHANGED); } }, false); }
<T,P> ParameterizedCachedValue<T,P> createParameterizedCachedValue(@NotNull ParameterizedCachedValueProvider<T,P> provider, boolean trackValue);
<T,P> ParameterizedCachedValue<T,P> createParameterizedCachedValue(@Nonnull ParameterizedCachedValueProvider<T,P> provider, boolean trackValue);