@Nullable
 private static IElementType getClosingBracket(ErrorState state, IElementType type) {
   if (state.braces == null) return null;
   for (BracePair pair : state.braces) {
     if (type == pair.getLeftBraceType()) return pair.getRightBraceType();
   }
   return null;
 }
 private static boolean isBrace(@NotNull PsiElement candidate) {
   final ASTNode node = candidate.getNode();
   if (node != null && node.getFirstChildNode() == null) {
     final PairedBraceMatcher braceMatcher =
         LanguageBraceMatching.INSTANCE.forLanguage(candidate.getLanguage());
     if (braceMatcher != null) {
       final IElementType elementType = node.getElementType();
       for (BracePair pair : braceMatcher.getPairs()) {
         if (elementType == pair.getLeftBraceType() || elementType == pair.getRightBraceType()) {
           return true;
         }
       }
     }
   }
   return false;
 }