Search in sources :

Example 1 with PairedBraceMatcher

use of com.intellij.lang.PairedBraceMatcher in project intellij-community by JetBrains.

the class XmlBraceMatcher method isLBraceToken.

@Override
public boolean isLBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
    final 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)
                return true;
        }
    }
    return tokenType == XmlTokenType.XML_START_TAG_START || tokenType == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER || tokenType == XmlTokenType.XML_CDATA_START;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) BracePair(com.intellij.lang.BracePair)

Example 2 with PairedBraceMatcher

use of com.intellij.lang.PairedBraceMatcher in project intellij-community by JetBrains.

the class XmlBraceMatcher method isRBraceToken.

@Override
public boolean isRBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
    final IElementType tokenType = iterator.getTokenType();
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(tokenType.getLanguage());
    if (matcher != null) {
        BracePair[] pairs = matcher.getPairs();
        for (BracePair pair : pairs) {
            if (pair.getRightBraceType() == tokenType)
                return true;
        }
    }
    if (tokenType == XmlTokenType.XML_EMPTY_ELEMENT_END || tokenType == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER || tokenType == XmlTokenType.XML_CDATA_END) {
        return true;
    } else if (tokenType == XmlTokenType.XML_TAG_END) {
        final boolean result = findEndTagStart(iterator);
        if (isFileTypeWithSingleHtmlTags(fileType)) {
            final String tagName = getTagName(fileText, iterator);
            if (tagName != null && HtmlUtil.isSingleHtmlTag(tagName)) {
                return !result;
            }
        }
        return result;
    } else {
        return false;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) BracePair(com.intellij.lang.BracePair)

Example 3 with PairedBraceMatcher

use of com.intellij.lang.PairedBraceMatcher in project intellij-plugins by JetBrains.

the class CfmlBraceMatcher method isLBraceToken.

public boolean isLBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
    final 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)
                return true;
        }
    }
    if (!tokenType.getLanguage().equals(CfmlLanguage.INSTANCE)) {
        FileType tokenFileType = iterator.getTokenType().getLanguage().getAssociatedFileType();
        if (tokenFileType != null && tokenFileType != CfmlFileType.INSTANCE) {
            for (FileTypeExtensionPoint<BraceMatcher> ext : Extensions.getExtensions(BraceMatcher.EP_NAME)) {
                if (ext.filetype != null && ext.filetype.equals(tokenFileType.getName())) {
                    return ext.getInstance().isLBraceToken(iterator, fileText, tokenFileType instanceof XmlFileType ? StdFileTypes.HTML : tokenFileType);
                }
            }
        }
    }
    for (BracePair pair : PAIRS) {
        if (pair.getLeftBraceType() == tokenType) {
            return true;
        }
    }
    return tokenType.equals(CfmlTokenTypes.OPENER) && (!CfmlUtil.isEndTagRequired(getTagName(fileText, iterator), null) || findEndTag(fileText, iterator));
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) BraceMatcher(com.intellij.codeInsight.highlighting.BraceMatcher) XmlFileType(com.intellij.ide.highlighter.XmlFileType) FileType(com.intellij.openapi.fileTypes.FileType) CfmlFileType(com.intellij.coldFusion.model.files.CfmlFileType) BracePair(com.intellij.lang.BracePair) XmlFileType(com.intellij.ide.highlighter.XmlFileType)

Example 4 with PairedBraceMatcher

use of com.intellij.lang.PairedBraceMatcher in project intellij-plugins by JetBrains.

the class CfmlBraceMatcher method isRBraceToken.

