Search in sources :

Example 6 with PairedBraceMatcher

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

the class BraceMatchingUtil method getBraceMatcher.

@NotNull
public static BraceMatcher getBraceMatcher(@NotNull FileType fileType, @NotNull Language lang) {
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(lang);
    if (matcher != null) {
        if (matcher instanceof XmlAwareBraceMatcher) {
            return (XmlAwareBraceMatcher) matcher;
        } else if (matcher instanceof PairedBraceMatcherAdapter) {
            return (BraceMatcher) matcher;
        } else {
            return new PairedBraceMatcherAdapter(matcher, lang);
        }
    }
    final BraceMatcher byFileType = getBraceMatcherByFileType(fileType);
    if (byFileType != null)
        return byFileType;
    if (fileType instanceof LanguageFileType) {
        final Language language = ((LanguageFileType) fileType).getLanguage();
        if (lang != language) {
            final FileType type1 = lang.getAssociatedFileType();
            if (type1 != null) {
                final BraceMatcher braceMatcher = getBraceMatcherByFileType(type1);
                if (braceMatcher != null) {
                    return braceMatcher;
                }
            }
            matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
            if (matcher != null) {
                return new PairedBraceMatcherAdapter(matcher, language);
            }
        }
    }
    return BraceMatcherHolder.ourDefaultBraceMatcher;
}
Also used : PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with PairedBraceMatcher

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

Example 8 with PairedBraceMatcher

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

the class XmlBraceMatcher method getBraceTokenGroupId.

@Override
public int getBraceTokenGroupId(IElementType tokenType) {
    final Language l = tokenType.getLanguage();
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(l);
    if (matcher != null) {
        BracePair[] pairs = matcher.getPairs();
        for (BracePair pair : pairs) {
            if (pair.getLeftBraceType() == tokenType || pair.getRightBraceType() == tokenType) {
                return l.hashCode();
            }
        }
    }
    if (tokenType instanceof IXmlLeafElementType) {
        return tokenType == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER || tokenType == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER ? XML_VALUE_DELIMITER_GROUP : XML_TAG_TOKEN_GROUP;
    } else {
        return BraceMatchingUtil.UNDEFINED_TOKEN_GROUP;
    }
}
Also used : PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) Language(com.intellij.lang.Language) IXmlLeafElementType(com.intellij.psi.tree.xml.IXmlLeafElementType) BracePair(com.intellij.lang.BracePair)

Example 9 with PairedBraceMatcher

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

the class XmlBraceMatcher method isPairBraces.

@Override
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;
        }
    }
    if (tokenType2.equals(PAIRING_TOKENS.get(tokenType1)))
        return true;
    List<IElementType> keys = PAIRING_TOKENS.getKeysByValue(tokenType1);
    return keys != null && keys.contains(tokenType2);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) 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