com.intellij.psi.util.CachedValueProvider Java Examples

The following examples show how to use com.intellij.psi.util.CachedValueProvider. 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: TemplateAnnotationTypeProvider.java    From idea-php-generics-plugin with MIT License 6 votes vote down vote up
@NotNull
private static Map<String, Collection<TemplateAnnotationUsage>> getTemplateAnnotationUsagesMap(@NotNull Project project) {
    return CachedValuesManager.getManager(project).getCachedValue(project, PHP_GENERICS_TEMPLATES, () -> {
        Map<String, Collection<TemplateAnnotationUsage>> map = new HashMap<>();

        FileBasedIndex instance = FileBasedIndex.getInstance();
        GlobalSearchScope scope = PhpIndex.getInstance(project).getSearchScope();

        instance.processAllKeys(TemplateAnnotationIndex.KEY, (key) -> {
            map.putIfAbsent(key, new HashSet<>());
            map.get(key).addAll(instance.getValues(TemplateAnnotationIndex.KEY, key, scope));
            return true;
        }, project);

        return CachedValueProvider.Result.create(map, getModificationTracker(project));
    }, false);
}
 
Example #2
Source File: ProducerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Based on {@link JUnitUtil#isTestClass}. We don't use that directly because it returns true for
 * all inner classes of a test class, regardless of whether they're also test classes.
 */
public static boolean isTestClass(PsiClass psiClass) {
  if (psiClass.getQualifiedName() == null) {
    return false;
  }
  if (JUnitUtil.isJUnit5(psiClass) && JUnitUtil.isJUnit5TestClass(psiClass, true)) {
    return true;
  }
  if (!PsiClassUtil.isRunnableClass(psiClass, true, true)) {
    return false;
  }
  if (isJUnit4Class(psiClass)) {
    return true;
  }
  if (isTestCaseInheritor(psiClass)) {
    return true;
  }
  return CachedValuesManager.getCachedValue(
      psiClass,
      () ->
          CachedValueProvider.Result.create(
              hasTestOrSuiteMethods(psiClass),
              PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT));
}
 
Example #3
Source File: PsiPackageSupportProviders.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
public static boolean isPackageSupported(@Nonnull Project project) {
  return CachedValuesManager.getManager(project).getCachedValue(project, () -> {
    boolean result = false;
    PsiPackageSupportProvider[] extensions = PsiPackageSupportProvider.EP_NAME.getExtensions();
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    loop:
    for (Module module : moduleManager.getModules()) {
      ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
      for (ModuleExtension moduleExtension : rootManager.getExtensions()) {
        for (PsiPackageSupportProvider extension : extensions) {
          if (extension.isSupported(moduleExtension)) {
            result = true;
            break loop;
          }
        }
      }
    }
    return CachedValueProvider.Result.create(result, ProjectRootManager.getInstance(project));
  });
}
 
Example #4
Source File: TestContextRunConfigurationProducer.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private RunConfigurationContext findTestContext(ConfigurationContext context) {
  if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
    // handled by a different producer
    return null;
  }
  ContextWrapper wrapper = new ContextWrapper(context);
  PsiElement psi = context.getPsiLocation();
  return psi == null
      ? null
      : CachedValuesManager.getCachedValue(
          psi,
          cacheKey,
          () ->
              CachedValueProvider.Result.create(
                  doFindTestContext(wrapper.context),
                  PsiModificationTracker.MODIFICATION_COUNT,
                  BlazeSyncModificationTracker.getInstance(wrapper.context.getProject())));
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
Source File: Unity3dManifest.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static Unity3dManifest parse(@Nonnull Project project)
{
	return CachedValuesManager.getManager(project).getCachedValue(project, () ->
	{
		Path projectPath = Paths.get(project.getBasePath());
		Path manifestJson = projectPath.resolve(Paths.get("Packages", "manifest.json"));
		if(Files.exists(manifestJson))
		{
			Gson gson = new Gson();
			try (Reader reader = Files.newBufferedReader(manifestJson))
			{
				return CachedValueProvider.Result.create(gson.fromJson(reader, Unity3dManifest.class), PsiModificationTracker.MODIFICATION_COUNT);
			}
			catch(Exception e)
			{
				LOG.error(e);
			}
		}
		return CachedValueProvider.Result.create(EMPTY, PsiModificationTracker.MODIFICATION_COUNT);
	});
}
 
Example #10
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 #11
Source File: CSharpModifierListImplUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredReadAction
public static EnumSet<CSharpModifier> getModifiersCached(@Nonnull CSharpModifierList modifierList)
{
	if(!modifierList.isValid())
	{
		return emptySet;
	}

	return CachedValuesManager.getCachedValue(modifierList, () ->
	{
		Set<CSharpModifier> modifiers = new THashSet<>();
		for(CSharpModifier modifier : CSharpModifier.values())
		{
			if(hasModifier(modifierList, modifier))
			{
				modifiers.add(modifier);
			}
		}
		return CachedValueProvider.Result.create(modifiers.isEmpty() ? emptySet : EnumSet.copyOf(modifiers), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
	});
}
 
Example #12
Source File: CSharpTypeDeclarationImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public DotNetTypeRef[] getExtendTypeRefs()
{
	return CachedValuesManager.getCachedValue(this, new CachedValueProvider<DotNetTypeRef[]>()
	{
		@Nullable
		@Override
		@RequiredReadAction
		public Result<DotNetTypeRef[]> compute()
		{
			DotNetTypeRef[] extendTypeRefs = CSharpTypeDeclarationImplUtil.getExtendTypeRefs(CSharpTypeDeclarationImpl.this);
			return Result.create(extendTypeRefs, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
		}
	});
}
 
Example #13
Source File: HaxeHierarchyUtils.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the list of classes implemented in the given File.
 *
 * @param psiRoot - File to search.
 * @return A List of found classes, or an empty array if none.
 */
@NotNull
public static List<HaxeClass> getClassList(@NotNull HaxeFile psiRoot) {
  CachedValuesManager manager = CachedValuesManager.getManager(psiRoot.getProject());
  ArrayList<HaxeClass> classList = manager.getCachedValue(psiRoot, () -> {
    ArrayList<HaxeClass> classes = new ArrayList<>();
    for (PsiElement child : psiRoot.getChildren()) {
      if (child instanceof HaxeClass) {
        classes.add((HaxeClass)child);
      }
    }
    return new CachedValueProvider.Result<>(classes, psiRoot);
  });

  return classList;
}
 
Example #14
Source File: CachedValueBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private Data<T> computeData(@Nullable CachedValueProvider.Result<T> result) {
  if (result == null) {
    return new Data<>(null, ArrayUtilRt.EMPTY_OBJECT_ARRAY, ArrayUtil.EMPTY_LONG_ARRAY);
  }
  T value = result.getValue();
  Object[] inferredDependencies = normalizeDependencies(result);
  long[] inferredTimeStamps = new long[inferredDependencies.length];
  for (int i = 0; i < inferredDependencies.length; i++) {
    inferredTimeStamps[i] = getTimeStamp(inferredDependencies[i]);
  }

  if (CachedValueProfiler.canProfile()) {
    ProfilingInfo profilingInfo = CachedValueProfiler.getInstance().getTemporaryInfo(result);
    if (profilingInfo != null) {
      return new ProfilingData<>(value, inferredDependencies, inferredTimeStamps, profilingInfo);
    }
  }

  return new Data<>(value, inferredDependencies, inferredTimeStamps);
}
 
Example #15
Source File: HaxeImportModel.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public List<HaxeModel> getExposedMembers() {
  List<HaxeModel> exposed = cacheManager.getCachedValue(getBasePsi(), () -> {
    List<HaxeModel> exposedMembers = getExposedMembersInternal();
    PsiElement [] dependencies = new PsiElement[exposedMembers.size() + 1];
    int i = 0;
    dependencies[i++] = getBasePsi();
    for (HaxeModel xMember : exposedMembers) {
      dependencies[i++] = xMember.getBasePsi();
    }
    return new CachedValueProvider.Result<>(exposedMembers, (Object[])dependencies);
  });

  return exposed;
}
 
Example #16
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 #17
Source File: ConfigAddPathTwigNamespaces.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Collection<TwigPath> getNamespaces(@NotNull TwigNamespaceExtensionParameter parameter) {
    Project project = parameter.getProject();

    Collection<Pair<String, String>> cachedValue = CachedValuesManager.getManager(project).getCachedValue(
        project,
        CACHE,
        () -> CachedValueProvider.Result.create(getTwigPaths(project), PsiModificationTracker.MODIFICATION_COUNT),
        false
    );

    // TwigPath is not cache able as it right now; we need to build it here
    return cachedValue.stream()
        .map(p -> new TwigPath(p.getFirst(), p.getSecond(), TwigUtil.NamespaceType.ADD_PATH, true))
        .collect(Collectors.toList());
}
 
Example #18
Source File: ServiceIndexUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
public static Map<String, Collection<ContainerService>> getDecoratedServices(@NotNull Project project) {
    return CachedValuesManager.getManager(project).getCachedValue(
        project,
        SERVICE_DECORATION_CACHE,
        () -> CachedValueProvider.Result.create(getDecoratedServicesInner(project), PsiModificationTracker.MODIFICATION_COUNT),
        false
    );
}
 
Example #19
Source File: FoldingUpdate.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static CachedValueProvider.Result<Runnable> getUpdateResult(PsiFile file,
                                                                    @Nonnull Document document,
                                                                    boolean quick,
                                                                    final Project project,
                                                                    final Editor editor,
                                                                    final boolean applyDefaultState) {

  final List<RegionInfo> elementsToFold = getFoldingsFor(file, document, quick);
  final UpdateFoldRegionsOperation operation = new UpdateFoldRegionsOperation(project, editor, file, elementsToFold, applyDefaultStateMode(applyDefaultState), !applyDefaultState, false);
  int documentLength = document.getTextLength();
  AtomicBoolean alreadyExecuted = new AtomicBoolean();
  Runnable runnable = () -> {
    if (alreadyExecuted.compareAndSet(false, true)) {
      int curLength = editor.getDocument().getTextLength();
      boolean committed = PsiDocumentManager.getInstance(project).isCommitted(document);
      if (documentLength != curLength || !committed) {
        LOG.error("Document has changed since fold regions were calculated: " + "lengths " + documentLength + " vs " + curLength + ", " + "document=" + document + ", " + "committed=" + committed);
      }
      editor.getFoldingModel().runBatchFoldingOperationDoNotCollapseCaret(operation);
    }
  };
  Set<Object> dependencies = new HashSet<>();
  dependencies.add(file);
  dependencies.add(editor.getFoldingModel());
  for (RegionInfo info : elementsToFold) {
    dependencies.addAll(info.descriptor.getDependencies());
  }
  return CachedValueProvider.Result.create(runnable, ArrayUtil.toObjectArray(dependencies));
}
 
Example #20
Source File: XQueryFile.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public Collection<XQueryVarName> getVariableNames() {
    if (variableNames == null) {
        variableNames = CachedValuesManager
                .getManager(getProject())
                .createCachedValue(new CachedValueProvider<Collection<XQueryVarName>>() {
                    @Override
                    public Result<Collection<XQueryVarName>> compute() {
                        return CachedValueProvider.Result.create(calcVariableNames(), XQueryFile.this);
                    }
                }, false);
    }
    return variableNames.getValue();
}
 
Example #21
Source File: ArtifactVirtualFileListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ArtifactVirtualFileListener(Project project, final ArtifactManagerImpl artifactManager) {
  myArtifactManager = artifactManager;
  myParentPathsToArtifacts =
    CachedValuesManager.getManager(project).createCachedValue(new CachedValueProvider<MultiValuesMap<String, Artifact>>() {
      public Result<MultiValuesMap<String, Artifact>> compute() {
        MultiValuesMap<String, Artifact> result = computeParentPathToArtifactMap();
        return Result.createSingleDependency(result, artifactManager.getModificationTracker());
      }
    }, false);
}
 
Example #22
Source File: XQueryFile.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public Collection<XQueryVarRef> getVariableReferences() {
    if (variableReferences == null) {
        variableReferences = CachedValuesManager
                .getManager(getProject())
                .createCachedValue(new CachedValueProvider<Collection<XQueryVarRef>>() {
                    @Override
                    public Result<Collection<XQueryVarRef>> compute() {
                        return CachedValueProvider.Result.create(calcVariableReferences(), XQueryFile.this);
                    }
                }, false);
    }
    return variableReferences.getValue();
}
 
Example #23
Source File: XQueryFile.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@NotNull
public Collection<XQueryFunctionDecl> getFunctionDeclarations() {
    if (functionDeclarations == null) {
        functionDeclarations = CachedValuesManager
                .getManager(getProject())
                .createCachedValue(new CachedValueProvider<Collection<XQueryFunctionDecl>>() {
                    @Override
                    public Result<Collection<XQueryFunctionDecl>> compute() {
                        return CachedValueProvider.Result.create(calcFunctionDeclarations(), XQueryFile.this);
                    }
                }, false);
    }
    return functionDeclarations.getValue();
}
 
Example #24
Source File: XQueryFile.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@NotNull
public Collection<XQueryModuleImport> getModuleImports() {
    if (moduleImports == null) {
        moduleImports = CachedValuesManager
                .getManager(getProject())
                .createCachedValue(new CachedValueProvider<Collection<XQueryModuleImport>>() {
                    @Override
                    public Result<Collection<XQueryModuleImport>> compute() {
                        return CachedValueProvider.Result.create(calcModuleImports(), XQueryFile.this);
                    }
                }, false);
    }
    return moduleImports.getValue();
}
 
Example #25
Source File: ArtifactSortingUtilImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> getArtifactToSelfIncludingNameMap() {
  if (myArtifactToSelfIncludingName == null) {
    myArtifactToSelfIncludingName = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Map<String, String>>() {
      public Result<Map<String, String>> compute() {
        return Result.create(computeArtifactToSelfIncludingNameMap(), ArtifactManager.getInstance(myProject).getModificationTracker());
      }
    }, false);
  }
  return myArtifactToSelfIncludingName.getValue();
}
 
Example #26
Source File: ArtifactSortingUtilImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getArtifactsSortedByInclusion() {
  if (mySortedArtifacts == null) {
    mySortedArtifacts = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<List<String>>() {
        @Override
        public Result<List<String>> compute() {
          return Result.create(doGetSortedArtifacts(), ArtifactManager.getInstance(myProject).getModificationTracker());
        }
      }, false);
  }
  return mySortedArtifacts.getValue();
}
 
Example #27
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 #28
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 #29
Source File: TranslationIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
private Collection<File> getTranslationRoot() {
    return CachedValuesManager.getManager(project)
        .getCachedValue(
            project,
            SYMFONY_TRANSLATION_COMPILED,
            () -> CachedValueProvider.Result.create(getTranslationRootInnerTime(), PsiModificationTracker.MODIFICATION_COUNT),
            false
        );
}
 
Example #30
Source File: CachedValueBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected Object[] normalizeDependencies(@Nonnull CachedValueProvider.Result<T> result) {
  Object[] items = result.getDependencyItems();
  T value = result.getValue();
  Object[] rawDependencies = myTrackValue && value != null ? ArrayUtil.append(items, value) : items;

  List<Object> flattened = new NotNullList<>(rawDependencies.length);
  collectDependencies(flattened, rawDependencies);
  return ArrayUtil.toObjectArray(flattened);
}