Search in sources :

Example 1 with XmlLikeFileType

use of com.intellij.ide.highlighter.XmlLikeFileType in project intellij-community by JetBrains.

the class BaseProcessor method process.

public boolean process(VirtualFile t) {
    myIndicator.checkCanceled();
    final FileType fileType = t.getFileType();
    if (fileType instanceof XmlLikeFileType) {
        processXmlFile(t);
    }
    return true;
}
Also used : XmlLikeFileType(com.intellij.ide.highlighter.XmlLikeFileType) FileType(com.intellij.openapi.fileTypes.FileType) XmlLikeFileType(com.intellij.ide.highlighter.XmlLikeFileType)

Example 2 with XmlLikeFileType

use of com.intellij.ide.highlighter.XmlLikeFileType in project intellij-community by JetBrains.

the class CheckValidXmlInScriptBodyInspectionBase method buildVisitor.

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

        @Override
        public void visitXmlTag(final XmlTag tag) {
            if (HtmlUtil.isHtmlTag(tag))
                return;
            if (HtmlUtil.SCRIPT_TAG_NAME.equals(tag.getName()) || tag instanceof HtmlTag && HtmlUtil.SCRIPT_TAG_NAME.equalsIgnoreCase(tag.getName())) {
                final PsiFile psiFile = tag.getContainingFile();
                final FileType fileType = psiFile.getFileType();
                if (fileType instanceof XmlLikeFileType) {
                    synchronized (CheckValidXmlInScriptBodyInspectionBase.class) {
                        if (myXmlLexer == null)
                            myXmlLexer = new XmlLexer();
                        final XmlTagValue tagValue = tag.getValue();
                        final String tagBodyText = tagValue.getText();
                        if (!tagBodyText.isEmpty()) {
                            myXmlLexer.start(tagBodyText);
                            while (myXmlLexer.getTokenType() != null) {
                                IElementType tokenType = myXmlLexer.getTokenType();
                                if (tokenType == XmlTokenType.XML_CDATA_START) {
                                    while (tokenType != null && tokenType != XmlTokenType.XML_CDATA_END) {
                                        myXmlLexer.advance();
                                        tokenType = myXmlLexer.getTokenType();
                                    }
                                    if (tokenType == null)
                                        break;
                                }
                                if (tokenType == XmlTokenType.XML_BAD_CHARACTER && "&".equals(TreeUtil.getTokenText(myXmlLexer)) || tokenType == XmlTokenType.XML_START_TAG_START) {
                                    final int valueStart = tagValue.getTextRange().getStartOffset();
                                    final int offset = valueStart + myXmlLexer.getTokenStart();
                                    final PsiElement psiElement = psiFile.findElementAt(offset);
                                    final TextRange elementRange = psiElement.getTextRange();
                                    final int offsetInElement = offset - elementRange.getStartOffset();
                                    holder.registerProblem(psiElement, XmlBundle.message("unescaped.xml.character"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, createFix(psiElement, offsetInElement));
                                    int endOfElementInScriptTag = elementRange.getEndOffset() - valueStart;
                                    while (myXmlLexer.getTokenEnd() < endOfElementInScriptTag) {
                                        myXmlLexer.advance();
                                        if (myXmlLexer.getTokenType() == null)
                                            break;
                                    }
                                }
                                myXmlLexer.advance();
                            }
                        }
                    }
                }
            }
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) XmlTagValue(com.intellij.psi.xml.XmlTagValue) XmlLikeFileType(com.intellij.ide.highlighter.XmlLikeFileType) HtmlTag(com.intellij.psi.html.HtmlTag) TextRange(com.intellij.openapi.util.TextRange) XmlLexer(com.intellij.lexer.XmlLexer) IElementType(com.intellij.psi.tree.IElementType) FileType(com.intellij.openapi.fileTypes.FileType) XmlLikeFileType(com.intellij.ide.highlighter.XmlLikeFileType) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with XmlLikeFileType

use of com.intellij.ide.highlighter.XmlLikeFileType in project intellij-community by JetBrains.

the class XmlBraceMatcher method isStructuralBrace.

@Override
public boolean isStructuralBrace(HighlighterIterator iterator, CharSequence text, FileType fileType) {
    IElementType tokenType = iterator.getTokenType();
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(tokenType.getLanguage());
    if (matcher != null) {
        BracePair[] pairs = matcher.getPairs();
        for (BracePair pair : pairs) {
            if ((pair.getLeftBraceType() == tokenType || pair.getRightBraceType() == tokenType) && pair.isStructural())
                return true;
        }
    }
    if (fileType instanceof XmlLikeFileType) {
        return isXmlStructuralBrace(iterator, text, fileType, tokenType);
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) XmlLikeFileType(com.intellij.ide.highlighter.XmlLikeFileType) BracePair(com.intellij.lang.BracePair)

Aggregations

XmlLikeFileType (com.intellij.ide.highlighter.XmlLikeFileType)3 FileType (com.intellij.openapi.fileTypes.FileType)2 IElementType (com.intellij.psi.tree.IElementType)2 BracePair (com.intellij.lang.BracePair)1 PairedBraceMatcher (com.intellij.lang.PairedBraceMatcher)1 XmlLexer (com.intellij.lexer.XmlLexer)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 XmlElementVisitor (com.intellij.psi.XmlElementVisitor)1 HtmlTag (com.intellij.psi.html.HtmlTag)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlTagValue (com.intellij.psi.xml.XmlTagValue)1 NotNull (org.jetbrains.annotations.NotNull)1