Search in sources :

Example 1 with TagNameReference

use of com.intellij.psi.impl.source.xml.TagNameReference 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 TagNameReference

use of com.intellij.psi.impl.source.xml.TagNameReference in project intellij-community by JetBrains.

the class XmlTagRenameDialog method completeVariable.

private void completeVariable(final Editor editor) {
    String prefix = myNameSuggestionsField.getEnteredName();
    final PsiReference reference = myTag.getReference();
    if (reference instanceof TagNameReference) {
        LookupElement[] lookupItems = TagNameReferenceCompletionProvider.getTagNameVariants(myTag, myTag.getNamespacePrefix());
        editor.getCaretModel().moveToOffset(prefix.length());
        editor.getSelectionModel().removeSelection();
        LookupManager.getInstance(getProject()).showLookup(editor, lookupItems, prefix);
    }
}
Also used : TagNameReference(com.intellij.psi.impl.source.xml.TagNameReference) PsiReference(com.intellij.psi.PsiReference) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

PsiReference (com.intellij.psi.PsiReference)2 TagNameReference (com.intellij.psi.impl.source.xml.TagNameReference)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 SmartList (com.intellij.util.SmartList)1 Converter (com.intellij.util.xml.Converter)1 ResolvingConverter (com.intellij.util.xml.ResolvingConverter)1 GenericDomValueReference (com.intellij.util.xml.impl.GenericDomValueReference)1 Collection (java.util.Collection)1 NotNull (org.jetbrains.annotations.NotNull)1 MavenSmartConverter (org.jetbrains.idea.maven.dom.converters.MavenSmartConverter)1