@NotNull
 @Override
 public GrReflectedMethod[] getReflectedMethods() {
   return CachedValuesManager.getCachedValue(
       this,
       new CachedValueProvider<GrReflectedMethod[]>() {
         @Override
         public Result<GrReflectedMethod[]> compute() {
           return Result.create(
               GrReflectedMethodImpl.createReflectedMethods(GrMethodBaseImpl.this),
               PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
         }
       });
 }
 @NotNull
 private static ParameterizedCachedValue<MembersMap, PsiClass> getValues(
     @NotNull PsiClass aClass) {
   ParameterizedCachedValue<MembersMap, PsiClass> value = aClass.getUserData(MAP_IN_CLASS_KEY);
   if (value == null) {
     value =
         CachedValuesManager.getManager(aClass.getProject())
             .createParameterizedCachedValue(ByNameCachedValueProvider.INSTANCE, false);
     // Do not cache for nonphysical elements
     if (aClass.isPhysical()) {
       value = ((UserDataHolderEx) aClass).putUserDataIfAbsent(MAP_IN_CLASS_KEY, value);
     }
   }
   return value;
 }
 @NotNull
 @Override
 public List<PyAssignmentStatement> findAttributes() {
   /**
    * TODO: This method if insanely heavy since it unstubs foreign files. Need to save stubs and
    * use them somehow.
    */
   return CachedValuesManager.getManager(getProject())
       .getCachedValue(
           this,
           ATTRIBUTES_KEY,
           () -> {
             final List<PyAssignmentStatement> result = findAttributesStatic(this);
             return CachedValueProvider.Result.create(
                 result, PsiModificationTracker.MODIFICATION_COUNT);
           },
           false);
 }
Пример #4
0
  @NotNull
  public XmlTag[] getSubTags() {
    return CachedValuesManager.getManager(getProject())
        .getCachedValue(
            this,
            new CachedValueProvider<XmlTag[]>() {
              @Override
              public Result<XmlTag[]> compute() {
                final List<XmlTag> result = new ArrayList<XmlTag>();

                fillSubTags(result);

                final int s = result.size();
                XmlTag[] tags = s > 0 ? ContainerUtil.toArray(result, new XmlTag[s]) : EMPTY;
                return Result.create(
                    tags,
                    PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT,
                    getContainingFile());
              }
            });
  }
 @Nullable
 @Override
 public StructuredDocString getStructuredDocString() {
   return CachedValuesManager.getCachedValue(this, myCachedStructuredDocStringProvider);
 }
Пример #6
0
  private Map<String, CachedValue<XmlNSDescriptor>> initializeSchema(
      final String namespace,
      final String version,
      final String fileLocation,
      Map<String, CachedValue<XmlNSDescriptor>> map) {
    if (map == null) map = new THashMap<String, CachedValue<XmlNSDescriptor>>();

    // We put cached value in any case to cause its value update on e.g. mapping change
    map.put(
        namespace,
        CachedValuesManager.getManager(getManager().getProject())
            .createCachedValue(
                new CachedValueProvider<XmlNSDescriptor>() {
                  public Result<XmlNSDescriptor> compute() {
                    XmlNSDescriptor descriptor = getImplicitNamespaceDescriptor(fileLocation);
                    if (descriptor != null) {
                      return new Result<XmlNSDescriptor>(
                          descriptor,
                          ArrayUtil.append(descriptor.getDependences(), XmlTagImpl.this));
                    }

                    XmlFile currentFile = retrieveFile(fileLocation, version);
                    if (currentFile == null) {
                      final XmlDocument document =
                          XmlUtil.getContainingFile(XmlTagImpl.this).getDocument();
                      if (document != null) {
                        final String uri = XmlUtil.getDtdUri(document);
                        if (uri != null) {
                          final XmlFile containingFile = XmlUtil.getContainingFile(document);
                          final XmlFile xmlFile = XmlUtil.findNamespace(containingFile, uri);
                          descriptor =
                              xmlFile == null
                                  ? null
                                  : (XmlNSDescriptor) xmlFile.getDocument().getMetaData();
                        }

                        // We want to get fixed xmlns attr from dtd and check its default with
                        // requested namespace
                        if (descriptor instanceof XmlNSDescriptorImpl) {
                          final XmlElementDescriptor elementDescriptor =
                              descriptor.getElementDescriptor(XmlTagImpl.this);
                          if (elementDescriptor != null) {
                            final XmlAttributeDescriptor attributeDescriptor =
                                elementDescriptor.getAttributeDescriptor("xmlns", XmlTagImpl.this);
                            if (attributeDescriptor != null && attributeDescriptor.isFixed()) {
                              final String defaultValue = attributeDescriptor.getDefaultValue();
                              if (defaultValue != null && defaultValue.equals(namespace)) {
                                return new Result<XmlNSDescriptor>(
                                    descriptor,
                                    descriptor.getDependences(),
                                    XmlTagImpl.this,
                                    ExternalResourceManager.getInstance());
                              }
                            }
                          }
                        }
                      }
                    }
                    PsiMetaOwner currentOwner = retrieveOwner(currentFile, namespace);
                    if (currentOwner != null) {
                      descriptor = (XmlNSDescriptor) currentOwner.getMetaData();
                      if (descriptor != null) {
                        return new Result<XmlNSDescriptor>(
                            descriptor,
                            descriptor.getDependences(),
                            XmlTagImpl.this,
                            ExternalResourceManager.getInstance());
                      }
                    }
                    return new Result<XmlNSDescriptor>(
                        null, XmlTagImpl.this, currentFile, ExternalResourceManager.getInstance());
                  }
                },
                false));

    return map;
  }