Java 类com.intellij.psi.util.CachedValueProvider.Result 实例源码

项目:intellij    文件:BlazeSourceJarNavigationPolicy.java   
@Nullable
private Result<PsiFile> getPsiFile(ClsFileImpl file) {
  Project project = file.getProject();
  BlazeProjectData blazeProjectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (blazeProjectData == null) {
    return null;
  }

  VirtualFile root = getSourceJarRoot(project, blazeProjectData, file);
  if (root == null) {
    return null;
  }

  return getSourceFileResult(file, root);
}
项目:consulo-javaee    文件:JamCommonUtil.java   
public static <T extends JamElement> CachedValue<List<T>> createClassCachedValue(final Project project, final Factory<GlobalSearchScope> scope, final JamClassMeta<? extends T>... meta)
{
    return CachedValuesManager.getManager(project).createCachedValue(() ->
    {
        GlobalSearchScope searchScope = scope.create();
        final JamService jamService = JamService.getJamService(project);
        List<T> result = new ArrayList<>();
        if(!DumbService.isDumb(project))
        {
            for(JamClassMeta<? extends T> classMeta : meta)
            {
                for(JamAnnotationMeta annotationMeta : classMeta.getRootAnnotations())
                {
                    result.addAll(jamService.getJamClassElements(classMeta, annotationMeta.getAnnoName(), searchScope));
                }
            }
        }
        return new Result<>(result, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    }, false);
}
项目:intellij    文件:AndroidPackageRClass.java   
@NotNull
@Override
public PsiClass[] getInnerClasses() {
  if (myClassCache == null) {
    myClassCache =
        CachedValuesManager.getManager(getProject())
            .createCachedValue(
                () ->
                    Result.create(
                        doGetInnerClasses(),
                        PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT));
  }
  return myClassCache.getValue();
}
项目:intellij    文件:BlazeSourceJarNavigationPolicy.java   
@Nullable
@Override
public PsiFile getFileNavigationElement(ClsFileImpl file) {
  return CachedValuesManager.getCachedValue(
      file,
      () -> {
        Result<PsiFile> result = getPsiFile(file);
        if (result == null) {
          result = notFound(file);
        }
        return result;
      });
}
项目:intellij    文件:BlazeSourceJarNavigationPolicy.java   
@Nullable
private Result<PsiFile> getSourceFileResult(ClsFileImpl clsFile, VirtualFile root) {
  // This code is adapted from JavaPsiImplementationHelperImpl#getClsFileNavigationElement
  PsiClass[] classes = clsFile.getClasses();
  if (classes.length == 0) {
    return null;
  }

  String sourceFileName = ((ClsClassImpl) classes[0]).getSourceFileName();
  String packageName = clsFile.getPackageName();
  String relativePath =
      packageName.isEmpty()
          ? sourceFileName
          : packageName.replace('.', '/') + '/' + sourceFileName;

  VirtualFile source = root.findFileByRelativePath(relativePath);
  if (source != null && source.isValid()) {
    // Since we have an actual source jar tracked down, use that source jar as the modification
    // tracker. This means the result will continue to be cached unless that source jar changes.
    // If we didn't find a source jar, we use a modification tracker that invalidates on every
    // Blaze sync, which is less efficient.
    PsiFile psiSource = clsFile.getManager().findFile(source);
    if (psiSource instanceof PsiClassOwner) {
      return Result.create(psiSource, source);
    }
    return Result.create(null, source);
  }

  return null;
}
项目:intellij    文件:BlazeSourceJarNavigationPolicy.java   
private Result<PsiFile> notFound(ClsFileImpl file) {
  // A "not-found" result is null, but depends on the project sync tracker, so it will expire
  // after the next blaze sync. This means we'll run this check again after every sync for files
  // that don't have source jars, but it's not a huge deal because checking for the source jar
  // only takes a few microseconds.
  projectSyncTrackers.putIfAbsent(file.getProject(), new SimpleModificationTracker());
  return Result.create(null, projectSyncTrackers.get(file.getProject()));
}
项目:consulo-javaee    文件:JamCommonUtil.java   
@NotNull
public static Module[] getAllModuleDependencies(@NotNull final Module module)
{
    return CachedValuesManager.getManager(module.getProject()).getCachedValue(module, MODULE_DEPENDENCIES, () ->
    {
        final Set<Module> result = addModuleDependencies(module, new THashSet<>(), false);
        return new Result<>(result.toArray(new Module[result.size()]), ProjectRootManager.getInstance(module.getProject()));
    }, false);
}
项目:consulo-javaee    文件:JamCommonUtil.java   
@NotNull
public static Module[] getAllDependentModules(@NotNull final Module module)
{
    return CachedValuesManager.getManager(module.getProject()).getCachedValue(module, MODULE_DEPENDENTS, () ->
    {
        final Module[] modules = ModuleManager.getInstance(module.getProject()).getModules();
        final Set<Module> result = addModuleDependents(module, new THashSet<>(), modules);
        return new Result<>(result.toArray(new Module[result.size()]), ProjectRootManager.getInstance(module.getProject()));
    }, false);
}
项目:consulo-java    文件:JavaModuleGraphUtil.java   
@Nullable
public static Collection<PsiJavaModule> findCycle(@NotNull PsiJavaModule module)
{
    Project project = module.getProject();
    List<Set<PsiJavaModule>> cycles = CachedValuesManager.getManager(project).getCachedValue(project, () -> Result.create(findCycles(project), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT));
    return ContainerUtil.find(cycles, set -> set.contains(module));
}
项目:consulo-java    文件:JavaModuleGraphUtil.java   
private static RequiresGraph getRequiresGraph(PsiJavaModule module)
{
    Project project = module.getProject();
    return CachedValuesManager.getManager(project).getCachedValue(project, () -> Result.create(buildRequiresGraph(project), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT));
}