com.intellij.psi.util.CachedValue Java Examples

The following examples show how to use com.intellij.psi.util.CachedValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceCollector.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
@Override
public void collectServices(@NotNull ServiceCollectorParameter.Service arg) {
    if(!ShopwareProjectComponent.isValidForProject(arg.getProject())) {
        return;
    }

    // cache
    CachedValue<Collection<ServiceInterface>> cache = arg.getProject().getUserData(SERVICE_CACHE);
    if (cache == null) {
        cache = CachedValuesManager.getManager(arg.getProject())
            .createCachedValue(new MyServiceCollectionCachedValueProvider(arg), false);

        arg.getProject().putUserData(SERVICE_CACHE, cache);
    }

    arg.addAll(cache.getValue());
}
 
Example #2
Source File: ClassMetadataProxy.java    From intellij-spring-assistant with MIT License 6 votes vote down vote up
private ClassMetadata getTarget(Module module) {
  String fqn = typeToFqn(module, type);
  if (fqn != null) {
    String userDataKeyRef = "spring_assistant_plugin_class_metadata:" + fqn;
    Key<CachedValue<ClassMetadata>> classMetadataKey =
        ConcurrencyUtil.cacheOrGet(fqnToKey, userDataKeyRef, Key.create(userDataKeyRef));
    return getCachedValue(targetClass, classMetadataKey, () -> {
      log.debug("Creating metadata instance for " + userDataKeyRef);
      Set<PsiClass> dependencies = computeDependencies(module, type);
      if (dependencies != null) {
        return create(newClassMetadata(type), dependencies);
      }
      return null;
    });
  }
  return null;
}
 
Example #3
Source File: FileIndexCaches.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @param dataHolderKey Main data to cache
 * @param dataHolderNames Cache extracted name Set
 */
static public synchronized <T> Map<String, List<T>> getSetDataCache(@NotNull final Project project, @NotNull Key<CachedValue<Map<String, List<T>>>> dataHolderKey, final @NotNull Key<CachedValue<Set<String>>> dataHolderNames, @NotNull final ID<String, T> ID, @NotNull final GlobalSearchScope scope) {
    return CachedValuesManager.getManager(project).getCachedValue(
        project,
        dataHolderKey,
        () -> {
            Map<String, List<T>> items = new HashMap<>();

            final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();

            getIndexKeysCache(project, dataHolderNames, ID).forEach(service ->
                items.put(service, fileBasedIndex.getValues(ID, service, scope))
            );

            return CachedValueProvider.Result.create(items, getModificationTrackerForIndexId(project, ID));
        },
        false
    );
}
 
Example #4
Source File: FileIndexCaches.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @param dataHolderKey Main data to cache
 * @param dataHolderNames Cache extracted name Set
 */
static public synchronized Map<String, List<String>> getStringDataCache(@NotNull final Project project, @NotNull Key<CachedValue<Map<String, List<String>>>> dataHolderKey, final @NotNull Key<CachedValue<Set<String>>> dataHolderNames, @NotNull final ID<String, String> ID, @NotNull final GlobalSearchScope scope) {
    return CachedValuesManager.getManager(project).getCachedValue(
        project,
        dataHolderKey,
        () -> {
            Map<String, List<String>> strings = new HashMap<>();

            final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
            getIndexKeysCache(project, dataHolderNames, ID).forEach(parameterName -> {
                // just for secure
                if(parameterName == null) {
                    return;
                }

                strings.put(parameterName, fileBasedIndex.getValues(ID, parameterName, scope));
            });

            return CachedValueProvider.Result.create(strings, getModificationTrackerForIndexId(project, ID));
        },
        false
    );
}
 
Example #5
Source File: ArtifactBySourceFileFinderImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CachedValue<MultiValuesMap<VirtualFile, Artifact>> getFileToArtifactsMap() {
  if (myFile2Artifacts == null) {
    myFile2Artifacts =
      CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<MultiValuesMap<VirtualFile, Artifact>>() {
        public Result<MultiValuesMap<VirtualFile, Artifact>> compute() {
          MultiValuesMap<VirtualFile, Artifact> result = computeFileToArtifactsMap();
          List<ModificationTracker> trackers = new ArrayList<ModificationTracker>();
          trackers.add(myArtifactManager.getModificationTracker());
          for (ComplexPackagingElementType<?> type : PackagingElementFactory.getInstance(myProject).getComplexElementTypes()) {
            ContainerUtil.addIfNotNull(trackers, type.getAllSubstitutionsModificationTracker(myProject));
          }
          return Result.create(result, trackers.toArray(new ModificationTracker[trackers.size()]));
        }
      }, false);
  }
  return myFile2Artifacts;
}
 
