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

项目: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();
}
项目: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    文件: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    文件:FacetFinderImpl.java   
private <F extends Facet & FacetRootsProvider> Map<VirtualFile, List<Facet>> getRootToFacetsMap(final FacetTypeId<F> type) {
  CachedValue<Map<VirtualFile, List<Facet>>> cachedValue = myCachedMaps.get(type);
  if (cachedValue == null) {
    cachedValue = myCachedValuesManager.createCachedValue(new CachedValueProvider<Map<VirtualFile, List<Facet>>>() {
      @Override
      public Result<Map<VirtualFile, List<Facet>>> compute() {
        Map<VirtualFile, List<Facet>> map = computeRootToFacetsMap(type);
        return Result.create(map, getAllFacetsOfTypeModificationTracker(type));
      }
    }, false);
    myCachedMaps.put(type, cachedValue);
  }
  final Map<VirtualFile, List<Facet>> value = cachedValue.getValue();
  LOG.assertTrue(value != null);
  return value;
}
项目: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    文件:ProjectResourceCachedValueProvider.java   
@Nullable
@Override
public final Result<T> compute() {
  AndroidFacet[] facets = myComponent.getDataBindingEnabledFacets();
  List<V> values = Lists.newArrayList();

  List<ModificationTracker> newDependencies = Lists.newArrayList();
  newDependencies.add(myComponent);
  Collections.addAll(newDependencies, myAdditionalTrackers);
  for (AndroidFacet facet : facets) {
    CachedValue<V> cachedValue = getCachedValue(facet);
    // we know this for sure since it is created from createCacheProvider
    if (cachedValue.getValueProvider() instanceof ModificationTracker) {
      newDependencies.add((ModificationTracker)cachedValue.getValueProvider());
    }
    V result = cachedValue.getValue();
    if (result != null) {
      values.add(result);
    }
  }
  myDependencyModificationCountOnCompute = calculateModificationCountFrom(newDependencies);
  myDependencies = newDependencies;
  return Result.create(merge(values), this);
}
项目: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();
}
项目:idea-php-shopware-plugin    文件:ServiceCollector.java   
@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());
}
项目:idea-php-shopware-plugin    文件:SubscriberIndexUtil.java   
@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();
}
项目:idea-php-drupal-symfony2-bridge    文件:GlobalNamespaceLoader.java   
@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();
}
项目:tools-idea    文件:JavaConstantExpressionEvaluator.java   
private JavaConstantExpressionEvaluator(Set<PsiVariable> visitedVars, final boolean throwExceptionOnOverflow, final Project project, final PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) {
  myMapFactory = auxEvaluator != null ? new Factory<ConcurrentMap<PsiElement, Object>>() {
    @Override
    public ConcurrentMap<PsiElement, Object> create() {
      return auxEvaluator.getCacheMap(throwExceptionOnOverflow);
    }
  } : 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);
    }
  };
  myProject = project;
  myConstantExpressionVisitor = new ConstantExpressionVisitor(visitedVars, throwExceptionOnOverflow, auxEvaluator);

}
项目:tools-idea    文件:ClassInnerStuffCache.java   
@NotNull
public PsiMethod[] getConstructors() {
  CachedValue<PsiMethod[]> cache = myConstructorsCache;
  if (cache == null) {
    final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject());
    final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker};

    myConstructorsCache = cache = manager.createCachedValue(new CachedValueProvider<PsiMethod[]>() {
      @Override
      public Result<PsiMethod[]> compute() {
        return Result.create(PsiImplUtil.getConstructors(myClass), dependencies);
      }
    }, false);
  }

  final PsiMethod[] constructors = cache.getValue();
  return constructors != null ? constructors : PsiMethod.EMPTY_ARRAY;
}
项目:tools-idea    文件:ClassInnerStuffCache.java   
@NotNull
public PsiField[] getFields() {
  CachedValue<PsiField[]> cache = myFieldsCache;
  if (cache == null) {
    final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject());
    final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker};

    myFieldsCache = cache = manager.createCachedValue(new CachedValueProvider<PsiField[]>() {
      @Override
      public Result<PsiField[]> compute() {
        return Result.create(getAllFields(), dependencies);
      }
    }, false);
  }
  final PsiField[] fields = cache.getValue();
  return fields != null ? fields : PsiField.EMPTY_ARRAY;
}
项目:tools-idea    文件:ClassInnerStuffCache.java   
@NotNull
public PsiMethod[] getMethods() {
  CachedValue<PsiMethod[]> cache = myMethodsCache;
  if (cache == null) {
    final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject());
    final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker};

    myMethodsCache = cache = manager.createCachedValue(new CachedValueProvider<PsiMethod[]>() {
      @Override
      public Result<PsiMethod[]> compute() {
        return Result.create(getAllMethods(), dependencies);
      }
    }, false);
  }
  final PsiMethod[] methods = cache.getValue();
  return methods != null ? methods : PsiMethod.EMPTY_ARRAY;
}
项目:tools-idea    文件:ClassInnerStuffCache.java   
@NotNull
public PsiClass[] getInnerClasses() {
  CachedValue<PsiClass[]> cache = myInnerClassesCache;
  if (cache == null) {
    final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject());
    final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker};

    myInnerClassesCache = cache = manager.createCachedValue(new CachedValueProvider<PsiClass[]>() {
      @Override
      public Result<PsiClass[]> compute() {
        return Result.create(getAllInnerClasses(), dependencies);
      }
    }, false);
  }
  final PsiClass[] classes = cache.getValue();
  return classes != null ? classes : PsiClass.EMPTY_ARRAY;
}
项目:tools-idea    文件:ClassInnerStuffCache.java   
@Nullable
public PsiField findFieldByName(final String name, final boolean checkBases) {
  if (!checkBases) {
    CachedValue<Map<String, PsiField>> cache = myFieldsMapCache;
    if (cache == null) {
      final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject());
      final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker};

      myFieldsMapCache = cache = manager.createCachedValue(new CachedValueProvider<Map<String, PsiField>>() {
        @Override
        public Result<Map<String, PsiField>> compute() {
          return Result.create(getFieldsMap(), dependencies);
        }
      }, false);
    }
    final Map<String, PsiField> cachedFields = cache.getValue();
    return cachedFields != null ? cachedFields.get(name) : null;
  }
  return PsiClassImplUtil.findFieldByName(myClass, name, checkBases);
}
项目:tools-idea    文件:ClassInnerStuffCache.java   
@NotNull
public PsiMethod[] findMethodsByName(final String name, final boolean checkBases) {
  if (!checkBases) {
    CachedValue<Map<String, List<PsiMethod>>> cache = myMethodsMapCache;
    if (cache == null) {
      final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject());
      final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker};

      myMethodsMapCache = cache = manager.createCachedValue(new CachedValueProvider<Map<String, List<PsiMethod>>>() {
        @Override
        public Result<Map<String, List<PsiMethod>>> compute() {
          return Result.create(getMethodsMap(), dependencies);
        }
      }, false);
    }
    final Map<String, List<PsiMethod>> cachedMethods = cache.getValue();
    if (cachedMethods != null) {
      final List<PsiMethod> methods = cachedMethods.get(name);
      if (methods != null && !methods.isEmpty()) {
        return methods.toArray(new PsiMethod[methods.size()]);
      }
    }
    return PsiMethod.EMPTY_ARRAY;
  }
  return PsiClassImplUtil.findMethodsByName(myClass, name, checkBases);
}
项目:tools-idea    文件:ClassInnerStuffCache.java   
@Nullable
public PsiClass findInnerClassByName(final String name, final boolean checkBases) {
  if (!checkBases) {
    CachedValue<Map<String, PsiClass>> cache = myInnerClassesMapCache;
    if (cache == null) {
      final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject());
      final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker};

      myInnerClassesMapCache = cache = manager.createCachedValue(new CachedValueProvider<Map<String, PsiClass>>() {
        @Override
        public Result<Map<String, PsiClass>> compute() {
          return Result.create(getInnerClassesMap(), dependencies);
        }
      }, false);
    }

    final Map<String, PsiClass> inners = cache.getValue();
    return inners != null ? inners.get(name) : null;
  }
  return PsiClassImplUtil.findInnerByName(myClass, name, checkBases);
}
项目:tools-idea    文件: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;
}
项目:tools-idea    文件:FacetFinderImpl.java   
private <F extends Facet & FacetRootsProvider> Map<VirtualFile, List<Facet>> getRootToFacetsMap(final FacetTypeId<F> type) {
  CachedValue<Map<VirtualFile, List<Facet>>> cachedValue = myCachedMaps.get(type);
  if (cachedValue == null) {
    cachedValue = myCachedValuesManager.createCachedValue(new CachedValueProvider<Map<VirtualFile, List<Facet>>>() {
      @Override
      public Result<Map<VirtualFile, List<Facet>>> compute() {
        Map<VirtualFile, List<Facet>> map = computeRootToFacetsMap(type);
        return Result.create(map, getAllFacetsOfTypeModificationTracker(type));
      }
    }, false);
    myCachedMaps.put(type, cachedValue);
  }
  final Map<VirtualFile, List<Facet>> value = cachedValue.getValue();
  LOG.assertTrue(value != null);
  return value;
}
项目:tools-idea    文件: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, myModificationTracker, ProjectRootManager.getInstance(myProject));
      }
    }, false);
    cachedValue.getValue();
    element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue);
  }
  return holder;
}
项目:tools-idea    文件: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());
}
项目:tools-idea    文件: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>() {
      @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();
}
项目:tools-idea    文件:XmlPsiUtil.java   
private static PsiElement parseEntityDecl(final XmlEntityDecl entityDecl,
                                          final PsiFile targetFile,
                                          final XmlEntityDecl.EntityContextType type,
                                          final XmlEntityRef entityRef) {
  synchronized (PsiLock.LOCK) { // we depend on targetFile and entityRef
    CachedValue<PsiElement> value = entityRef.getUserData(PARSED_DECL_KEY);
    //    return entityDecl.parse(targetFile, type);

    if (value == null) {
      value = CachedValuesManager.getManager(entityDecl.getProject()).createCachedValue(new CachedValueProvider<PsiElement>() {
        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();
  }
}
项目:tools-idea    文件:XmlNSDescriptorImpl.java   
private CachedValue<Map<String, XmlElementDescriptor>> doBuildDeclarationMap() {
  return CachedValuesManager.getManager(myElement.getProject()).createCachedValue(new CachedValueProvider<Map<String, XmlElementDescriptor>>() {
    public Result<Map<String, XmlElementDescriptor>> compute() {
      final List<XmlElementDecl> result = new ArrayList<XmlElementDecl>();
      myElement.processElements(new FilterElementProcessor(new ClassFilter(XmlElementDecl.class), result), getDeclaration());
      final Map<String, XmlElementDescriptor> ret = new LinkedHashMap<String, XmlElementDescriptor>((int)(result.size() * 1.5));

      for (final XmlElementDecl xmlElementDecl : result) {
        final String name = xmlElementDecl.getName();
        if (name != null) {
          if (!ret.containsKey(name)) {
            ret.put(name, new XmlElementDescriptorImpl(xmlElementDecl));
          }
        }
      }
      return new Result<Map<String, XmlElementDescriptor>>(ret, myDescriptorFile);
     }
   }, false);
}
项目:tools-idea    文件: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>() {
    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);
      }
      final ComplexTypeDescriptor complexTypeDescriptor = new ComplexTypeDescriptor(XmlNSDescriptorImpl.this, tag); 
      return new Result<TypeDescriptor>(complexTypeDescriptor, tag);
    }
  }, false);
  myTypesMap.put(pair, value);
  return value;
}
项目:tools-idea    文件: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>() {
        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,null);
        }
      },
      false
    ));
  }
}
项目:tools-idea    文件:PatternEditorContextMembersProvider.java   
@Override
public void processDynamicElements(@NotNull PsiType qualifierType,
                                   PsiScopeProcessor processor,
                                   PsiElement place,
                                   ResolveState state) {
  final PsiFile file = place.getContainingFile().getOriginalFile();
  CachedValue<List<PsiElement>> value = file.getUserData(INJECTION_PARSED_CONTEXT);
  if (value == null) {
    final BaseInjection injection = file.getUserData(BaseInjection.INJECTION_KEY);
    final CachedValueProvider<List<PsiElement>> provider;
    if (injection == null) {
      provider = createDevProvider(file);
    }
    else {
      provider = createPatternProvider(injection, file);
    }
    if (provider == null) return;
    file.putUserData(INJECTION_PARSED_CONTEXT,
                     value = CachedValuesManager.getManager(file.getProject()).createCachedValue(provider, false));
  }
  final List<PsiElement> roots = value.getValue();
  for (PsiElement root : roots) {
    if (!root.processDeclarations(processor, state, null, place)) return;
  }
}
项目:tools-idea    文件: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), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
      }
    });
    original.putUserData(cachedValueKey, cachedValue);
  }

  return cachedValue.getValue();
}
项目:idea-php-symfony2-plugin    文件:DotEnvUtil.java   
@NotNull
public static Collection<String> getEnvironmentVariables(@NotNull Project project) {
    CachedValue<Set<String>> cache = project.getUserData(DOT_ENV_VARIABLE_CACHE);
    if (cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> {
            Set<String> items = new HashSet<>();

            DotEnvUtil.visitEnvironment(project, pair ->
                items.add(pair.getFirst())
            );

            return CachedValueProvider.Result.create(items, PsiModificationTracker.MODIFICATION_COUNT);
            }, false
        );
        project.putUserData(DOT_ENV_VARIABLE_CACHE, cache);
    }

    return cache.getValue();
}
项目:idea-php-symfony2-plugin    文件:JsonFileIndexTwigNamespaces.java   
@NotNull
@Override
public Collection<TwigPath> getNamespaces(final @NotNull TwigNamespaceExtensionParameter parameter) {

    CachedValue<Collection<TwigPath>> cache = parameter.getProject().getUserData(CACHE);
    if (cache == null) {
        cache = CachedValuesManager.getManager(parameter.getProject()).createCachedValue(() ->
            CachedValueProvider.Result.create(getNamespacesInner(parameter), PsiModificationTracker.MODIFICATION_COUNT),
            false
        );

        parameter.getProject().putUserData(CACHE, cache);
    }

    return cache.getValue();
}
项目:idea-php-symfony2-plugin    文件:FileIndexCaches.java   
/**
 * @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) {

    CachedValue<Map<String, List<T>>> cache = project.getUserData(dataHolderKey);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> {
            Map<String, List<T>> items = new HashMap<>();

            final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();

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

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

        project.putUserData(dataHolderKey, cache);
    }

    return cache.getValue();
}