diff --git a/json/src/com/jetbrains/jsonSchema/impl/CachedValueProviderOnPsiFile.java b/json/src/com/jetbrains/jsonSchema/impl/CachedValueProviderOnPsiFile.java deleted file mode 100644 index b069841aafcf..000000000000 --- a/json/src/com/jetbrains/jsonSchema/impl/CachedValueProviderOnPsiFile.java +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2000-2018 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. -package com.jetbrains.jsonSchema.impl; - -import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.util.Key; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.CachedValue; -import com.intellij.psi.util.CachedValueProvider; -import com.intellij.psi.util.CachedValuesManager; -import com.intellij.util.Function; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public abstract class CachedValueProviderOnPsiFile implements CachedValueProvider { - private final PsiFile myPsiFile; - - public CachedValueProviderOnPsiFile(@NotNull PsiFile psiFile) { - myPsiFile = psiFile; - } - - @Nullable - @Override - public Result compute() { - return CachedValueProvider.Result.create(evaluate(myPsiFile), myPsiFile); - } - - @Nullable - public abstract T evaluate(@NotNull PsiFile psiFile); - - @Nullable - public static T getOrCompute(@NotNull PsiFile psiFile, @NotNull Function eval, @NotNull Key> key) { - final CachedValueProvider provider = new CachedValueProviderOnPsiFile(psiFile) { - @Override - @Nullable - public T evaluate(@NotNull PsiFile psiFile) { - return eval.fun(psiFile); - } - }; - return ReadAction.compute(() -> CachedValuesManager.getCachedValue(psiFile, key, provider)); - } -} diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonCachedValues.java b/json/src/com/jetbrains/jsonSchema/impl/JsonCachedValues.java index aa52c3534a27..673a28440276 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonCachedValues.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonCachedValues.java @@ -12,6 +12,8 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.SyntaxTraverser; import com.intellij.psi.util.CachedValue; +import com.intellij.psi.util.CachedValueProvider; +import com.intellij.psi.util.CachedValuesManager; import com.intellij.util.AstLoadingFilter; import com.intellij.util.Function; import com.intellij.util.ObjectUtils; @@ -58,8 +60,7 @@ public class JsonCachedValues { } PsiFile psiFile = resolveFile(file, project); - return !(psiFile instanceof JsonFile) ? null : CachedValueProviderOnPsiFile - .getOrCompute(psiFile, JsonCachedValues::fetchSchemaUrl, SCHEMA_URL_KEY); + return !(psiFile instanceof JsonFile) ? null : getOrCompute(psiFile, JsonCachedValues::fetchSchemaUrl, SCHEMA_URL_KEY); } private static PsiFile resolveFile(@NotNull VirtualFile file, @@ -98,18 +99,18 @@ public class JsonCachedValues { @NotNull Key> cacheKey) { final PsiFile psiFile = resolveFile(schemaFile, project); if (!(psiFile instanceof JsonFile)) return null; - return CachedValueProviderOnPsiFile.getOrCompute(psiFile, eval, cacheKey); + return getOrCompute(psiFile, eval, cacheKey); } static final String ID_PATHS_CACHE_KEY = "JsonSchemaIdToPointerCache"; private static final Key>> SCHEMA_ID_PATHS_CACHE_KEY = Key.create(ID_PATHS_CACHE_KEY); public static Collection getAllIdsInFile(PsiFile psiFile) { - final Map map = CachedValueProviderOnPsiFile.getOrCompute(psiFile, JsonCachedValues::computeIdsMap, SCHEMA_ID_PATHS_CACHE_KEY); + Map map = getOrCompute(psiFile, JsonCachedValues::computeIdsMap, SCHEMA_ID_PATHS_CACHE_KEY); return map == null ? ContainerUtil.emptyList() : map.keySet(); } @Nullable public static String resolveId(PsiFile psiFile, String id) { - final Map map = CachedValueProviderOnPsiFile.getOrCompute(psiFile, JsonCachedValues::computeIdsMap, SCHEMA_ID_PATHS_CACHE_KEY); + Map map = getOrCompute(psiFile, JsonCachedValues::computeIdsMap, SCHEMA_ID_PATHS_CACHE_KEY); return map == null ? null : map.get(id); } @@ -199,4 +200,11 @@ public class JsonCachedValues { return ContainerUtil.emptyList(); } + + @Nullable + private static T getOrCompute(@NotNull PsiFile psiFile, + @NotNull Function eval, + @NotNull Key> key) { + return CachedValuesManager.getCachedValue(psiFile, key, () -> CachedValueProvider.Result.create(eval.fun(psiFile), psiFile)); + } }