fix "IDEA-221944 Deadlock on opening second project" and support preloading for proje...
[idea/community.git] / platform / core-impl / src / com / intellij / psi / impl / PsiCachedValuesFactory.java
1 // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2
3 package com.intellij.psi.impl;
4
5 import com.intellij.openapi.project.Project;
6 import com.intellij.psi.PsiManager;
7 import com.intellij.psi.util.CachedValue;
8 import com.intellij.psi.util.CachedValueProvider;
9 import com.intellij.psi.util.ParameterizedCachedValue;
10 import com.intellij.psi.util.ParameterizedCachedValueProvider;
11 import com.intellij.util.CachedValuesFactory;
12 import org.jetbrains.annotations.NotNull;
13
14 /**
15  * @author Dmitry Avdeev
16  */
17 public final class PsiCachedValuesFactory implements CachedValuesFactory {
18   private final PsiManager myManager;
19
20   public PsiCachedValuesFactory(@NotNull Project project) {
21     myManager = PsiManager.getInstance(project);
22   }
23
24   @Deprecated
25   public PsiCachedValuesFactory(PsiManager manager) {
26     myManager = manager;
27   }
28
29   @NotNull
30   @Override
31   public <T> CachedValue<T> createCachedValue(@NotNull CachedValueProvider<T> provider, boolean trackValue) {
32     return new PsiCachedValueImpl<>(myManager, provider, trackValue);
33   }
34
35   @NotNull
36   @Override
37   public <T, P> ParameterizedCachedValue<T, P> createParameterizedCachedValue(@NotNull ParameterizedCachedValueProvider<T, P> provider,
38                                                                               boolean trackValue) {
39     return new PsiParameterizedCachedValue<>(myManager, provider, trackValue);
40   }
41 }