Search in sources :

Example 6 with JavaClassReference

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

the class StrutsConstantValueReference method getVariants.

@NotNull
@SuppressWarnings({ "unchecked" })
public Object[] getVariants() {
    if (elementConverterPair == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final Converter converter = elementConverterPair.second;
    if (!(converter instanceof ResolvingConverter)) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final ResolvingConverter resolvingConverter = (ResolvingConverter) converter;
    // merge "normal" + additional variants
    final DomElement paramValueElement = elementConverterPair.first;
    final ConvertContext convertContext = ConvertContextFactory.createConvertContext(paramValueElement);
    // wrap explicitly for empty list
    final Collection converterVariants = new ArrayList(resolvingConverter.getVariants(convertContext));
    final Collection variants;
    if (!converterVariants.isEmpty() && converterVariants.iterator().next() instanceof DomElement) {
        variants = Arrays.asList(ElementPresentationManager.getInstance().createVariants(converterVariants));
    } else {
        variants = converterVariants;
    }
    variants.addAll(resolvingConverter.getAdditionalVariants(convertContext));
    // add custom created references
    if (resolvingConverter instanceof CustomReferenceConverter) {
        final PsiReference[] references = ((CustomReferenceConverter) resolvingConverter).createReferences((GenericDomValue) paramValueElement, myElement, convertContext);
        for (final PsiReference customReference : references) {
            if (customReference instanceof JavaClassReference) {
                JavaClassReference javaClassReference = (JavaClassReference) customReference;
                String[] names = javaClassReference.getExtendClassNames();
                PsiElement context = javaClassReference.getCompletionContext();
                if (names != null && context instanceof PsiPackage) {
                    javaClassReference.processSubclassVariants((PsiPackage) context, names, element -> variants.add(element));
                    continue;
                }
            }
            Collections.addAll(variants, customReference.getVariants());
        }
    }
    return ArrayUtil.toObjectArray(variants);
}
Also used : JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference) PsiReference(com.intellij.psi.PsiReference) PsiPackage(com.intellij.psi.PsiPackage) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JavaClassReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference)6 JavaClassReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet)3 PsiElement (com.intellij.psi.PsiElement)2 PsiPackage (com.intellij.psi.PsiPackage)2 NotNull (org.jetbrains.annotations.NotNull)2 JavaCompletionProcessor (com.intellij.codeInsight.completion.scope.JavaCompletionProcessor)1 ASTNode (com.intellij.lang.ASTNode)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiReference (com.intellij.psi.PsiReference)1 PsiJavaCodeReferenceElementImpl (com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl)1 JspxImportStatement (com.intellij.psi.impl.source.jsp.jspJava.JspxImportStatement)1 JavaClassReferenceProvider (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider)1 CandidateInfo (com.intellij.psi.infos.CandidateInfo)1 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)1 IElementType (com.intellij.psi.tree.IElementType)1 XmlElement (com.intellij.psi.xml.XmlElement)1 ProcessingContext (com.intellij.util.ProcessingContext)1 DomElementProblemDescriptor (com.intellij.util.xml.highlighting.DomElementProblemDescriptor)1