Search in sources :

Example 1 with ResolvingConverter

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

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

the class ToolsAttributeUtil method getConverter.

/**
   * Returns a {@link ResolvingConverter} for the given attribute definition
   */
@Nullable
public static ResolvingConverter getConverter(@NotNull AttributeDefinition attrDef) {
    String name = attrDef.getName();
    ResolvingConverter converter = CONVERTERS.get(name);
    return converter != null ? converter : AndroidDomUtil.getConverter(attrDef);
}
Also used : ResolvingConverter(com.intellij.util.xml.ResolvingConverter) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ResolvingConverter

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

the class NlDesignProperties method getDefinitionByName.

private static AttributeDefinition getDefinitionByName(@NotNull String name) {
    AttributeDefinition definition = ToolsAttributeUtil.getAttrDefByName(name);
    assert definition != null;
    ResolvingConverter converter = ToolsAttributeUtil.getConverter(definition);
    // TODO: Figure out how to provide the correct reference editor depending on the converter.
    if (converter instanceof StaticEnumConverter) {
        Collection variants = converter.getVariants(null);
        for (Object variant : variants) {
            definition.addValue(variant.toString());
        }
    }
    return definition;
}
Also used : ResolvingConverter(com.intellij.util.xml.ResolvingConverter) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) Collection(java.util.Collection) StaticEnumConverter(org.jetbrains.android.dom.converters.StaticEnumConverter)

Example 4 with ResolvingConverter

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

ResolvingConverter (com.intellij.util.xml.ResolvingConverter)4 Collection (java.util.Collection)2 PsiReference (com.intellij.psi.PsiReference)1 TagNameReference (com.intellij.psi.impl.source.xml.TagNameReference)1 SmartList (com.intellij.util.SmartList)1 Converter (com.intellij.util.xml.Converter)1 XmlName (com.intellij.util.xml.XmlName)1 GenericDomValueReference (com.intellij.util.xml.impl.GenericDomValueReference)1 DomExtension (com.intellij.util.xml.reflect.DomExtension)1 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)1 StaticEnumConverter (org.jetbrains.android.dom.converters.StaticEnumConverter)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 MavenSmartConverter (org.jetbrains.idea.maven.dom.converters.MavenSmartConverter)1