Example #6
Source File: GlobalNamespaceLoader.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@Override
@NotNull
public Collection<String> getGlobalNamespaces(@NotNull AnnotationGlobalNamespacesLoaderParameter parameter) {
    Project project = parameter.getProject();

    CachedValue<Collection<String>> cache = project.getUserData(CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() ->
            CachedValueProvider.Result.create(getGlobalNamespacesInner(project), PsiModificationTracker.MODIFICATION_COUNT), false
        );

        project.putUserData(CACHE, cache);
    }

    return cache.getValue();
}
 
Example #7
Source File: SubscriberIndexUtil.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
@NotNull
public static Collection<ServiceResource> getIndexedBootstrapResources(@NotNull Project project) {

    // cache
    CachedValue<Collection<ServiceResource>> cache = project.getUserData(SERVICE_RESOURCE);
    if (cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(
            getIndexedBootstrapResources(project, BootstrapResource.INIT_RESOURCE, BootstrapResource.AFTER_INIT_RESOURCE, BootstrapResource.AFTER_REGISTER_RESOURCE),
            PsiModificationTracker.MODIFICATION_COUNT
        ), false);

        project.putUserData(SERVICE_RESOURCE, cache);
    }

    return cache.getValue();
}
 
Example #8
Source File: FoldingUpdate.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
static Runnable updateFoldRegions(@Nonnull final Editor editor, @Nonnull PsiFile file, final boolean applyDefaultState, final boolean quick) {
  ApplicationManager.getApplication().assertReadAccessAllowed();

  final Project project = file.getProject();
  final Document document = editor.getDocument();
  LOG.assertTrue(!PsiDocumentManager.getInstance(project).isUncommited(document));

  CachedValue<Runnable> value = editor.getUserData(CODE_FOLDING_KEY);

  if (value != null && !applyDefaultState) {
    Getter<Runnable> cached = value.getUpToDateOrNull();
    if (cached != null) {
      return cached.get();
    }
  }
  if (quick || applyDefaultState) return getUpdateResult(file, document, quick, project, editor, applyDefaultState).getValue();

  return CachedValuesManager.getManager(project).getCachedValue(editor, CODE_FOLDING_KEY, () -> {
    PsiFile file1 = PsiDocumentManager.getInstance(project).getPsiFile(document);
    return getUpdateResult(file1, document, false, project, editor, false);
  }, false);
}
 
Example #9
Source File: ArbitraryPlaceUrlReferenceProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected CachedValue<PsiReference[]> compute(final PsiElement element, Object p) {
  return CachedValuesManager.getManager(element.getProject()).createCachedValue(() -> {
    IssueNavigationConfiguration navigationConfiguration = IssueNavigationConfiguration.getInstance(element.getProject());
    if (navigationConfiguration == null) {
      return CachedValueProvider.Result.create(PsiReference.EMPTY_ARRAY, element);
    }

    List<PsiReference> refs = null;
    GlobalPathReferenceProvider provider = myReferenceProvider.get();
    CharSequence commentText = StringUtil.newBombedCharSequence(element.getText(), 500);
    for (IssueNavigationConfiguration.LinkMatch link : navigationConfiguration.findIssueLinks(commentText)) {
      if (refs == null) refs = new SmartList<>();
      if (provider == null) {
        provider = (GlobalPathReferenceProvider)PathReferenceManager.getInstance().getGlobalWebPathReferenceProvider();
        myReferenceProvider.lazySet(provider);
      }
      provider.createUrlReference(element, link.getTargetUrl(), link.getRange(), refs);
    }
    PsiReference[] references = refs != null ? refs.toArray(new PsiReference[refs.size()]) : PsiReference.EMPTY_ARRAY;
    return new CachedValueProvider.Result<>(references, element, navigationConfiguration);
  }, false);
}
 
Example #10
Source File: MakefileIdentifierReference.java    From CppTools with Apache License 2.0 6 votes vote down vote up
@NotNull
public ResolveResult[] multiResolve(boolean b) {
  if (isSelfReference()) {
    return new ResolveResult[] {new PsiElementResolveResult(myElement)};
  }
  CachedValue<Map<String, Object>> mapCachedValue = getDeclarationsMap();

  Object o = mapCachedValue.getValue().get(getCanonicalText());

  if (o instanceof PsiElement) {
    return new ResolveResult[] {new com.advancedtools.cpp.psi.PsiElementResolveResult((PsiElement) o)};
  } else if (o != null) {
    Object[] objects = (Object[]) o;
    ResolveResult r[] = new ResolveResult[objects.length];
    for(int i = 0; i < r.length; ++i) {
      r[i] = new PsiElementResolveResult((PsiElement) objects[i]);
    }
    return r;
  }
  return ResolveResult.EMPTY_ARRAY;
}
 
