void updateBraces() {
    ThreadingAssertions.assertEventDispatchThread();

    clearBraceHighlighters();

    if (!BackgroundHighlightingUtil.needMatching(myEditor, myCodeInsightSettings)) return;

    int offset = myEditor.getCaretModel().getOffset();
    CharSequence chars = myEditor.getDocument().getCharsSequence();

    alarm.cancelAllRequests();

    BraceHighlightingAndNavigationContext context = BraceMatchingUtil.computeHighlightingAndNavigationContext(myEditor, myPsiFile);
    if (context != null) {
      doHighlight(context.currentBraceOffset(), context.isCaretAfterBrace());
      offset = context.currentBraceOffset();
    }
    else if (offset > 0 && offset < chars.length()) {
      // There is a possible case that there are paired braces nearby the caret position and the document contains only white
      // space symbols between them. We want to highlight such braces as well.
      // Example:
      //     public void test() { <caret>
      //     }
      char c = chars.charAt(offset);
      boolean searchForward = c != '\n';

      // Try to find matched brace backwards.
      int backwardNonSpaceEndOffset = CharArrayUtil.shiftBackward(chars, offset - 1, "\t ") + 1;
      if (backwardNonSpaceEndOffset > 0 && backwardNonSpaceEndOffset < offset) {
        context = BraceMatchingUtil.computeHighlightingAndNavigationContext(myEditor, myPsiFile, backwardNonSpaceEndOffset);
        if (context != null) {
          doHighlight(context.currentBraceOffset(), true);
          offset = context.currentBraceOffset();
          searchForward = false;
        }
      }

      // Try to find matched brace forward.
      if (searchForward) {
        int nextNonSpaceCharOffset = CharArrayUtil.shiftForward(chars, offset, "\t ");
        if (nextNonSpaceCharOffset > offset) {
          context = BraceMatchingUtil.computeHighlightingAndNavigationContext(myEditor, myPsiFile, nextNonSpaceCharOffset);
          if (context != null) {
            doHighlight(context.currentBraceOffset(), true);
            offset = context.currentBraceOffset();
          }
        }
      }
    }

    if (myCodeInsightSettings.HIGHLIGHT_SCOPE) {
      highlightScope(offset);
    }
  }
void updateBraces()