Search in sources :

Example 1 with PsiReferenceBase

use of com.intellij.psi.PsiReferenceBase in project intellij-community by JetBrains.

the class RncDefineImpl method getReference.

@Override
public PsiReference getReference() {
    if (getParent() instanceof RncInclude) {
        final TextRange range = TextRange.from(0, getNameNode().getTextLength());
        return new PsiReferenceBase<RncDefine>(this, range, true) {

            @Override
            public PsiElement resolve() {
                return RncDefineImpl.this;
            }

            @Override
            @NotNull
            public Object[] getVariants() {
                final RncInclude parent = (RncInclude) getParent();
                final RncFile referencedFile = parent.getReferencedFile();
                if (referencedFile == null) {
                    return EMPTY_ARRAY;
                }
                final RncGrammar grammar = referencedFile.getGrammar();
                if (grammar == null) {
                    return EMPTY_ARRAY;
                }
                final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(grammar);
                if (map != null) {
                    return map.keySet().toArray();
                }
                return EMPTY_ARRAY;
            }
        };
    }
    return super.getReference();
}
Also used : Set(java.util.Set) PsiReferenceBase(com.intellij.psi.PsiReferenceBase) TextRange(com.intellij.openapi.util.TextRange)

Example 2 with PsiReferenceBase

use of com.intellij.psi.PsiReferenceBase in project intellij-community by JetBrains.

the class RngReferenceConverter method createReferences.

@Override
@NotNull
public PsiReference[] createReferences(GenericDomValue genericDomValue, PsiElement element, ConvertContext context) {
    final GenericAttributeValue<String> e = (GenericAttributeValue<String>) genericDomValue;
    if (genericDomValue.getParent() instanceof RngDefine) {
        final XmlAttributeValue value = e.getXmlAttributeValue();
        if (value == null) {
            return PsiReference.EMPTY_ARRAY;
        }
        return new PsiReference[] { new PsiReferenceBase<XmlAttributeValue>(value, true) {

            @Override
            public PsiElement resolve() {
                //                  }
                return myElement.getParent().getParent();
            }

            @Override
            @NotNull
            public Object[] getVariants() {
                final RngInclude include = e.getParentOfType(RngInclude.class, true);
                final RngGrammar scope = e.getParentOfType(RngGrammar.class, true);
                if (scope != null && include != null && DomUtil.isAncestor(scope, include, true)) {
                    final XmlFile file = include.getIncludedFile().getValue();
                    if (file != null) {
                        final DomFileElement<DomElement> fileElement = scope.getManager().getFileElement(file, DomElement.class);
                        if (fileElement == null) {
                            return EMPTY_ARRAY;
                        }
                        final Ref<Object[]> ref = new Ref<>(ArrayUtil.EMPTY_STRING_ARRAY);
                        fileElement.acceptChildren(new RngDomVisitor() {

                            @Override
                            public void visit(RngGrammar grammar) {
                                final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(grammar);
                                if (map != null) {
                                    ref.set(map.keySet().toArray());
                                }
                            }
                        });
                        return ref.get();
                    }
                }
                // TODO: look for unresolved refs;
                return ArrayUtil.EMPTY_STRING_ARRAY;
            }
        } };
    }
    return new PsiReference[] { new DefinitionReference(e) };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar) RngDefine(org.intellij.plugins.relaxNG.xml.dom.RngDefine) Ref(com.intellij.openapi.util.Ref) RngDefine(org.intellij.plugins.relaxNG.xml.dom.RngDefine) Define(org.intellij.plugins.relaxNG.model.Define) RngInclude(org.intellij.plugins.relaxNG.xml.dom.RngInclude) PsiReferenceBase(com.intellij.psi.PsiReferenceBase) RngDomVisitor(org.intellij.plugins.relaxNG.xml.dom.RngDomVisitor) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiReferenceBase (com.intellij.psi.PsiReferenceBase)2 Ref (com.intellij.openapi.util.Ref)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiReference (com.intellij.psi.PsiReference)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlFile (com.intellij.psi.xml.XmlFile)1 Map (java.util.Map)1 Set (java.util.Set)1 Define (org.intellij.plugins.relaxNG.model.Define)1 RngDefine (org.intellij.plugins.relaxNG.xml.dom.RngDefine)1 RngDomVisitor (org.intellij.plugins.relaxNG.xml.dom.RngDomVisitor)1 RngGrammar (org.intellij.plugins.relaxNG.xml.dom.RngGrammar)1 RngInclude (org.intellij.plugins.relaxNG.xml.dom.RngInclude)1 NotNull (org.jetbrains.annotations.NotNull)1