Example #11
Source File: HtmlNSNamespaceProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
private synchronized Collection<FluidNamespace> doProvide(@NotNull PsiElement element) {
    FileViewProvider viewProvider = element.getContainingFile().getViewProvider();
    if (!viewProvider.getLanguages().contains(HTMLLanguage.INSTANCE)) {
        return ContainerUtil.emptyList();
    }

    PsiFile htmlFile = viewProvider.getPsi(HTMLLanguage.INSTANCE);
    CachedValue userData = htmlFile.getUserData(HTML_NS_KEY);
    if (userData != null) {
        return (Collection<FluidNamespace>) userData.getValue();
    }

    CachedValue<Collection<FluidNamespace>> cachedValue = CachedValuesManager.getManager(element.getProject()).createCachedValue(() -> {
        HtmlNSVisitor visitor = new HtmlNSVisitor();
        htmlFile.accept(visitor);

        return CachedValueProvider.Result.createSingleDependency(visitor.namespaces, htmlFile);
    }, false);

    htmlFile.putUserData(HTML_NS_KEY, cachedValue);

    return cachedValue.getValue();
}
 
Example #12
Source File: TranslationUtil.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
private synchronized static Collection<String> getAllKeys(@NotNull Project project) {
    CachedValue<Collection<String>> cachedValue = project.getUserData(TRANSLATION_KEYS);
    if (cachedValue != null && cachedValue.hasUpToDateValue()) {
        return TRANSLATION_KEYS_LOCAL_CACHE.getOrDefault(project, new ArrayList<>());
    }

    cachedValue = CachedValuesManager.getManager(project).createCachedValue(() -> {
        Collection<String> allKeys = FileBasedIndex.getInstance().getAllKeys(TranslationIndex.KEY, project);
        if (TRANSLATION_KEYS_LOCAL_CACHE.containsKey(project)) {
            TRANSLATION_KEYS_LOCAL_CACHE.replace(project, allKeys);
        } else {
            TRANSLATION_KEYS_LOCAL_CACHE.put(project, allKeys);
        }

        return CachedValueProvider.Result.create(new ArrayList<>(), MODIFICATION_COUNT);
    }, false);

    project.putUserData(TRANSLATION_KEYS, cachedValue);

    return TRANSLATION_KEYS_LOCAL_CACHE.getOrDefault(project, cachedValue.getValue());
}
 
Example #13
Source File: ResourcePathIndex.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
private synchronized static Collection<String> getAllResourceKeys(@NotNull Project project) {
    CachedValue<Collection<String>> userData = project.getUserData(RESOURCE_KEYS);
    if (userData != null && userData.hasUpToDateValue()) {
        return RESOURCE_KEYS_LOCAL_CACHE.getOrDefault(project, new ArrayList<>());
    }

    CachedValue<Collection<String>> cachedValue = CachedValuesManager.getManager(project).createCachedValue(() -> {
        Collection<String> allKeys = FileBasedIndex.getInstance().getAllKeys(ResourcePathIndex.KEY, project);
        if (RESOURCE_KEYS_LOCAL_CACHE.containsKey(project)) {
            RESOURCE_KEYS_LOCAL_CACHE.replace(project, allKeys);
        } else {
            RESOURCE_KEYS_LOCAL_CACHE.put(project, allKeys);
        }

        return CachedValueProvider.Result.create(new ArrayList<>(), PsiModificationTracker.MODIFICATION_COUNT);
    }, false);
    project.putUserData(RESOURCE_KEYS, cachedValue);

    return RESOURCE_KEYS_LOCAL_CACHE.getOrDefault(project, cachedValue.getValue());
}
 
Example #14
Source File: CSharpResolveContextUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static <T extends PsiElement> CSharpResolveContext cacheSimple(@Nonnull final T element, final NotNullFunction<T, CSharpResolveContext> fun)
{
	CachedValue<CSharpResolveContext> provider = element.getUserData(RESOLVE_CONTEXT);
	if(provider != null)
	{
		return provider.getValue();
	}

	CachedValue<CSharpResolveContext> cachedValue = CachedValuesManager.getManager(element.getProject()).createCachedValue(() -> CachedValueProvider.Result.create(fun.fun(element),
			PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT), false);
	element.putUserData(RESOLVE_CONTEXT, cachedValue);
	return cachedValue.getValue();
}
 
