Search in sources :

Example 1 with RngGrammar

use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar in project intellij-community by JetBrains.

the class CreatePatternFix method doFix.

private void doFix() throws IncorrectOperationException {
    final XmlTag tag = PsiTreeUtil.getParentOfType(myReference.getElement(), XmlTag.class);
    assert tag != null;
    final XmlTag defineTag = tag.createChildTag("define", ApplicationLoader.RNG_NAMESPACE, "\n \n", false);
    defineTag.setAttribute("name", myReference.getCanonicalText());
    final RngGrammar grammar = ((DefinitionReference) myReference).getScope();
    if (grammar == null)
        return;
    final XmlTag root = grammar.getXmlTag();
    if (root == null)
        return;
    final XmlTag[] tags = root.getSubTags();
    for (XmlTag xmlTag : tags) {
        if (PsiTreeUtil.isAncestor(xmlTag, tag, false)) {
            final XmlElementFactory ef = XmlElementFactory.getInstance(tag.getProject());
            final XmlText text = ef.createDisplayText(" ");
            final PsiElement e = root.addAfter(text, xmlTag);
            root.addAfter(defineTag, e);
            return;
        }
    }
    root.add(defineTag);
}
Also used : XmlElementFactory(com.intellij.psi.XmlElementFactory) XmlText(com.intellij.psi.xml.XmlText) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar)

Example 2 with RngGrammar

use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar in project intellij-community by JetBrains.

the class DefinitionReference method getQuickFixes.

@Override
public LocalQuickFix[] getQuickFixes() {
    final XmlTag tag = PsiTreeUtil.getParentOfType(getElement(), XmlTag.class);
    assert tag != null;
    final RngGrammar scope = myValue.getParentOfType(RngGrammar.class, true);
    if (scope != null) {
        return new LocalQuickFix[] { new CreatePatternFix(this) };
    }
    return LocalQuickFix.EMPTY_ARRAY;
}
Also used : LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) XmlTag(com.intellij.psi.xml.XmlTag) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar)

Example 3 with RngGrammar

use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar in project intellij-community by JetBrains.

the class RngRefImpl method getPattern.

@Override
public Define getPattern() {
    final XmlAttributeValue value = getName().getXmlAttributeValue();
    if (value == null)
        return null;
    final String name = getReferencedName();
    if (name == null) {
        return null;
    }
    final RngGrammar scope = getScope();
    if (scope == null) {
        return null;
    }
    final Set<Define> defines = DefinitionResolver.resolve(scope, name);
    // TODO: honor combine & return virtual element if defines.size() > 1
    return defines != null && defines.size() > 0 ? defines.iterator().next() : null;
}
Also used : Define(org.intellij.plugins.relaxNG.model.Define) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar)

Example 4 with RngGrammar

use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar in project intellij-community by JetBrains.

the class DefinitionReference method getVariants.

@Override
@NotNull
public Object[] getVariants() {
    final RngGrammar scope = getScope();
    if (scope == null) {
        return ResolveResult.EMPTY_ARRAY;
    }
    final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(scope);
    if (map == null || map.size() == 0)
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    return ContainerUtil.mapNotNull(map.values(), defines -> {
        final Define define = defines.iterator().next();
        if (defines.size() == 0) {
            return null;
        } else {
            final PsiElement element = define.getPsiElement();
            if (element != null) {
                final PsiPresentableMetaData data = (PsiPresentableMetaData) ((PsiMetaOwner) element).getMetaData();
                if (data != null) {
                    return LookupValueFactory.createLookupValue(data.getName(), data.getIcon());
                } else {
                    return define.getName();
                }
            } else {
                return define.getName();
            }
        }
    }).toArray();
}
Also used : PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) ArrayUtil(com.intellij.util.ArrayUtil) ContainerUtil(com.intellij.util.containers.ContainerUtil) LookupValueFactory(com.intellij.codeInsight.lookup.LookupValueFactory) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) LocalQuickFixProvider(com.intellij.codeInspection.LocalQuickFixProvider) PsiReferenceBase(com.intellij.psi.PsiReferenceBase) RngParentRef(org.intellij.plugins.relaxNG.xml.dom.RngParentRef) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) Define(org.intellij.plugins.relaxNG.model.Define) XmlTag(com.intellij.psi.xml.XmlTag) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue) Set(java.util.Set) DefinitionResolver(org.intellij.plugins.relaxNG.model.resolve.DefinitionResolver) Nullable(org.jetbrains.annotations.Nullable) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar) Function(com.intellij.util.Function) XmlElement(com.intellij.psi.xml.XmlElement) EmptyResolveMessageProvider(com.intellij.codeInsight.daemon.EmptyResolveMessageProvider) NotNull(org.jetbrains.annotations.NotNull) PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) Set(java.util.Set) Define(org.intellij.plugins.relaxNG.model.Define) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) PsiElement(com.intellij.psi.PsiElement) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with RngGrammar

use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar in project intellij-community by JetBrains.

the class DefinitionReference method multiResolve.

@Override
@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode) {
    final RngGrammar scope = getScope();
    if (scope == null) {
        return ResolveResult.EMPTY_ARRAY;
    }
    final Set<Define> set = DefinitionResolver.resolve(scope, myValue.getValue());
    if (set == null || set.size() == 0)
        return ResolveResult.EMPTY_ARRAY;
    return ContainerUtil.map2Array(set, ResolveResult.class, this);
}
Also used : Define(org.intellij.plugins.relaxNG.model.Define) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RngGrammar (org.intellij.plugins.relaxNG.xml.dom.RngGrammar)6 Define (org.intellij.plugins.relaxNG.model.Define)4 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)3 XmlTag (com.intellij.psi.xml.XmlTag)3 NotNull (org.jetbrains.annotations.NotNull)3 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)2 PsiElement (com.intellij.psi.PsiElement)2 PsiReferenceBase (com.intellij.psi.PsiReferenceBase)2 Map (java.util.Map)2 EmptyResolveMessageProvider (com.intellij.codeInsight.daemon.EmptyResolveMessageProvider)1 LookupValueFactory (com.intellij.codeInsight.lookup.LookupValueFactory)1 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)1 Ref (com.intellij.openapi.util.Ref)1 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)1 PsiReference (com.intellij.psi.PsiReference)1 ResolveResult (com.intellij.psi.ResolveResult)1 XmlElementFactory (com.intellij.psi.XmlElementFactory)1 PsiMetaOwner (com.intellij.psi.meta.PsiMetaOwner)1 PsiPresentableMetaData (com.intellij.psi.meta.PsiPresentableMetaData)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1