Search in sources :

Example 1 with Converter

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

the class MavenSmartCompletionContributor method getVariants.

@NotNull
private static Collection<?> getVariants(CompletionParameters parameters) {
    if (!MavenDomUtil.isMavenFile(parameters.getOriginalFile()))
        return Collections.emptyList();
    SmartList<?> result = new SmartList<>();
    for (PsiReference each : getReferences(parameters)) {
        if (each instanceof TagNameReference)
            continue;
        if (each instanceof GenericDomValueReference) {
            GenericDomValueReference reference = (GenericDomValueReference) each;
            Converter converter = reference.getConverter();
            if (converter instanceof MavenSmartConverter) {
                Collection variants = ((MavenSmartConverter) converter).getSmartVariants(reference.getConvertContext());
                if (converter instanceof ResolvingConverter) {
                    addVariants((ResolvingConverter) converter, variants, result);
                } else {
                    result.addAll(variants);
                }
            } else if (converter instanceof ResolvingConverter) {
                //noinspection unchecked
                ResolvingConverter resolvingConverter = (ResolvingConverter) converter;
                Collection variants = resolvingConverter.getVariants(reference.getConvertContext());
                addVariants(resolvingConverter, variants, result);
            }
        } else {
            //noinspection unchecked
            Collections.addAll((Collection) result, each.getVariants());
        }
    }
    return result;
}
Also used : ResolvingConverter(com.intellij.util.xml.ResolvingConverter) MavenSmartConverter(org.jetbrains.idea.maven.dom.converters.MavenSmartConverter) TagNameReference(com.intellij.psi.impl.source.xml.TagNameReference) GenericDomValueReference(com.intellij.util.xml.impl.GenericDomValueReference) PsiReference(com.intellij.psi.PsiReference) Converter(com.intellij.util.xml.Converter) MavenSmartConverter(org.jetbrains.idea.maven.dom.converters.MavenSmartConverter) ResolvingConverter(com.intellij.util.xml.ResolvingConverter) Collection(java.util.Collection) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Converter

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

Aggregations

Converter (com.intellij.util.xml.Converter)2 ResolvingConverter (com.intellij.util.xml.ResolvingConverter)2 PsiReference (com.intellij.psi.PsiReference)1 TagNameReference (com.intellij.psi.impl.source.xml.TagNameReference)1 SmartList (com.intellij.util.SmartList)1 XmlName (com.intellij.util.xml.XmlName)1 GenericDomValueReference (com.intellij.util.xml.impl.GenericDomValueReference)1 DomExtension (com.intellij.util.xml.reflect.DomExtension)1 Collection (java.util.Collection)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 NotNull (org.jetbrains.annotations.NotNull)1 MavenSmartConverter (org.jetbrains.idea.maven.dom.converters.MavenSmartConverter)1