Search in sources :

Example 1 with BracePair

use of com.intellij.lang.BracePair in project intellij-elixir by KronicDeth.

the class NonTrivial method findPair.

@Nullable
@Override
public BracePair findPair(boolean left, HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
    BracePair pair = super.findPair(left, iterator, fileText, fileType);
    if (pair == Paired.DO_END || pair == Paired.FN_END) {
        iterator.advance();
        if (!iterator.atEnd()) {
            IElementType tokenType = iterator.getTokenType();
            if (tokenType == ElixirTypes.KEYWORD_PAIR_COLON) {
                pair = null;
            }
        }
        iterator.retreat();
    }
    return pair;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) BracePair(com.intellij.lang.BracePair) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with BracePair

use of com.intellij.lang.BracePair 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 3 with BracePair

use of com.intellij.lang.BracePair 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 4 with BracePair

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

the class JavaPairedBraceMatcher method isBrace.

private boolean isBrace(HighlighterIterator iterator, CharSequence fileText, FileType fileType, boolean left) {
    final BracePair pair = findPair(left, iterator, fileText, fileType);
    if (pair == null)
        return false;
    final IElementType opposite = left ? JavaTokenType.GT : JavaTokenType.LT;
    if ((left ? pair.getRightBraceType() : pair.getLeftBraceType()) != opposite)
        return true;
    if (fileType != JavaFileType.INSTANCE)
        return false;
    final IElementType braceElementType = left ? JavaTokenType.LT : JavaTokenType.GT;
    int count = 0;
    try {
        int paired = 1;
        while (true) {
            count++;
            if (left) {
                iterator.advance();
            } else {
                iterator.retreat();
            }
            if (iterator.atEnd())
                break;
            final IElementType tokenType = iterator.getTokenType();
            if (tokenType == opposite) {
                paired--;
                if (paired == 0)
                    return true;
                continue;
            }
            if (tokenType == braceElementType) {
                paired++;
                continue;
            }
            if (!Holder.TYPE_TOKENS.contains(tokenType)) {
                return false;
            }
        }
        return false;
    } finally {
        while (count-- > 0) {
            if (left) {
                iterator.retreat();
            } else {
                iterator.advance();
            }
        }
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) BracePair(com.intellij.lang.BracePair)

Example 5 with BracePair

use of com.intellij.lang.BracePair 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)

Aggregations

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