Example #15
Source File: MetaRegistry.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void bindDataToElement(final PsiElement element, final PsiMetaData data) {
  CachedValue<PsiMetaData> value =
    CachedValuesManager.getManager(element.getProject()).createCachedValue(new CachedValueProvider<PsiMetaData>() {
      @Override
      public Result<PsiMetaData> compute() {
        data.init(element);
        return new Result<PsiMetaData>(data, data.getDependences());
      }
    });
  element.putUserData(META_DATA_KEY, value);
}
 
Example #16
Source File: CppStructureViewBuilder.java    From CppTools with Apache License 2.0 5 votes vote down vote up
@NotNull
public StructureViewTreeElement getRoot() {
  CachedValue<StructureViewTreeElement> value = myFile.getUserData(ourCachedKey);
  if (value == null) {
    value = CachedValuesManager.getManager(myFile.getManager().getProject()).createCachedValue(new CachedValueProvider<StructureViewTreeElement>() {
      public Result<StructureViewTreeElement> compute() {
        final OutlineCommand outlineCommand = new OutlineCommand(myFile.getVirtualFile().getPath());
        outlineCommand.post(myFile.getProject());

        final Communicator communicator = Communicator.getInstance(myFile.getProject());

        if (outlineCommand.hasReadyResult()) {
          final OutlineData first = outlineCommand.outlineDatumStack.getFirst();
          return new Result<StructureViewTreeElement>(
            new CppStructureViewTreeElement((CppFile) myFile, first),
            communicator.getServerRestartTracker(),
            communicator.getModificationTracker()
          );
        }

        return new Result<StructureViewTreeElement>(new CppStructureViewTreeElement((CppFile) myFile, null),
          communicator.getServerRestartTracker(),
          communicator.getModificationTracker()
        );
      }
    }, false);

    myFile.putUserData(ourCachedKey, value);
  }

  return value.getValue();
}
 
Example #17
Source File: MakefileIdentifierReference.java    From CppTools with Apache License 2.0 5 votes vote down vote up
@NotNull
public Object[] getVariants() {
  if (isSelfReference()) {
    return new Object[0];
  }
  CachedValue<Map<String, Object>> mapCachedValue = getDeclarationsMap();
  Map<String, Object> declMap = mapCachedValue.getValue();
  return declMap.keySet().toArray();
}
 
Example #18
Source File: FileIndexCaches.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * There several methods that just need to check for names, as they also needed for value extraction, so cache them also
 */
static public synchronized Set<String> getIndexKeysCache(@NotNull final Project project, @NotNull Key<CachedValue<Set<String>>> dataHolderKey, @NotNull final ID<String, ?> id) {
    return CachedValuesManager.getManager(project).getCachedValue(
        project,
        dataHolderKey,
        () -> CachedValueProvider.Result.create(SymfonyProcessors.createResult(project, id), getModificationTrackerForIndexId(project, id)),
        false
    );
}
 
Example #19
Source File: CSharpTypeRefCacher.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public DotNetTypeRef toTypeRef(E element, boolean resolveFromParentOrInitializer, Object... dropKeys)
{
	if(CSharpReferenceExpressionImplUtil.isCacheDisabled(element))
	{
		return toTypeRefImpl(element, resolveFromParentOrInitializer);
	}

	Key<CachedValue<DotNetTypeRef>> key = resolveFromParentOrInitializer ? ourTrueTypeRefKey : ourFalseTypeRefKey;
	NotNullFunction<E, DotNetTypeRef> resolver = resolveFromParentOrInitializer ? myTrueFunction : myFalseFunction;
	return DotNetTypeRefCacheUtil.cacheTypeRef(key, element, resolver, dropKeys);
}
 
