Java 类com.intellij.psi.util.CachedValuesManager 实例源码

项目:hybris-integration-intellij-idea-plugin    文件:JspPropertyFoldingBuilder.java   
@Nullable
private static IProperty getResolvedProperty(@NotNull final XmlAttributeValue codeValue) {
    return CachedValuesManager.getCachedValue(codeValue, KEY, () -> {
        List<IProperty> allProperties = new SmartList<>();
        for (PsiReference nextRef : codeValue.getReferences()) {
            if (nextRef instanceof PsiPolyVariantReference) {
                Arrays.stream(((PsiPolyVariantReference) nextRef).multiResolve(false))
                      .filter(ResolveResult::isValidResult)
                      .map(ResolveResult::getElement)
                      .map(o -> ObjectUtils.tryCast(o, IProperty.class))
                      .filter(Objects::nonNull)
                      .forEach(allProperties::add);
            } else {
                Optional.ofNullable(nextRef.resolve())
                        .map(o -> ObjectUtils.tryCast(o, IProperty.class))
                        .ifPresent(allProperties::add);
            }
        }

        IProperty theChosenOne = chooseForLocale(allProperties);
        return new CachedValueProvider.Result<>(theChosenOne, PsiModificationTracker.MODIFICATION_COUNT);
    });
}
项目:hybris-integration-intellij-idea-plugin    文件:TSMetaModelAccessImpl.java   
@Override
public synchronized TSMetaModel getTypeSystemMeta(@Nullable final PsiFile contextFile) {
    if (contextFile == null || !TSMetaModelBuilder.isTsFile(contextFile)) {
        return myCachedValue.getValue();
    }
    final TSMetaModelImpl externalModel = doGetExternalModel(contextFile);
    final Project project = contextFile.getProject();
    CachedValue<TSMetaModelImpl> fileModelCache = contextFile.getUserData(FILE_MODEL_CACHE_KEY);

    if (fileModelCache == null) {
        fileModelCache = CachedValuesManager.getManager(project).createCachedValue(
            () -> ApplicationManager.getApplication().runReadAction(
                (Computable<CachedValueProvider.Result<TSMetaModelImpl>>) () -> {

                    final TSMetaModelBuilder builder = new TSMetaModelBuilder(project);
                    final TSMetaModelImpl modelForFile = builder.buildModelForFile(contextFile);
                    return CachedValueProvider.Result.create(modelForFile, contextFile);

                }), false);
        contextFile.putUserData(FILE_MODEL_CACHE_KEY, fileModelCache);
    }
    final TSMetaModelImpl fileModel = fileModelCache.getValue();
    return new TSMetaModelImpl(Arrays.asList(externalModel, fileModel));
}
项目:hybris-integration-intellij-idea-plugin    文件:TSMetaModelAccessImpl.java   
@NotNull
private TSMetaModelImpl doGetExternalModel(final @NotNull PsiFile contextFile) {
    final PsiFile originalFile = contextFile.getOriginalFile();
    final VirtualFile vFile = originalFile.getVirtualFile();
    final Project project = originalFile.getProject();
    CachedValue<TSMetaModelImpl> externalModelCache = originalFile.getUserData(EXTERNAL_MODEL_CACHE_KEY);

    if (externalModelCache == null) {

        externalModelCache = CachedValuesManager.getManager(project).createCachedValue(
            () -> ApplicationManager.getApplication().runReadAction(
                (Computable<CachedValueProvider.Result<TSMetaModelImpl>>) () -> {

                    final List<VirtualFile> excludes = vFile == null
                        ? Collections.emptyList()
                        : Collections.singletonList(vFile);

                    final TSMetaModelBuilder builder = new TSMetaModelBuilder(project, excludes);
                    final TSMetaModelImpl model = builder.buildModel();
                    return CachedValueProvider.Result.create(model, builder.getFiles());

                }), false);
        originalFile.putUserData(EXTERNAL_MODEL_CACHE_KEY, externalModelCache);
    }
    return externalModelCache.getValue();
}
项目:catberry-idea-plugin    文件:CatberryProjectConfigurationManager.java   
@Nullable
private String getCatberryVersion() {
  if (DumbService.isDumb(project))
    return null;

  final NotNullLazyValue<ModificationTracker> tracker = getCatberryTracker();
  return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<String>() {
    @Nullable
    @Override
    public Result<String> compute() {
      VirtualFile vf = project.getBaseDir().findChild("package.json");
      if (vf == null)
        return Result.create(null, tracker.getValue());
      final JsonFile file = (JsonFile) PsiManager.getInstance(project).findFile(vf);
      if (file == null || file.getTopLevelValue()==null)
        return Result.create(null, tracker.getValue());
      JsonValue value = JsonPsiUtil.findPropertyValue(file.getTopLevelValue(), "dependencies/catberry");
      if (value != null)
        return Result.create(value.getText(), file);
      return Result.create(null, tracker.getValue());
    }
  });
}
项目:catberry-idea-plugin    文件:CatberryProjectConfigurationManager.java   
@NotNull
public PsiDirectory[] getComponentsDirectories() {
  if (DumbService.isDumb(project))
    return new PsiDirectory[0];

  final NotNullLazyValue<ModificationTracker> tracker = getCatberryTracker();
  ComponentsDirectoriesProvider provider = new ComponentsDirectoriesProvider(project, tracker);
  String[] res = CachedValuesManager.getManager(project).getCachedValue(project, provider);

  List<PsiDirectory> result = new ArrayList<PsiDirectory>(res.length);
  for(String path : res) {
    VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(path);
    if(virtualFile == null)
      continue;
    PsiManager manager = PsiManager.getInstance(project);
    PsiDirectory dir = manager.findDirectory(virtualFile);
    if(dir != null)
      result.add(dir);
  }
  return result.toArray(new PsiDirectory[result.size()]);
}
项目:intellij-ce-playground    文件:JavaConstantExpressionEvaluator.java   
private JavaConstantExpressionEvaluator(Set<PsiVariable> visitedVars,
                                        final boolean throwExceptionOnOverflow,
                                        @NotNull Project project,
                                        final PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) {
  myMapFactory = auxEvaluator == null ? new Factory<ConcurrentMap<PsiElement, Object>>() {
    @Override
    public ConcurrentMap<PsiElement, Object> create() {
      final Key<CachedValue<ConcurrentMap<PsiElement, Object>>> key =
        throwExceptionOnOverflow ? CONSTANT_VALUE_WITH_OVERFLOW_MAP_KEY : CONSTANT_VALUE_WO_OVERFLOW_MAP_KEY;
      return CachedValuesManager.getManager(myProject).getCachedValue(myProject, key, PROVIDER, false);
    }
  } : new Factory<ConcurrentMap<PsiElement, Object>>() {
    @Override
    public ConcurrentMap<PsiElement, Object> create() {
      return auxEvaluator.getCacheMap(throwExceptionOnOverflow);
    }
  };
  myProject = project;
  myConstantExpressionVisitor = new ConstantExpressionVisitor(visitedVars, throwExceptionOnOverflow, auxEvaluator);
}
项目:intellij-ce-playground    文件:PsiDisjunctionType.java   
public PsiDisjunctionType(@NotNull List<PsiType> types, @NotNull PsiManager psiManager) {
  super(PsiAnnotation.EMPTY_ARRAY);

  myManager = psiManager;
  myTypes = Collections.unmodifiableList(types);

  myLubCache = CachedValuesManager.getManager(myManager.getProject()).createCachedValue(new CachedValueProvider<PsiType>() {
    @Override
    public Result<PsiType> compute() {
      PsiType lub = myTypes.get(0);
      for (int i = 1; i < myTypes.size(); i++) {
        lub = GenericsUtil.getLeastUpperBound(lub, myTypes.get(i), myManager);
        if (lub == null) {
          lub = PsiType.getJavaLangObject(myManager, GlobalSearchScope.allScope(myManager.getProject()));
          break;
        }
      }
      return Result.create(lub, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
    }
  }, false);
}
项目:intellij-ce-playground    文件:ContractInference.java   
@NotNull
public static List<MethodContract> inferContracts(@NotNull final PsiMethod method) {
  if (!InferenceFromSourceUtil.shouldInferFromSource(method)) {
    return Collections.emptyList();
  }

  return CachedValuesManager.getCachedValue(method, new CachedValueProvider<List<MethodContract>>() {
    @Nullable
    @Override
    public Result<List<MethodContract>> compute() {
      List<MethodContract> result = RecursionManager.doPreventingRecursion(method, true, new Computable<List<MethodContract>>() {
        @Override
        public List<MethodContract> compute() {
          return new ContractInferenceInterpreter(method).inferContracts();
        }
      });
      if (result == null) result = Collections.emptyList();
      return Result.create(result, method, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    }
  });
}
项目:intellij-ce-playground    文件:NullityInference.java   
public static Nullness inferNullity(final PsiMethod method) {
  if (!InferenceFromSourceUtil.shouldInferFromSource(method)) {
    return Nullness.UNKNOWN;
  }

  PsiType type = method.getReturnType();
  if (type == null || type instanceof PsiPrimitiveType) {
    return Nullness.UNKNOWN;
  }

  return CachedValuesManager.getCachedValue(method, new CachedValueProvider<Nullness>() {
    @Nullable
    @Override
    public Result<Nullness> compute() {
      Nullness result = RecursionManager.doPreventingRecursion(method, true, new Computable<Nullness>() {
        @Override
        public Nullness compute() {
          return doInferNullity(method);
        }
      });
      if (result == null) result = Nullness.UNKNOWN;
      return Result.create(result, method, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    }
  });
}
项目:intellij-ce-playground    文件:PurityInference.java   
public static boolean inferPurity(@NotNull final PsiMethod method) {
  if (!InferenceFromSourceUtil.shouldInferFromSource(method) ||
      method.getReturnType() == PsiType.VOID ||
      method.getBody() == null ||
      method.isConstructor() || 
      PropertyUtil.isSimpleGetter(method)) {
    return false;
  }

  return CachedValuesManager.getCachedValue(method, new CachedValueProvider<Boolean>() {
    @Nullable
    @Override
    public Result<Boolean> compute() {
      boolean pure = RecursionManager.doPreventingRecursion(method, true, new Computable<Boolean>() {
        @Override
        public Boolean compute() {
          return doInferPurity(method);
        }
      }) == Boolean.TRUE;
      return Result.create(pure, method);
    }
  });
}
项目:intellij-ce-playground    文件:ArtifactBySourceFileFinderImpl.java   
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(ArtifactManager.getInstance(myProject).getModificationTracker());
          for (ComplexPackagingElementType<?> type : PackagingElementFactory.getInstance().getComplexElementTypes()) {
            ContainerUtil.addIfNotNull(type.getAllSubstitutionsModificationTracker(myProject), trackers);
          }
          return Result.create(result, trackers.toArray(new ModificationTracker[trackers.size()]));
        }
      }, false);
  }
  return myFile2Artifacts;
}
项目:intellij-ce-playground    文件:ModuleWithDependentsScope.java   
private static ModuleIndex getModuleIndex(final Project project) {
  return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<ModuleIndex>() {
      @Nullable
      @Override
      public Result<ModuleIndex> compute() {
        ModuleIndex index = new ModuleIndex();
        for (Module module : ModuleManager.getInstance(project).getModules()) {
          for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) {
            if (orderEntry instanceof ModuleOrderEntry) {
              Module referenced = ((ModuleOrderEntry)orderEntry).getModule();
              if (referenced != null) {
                MultiMap<Module, Module> map = ((ModuleOrderEntry)orderEntry).isExported() ? index.exportingUsages : index.plainUsages;
                map.putValue(referenced, module);
              }
            }
          }
        }
        return Result.create(index, ProjectRootManager.getInstance(project));
      }
    });
}
项目:intellij-ce-playground    文件:ArbitraryPlaceUrlReferenceProvider.java   
@Override
protected CachedValue<PsiReference[]> compute(final PsiElement element, Object p) {
  return CachedValuesManager.getManager(element.getProject()).createCachedValue(new CachedValueProvider<PsiReference[]>() {
    public Result<PsiReference[]> compute() {
      IssueNavigationConfiguration navigationConfiguration = IssueNavigationConfiguration.getInstance(element.getProject());
      if (navigationConfiguration == null) {
        return 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<PsiReference>();
        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 Result<PsiReference[]>(references, element, navigationConfiguration);
    }
  }, false);
}
项目:intellij-ce-playground    文件:DomElementAnnotationsManagerImpl.java   
private DomElementsProblemsHolderImpl _getOrCreateProblemsHolder(final DomFileElement element) {
  DomElementsProblemsHolderImpl holder;
  final DomElement rootElement = element.getRootElement();
  final XmlTag rootTag = rootElement.getXmlTag();
  if (rootTag == null) return new DomElementsProblemsHolderImpl(element);

  holder = rootTag.getUserData(DOM_PROBLEM_HOLDER_KEY);
  if (isHolderOutdated(element.getFile()) || holder == null) {
    holder = new DomElementsProblemsHolderImpl(element);
    rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder);
    final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Boolean>() {
      @Override
      public Result<Boolean> compute() {
        return new Result<Boolean>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, DomElementAnnotationsManagerImpl.this, ProjectRootManager.getInstance(myProject));
      }
    }, false);
    cachedValue.getValue();
    element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue);
  }
  return holder;
}
项目:intellij-ce-playground    文件:GetInvocation.java   
@Override
public Object invoke(final DomInvocationHandler<?, ?> handler, final Object[] args) throws Throwable {
  if (myConverter == Converter.EMPTY_CONVERTER) {
    return getValueInner(handler, myConverter);
  }

  CachedValue<List<Pair<Converter,Object>>> value = handler.getUserData(DOM_VALUE_KEY);
  if (value == null) {
    final DomManagerImpl domManager = handler.getManager();
    final Project project = domManager.getProject();
    final CachedValuesManager cachedValuesManager = CachedValuesManager.getManager(project);
    handler.putUserData(DOM_VALUE_KEY, value = cachedValuesManager.createCachedValue(new CachedValueProvider<List<Pair<Converter,Object>>>() {
      @Override
      public Result<List<Pair<Converter,Object>>> compute() {
        List<Pair<Converter, Object>> list = ContainerUtil.createLockFreeCopyOnWriteList();
        return Result
          .create(list, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, domManager, ProjectRootManager.getInstance(project));
      }
    }, false));
  }

  return getOrCalcValue(handler, value.getValue());
}
项目:intellij-ce-playground    文件:DomModelCache.java   
@Nullable
public T getCachedValue(final @NotNull H dataHolder) {
  CachedValue<T> cachedValue = dataHolder.getUserData(myKey);
  if (cachedValue == null) {
    final CachedValueProvider<T> myProvider = new CachedValueProvider<T>() {
      @Override
      @Nullable
      public Result<T> compute() {
        return computeValue(dataHolder);
      }
    };
    final CachedValuesManager manager = CachedValuesManager.getManager(myProject);
    cachedValue = manager.createCachedValue(myProvider, false);
    dataHolder.putUserData(myKey, cachedValue);
  }
  return cachedValue.getValue();
}
项目:intellij-ce-playground    文件:XmlPsiUtil.java   
private static PsiElement parseEntityDecl(final XmlEntityDecl entityDecl,
                                          final PsiFile targetFile,
                                          final XmlEntityDecl.EntityContextType type,
                                          final XmlEntityRef entityRef) {
  CachedValue<PsiElement> value;
  synchronized (PsiLock.LOCK) { // we depend on targetFile and entityRef
    value = entityRef.getUserData(PARSED_DECL_KEY);
    //    return entityDecl.parse(targetFile, type);

    if (value == null) {
      value = CachedValuesManager.getManager(entityDecl.getProject()).createCachedValue(new CachedValueProvider<PsiElement>() {
        @Override
        public Result<PsiElement> compute() {
          final PsiElement res = entityDecl.parse(targetFile, type, entityRef);
          if (res == null) return new Result<PsiElement>(res, targetFile);
          if (!entityDecl.isInternalReference()) XmlEntityCache.copyEntityCaches(res.getContainingFile(), targetFile);
          return new Result<PsiElement>(res, res.getUserData(XmlElement.DEPENDING_ELEMENT), entityDecl, targetFile, entityRef);
        }
      }, false);
      entityRef.putUserData(PARSED_DECL_KEY, value);
    }
  }

  return value.getValue();
}
项目:intellij-ce-playground    文件:XmlNSDescriptorImpl.java   
private CachedValue<TypeDescriptor> createAndPutTypesCachedValue(final XmlTag tag, final Pair<QNameKey, XmlTag> pair) {
  final CachedValue<TypeDescriptor> value = CachedValuesManager.getManager(tag.getProject()).createCachedValue(
    new CachedValueProvider<TypeDescriptor>() {
      @Override
      public CachedValueProvider.Result<TypeDescriptor> compute() {
        final String name = tag.getAttributeValue("name");

        if (name != null &&
            pair.first != null &&
            pair.first.first != null &&
            !name.equals(XmlUtil.findLocalNameByQualifiedName(pair.first.first))
          ) {
          myTypesMap.remove(pair);
          return new Result<TypeDescriptor>(null, PsiModificationTracker.MODIFICATION_COUNT);
        }
        final ComplexTypeDescriptor complexTypeDescriptor = new ComplexTypeDescriptor(XmlNSDescriptorImpl.this, tag);
        return new Result<TypeDescriptor>(complexTypeDescriptor, tag);
      }
    }, false);
  myTypesMap.put(pair, value);
  return value;
}
项目:intellij-ce-playground    文件:XmlEntityCache.java   
public static void cacheParticularEntity(PsiFile file, XmlEntityDecl decl) {
  synchronized(PsiLock.LOCK) {
    final Map<String, CachedValue<XmlEntityDecl>> cachingMap = getCachingMap(file);
    final String name = decl.getName();
    if (cachingMap.containsKey(name)) return;
    final SmartPsiElementPointer declPointer = SmartPointerManager.getInstance(file.getProject()).createSmartPsiElementPointer(decl);

    cachingMap.put(
      name, CachedValuesManager.getManager(file.getProject()).createCachedValue(new CachedValueProvider<XmlEntityDecl>() {
        @Override
        public Result<XmlEntityDecl> compute() {
          PsiElement declElement = declPointer.getElement();
          if (declElement instanceof XmlEntityDecl && declElement.isValid() && name.equals(((XmlEntityDecl)declElement).getName()))
            return new Result<XmlEntityDecl>((XmlEntityDecl)declElement, declElement);
          cachingMap.put(name,null);
          return new Result<XmlEntityDecl>(null, ModificationTracker.NEVER_CHANGED);
        }
      },
      false
    ));
  }
}
项目:intellij-ce-playground    文件:AndroidFacet.java   
@NotNull
public Map<String, PsiClass> getClassMap(@NotNull final String className, @NotNull final ClassMapConstructor constructor) {
  synchronized (myClassMapLock) {
    CachedValue<Map<String, PsiClass>> value = myClassMaps.get(className);

    if (value == null) {
      value = CachedValuesManager.getManager(getModule().getProject()).createCachedValue(
        new CachedValueProvider<Map<String, PsiClass>>() {
        @Nullable
        @Override
        public Result<Map<String, PsiClass>> compute() {
          Map<String, PsiClass> map = computeClassMap(className, constructor);
          return Result.create(map, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
        }
      }, false);
      myClassMaps.put(className, value);
    }
    return value.getValue();
  }
}
项目:intellij-ce-playground    文件:DataBindingProjectComponent.java   
public DataBindingProjectComponent(final Project project) {
  myProject = project;
  myDataBindingEnabledModules = CachedValuesManager.getManager(project).createCachedValue(new CachedValueProvider<AndroidFacet[]>() {
    @Nullable
    @Override
    public Result<AndroidFacet[]> compute() {
      Module[] modules = ModuleManager.getInstance(myProject).getModules();
      List<AndroidFacet> facets = new ArrayList<AndroidFacet>();
      for (Module module : modules) {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet == null) {
          continue;
        }
        if (facet.isDataBindingEnabled()) {
          facets.add(facet);
        }
      }
      myModificationCount.incrementAndGet();
      return Result.create(facets.toArray(new AndroidFacet[facets.size()]), DataBindingUtil.DATA_BINDING_ENABLED_TRACKER, ModuleManager.getInstance(project));
    }
  }, false);
}
项目:intellij-ce-playground    文件:BrShortNamesCache.java   
public BrShortNamesCache(DataBindingProjectComponent dataBindingProjectComponent) {
  myComponent = dataBindingProjectComponent;
  myAllFieldNamesCache = CachedValuesManager.getManager(myComponent.getProject()).createCachedValue(new CachedValueProvider<String[]>() {
    @Nullable
    @Override
    public Result<String[]> compute() {
      AndroidFacet[] facets = myComponent.getDataBindingEnabledFacets();
      String[] result;
      if (facets.length == 0) {
        result = ArrayUtil.EMPTY_STRING_ARRAY;
      } else {
        Set<String> allFields = Sets.newHashSet();
        for (AndroidFacet facet : facets) {
          DataBindingUtil.LightBrClass brClass = DataBindingUtil.getOrCreateBrClassFor(facet);
          Collections.addAll(allFields, brClass.getAllFieldNames());
        }
        result = ArrayUtil.toStringArray(allFields);
      }
      return Result.create(result, myComponent);
    }
  }, false);
}
项目:intellij-ce-playground    文件:BrClassFinder.java   
public BrClassFinder(DataBindingProjectComponent component) {
  myComponent = component;
  myClassByPackageCache = CachedValuesManager.getManager(component.getProject()).createCachedValue(
    new CachedValueProvider<Map<String, PsiClass>>() {
      @Nullable
      @Override
      public Result<Map<String, PsiClass>> compute() {
        Map<String, PsiClass> classes = new HashMap<String, PsiClass>();
        for (AndroidFacet facet : myComponent.getDataBindingEnabledFacets()) {
          if (facet.isDataBindingEnabled()) {
            classes.put(DataBindingUtil.getBrQualifiedName(facet), DataBindingUtil.getOrCreateBrClassFor(facet));
          }
        }
        return Result.create(classes, myComponent);
      }
    }, false);
}
项目:intellij-ce-playground    文件:SettingsProviderComponent.java   
public Set<String> getRootDirs(final Project project) {
  if (!Registry.is("editor.config.stop.at.project.root")) {
    return Collections.emptySet();
  }

  return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Set<String>>() {
    @Nullable
    @Override
    public Result<Set<String>> compute() {
      final Set<String> dirs = new HashSet<String>();
      final VirtualFile projectBase = project.getBaseDir();
      if (projectBase != null) {
        dirs.add(project.getBasePath());
        for (Module module : ModuleManager.getInstance(project).getModules()) {
          for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
            if (!VfsUtilCore.isAncestor(projectBase, root, false)) {
              dirs.add(root.getPath());
            }
          }
        }
      }
      dirs.add(PathManager.getConfigPath());
      return new Result<Set<String>>(dirs, ProjectRootModificationTracker.getInstance(project));
    }
  });
}
项目:intellij-ce-playground    文件:GroovyScriptClass.java   
@Override
@NotNull
public PsiMethod[] getMethods() {
  return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiMethod[]>() {
    @Nullable
    @Override
    public Result<PsiMethod[]> compute() {
      if (!myInitialized) {
        initMethods();
      }

      PsiMethod[] methods = myFile.getMethods();

      int addMain = hasMain(methods) ? 0 : 1;
      int addRun = hasRun(methods) ? 0 : 1;

      PsiMethod[] result = initMethods(methods, addMain, addRun);
      return Result.create(result, myFile);
    }
  });
}
项目:intellij-ce-playground    文件:GrGdkMethodImpl.java   
@NotNull
public static GrGdkMethod createGdkMethod(@NotNull final PsiMethod original,
                                          final boolean isStatic,
                                          @Nullable final String originInfo) {
  final Key<CachedValue<GrGdkMethodImpl>> cachedValueKey = isStatic ? CACHED_STATIC : CACHED_NON_STATIC;
  CachedValue<GrGdkMethodImpl> cachedValue = original.getUserData(cachedValueKey);
  if (cachedValue == null) {
    cachedValue = CachedValuesManager.getManager(original.getProject()).createCachedValue(new CachedValueProvider<GrGdkMethodImpl>() {
      @Override
      public Result<GrGdkMethodImpl> compute() {
        return Result.create(new GrGdkMethodImpl(original, isStatic, originInfo),
                             PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
      }
    });
    original.putUserData(cachedValueKey, cachedValue);
  }

  return cachedValue.getValue();
}
项目:intellij-ce-playground    文件:ControlFlowUtils.java   
public static Set<GrExpression> getAllReturnValues(@NotNull final GrControlFlowOwner block) {
  return CachedValuesManager.getCachedValue(block, new CachedValueProvider<Set<GrExpression>>() {
    @Override
    public Result<Set<GrExpression>> compute() {
      final Set<GrExpression> result = new HashSet<GrExpression>();
      visitAllExitPoints(block, new ExitPointVisitor() {
        @Override
        public boolean visitExitPoint(Instruction instruction, @Nullable GrExpression returnValue) {
          ContainerUtil.addIfNotNull(result, returnValue);
          return true;
        }
      });
      return Result.create(result, block);
    }
  });
}
项目:intellij-spring-assistant    文件:PsiUtil.java   
@NotNull
public static Map<String, PsiMember> findWritableProperties(@Nullable PsiClass psiClass) {
  if (psiClass != null) {
    return CachedValuesManager.getCachedValue(psiClass, () -> CachedValueProvider.Result
        .create(prepareWritableProperties(psiClass), JAVA_STRUCTURE_MODIFICATION_COUNT));
  }
  return Collections.emptyMap();
}
项目:intellij-spring-assistant    文件:PsiUtil.java   
@Nullable
public static PsiType getWrappedPropertyType(final PsiField field) {
  return CachedValuesManager.getCachedValue(field, () -> {
    final PsiType fieldType = field.getType();
    final PsiClassType.ClassResolveResult resolveResult =
        com.intellij.psi.util.PsiUtil.resolveGenericsClassInType(fieldType);
    final PsiClass fieldClass = resolveResult.getElement();
    if (fieldClass == null) {
      final PsiType propertyType = eraseFreeTypeParameters(fieldType, field);
      return CachedValueProvider.Result.create(propertyType, JAVA_STRUCTURE_MODIFICATION_COUNT);
    }
    return CachedValueProvider.Result.create(null, JAVA_STRUCTURE_MODIFICATION_COUNT);
  });
}
项目:intellij-spring-assistant    文件:PsiUtil.java   
@Nullable
private static PsiType getSetterArgumentType(@NotNull PsiMethod method) {
  return CachedValuesManager.getCachedValue(method, () -> {
    final PsiParameter[] parameters = method.getParameterList().getParameters();
    if (!method.hasModifierProperty(STATIC) && parameters.length == 1) {
      final PsiType argumentType = eraseFreeTypeParameters(parameters[0].getType(), method);
      return CachedValueProvider.Result.create(argumentType, JAVA_STRUCTURE_MODIFICATION_COUNT);
    }
    return CachedValueProvider.Result.create(null, JAVA_STRUCTURE_MODIFICATION_COUNT);
  });
}
项目:hybris-integration-intellij-idea-plugin    文件:TSMetaModelAccessImpl.java   
public TSMetaModelAccessImpl(@NotNull final Project project) {
    myCachedValue = CachedValuesManager.getManager(project).createCachedValue(
        () -> ApplicationManager.getApplication().runReadAction(
            (Computable<CachedValueProvider.Result<TSMetaModel>>) () -> {

                final TSMetaModelBuilder builder = new TSMetaModelBuilder(project);
                final TSMetaModelImpl model = builder.buildModel();
                return CachedValueProvider.Result.create(model, builder.getFiles());

            }), false);
}
项目:mule-intellij-plugins    文件:WeaveEditor.java   
protected void runPreview(boolean forceRefresh) {
    if (!isAutoSync() && !forceRefresh)
        return;

    final Map<String, Object> payload = new HashMap<String, Object>();
    Map<String, Map<String, Object>> flowVars = new HashMap<String, Map<String, Object>>();
    /*
    1. Get input from tabs - if payload exists, use payload, otherwise put in the Map
    2. Get text from DW
    3. Run preview, put the output to the output tab
     */

    int count = inputTabs.getTabCount();
    for (int index = 0; index < count; index++) {
        String title = inputTabs.getTitleAt(index);
        Editor editor = editors.get(title);
        Document document = editor.getDocument();
        String text = document.getText();
        String contentType = contentTypes.get(title);
        Map<String, Object> content = WeavePreview.createContent(contentType, text);
        if ("payload".equalsIgnoreCase(title)) {
            payload.clear();
            payload.putAll(content);
        } else {
            flowVars.put(title, content);
        }
    }

    final CachedValuesManager manager = CachedValuesManager.getManager(project);
    List<String> melFunctions = manager.getCachedValue(psiFile, MEL_STRINGS_KEY, new MelStringsCachedProvider());

    String dwScript = this.textEditor.getEditor().getDocument().getText();

    String output = WeavePreview.runPreview(module, dwScript, payload, flowVars, flowVars, flowVars, flowVars, flowVars, melFunctions);
    if (output != null)
        editors.get("output").getDocument().setText(output);
}
项目:cup-plugin    文件:CupPsiImplUtil.java   
private static boolean processSymbolsVariants(PsiElement context, Processor<CupSymbolDefinition> processor) {
    final PsiFile file = context.getContainingFile();
    List<CupSymbolDefinition> symbols = CachedValuesManager.getCachedValue(
            file, new CachedValueProvider<List<CupSymbolDefinition>>() {
                @Nullable
                @Override
                public Result<List<CupSymbolDefinition>> compute() {
                    return Result.create(computeDefinitions(file, CupSymbolDefinition.class), file);
                }
            }
    );
    return ContainerUtil.process(symbols, processor);
}
项目:intellij-ce-playground    文件:GrFieldImpl.java   
@Override
@NotNull
public GrAccessorMethod[] getGetters() {
  return CachedValuesManager.getCachedValue(this, new CachedValueProvider<GrAccessorMethod[]>() {
    @Nullable
    @Override
    public Result<GrAccessorMethod[]> compute() {
      return Result.create(GrAccessorMethodImpl.createGetterMethods(GrFieldImpl.this), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
    }
  });
}
项目:catberry-idea-plugin    文件:CatberryProjectConfigurationManager.java   
@Nullable
public PsiDirectory getStoresDirectory() {
  if (DumbService.isDumb(project))
    return null;
  final NotNullLazyValue<ModificationTracker> tracker = getCatberryTracker();
  StoresDirectoryProvider provider = new StoresDirectoryProvider(project, tracker);
  String res = CachedValuesManager.getManager(project).getCachedValue(project, provider);
  VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(res);
  if(virtualFile == null)
    return null;
  PsiManager manager = PsiManager.getInstance(project);
  return manager.findDirectory(virtualFile);
}
项目: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-ce-playground    文件:ClsParameterImpl.java   
@Override
public String getName() {
  return CachedValuesManager.getCachedValue(this, new CachedValueProvider<String>() {
    @Nullable
    @Override
    public Result<String> compute() {
      return Result.create(calcName(), 
                           getContainingFile(),
                           getContainingFile().getNavigationElement(),
                           FileIndexFacade.getInstance(getProject()).getRootModificationTracker(),
                           DumbService.getInstance(getProject()).getModificationTracker());
    }
  });
}
项目:intellij-ce-playground    文件:ClassInnerStuffCache.java   
@NotNull
public PsiMethod[] getConstructors() {
  return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiMethod[]>() {
    @Nullable
    @Override
    public Result<PsiMethod[]> compute() {
      return Result.create(PsiImplUtil.getConstructors(myClass), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
    }
  });
}
项目:intellij-ce-playground    文件:ClassInnerStuffCache.java   
@NotNull
public PsiField[] getFields() {
  return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiField[]>() {
    @Nullable
    @Override
    public Result<PsiField[]> compute() {
      return Result.create(getAllFields(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
    }
  });
}
项目:intellij-ce-playground    文件:ClassInnerStuffCache.java   
@NotNull
public PsiMethod[] getMethods() {
  return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiMethod[]>() {
    @Nullable
    @Override
    public Result<PsiMethod[]> compute() {
      return Result.create(getAllMethods(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
    }
  });
}