Search in sources :

Example 1 with XmlAttributeImpl

use of com.intellij.psi.impl.source.xml.XmlAttributeImpl in project intellij-plugins by JetBrains.

the class MxmlLanguageTagsUtil method addErrorMessage.

private static void addErrorMessage(final XmlElement element, final String message, final Validator.ValidationHost host, @NotNull IntentionAction... intentionActions) {
    PsiElement target = element;
    PsiElement secondaryTarget = null;
    if (element instanceof XmlAttributeValue) {
        final ASTNode node = element.getNode();
        final ASTNode value = node == null ? null : XmlChildRole.ATTRIBUTE_VALUE_VALUE_FINDER.findChild(node);
        if (value instanceof PsiElement) {
            target = (PsiElement) value;
        }
    } else if (element instanceof XmlAttributeImpl) {
        target = ((XmlAttributeImpl) element).getNameElement();
    } else if (element instanceof XmlTag) {
        target = XmlTagUtil.getStartTagNameElement((XmlTag) element);
        secondaryTarget = XmlTagUtil.getEndTagNameElement((XmlTag) element);
    }
    if (host instanceof IdeValidationHost) {
        if (target != null) {
            ((IdeValidationHost) host).addMessageWithFixes(target, message, Validator.ValidationHost.ErrorType.ERROR, intentionActions);
        }
        if (secondaryTarget != null) {
            ((IdeValidationHost) host).addMessageWithFixes(secondaryTarget, message, Validator.ValidationHost.ErrorType.ERROR, intentionActions);
        }
    } else {
        if (target != null) {
            host.addMessage(target, message, Validator.ValidationHost.ErrorType.ERROR);
        }
        if (secondaryTarget != null) {
            host.addMessage(secondaryTarget, message, Validator.ValidationHost.ErrorType.ERROR);
        }
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) XmlAttributeImpl(com.intellij.psi.impl.source.xml.XmlAttributeImpl) IdeValidationHost(com.intellij.codeInsight.daemon.IdeValidationHost) PsiElement(com.intellij.psi.PsiElement)

Example 2 with XmlAttributeImpl

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

the class NSDeclTracker method queryCount.

@SuppressWarnings({ "AutoUnboxing" })
private synchronized long queryCount() {
    for (XmlAttribute decl : myNSDecls) {
        if (!decl.isValid()) {
            return update();
        }
        final Integer modCount = decl.getUserData(MOD_COUNT);
        if (modCount != null && ((XmlAttributeImpl) decl).getModificationCount() != modCount) {
            return update();
        }
    }
    final ArrayList<XmlAttribute> list = getNSDecls(false);
    if (!list.equals(myNSDecls)) {
        return update();
    }
    myRootCount = myRootTag.getModificationCount();
    return myCount;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeImpl(com.intellij.psi.impl.source.xml.XmlAttributeImpl)

Example 3 with XmlAttributeImpl

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

the class XmlAttributeReferenceCompletionProvider method addVariants.

private static void addVariants(final CompletionResultSet result, final XmlAttribute[] attributes, final XmlAttributeDescriptor[] descriptors, XmlAttribute attribute, @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
    final XmlTag tag = attribute.getParent();
    final PsiFile file = tag.getContainingFile();
    final XmlExtension extension = XmlExtension.getExtension(file);
    final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0 ? attribute.getNamespacePrefix() + ":" : null;
    for (XmlAttributeDescriptor descriptor : descriptors) {
        if (isValidVariant(attribute, descriptor, attributes, extension)) {
            String name = descriptor.getName(tag);
            InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;
            if (tag instanceof HtmlTag && HtmlUtil.isShortNotationOfBooleanAttributePreferred() && HtmlUtil.isBooleanAttribute(descriptor, tag)) {
                insertHandler = null;
            }
            if (replacementInsertHandler != null) {
                insertHandler = replacementInsertHandler;
            } else if (descriptor instanceof NamespaceAwareXmlAttributeDescriptor) {
                final String namespace = ((NamespaceAwareXmlAttributeDescriptor) descriptor).getNamespace(tag);
                if (file instanceof XmlFile && namespace != null && namespace.length() > 0 && !name.contains(":") && tag.getPrefixByNamespace(namespace) == null) {
                    insertHandler = new XmlAttributeInsertHandler(namespace);
                }
            }
            if (prefix == null || name.startsWith(prefix)) {
                if (prefix != null && name.length() > prefix.length()) {
                    name = descriptor.getName(tag).substring(prefix.length());
                }
                LookupElementBuilder element = LookupElementBuilder.create(name);
                if (descriptor instanceof PsiPresentableMetaData) {
                    element = element.withIcon(((PsiPresentableMetaData) descriptor).getIcon());
                }
                final int separator = name.indexOf(':');
                if (separator > 0) {
                    element = element.withLookupString(name.substring(separator + 1));
                }
                element = element.withCaseSensitivity(!(descriptor instanceof HtmlAttributeDescriptorImpl)).withInsertHandler(insertHandler);
                result.addElement(descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) : HtmlUtil.isOwnHtmlAttribute(descriptor) ? PrioritizedLookupElement.withPriority(element, 50) : element);
            }
        }
    }
}
Also used : HtmlAttributeDescriptorImpl(com.intellij.psi.impl.source.html.dtd.HtmlAttributeDescriptorImpl) XmlFile(com.intellij.psi.xml.XmlFile) HtmlTag(com.intellij.psi.html.HtmlTag) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) XmlExtension(com.intellij.xml.XmlExtension) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) NamespaceAwareXmlAttributeDescriptor(com.intellij.xml.NamespaceAwareXmlAttributeDescriptor) NamespaceAwareXmlAttributeDescriptor(com.intellij.xml.NamespaceAwareXmlAttributeDescriptor) XmlAttributeImpl(com.intellij.psi.impl.source.xml.XmlAttributeImpl) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiFile(com.intellij.psi.PsiFile) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlAttributeImpl (com.intellij.psi.impl.source.xml.XmlAttributeImpl)3 IdeValidationHost (com.intellij.codeInsight.daemon.IdeValidationHost)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 ASTNode (com.intellij.lang.ASTNode)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 HtmlTag (com.intellij.psi.html.HtmlTag)1 HtmlAttributeDescriptorImpl (com.intellij.psi.impl.source.html.dtd.HtmlAttributeDescriptorImpl)1 PsiPresentableMetaData (com.intellij.psi.meta.PsiPresentableMetaData)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 NamespaceAwareXmlAttributeDescriptor (com.intellij.xml.NamespaceAwareXmlAttributeDescriptor)1 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)1 XmlExtension (com.intellij.xml.XmlExtension)1