@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; } }
@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; }
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; } }
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; }
@Override public IElementType getOppositeBraceTokenType(@NotNull final IElementType type) { PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(type.getLanguage()); if(matcher != null) { BracePair[] pairs = matcher.getPairs(); for(BracePair pair : pairs) { if(pair.getLeftBraceType() == type) { return pair.getRightBraceType(); } if(pair.getRightBraceType() == type) { return pair.getLeftBraceType(); } } } return null; }
public PlayBaseTemplateBraceMatcher() { super(new PairedBraceMatcher() { @Override public BracePair[] getPairs() { return new BracePair[0]; } @Override public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) { return true; } @Override public int getCodeConstructStart(PsiFile file, int openingBraceOffset) { return openingBraceOffset; } }, PlayBaseTemplateLanguage.INSTANCE); }
@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; }
@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; }
@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; } }
@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); }
@Override public IElementType getOppositeBraceTokenType(@NotNull final IElementType type) { PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(type.getLanguage()); if (matcher != null) { BracePair[] pairs = matcher.getPairs(); for (BracePair pair : pairs) { if (pair.getLeftBraceType() == type ) return pair.getRightBraceType(); if (pair.getRightBraceType() == type ) return pair.getLeftBraceType(); } } return null; }
public DbPairedBraceMatcher() { super(new PairedBraceMatcher() { @Override public BracePair[] getPairs() { return BRACE_PAIRS; } @Override public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) { // TODO: improve this. return true; } @Override public int getCodeConstructStart(PsiFile file, int openingBraceOffset) { PsiElement element = file.findElementAt(openingBraceOffset); if (element == null || element instanceof PsiFile) { return openingBraceOffset; } PsiElement parent = element.getParent(); if (parent instanceof PsiDbCastExpr || parent instanceof PsiDbParenExpr) { return openingBraceOffset; } if (parent instanceof PsiDbMethodExpr) { return parent.getTextRange().getStartOffset(); } if (parent instanceof PsiDbResourceParameters) { parent = parent.getParent(); if (parent instanceof PsiDbResourcesExpr) { return parent.getTextRange().getStartOffset(); } } return openingBraceOffset; } }, DbLanguage.INSTANCE); }
@NotNull public static BraceMatcher getBraceMatcher(FileType fileType, Language lang) { PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(lang); if (matcher != null) { if (matcher instanceof XmlAwareBraceMatcher) { return (XmlAwareBraceMatcher)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; }
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; }
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; } }
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); }
public IElementType getOppositeBraceTokenType(@NotNull final IElementType type) { PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(type.getLanguage()); if (matcher != null) { BracePair[] pairs = matcher.getPairs(); for (BracePair pair : pairs) { if (pair.getLeftBraceType() == type ) return pair.getRightBraceType(); if (pair.getRightBraceType() == type ) return pair.getLeftBraceType(); } } return null; }
@Nonnull public static BraceMatcher getBraceMatcher(@Nonnull FileType fileType, @Nonnull Language lang) { PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(lang); if (matcher != null) { if (matcher instanceof XmlAwareBraceMatcher) { return (XmlAwareBraceMatcher)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; }
public PairedBraceMatcherAdapter(final PairedBraceMatcher matcher, Language language) { myMatcher = matcher; myLanguage = language; }