Search in sources :

Example 1 with DependentNSReference

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.DependentNSReference in project intellij-community by JetBrains.

the class XmlLocationCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiReference reference = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
    if (reference instanceof URLReference) {
        if (((URLReference) reference).isSchemaLocation()) {
            Object[] objects = completeSchemaLocation(reference.getElement());
            result.addAllElements(ContainerUtil.map(objects, MAPPING));
            return;
        }
        Object[] objects = completeNamespace(reference.getElement());
        result.addAllElements(ContainerUtil.map(objects, MAPPING));
        return;
    }
    if (reference instanceof PsiMultiReference)
        reference = ((PsiMultiReference) reference).getReferences()[0];
    if (reference instanceof DependentNSReference) {
        MultiMap<String, String> map = ExternalResourceManagerEx.getInstanceEx().getUrlsByNamespace(parameters.getOriginalFile().getProject());
        String namespace = ((DependentNSReference) reference).getNamespaceReference().getCanonicalText();
        Collection<String> strings = map.get(namespace);
        for (String string : strings) {
            if (!namespace.equals(string)) {
                // exclude namespaces from location urls
                result.consume(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(string), 100));
            }
        }
        if (!strings.isEmpty())
            result.stopHere();
    }
}
Also used : DependentNSReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.DependentNSReference) URLReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.URLReference) PsiReference(com.intellij.psi.PsiReference) PsiMultiReference(com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)

Example 2 with DependentNSReference

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.DependentNSReference in project intellij-community by JetBrains.

the class MicrodataUtil method getUrlReferencesForAttributeValue.

public static PsiReference[] getUrlReferencesForAttributeValue(final XmlAttributeValue element) {
    return getReferencesForAttributeValue(element, (token, offset) -> {
        if (HtmlUtil.hasHtmlPrefix(token)) {
            final TextRange range = TextRange.from(offset, token.length());
            final URLReference urlReference = new URLReference(element, range, true);
            return new DependentNSReference(element, range, urlReference, true);
        }
        return null;
    });
}
Also used : DependentNSReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.DependentNSReference) URLReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.URLReference) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

DependentNSReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.DependentNSReference)2 URLReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.URLReference)2 TextRange (com.intellij.openapi.util.TextRange)1 PsiReference (com.intellij.psi.PsiReference)1 PsiMultiReference (com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)1