Search in sources :

Example 1 with DomExtension

use of com.intellij.util.xml.reflect.DomExtension 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 DomExtension

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

the class ExtensionDomExtender method registerExtensionPoint.

private static void registerExtensionPoint(final DomExtensionsRegistrar registrar, final ExtensionPoint extensionPoint, String epPrefix, @Nullable String pluginId) {
    String epName = extensionPoint.getName().getStringValue();
    if (epName != null && StringUtil.isNotEmpty(pluginId))
        epName = pluginId + "." + epName;
    if (epName == null)
        epName = extensionPoint.getQualifiedName().getStringValue();
    if (epName == null)
        return;
    if (!epName.startsWith(epPrefix))
        return;
    final DomExtension domExtension = registrar.registerCollectionChildrenExtension(new XmlName(epName.substring(epPrefix.length())), Extension.class);
    domExtension.setDeclaringElement(extensionPoint);
    domExtension.addExtender(EXTENSION_EXTENDER);
}
Also used : DomExtension(com.intellij.util.xml.reflect.DomExtension)

Example 3 with DomExtension

use of com.intellij.util.xml.reflect.DomExtension 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)

Example 4 with DomExtension

use of com.intellij.util.xml.reflect.DomExtension in project android by JetBrains.

the class AttributeProcessingUtil method registerAttribute.

private static void registerAttribute(@NotNull AttributeDefinition attrDef, @Nullable String parentStyleableName, @Nullable String namespaceKey, @NotNull DomElement element, @NotNull AttributeProcessor callback) {
    String name = attrDef.getName();
    if (!NS_RESOURCES.equals(namespaceKey) && name.startsWith(PREFIX_ANDROID)) {
        // A styleable-definition in the app namespace (user specified or from a library) can include
        // a reference to a platform attribute. In such a case, register it under the android namespace
        // as opposed to the app namespace. See https://code.google.com/p/android/issues/detail?id=171162
        name = name.substring(PREFIX_ANDROID.length());
        namespaceKey = NS_RESOURCES;
    }
    XmlName xmlName = new XmlName(name, namespaceKey);
    final DomExtension extension = callback.processAttribute(xmlName, attrDef, parentStyleableName);
    if (extension == null) {
        return;
    }
    Converter converter = AndroidDomUtil.getSpecificConverter(xmlName, element);
    if (converter == null) {
        if (TOOLS_URI.equals(namespaceKey)) {
            converter = ToolsAttributeUtil.getConverter(attrDef);
        } else {
            converter = AndroidDomUtil.getConverter(attrDef);
            if (converter != null && element.getParentOfType(Manifest.class, true) != null) {
                converter = new ManifestPlaceholderConverter(converter);
            }
        }
    }
    if (converter != null) {
        extension.setConverter(converter, mustBeSoft(converter, attrDef.getFormats()));
    }
    // tag completion. If attribute is not required, no additional action is needed.
    if (element instanceof LayoutElement && isLayoutAttributeRequired(xmlName, element) || element instanceof ManifestElement && AndroidManifestUtils.isRequiredAttribute(xmlName, element)) {
        extension.addCustomAnnotation(new RequiredImpl());
    }
}
Also used : DomExtension(com.intellij.util.xml.reflect.DomExtension) ManifestElement(org.jetbrains.android.dom.manifest.ManifestElement) ManifestPlaceholderConverter(org.jetbrains.android.dom.converters.ManifestPlaceholderConverter) XmlName(com.intellij.util.xml.XmlName) CompositeConverter(org.jetbrains.android.dom.converters.CompositeConverter) Converter(com.intellij.util.xml.Converter) ResourceReferenceConverter(org.jetbrains.android.dom.converters.ResourceReferenceConverter) ManifestPlaceholderConverter(org.jetbrains.android.dom.converters.ManifestPlaceholderConverter) ResolvingConverter(com.intellij.util.xml.ResolvingConverter)

Example 5 with DomExtension

use of com.intellij.util.xml.reflect.DomExtension in project android by JetBrains.

the class AttributeProcessingUtil method registerToolsAttribute.

private static void registerToolsAttribute(@NotNull String attributeName, @NotNull AttributeProcessor callback) {
    final AttributeDefinition definition = ToolsAttributeUtil.getAttrDefByName(attributeName);
    if (definition != null) {
        final XmlName name = new XmlName(attributeName, TOOLS_URI);
        final DomExtension domExtension = callback.processAttribute(name, definition, null);
        final ResolvingConverter converter = ToolsAttributeUtil.getConverter(definition);
        if (domExtension != null && converter != null) {
            domExtension.setConverter(converter);
        }
    } else {
        getLog().warn("No attribute definition for tools attribute " + attributeName);
    }
}
Also used : DomExtension(com.intellij.util.xml.reflect.DomExtension) ResolvingConverter(com.intellij.util.xml.ResolvingConverter) XmlName(com.intellij.util.xml.XmlName)

Aggregations

DomExtension (com.intellij.util.xml.reflect.DomExtension)5 XmlName (com.intellij.util.xml.XmlName)3 ResolvingConverter (com.intellij.util.xml.ResolvingConverter)2 DomExtender (com.intellij.util.xml.reflect.DomExtender)2 DomExtensionsRegistrar (com.intellij.util.xml.reflect.DomExtensionsRegistrar)2 Converter (com.intellij.util.xml.Converter)1 DomElement (com.intellij.util.xml.DomElement)1 CompositeConverter (org.jetbrains.android.dom.converters.CompositeConverter)1 ManifestPlaceholderConverter (org.jetbrains.android.dom.converters.ManifestPlaceholderConverter)1 ResourceReferenceConverter (org.jetbrains.android.dom.converters.ResourceReferenceConverter)1 ManifestElement (org.jetbrains.android.dom.manifest.ManifestElement)1 MavenDomConfigurationParameter (org.jetbrains.idea.maven.dom.model.MavenDomConfigurationParameter)1