Search in sources :

Example 11 with XmlTag

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

the class HtmlLocalInspectionTool method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new XmlElementVisitor() {

        @Override
        public void visitXmlToken(final XmlToken token) {
            IElementType tokenType = token.getTokenType();
            if (tokenType == XmlTokenType.XML_NAME || tokenType == XmlTokenType.XML_TAG_NAME) {
                PsiElement element = token.getPrevSibling();
                while (element instanceof PsiWhiteSpace) element = element.getPrevSibling();
                if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_START_TAG_START) {
                    PsiElement parent = element.getParent();
                    if (parent instanceof XmlTag && !(token.getNextSibling() instanceof OuterLanguageElement)) {
                        XmlTag tag = (XmlTag) parent;
                        checkTag(tag, holder, isOnTheFly);
                    }
                }
            }
        }

        @Override
        public void visitXmlAttribute(final XmlAttribute attribute) {
            checkAttribute(attribute, holder, isOnTheFly);
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) IElementType(com.intellij.psi.tree.IElementType) OuterLanguageElement(com.intellij.psi.templateLanguages.OuterLanguageElement) XmlAttribute(com.intellij.psi.xml.XmlAttribute) PsiElement(com.intellij.psi.PsiElement) XmlToken(com.intellij.psi.xml.XmlToken) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with XmlTag

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

the class IdRefReference method getIdValue.

@Nullable
protected String getIdValue(final PsiElement element) {
    if (element instanceof XmlTag) {
        final XmlTag tag = (XmlTag) element;
        String s = tag.getAttributeValue(IdReferenceProvider.ID_ATTR_NAME);
        if (!myIdAttrsOnly) {
            if (s == null)
                s = tag.getAttributeValue(IdReferenceProvider.NAME_ATTR_NAME);
            if (s == null)
                s = tag.getAttributeValue(IdReferenceProvider.STYLE_ID_ATTR_NAME);
        }
        return s != null ? s : getImplicitIdRefValue(tag);
    } else if (element instanceof PsiComment) {
        return getImplicitIdValue((PsiComment) element);
    }
    return null;
}
Also used : PsiComment(com.intellij.psi.PsiComment) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with XmlTag

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

the class IdRefReference method getIdValueElement.

@Nullable
protected PsiElement getIdValueElement(PsiElement element) {
    if (element instanceof XmlTag) {
        final XmlTag tag = (XmlTag) element;
        XmlAttribute attribute = tag.getAttribute(IdReferenceProvider.ID_ATTR_NAME, null);
        if (!myIdAttrsOnly) {
            if (attribute == null) {
                attribute = tag.getAttribute(IdReferenceProvider.NAME_ATTR_NAME, null);
            }
            if (attribute == null) {
                attribute = tag.getAttribute(IdReferenceProvider.STYLE_ID_ATTR_NAME, null);
            }
        }
        return attribute != null ? attribute.getValueElement() : getImplicitIdRefValueElement(tag);
    } else {
        return element;
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with XmlTag

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

the class CheckEmptyTagInspection method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new XmlElementVisitor() {

        @Override
        public void visitXmlTag(final XmlTag tag) {
            if (!isTagWithEmptyEndNotAllowed(tag)) {
                return;
            }
            final ASTNode child = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(tag.getNode());
            if (child == null) {
                return;
            }
            final LocalQuickFix fix = new MyLocalQuickFix();
            holder.registerProblem(tag, XmlBundle.message("html.inspections.check.empty.script.message"), tag.getContainingFile().getContext() != null ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fix);
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) ASTNode(com.intellij.lang.ASTNode) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with XmlTag

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

the class XmlConstraintsTest method configure.

private Map<String, XmlElementDescriptor> configure(String... files) {
    myFixture.configureByFiles(files);
    XmlTag tag = ((XmlFile) getFile()).getRootTag();
    assertNotNull(tag);
    XmlElementDescriptor descriptor = tag.getDescriptor();
    assertNotNull(descriptor);
    XmlElementDescriptor[] descriptors = descriptor.getElementsDescriptors(tag);
    Map<String, XmlElementDescriptor> map = ContainerUtil.newMapFromValues(Arrays.asList(descriptors).iterator(), new Convertor<XmlElementDescriptor, String>() {

        @Override
        public String convert(XmlElementDescriptor o) {
            return o.getName();
        }
    });
    map.put(tag.getName(), tag.getDescriptor());
    return map;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlTag (com.intellij.psi.xml.XmlTag)673 XmlFile (com.intellij.psi.xml.XmlFile)151 PsiElement (com.intellij.psi.PsiElement)130 XmlAttribute (com.intellij.psi.xml.XmlAttribute)121 Nullable (org.jetbrains.annotations.Nullable)99 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)89 NotNull (org.jetbrains.annotations.NotNull)89 PsiFile (com.intellij.psi.PsiFile)71 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)52 VirtualFile (com.intellij.openapi.vfs.VirtualFile)50 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)50 Project (com.intellij.openapi.project.Project)48 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)47 ArrayList (java.util.ArrayList)43 XmlDocument (com.intellij.psi.xml.XmlDocument)39 DomElement (com.intellij.util.xml.DomElement)35 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 TextRange (com.intellij.openapi.util.TextRange)32 Result (com.intellij.openapi.application.Result)24 Document (com.intellij.openapi.editor.Document)24