Example #20
Source File: CSharpResolveContextUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
private static CSharpResolveContext cacheTypeContextImpl(@Nonnull DotNetGenericExtractor genericExtractor,
														 @Nonnull final CSharpTypeDeclaration typeDeclaration,
														 @Nullable final Set<PsiElement> recursiveGuardSet)
{
	if(genericExtractor == DotNetGenericExtractor.EMPTY && (recursiveGuardSet == null || recursiveGuardSet.size() == 1 && recursiveGuardSet.contains(typeDeclaration)))
	{
		CachedValue<CSharpResolveContext> provider = typeDeclaration.getUserData(RESOLVE_CONTEXT);
		if(provider != null)
		{
			return provider.getValue();
		}

		CachedValue<CSharpResolveContext> cachedValue = CachedValuesManager.getManager(typeDeclaration.getProject()).createCachedValue(new CachedValueProvider<CSharpResolveContext>()
		{
			@Nullable
			@Override
			@RequiredReadAction
			public Result<CSharpResolveContext> compute()
			{
				return Result.<CSharpResolveContext>create(new CSharpTypeResolveContext(typeDeclaration, DotNetGenericExtractor.EMPTY, null), PsiModificationTracker.MODIFICATION_COUNT);
			}
		}, false);
		typeDeclaration.putUserData(RESOLVE_CONTEXT, cachedValue);
		return cachedValue.getValue();
	}
	else
	{
		return new CSharpTypeResolveContext(typeDeclaration, genericExtractor, recursiveGuardSet);
	}
}
 
Example #21
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
synchronized public static Collection<JsonConfigFile> getJsonConfigs(final @NotNull Project project, final @NotNull PhpToolboxApplicationService phpToolboxApplicationService) {
    CachedValue<Collection<JsonConfigFile>> cache = project.getUserData(CONFIGS_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getJsonConfigsInner(project, phpToolboxApplicationService), PsiModificationTracker.MODIFICATION_COUNT), false);
        project.putUserData(CONFIGS_CACHE, cache);
    }

    Collection<JsonConfigFile> jsonConfigFiles = new ArrayList<>(cache.getValue());

    // prevent reindex issues
    if (!DumbService.getInstance(project).isDumb()) {
        CachedValue<Collection<JsonConfigFile>> indexCache = project.getUserData(CONFIGS_CACHE_INDEX);

        if (indexCache == null) {
            indexCache = CachedValuesManager.getManager(project).createCachedValue(() -> {
                Collection<JsonConfigFile> jsonConfigFiles1 = new ArrayList<>();

                for (final PsiFile psiFile : FilenameIndex.getFilesByName(project, ".ide-toolbox.metadata.json", GlobalSearchScope.allScope(project))) {
                    JsonConfigFile cachedValue = CachedValuesManager.getCachedValue(psiFile, () -> new CachedValueProvider.Result<>(
                        JsonParseUtil.getDeserializeConfig(psiFile.getText()),
                        psiFile,
                        psiFile.getVirtualFile()
                    ));

                    if(cachedValue != null) {
                        jsonConfigFiles1.add(cachedValue);
                    }
                }

                return CachedValueProvider.Result.create(jsonConfigFiles1, PsiModificationTracker.MODIFICATION_COUNT);
            }, false);
        }

        project.putUserData(CONFIGS_CACHE_INDEX, indexCache);
        jsonConfigFiles.addAll(indexCache.getValue());
    }

    return jsonConfigFiles;
}
 
Example #22
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
synchronized public static Collection<JsonRegistrar> getTypes(final @NotNull Project project) {
    CachedValue<Collection<JsonRegistrar>> cache = project.getUserData(TYPE_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getTypesInner(project), PsiModificationTracker.MODIFICATION_COUNT), false);

        project.putUserData(TYPE_CACHE, cache);
    }

    return cache.getValue();
}
 
Example #23
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
synchronized public static Collection<JsonRegistrar> getRegistrar(final @NotNull Project project, final @NotNull PhpToolboxApplicationService phpToolboxApplicationService) {
    CachedValue<Collection<JsonRegistrar>> cache = project.getUserData(REGISTRAR_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getRegistrarInner(project, phpToolboxApplicationService), PsiModificationTracker.MODIFICATION_COUNT), false);

        project.putUserData(REGISTRAR_CACHE, cache);
    }

    return cache.getValue();
}
 
Example #24
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
synchronized public static Collection<PhpToolboxProviderInterface> getProviders(final @NotNull Project project) {
    CachedValue<Collection<PhpToolboxProviderInterface>> cache = project.getUserData(PROVIDER_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getProvidersInner(project), PsiModificationTracker.MODIFICATION_COUNT), false);

        project.putUserData(PROVIDER_CACHE, cache);
    }

    return cache.getValue();
}
 