public boolean isRBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
    final IElementType tokenType = iterator.getTokenType();
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(tokenType.getLanguage());
    if (matcher != null) {
        BracePair[] pairs = matcher.getPairs();
        for (BracePair pair : pairs) {
            if (pair.getRightBraceType() == tokenType)
                return true;
        }
    }
    if (!tokenType.getLanguage().equals(CfmlLanguage.INSTANCE)) {
        FileType tokenFileType = iterator.getTokenType().getLanguage().getAssociatedFileType();
        if (tokenFileType != null && tokenFileType != CfmlFileType.INSTANCE) {
            for (FileTypeExtensionPoint<BraceMatcher> ext : Extensions.getExtensions(BraceMatcher.EP_NAME)) {
                if (ext.filetype != null && ext.filetype.equals(tokenFileType.getName())) {
                    return ext.getInstance().isRBraceToken(iterator, fileText, tokenFileType instanceof XmlFileType ? StdFileTypes.HTML : tokenFileType);
                }
            }
        }
    }
    for (BracePair pair : PAIRS) {
        if (pair.getRightBraceType() == tokenType)
            return true;
    }
    return ((tokenType.equals(CfmlTokenTypes.CLOSER)) && findBeginTag(fileText, iterator)) || (tokenType.equals(CfmlTokenTypes.R_ANGLEBRACKET) && !CfmlUtil.isEndTagRequired(getTagName(fileText, iterator), null) && !findEndTag(fileText, iterator));
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) BraceMatcher(com.intellij.codeInsight.highlighting.BraceMatcher) XmlFileType(com.intellij.ide.highlighter.XmlFileType) FileType(com.intellij.openapi.fileTypes.FileType) CfmlFileType(com.intellij.coldFusion.model.files.CfmlFileType) BracePair(com.intellij.lang.BracePair) XmlFileType(com.intellij.ide.highlighter.XmlFileType)

Example 5 with PairedBraceMatcher

use of com.intellij.lang.PairedBraceMatcher in project intellij-plugins by JetBrains.

the class CfmlBraceMatcher method isPairBraces.

public boolean isPairBraces(IElementType tokenType1, IElementType tokenType2) {
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(tokenType1.getLanguage());
    if (matcher != null) {
        BracePair[] pairs = matcher.getPairs();
        for (BracePair pair : pairs) {
            if (pair.getLeftBraceType() == tokenType1)
                return pair.getRightBraceType() == tokenType2;
            if (pair.getRightBraceType() == tokenType1)
                return pair.getLeftBraceType() == tokenType2;
        }
    }
    FileType tokenFileType1 = tokenType1.getLanguage().getAssociatedFileType();
    FileType tokenFileType2 = tokenType2.getLanguage().getAssociatedFileType();
    if (tokenFileType2 != tokenFileType1) {
        return false;
    }
    if (tokenFileType1 != CfmlFileType.INSTANCE && tokenFileType1 != null) {
        for (FileTypeExtensionPoint<BraceMatcher> ext : Extensions.getExtensions(BraceMatcher.EP_NAME)) {
            if (ext.filetype.equals(tokenFileType1.getName())) {
                return ext.getInstance().isPairBraces(tokenType1, tokenType2);
            }
        }
    }
    for (BracePair pair : PAIRS) {
        if (pair.getLeftBraceType() == tokenType1)
            return pair.getRightBraceType() == tokenType2;
        if (pair.getRightBraceType() == tokenType1)
            return pair.getLeftBraceType() == tokenType2;
    }
    return (tokenType1.equals(CfmlTokenTypes.OPENER) && tokenType2.equals(CfmlTokenTypes.CLOSER)) || (tokenType1.equals(CfmlTokenTypes.CLOSER) && tokenType2.equals(CfmlTokenTypes.OPENER)) || (tokenType1.equals(CfmlTokenTypes.R_ANGLEBRACKET) && tokenType2.equals(CfmlTokenTypes.OPENER)) || (tokenType1.equals(CfmlTokenTypes.OPENER) && tokenType2.equals(CfmlTokenTypes.R_ANGLEBRACKET));
}
Also used : PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) BraceMatcher(com.intellij.codeInsight.highlighting.BraceMatcher) XmlFileType(com.intellij.ide.highlighter.XmlFileType) FileType(com.intellij.openapi.fileTypes.FileType) CfmlFileType(com.intellij.coldFusion.model.files.CfmlFileType) BracePair(com.intellij.lang.BracePair)

Aggregations

PairedBraceMatcher (com.intellij.lang.PairedBraceMatcher)9 BracePair (com.intellij.lang.BracePair)8 IElementType (com.intellij.psi.tree.IElementType)6 FileType (com.intellij.openapi.fileTypes.FileType)4 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)3 CfmlFileType (com.intellij.coldFusion.model.files.CfmlFileType)3 XmlFileType (com.intellij.ide.highlighter.XmlFileType)3 Language (com.intellij.lang.Language)2 XmlLikeFileType (com.intellij.ide.highlighter.XmlLikeFileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 IXmlLeafElementType (com.intellij.psi.tree.xml.IXmlLeafElementType)1 NotNull (org.jetbrains.annotations.NotNull)1