Search in sources :

Example 1 with DomExtender

use of com.intellij.util.xml.reflect.DomExtender in project intellij-community by JetBrains.

the class ExtensionDomExtender method registerField.

private static void registerField(final DomExtensionsRegistrar registrar, @NotNull final PsiField field, With withElement) {
    final PsiMethod getter = PropertyUtil.findGetterForField(field);
    final PsiMethod setter = PropertyUtil.findSetterForField(field);
    if (!field.hasModifierProperty(PsiModifier.PUBLIC) && (getter == null || setter == null)) {
        return;
    }
    final String fieldName = field.getName();
    final PsiConstantEvaluationHelper evalHelper = JavaPsiFacade.getInstance(field.getProject()).getConstantEvaluationHelper();
    final PsiAnnotation attrAnno = findAnnotation(Attribute.class, field, getter, setter);
    if (attrAnno != null) {
        final String attrName = getStringAttribute(attrAnno, "value", evalHelper);
        if (attrName != null) {
            Class clazz = String.class;
            if (withElement != null || isClassField(fieldName)) {
                clazz = PsiClass.class;
            } else if (PsiType.BOOLEAN.equals(field.getType())) {
                clazz = Boolean.class;
            }
            final DomExtension extension = registrar.registerGenericAttributeValueChildExtension(new XmlName(attrName), clazz).setDeclaringElement(field);
            markAsClass(extension, fieldName, withElement);
            if (clazz.equals(String.class)) {
                markAsLanguage(extension, fieldName);
            }
        }
        return;
    }
    final PsiAnnotation tagAnno = findAnnotation(Tag.class, field, getter, setter);
    final PsiAnnotation propAnno = findAnnotation(Property.class, field, getter, setter);
    final PsiAnnotation absColAnno = findAnnotation(AbstractCollection.class, field, getter, setter);
    //final PsiAnnotation colAnno = modifierList.findAnnotation(Collection.class.getName()); // todo
    final String tagName = tagAnno != null ? getStringAttribute(tagAnno, "value", evalHelper) : propAnno != null && getBooleanAttribute(propAnno, "surroundWithTag", evalHelper) ? Constants.OPTION : null;
    if (tagName != null) {
        if (absColAnno == null) {
            final DomExtension extension = registrar.registerFixedNumberChildExtension(new XmlName(tagName), SimpleTagValue.class).setDeclaringElement(field);
            markAsClass(extension, fieldName, withElement);
        } else {
            registrar.registerFixedNumberChildExtension(new XmlName(tagName), DomElement.class).addExtender(new DomExtender() {

                @Override
                public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) {
                    registerCollectionBinding(field.getType(), registrar, absColAnno, evalHelper);
                }
            });
        }
    } else if (absColAnno != null) {
        registerCollectionBinding(field.getType(), registrar, absColAnno, evalHelper);
    }
}
Also used : DomExtender(com.intellij.util.xml.reflect.DomExtender) DomExtensionsRegistrar(com.intellij.util.xml.reflect.DomExtensionsRegistrar) DomExtension(com.intellij.util.xml.reflect.DomExtension)

Example 2 with DomExtender

use of com.intellij.util.xml.reflect.DomExtender in project intellij-community by JetBrains.

the class ExtensionDomExtender method registerCollectionBinding.

private static void registerCollectionBinding(PsiType type, DomExtensionsRegistrar registrar, PsiAnnotation anno, PsiConstantEvaluationHelper evalHelper) {
    final boolean surroundWithTag = getBooleanAttribute(anno, "surroundWithTag", evalHelper);
    // todo Set, List, Array
    if (surroundWithTag)
        return;
    final String tagName = getStringAttribute(anno, "elementTag", evalHelper);
    final String attrName = getStringAttribute(anno, "elementValueAttribute", evalHelper);
    final PsiType elementType = getElementType(type);
    if (elementType == null || TypeConversionUtil.isPrimitiveAndNotNullOrWrapper(elementType) || CommonClassNames.JAVA_LANG_STRING.equals(elementType.getCanonicalText()) || TypeConversionUtil.isEnumType(elementType)) {
        if (tagName != null && attrName == null) {
            registrar.registerCollectionChildrenExtension(new XmlName(tagName), SimpleTagValue.class);
        } else if (tagName != null) {
            registrar.registerCollectionChildrenExtension(new XmlName(tagName), DomElement.class).addExtender(new DomExtender() {

                @Override
                public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) {
                    registrar.registerGenericAttributeValueChildExtension(new XmlName(attrName), String.class);
                }
            });
        }
    } else {
        final PsiClass psiClass = PsiTypesUtil.getPsiClass(elementType);
        if (psiClass != null) {
            final PsiModifierList modifierList = psiClass.getModifierList();
            final PsiAnnotation tagAnno = modifierList == null ? null : modifierList.findAnnotation(Tag.class.getName());
            final String classTagName = tagAnno == null ? psiClass.getName() : getStringAttribute(tagAnno, "value", evalHelper);
            if (classTagName != null) {
                registrar.registerCollectionChildrenExtension(new XmlName(classTagName), DomElement.class).addExtender(new DomExtender() {

                    @Override
                    public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) {
                        registerXmlb(registrar, psiClass, Collections.<With>emptyList());
                    }
                });
            }
        }
    }
}
Also used : DomExtender(com.intellij.util.xml.reflect.DomExtender) DomExtensionsRegistrar(com.intellij.util.xml.reflect.DomExtensionsRegistrar) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with DomExtender

use of com.intellij.util.xml.reflect.DomExtender in project intellij-community by JetBrains.

the class MavenPluginConfigurationDomExtender method registerPluginParameter.

private static void registerPluginParameter(boolean isInPluginManagement, DomExtensionsRegistrar r, final ParameterData data, final String parameterName) {
    DomExtension e = r.registerFixedNumberChildExtension(new XmlName(parameterName), MavenDomConfigurationParameter.class);
    if (isCollection(data.parameter)) {
        e.addExtender(new DomExtender() {

            public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) {
                for (String each : collectPossibleNameForCollectionParameter(parameterName)) {
                    DomExtension inner = registrar.registerCollectionChildrenExtension(new XmlName(each), MavenDomConfigurationParameter.class);
                    inner.setDeclaringElement(data.parameter);
                }
            }
        });
    } else {
        addValueConverter(e, data.parameter);
        if (!isInPluginManagement) {
            addRequiredAnnotation(e, data);
        }
    }
    e.setDeclaringElement(data.parameter);
    data.parameter.getXmlElement().putUserData(PLUGIN_PARAMETER_KEY, data);
}
Also used : DomExtension(com.intellij.util.xml.reflect.DomExtension) DomElement(com.intellij.util.xml.DomElement) DomExtender(com.intellij.util.xml.reflect.DomExtender) DomExtensionsRegistrar(com.intellij.util.xml.reflect.DomExtensionsRegistrar) XmlName(com.intellij.util.xml.XmlName) MavenDomConfigurationParameter(org.jetbrains.idea.maven.dom.model.MavenDomConfigurationParameter)

Aggregations

DomExtender (com.intellij.util.xml.reflect.DomExtender)3 DomExtensionsRegistrar (com.intellij.util.xml.reflect.DomExtensionsRegistrar)3 DomExtension (com.intellij.util.xml.reflect.DomExtension)2 DomElement (com.intellij.util.xml.DomElement)1 XmlName (com.intellij.util.xml.XmlName)1 NotNull (org.jetbrains.annotations.NotNull)1 MavenDomConfigurationParameter (org.jetbrains.idea.maven.dom.model.MavenDomConfigurationParameter)1