Java 类com.intellij.util.xml.reflect.DomAttributeChildDescription 实例源码

项目:consulo-apache-ant    文件:AntDomExtender.java   
private static Map<String, Pair<Type, Class>> getStaticallyRegisteredAttributes(final DomGenericInfo genericInfo) {
  final Map<String, Pair<Type, Class>> map = new HashMap<String, Pair<Type, Class>>();
  for (DomAttributeChildDescription description : genericInfo.getAttributeChildrenDescriptions()) {
    final Type type = description.getType();
    if (type instanceof ParameterizedType) {
      final Type[] typeArguments = ((ParameterizedType)type).getActualTypeArguments();
      if (typeArguments.length == 1) {
        String name = description.getXmlElementName();
        final Type attribType = typeArguments[0];
        Class<? extends Converter> converterType = null;
        final Convert converterAnnotation = description.getAnnotation(Convert.class);
        if (converterAnnotation != null) {
          converterType = converterAnnotation.value();
        }
        map.put(name.toLowerCase(Locale.US), new Pair<Type, Class>(attribType, converterType));
      }
    }
  }
  return map;
}
项目:intellij-ce-playground    文件:DomBasicsTest.java   
public void testAttributeChildrenGenerics() throws Throwable {
  final StaticGenericInfo genericInfo = DomApplicationComponent.getInstance().getStaticGenericInfo(MyElement.class);
  final List<? extends DomAttributeChildDescription> descriptions = genericInfo.getAttributeChildrenDescriptions();
  assertEquals(1, descriptions.size());
  final DomAttributeChildDescription description = descriptions.get(0);

  final MyElement element = createElement("");
  assertEquals(element.getAttr(), description.getValues(element).get(0));
  assertEquals(element.getAttr(), description.getDomAttributeValue(element));
}
项目:intellij-ce-playground    文件:AntDomPattern.java   
@Nullable
private static String getAttributeValue(AntDomElement element, final String attributeName) {
  final DomAttributeChildDescription description = element.getGenericInfo().getAttributeChildDescription(attributeName);
  if (description == null) {
    return null;
  }
  return description.getDomAttributeValue(element).getStringValue();
}
项目:tools-idea    文件:DomBasicsTest.java   
public void testAttributeChildrenGenerics() throws Throwable {
  final StaticGenericInfo genericInfo = DomApplicationComponent.getInstance().getStaticGenericInfo(MyElement.class);
  final List<? extends DomAttributeChildDescription> descriptions = genericInfo.getAttributeChildrenDescriptions();
  assertEquals(1, descriptions.size());
  final DomAttributeChildDescription description = descriptions.get(0);

  final MyElement element = createElement("");
  assertEquals(element.getAttr(), description.getValues(element).get(0));
  assertEquals(element.getAttr(), description.getDomAttributeValue(element));
}
项目:tools-idea    文件:AntDomPattern.java   
@Nullable
private static String getAttributeValue(AntDomElement element, final String attributeName) {
  final DomAttributeChildDescription description = element.getGenericInfo().getAttributeChildDescription(attributeName);
  if (description == null) {
    return null;
  }
  return description.getDomAttributeValue(element).getStringValue();
}
项目:consulo-apache-ant    文件:AntDomPattern.java   
@Nullable
private static String getAttributeValue(AntDomElement element, final String attributeName) {
  final DomAttributeChildDescription description = element.getGenericInfo().getAttributeChildDescription(attributeName);
  if (description == null) {
    return null;
  }
  return description.getDomAttributeValue(element).getStringValue();
}
项目:consulo-xml    文件:DomBasicsTest.java   
public void testAttributeChildrenGenerics() throws Throwable {
  final StaticGenericInfo genericInfo = DomApplicationComponent.getInstance().getStaticGenericInfo(MyElement.class);
  final List<? extends DomAttributeChildDescription> descriptions = genericInfo.getAttributeChildrenDescriptions();
  assertEquals(1, descriptions.size());
  final DomAttributeChildDescription description = descriptions.get(0);

  final MyElement element = createElement("");
  assertEquals(element.getAttr(), description.getValues(element).get(0));
  assertEquals(element.getAttr(), description.getDomAttributeValue(element));
}
项目:consulo-xml    文件:DomExtensionsTest.java   
public void testUserData() throws Throwable {
  registerDomExtender(AttrDomExtender3.class);
  final MyElement element = createElement("<a attr=\"xxx\"/>", MyElement.class);
  final DomAttributeChildDescription description = element.getGenericInfo().getAttributeChildDescription("xxx");
  assertNotNull(description);
  assertSame(Boolean.TRUE, description.getUserData(BOOL_KEY));
}
项目:intellij-ce-playground    文件:DomAttributeXmlDescriptor.java   
public DomAttributeXmlDescriptor(final DomAttributeChildDescription description, Project project) {
  myDescription = description;
  myProject = project;
}
项目:intellij-ce-playground    文件:AndroidXmlDocumentationProvider.java   
@Nullable
private static String generateDocForXmlAttribute(@NotNull DomAttributeChildDescription description, @NotNull final PsiElement originalElement) {
  final XmlName xmlName = description.getXmlName();

  Map<XmlName, CachedValue<String>> cachedDocsMap = SoftReference.dereference(
    originalElement.getUserData(ANDROID_ATTRIBUTE_DOCUMENTATION_CACHE_KEY));

  if (cachedDocsMap != null) {
    final CachedValue<String> cachedDoc = cachedDocsMap.get(xmlName);

    if (cachedDoc != null) {
      return cachedDoc.getValue();
    }
  }
  final AndroidFacet facet = AndroidFacet.getInstance(originalElement);

  if (facet == null) {
    return null;
  }
  final String localName = xmlName.getLocalName();
  String namespace = xmlName.getNamespaceKey();

  if (namespace == null) {
    return null;
  }
  if (AndroidUtils.NAMESPACE_KEY.equals(namespace)) {
    namespace = ANDROID_URI;
  }

  if (namespace.startsWith(URI_PREFIX)) {
    final String finalNamespace = namespace;

    final CachedValue<String> cachedValue = CachedValuesManager.getManager(originalElement.getProject()).createCachedValue(
      new CachedValueProvider<String>() {
        @Nullable
        @Override
        public Result<String> compute() {
          final Pair<AttributeDefinition, String> pair = findAttributeDefinition(originalElement, facet, finalNamespace, localName);
          final String doc = pair != null ? generateDocForXmlAttribute(pair.getFirst(), pair.getSecond()) : null;
          return Result.create(doc, PsiModificationTracker.MODIFICATION_COUNT);
        }
      }, false);
    if (cachedDocsMap == null) {
      cachedDocsMap = new HashMap<XmlName, CachedValue<String>>();
      originalElement.putUserData(ANDROID_ATTRIBUTE_DOCUMENTATION_CACHE_KEY,
                                  new SoftReference<Map<XmlName, CachedValue<String>>>(cachedDocsMap));
    }
    cachedDocsMap.put(xmlName, cachedValue);
    return cachedValue.getValue();
  }
  return null;
}
项目:tools-idea    文件:DomAttributeXmlDescriptor.java   
public DomAttributeXmlDescriptor(final DomAttributeChildDescription description, Project project) {
  myDescription = description;
  myProject = project;
}
项目:consulo-xml    文件:DomAttributeXmlDescriptor.java   
public DomAttributeXmlDescriptor(final DomAttributeChildDescription description, Project project) {
  myDescription = description;
  myProject = project;
}