Example #25
Source File: CSharpTypeRefCacher.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public DotNetTypeRef toTypeRef(E element, boolean resolveFromParentOrInitializer)
{
	if(CSharpReferenceExpressionImplUtil.isCacheDisabled(element))
	{
		return toTypeRefImpl(element, resolveFromParentOrInitializer);
	}

	Key<CachedValue<DotNetTypeRef>> key = resolveFromParentOrInitializer ? ourTrueTypeRefKey : ourFalseTypeRefKey;
	NotNullFunction<E, DotNetTypeRef> resolver = resolveFromParentOrInitializer ? myTrueFunction : myFalseFunction;
	return myLocal ? DotNetTypeRefCacheUtil.localCacheTypeRef(key, element, resolver) : DotNetTypeRefCacheUtil.cacheTypeRef(key, element, resolver);
}
 
Example #26
Source File: ServiceCollector.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Override
public void collectIds(@NotNull ServiceCollectorParameter.Id arg) {
    if(!ShopwareProjectComponent.isValidForProject(arg.getProject())) {
        return;
    }

    // cache
    CachedValue<Collection<String>> cache = arg.getProject().getUserData(SERVICE_NAME_CACHE);
    if (cache == null) {
        cache = CachedValuesManager.getManager(arg.getProject()).createCachedValue(new MyServiceNameCachedValueProvider(arg), false);
        arg.getProject().putUserData(SERVICE_NAME_CACHE, cache);
    }

    arg.addAll(cache.getValue());
}
 
Example #27
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
synchronized public static Collection<JsonConfigFile> getJsonConfigs(final @NotNull Project project, final @NotNull PhpToolboxApplicationService phpToolboxApplicationService) {
    CachedValue<Collection<JsonConfigFile>> cache = project.getUserData(CONFIGS_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getJsonConfigsInner(project, phpToolboxApplicationService), PsiModificationTracker.MODIFICATION_COUNT), false);
        project.putUserData(CONFIGS_CACHE, cache);
    }

    Collection<JsonConfigFile> jsonConfigFiles = new ArrayList<>(cache.getValue());

    // prevent reindex issues
    if (!DumbService.getInstance(project).isDumb()) {
        CachedValue<Collection<JsonConfigFile>> indexCache = project.getUserData(CONFIGS_CACHE_INDEX);

        if (indexCache == null) {
            indexCache = CachedValuesManager.getManager(project).createCachedValue(() -> {
                Collection<JsonConfigFile> jsonConfigFiles1 = new ArrayList<>();

                for (final PsiFile psiFile : FilenameIndex.getFilesByName(project, ".ide-toolbox.metadata.json", GlobalSearchScope.allScope(project))) {
                    JsonConfigFile cachedValue = CachedValuesManager.getCachedValue(psiFile, () -> new CachedValueProvider.Result<>(
                        JsonParseUtil.getDeserializeConfig(psiFile.getText()),
                        psiFile,
                        psiFile.getVirtualFile()
                    ));

                    if(cachedValue != null) {
                        jsonConfigFiles1.add(cachedValue);
                    }
                }

                return CachedValueProvider.Result.create(jsonConfigFiles1, PsiModificationTracker.MODIFICATION_COUNT);
            }, false);
        }

        project.putUserData(CONFIGS_CACHE_INDEX, indexCache);
        jsonConfigFiles.addAll(indexCache.getValue());
    }

    return jsonConfigFiles;
}
 
Example #28
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
synchronized public static Collection<PhpToolboxProviderInterface> getProviders(final @NotNull Project project) {
    CachedValue<Collection<PhpToolboxProviderInterface>> cache = project.getUserData(PROVIDER_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getProvidersInner(project), PsiModificationTracker.MODIFICATION_COUNT), false);

        project.putUserData(PROVIDER_CACHE, cache);
    }

    return cache.getValue();
}
 
Example #29
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
synchronized public static Collection<JsonRegistrar> getTypes(final @NotNull Project project) {
    CachedValue<Collection<JsonRegistrar>> cache = project.getUserData(TYPE_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getTypesInner(project), PsiModificationTracker.MODIFICATION_COUNT), false);

        project.putUserData(TYPE_CACHE, cache);
    }

    return cache.getValue();
}
 
Example #30
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
synchronized public static Collection<JsonRegistrar> getRegistrar(final @NotNull Project project, final @NotNull PhpToolboxApplicationService phpToolboxApplicationService) {
    CachedValue<Collection<JsonRegistrar>> cache = project.getUserData(REGISTRAR_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getRegistrarInner(project, phpToolboxApplicationService), PsiModificationTracker.MODIFICATION_COUNT), false);

        project.putUserData(REGISTRAR_CACHE, cache);
    }

    return cache.getValue();
}