Java Code Examples for com.intellij.openapi.editor.highlighter.HighlighterIterator#atEnd()

The following examples show how to use com.intellij.openapi.editor.highlighter.HighlighterIterator#atEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSharpQuoteHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isOpeningQuote(HighlighterIterator iterator, int offset)
{
	boolean openingQuote = super.isOpeningQuote(iterator, offset);

	if(openingQuote)
	{
		// check escape next
		if(!iterator.atEnd())
		{
			iterator.retreat();

			if(!iterator.atEnd() && StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(iterator.getTokenType()))
			{
				openingQuote = false;
			}
			iterator.advance();
		}
	}
	return openingQuote;
}
 
Example 2
Source File: CSharpQuoteHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isClosingQuote(HighlighterIterator iterator, int offset)
{
	boolean closingQuote = super.isClosingQuote(iterator, offset);

	if(closingQuote)
	{
		// check escape next
		if(!iterator.atEnd())
		{
			iterator.advance();

			if(!iterator.atEnd() && StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(iterator.getTokenType()))
			{
				closingQuote = false;
			}
			iterator.retreat();
		}
	}
	return closingQuote;
}
 
Example 3
Source File: XQueryQuoteHandler.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
@Override
public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) {
    int start = iterator.getStart();
    try {
        Document doc = editor.getDocument();
        CharSequence chars = doc.getCharsSequence();
        int lineEnd = doc.getLineEndOffset(doc.getLineNumber(offset));

        while (!iterator.atEnd() && iterator.getStart() < lineEnd) {
            IElementType tokenType = iterator.getTokenType();

            if (myLiteralTokenSet.contains(tokenType)) {
                if (isNonClosedLiteral(iterator, chars)) return true;
            }
            iterator.advance();
        }
    }
    finally {
        while(iterator.atEnd() || iterator.getStart() != start) iterator.retreat();
    }

    return false;
}
 
Example 4
Source File: SimpleTokenSetQuoteHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) {
  int start = iterator.getStart();
  try {
    Document doc = editor.getDocument();
    CharSequence chars = doc.getCharsSequence();
    int lineEnd = doc.getLineEndOffset(doc.getLineNumber(offset));

    while (!iterator.atEnd() && iterator.getStart() < lineEnd) {
      IElementType tokenType = iterator.getTokenType();

      if (myLiteralTokenSet.contains(tokenType)) {
        if (isNonClosedLiteral(iterator, chars)) return true;
      }
      iterator.advance();
    }
  }
  finally {
    while(iterator.atEnd() || iterator.getStart() != start) iterator.retreat();
  }

  return false;
}
 
Example 5
Source File: ToggleCaseAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static String toCase(Editor editor, int startOffset, int endOffset, final boolean lower) {
  CharSequence text = editor.getDocument().getImmutableCharSequence();
  EditorHighlighter highlighter;
  if (editor instanceof EditorEx) {
    highlighter = ((EditorEx)editor).getHighlighter();
  }
  else {
    highlighter = new EmptyEditorHighlighter(null);
    highlighter.setText(text);
  }
  HighlighterIterator iterator = highlighter.createIterator(startOffset);
  StringBuilder builder = new StringBuilder(endOffset - startOffset);
  while (!iterator.atEnd()) {
    int start = trim(iterator.getStart(), startOffset, endOffset);
    int end = trim(iterator.getEnd(), startOffset, endOffset);
    CharSequence fragment = text.subSequence(start, end);

    builder.append(iterator.getTokenType() == VALID_STRING_ESCAPE_TOKEN ? fragment :
                   lower ? fragment.toString().toLowerCase(Locale.getDefault()) :
                   fragment.toString().toUpperCase(Locale.getDefault()));

    if (end == endOffset) break;
    iterator.advance();
  }
  return builder.toString();
}
 
Example 6
Source File: BraceMatchingUtilAdapter.java    From HighlightBracketPair with Apache License 2.0 5 votes vote down vote up
/**
 * find the right closest brace offset position
 *
 * @param iterator highlight iterator
 * @param rparenTokenType right token type to paired
 * @param fileText file text
 * @param fileType file type
 * @return offset
 */
public static int findRightRParen(HighlighterIterator iterator,
                                  IElementType rparenTokenType,
                                  CharSequence fileText,
                                  FileType fileType, boolean isBlockCaret) {
    int lastRbraceOffset = -1;
    int initOffset = iterator.atEnd() ? -1 : iterator.getStart();
    Stack<IElementType> braceStack = new Stack<>();
    for (; !iterator.atEnd(); iterator.advance()) {
        final IElementType tokenType = iterator.getTokenType();

        if (isRBraceToken(iterator, fileText, fileType)) {
            if (!braceStack.isEmpty()) {
                IElementType topToken = braceStack.pop();
                if (!isPairBraces(tokenType, topToken, fileType)) {
                    break; // unmatched braces
                }
            } else {
                if (tokenType == rparenTokenType) {
                    return iterator.getStart();
                } else {
                    break;
                }
            }
        } else if (isLBraceToken(iterator, fileText, fileType)) {
            if (isBlockCaret && initOffset == iterator.getStart())
                continue;
            else
                braceStack.push(iterator.getTokenType());
        }
    }

    return lastRbraceOffset;
}
 
Example 7
Source File: TypedHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isInsideLiteral(@Nonnull Editor editor, @Nonnull QuoteHandler quoteHandler, int offset) {
  if (offset == 0) return false;

  HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset - 1);
  if (iterator.atEnd()) {
    LOG.assertTrue(false);
    return false;
  }

  return quoteHandler.isInsideLiteral(iterator);
}
 
Example 8
Source File: TypedHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isClosingQuote(@Nonnull Editor editor, @Nonnull QuoteHandler quoteHandler, int offset) {
  HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset);
  if (iterator.atEnd()) {
    LOG.assertTrue(false);
    return false;
  }

  return quoteHandler.isClosingQuote(iterator, offset);
}
 
Example 9
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void doHighlight(int offset, int originalOffset, @Nonnull FileType fileType) {
  if (myEditor.getFoldingModel().isOffsetCollapsed(offset)) return;

  HighlighterIterator iterator = getEditorHighlighter().createIterator(offset);
  final CharSequence chars = myDocument.getCharsSequence();

  if (BraceMatchingUtil.isLBraceToken(iterator, chars, fileType)) {
    IElementType tokenType = iterator.getTokenType();

    iterator.advance();
    if (!iterator.atEnd() && BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) {
      if (BraceMatchingUtil.isPairBraces(tokenType, iterator.getTokenType(), fileType) &&
          originalOffset == iterator.getStart()) return;
    }

    iterator.retreat();
    highlightLeftBrace(iterator, false, fileType);

    if (offset > 0) {
      iterator = getEditorHighlighter().createIterator(offset - 1);
      if (BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) {
        highlightRightBrace(iterator, fileType);
      }
    }
  }
  else if (BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) {
    highlightRightBrace(iterator, fileType);
  }
}
 
Example 10
Source File: CustomFileTypeQuoteHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) {
  try {
    Document doc = editor.getDocument();
    CharSequence chars = doc.getCharsSequence();
    int lineEnd = doc.getLineEndOffset(doc.getLineNumber(offset));

    while (!iterator.atEnd() && iterator.getStart() < lineEnd) {
      IElementType tokenType = iterator.getTokenType();

      if (tokenType == CustomHighlighterTokenType.STRING ||
          tokenType == CustomHighlighterTokenType.SINGLE_QUOTED_STRING ||
          tokenType == CustomHighlighterTokenType.CHARACTER) {

        if (iterator.getStart() >= iterator.getEnd() - 1 ||
            chars.charAt(iterator.getEnd() - 1) != '\"' && chars.charAt(iterator.getEnd() - 1) != '\'') {
          return true;
        }
      }
      iterator.advance();
    }
  } finally {
    while (!iterator.atEnd() && iterator.getStart() != offset) iterator.retreat();
  }

  return false;
}
 
Example 11
Source File: BraceMatchingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static int findRightmostRParen(HighlighterIterator iterator,
                                      IElementType rparenTokenType,
                                      CharSequence fileText,
                                      FileType fileType) {
  int lastRbraceOffset = -1;

  Stack<IElementType> braceStack = new Stack<IElementType>();
  for (; !iterator.atEnd(); iterator.advance()) {
    final IElementType tokenType = iterator.getTokenType();

    if (isRBraceToken(iterator, fileText, fileType)) {
      if (!braceStack.isEmpty()) {
        IElementType topToken = braceStack.pop();
        if (!isPairBraces(tokenType, topToken, fileType)) {
          break; // unmatched braces
        }
      }
      else {
        if (tokenType == rparenTokenType) {
          lastRbraceOffset = iterator.getStart();
        }
        else {
          break;
        }
      }
    }
    else if (isLBraceToken(iterator, fileText, fileType)) {
      braceStack.push(iterator.getTokenType());
    }
  }

  return lastRbraceOffset;
}
 
Example 12
Source File: EditorPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void paintBorderEffect(EditorHighlighter highlighter) {
  HighlighterIterator it = highlighter.createIterator(myStartOffset);
  while (!it.atEnd() && it.getStart() < myEndOffset) {
    TextAttributes attributes = it.getTextAttributes();
    EffectDescriptor borderDescriptor = getBorderDescriptor(attributes);
    if (borderDescriptor != null) {
      paintBorderEffect(it.getStart(), it.getEnd(), borderDescriptor);
    }
    it.advance();
  }
}
 
Example 13
Source File: TypedHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static CharSequence getClosingQuote(@Nonnull Editor editor, @Nonnull MultiCharQuoteHandler quoteHandler, int offset) {
  HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset);
  if (iterator.atEnd()) {
    LOG.assertTrue(false);
    return null;
  }

  return quoteHandler.getClosingQuote(iterator, offset);
}
 
Example 14
Source File: CodeBlockUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static int calcBlockEndOffset(Editor editor, PsiFile file) {

    Document document = editor.getDocument();
    int offset = editor.getCaretModel().getOffset();
    final FileType fileType = file.getFileType();
    HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset);
    if (iterator.atEnd()) return -1;

    int depth = 0;
    Language braceType;
    boolean isBeforeLBrace = false;
    if (isLStructuralBrace(fileType, iterator, document.getCharsSequence())) {
      isBeforeLBrace = true;
      depth = -1;
      braceType = getBraceType(iterator);
    } else {
      braceType = null;
    }

    boolean moved = false;
    while (true) {
      if (iterator.atEnd()) return -1;

      if (isRStructuralBrace(fileType, iterator,document.getCharsSequence()) &&
          ( braceType == getBraceType(iterator) ||
            braceType == null
          )
          ) {
        if (moved) {
          if (depth == 0) break;
          depth--;
        }

        if (braceType == null) {
          braceType = getBraceType(iterator);
        }
      }
      else if (isLStructuralBrace(fileType, iterator,document.getCharsSequence()) &&
               ( braceType == getBraceType(iterator) ||
                 braceType == null
               )
              ) {
        if (braceType == null) {
          braceType = getBraceType(iterator);
        }
        depth++;
      }

      moved = true;
      iterator.advance();
    }

    return isBeforeLBrace? iterator.getEnd() : iterator.getStart();
  }
 
Example 15
Source File: InjectionRegistrarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static List<InjectedLanguageUtil.TokenInfo> obtainHighlightTokensFromLexer(@Nonnull LanguageVersion languageVersion,
                                                                                   @Nonnull CharSequence outChars,
                                                                                   @Nonnull VirtualFileWindow virtualFile,
                                                                                   @Nonnull Project project,
                                                                                   @Nonnull List<? extends PlaceInfo> placeInfos) {
  VirtualFile file = (VirtualFile)virtualFile;
  FileType fileType = file.getFileType();
  EditorHighlighterProvider provider = FileTypeEditorHighlighterProviders.INSTANCE.forFileType(fileType);
  EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  EditorHighlighter highlighter = provider.getEditorHighlighter(project, fileType, file, scheme);
  highlighter.setText(outChars);
  HighlighterIterator iterator = highlighter.createIterator(0);
  int hostNum = -1;
  int prevHostEndOffset = 0;
  LiteralTextEscaper escaper = null;
  int prefixLength = 0;
  int suffixLength = 0;
  TextRange rangeInsideHost = null;
  int shredEndOffset = -1;
  List<InjectedLanguageUtil.TokenInfo> tokens = new ArrayList<>(outChars.length() / 5); // avg. token per 5 chars
  while (!iterator.atEnd()) {
    IElementType tokenType = iterator.getTokenType();
    TextRange range = new ProperTextRange(iterator.getStart(), iterator.getEnd());
    while (range != null && !range.isEmpty()) {
      if (range.getStartOffset() >= shredEndOffset) {
        hostNum++;
        PlaceInfo info = placeInfos.get(hostNum);
        shredEndOffset = info.rangeInDecodedPSI.getEndOffset();
        prevHostEndOffset = range.getStartOffset();
        escaper = info.myEscaper;
        rangeInsideHost = info.rangeInHostElement;
        prefixLength = info.prefix.length();
        suffixLength = info.suffix.length();
      }
      //in prefix/suffix or spills over to next fragment
      if (range.getStartOffset() < prevHostEndOffset + prefixLength) {
        range = new UnfairTextRange(prevHostEndOffset + prefixLength, range.getEndOffset());
      }
      TextRange spilled = null;
      if (range.getEndOffset() > shredEndOffset - suffixLength) {
        spilled = new UnfairTextRange(shredEndOffset, range.getEndOffset());
        range = new UnfairTextRange(range.getStartOffset(), shredEndOffset - suffixLength);
      }
      if (!range.isEmpty()) {
        int start = escaper.getOffsetInHost(range.getStartOffset() - prevHostEndOffset - prefixLength, rangeInsideHost);
        if (start == -1) start = rangeInsideHost.getStartOffset();
        int end = escaper.getOffsetInHost(range.getEndOffset() - prevHostEndOffset - prefixLength, rangeInsideHost);
        if (end == -1) {
          end = rangeInsideHost.getEndOffset();
          prevHostEndOffset = shredEndOffset;
        }
        ProperTextRange rangeInHost = new ProperTextRange(start, end);
        tokens.add(new InjectedLanguageUtil.TokenInfo(tokenType, rangeInHost, hostNum, iterator.getTextAttributes()));
      }
      range = spilled;
    }
    iterator.advance();
  }
  return tokens;
}
 
Example 16
Source File: TypedHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean handleRParen(@Nonnull Editor editor, @Nonnull FileType fileType, char charTyped) {
  if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) return false;

  int offset = editor.getCaretModel().getOffset();

  if (offset == editor.getDocument().getTextLength()) return false;

  HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset);
  if (iterator.atEnd()) return false;

  if (iterator.getEnd() - iterator.getStart() != 1 || editor.getDocument().getCharsSequence().charAt(iterator.getStart()) != charTyped) {
    return false;
  }

  BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
  CharSequence text = editor.getDocument().getCharsSequence();
  if (!braceMatcher.isRBraceToken(iterator, text, fileType)) {
    return false;
  }

  IElementType tokenType = iterator.getTokenType();

  iterator.retreat();

  IElementType lparenTokenType = braceMatcher.getOppositeBraceTokenType(tokenType);
  int lparenthOffset = BraceMatchingUtil.findLeftmostLParen(iterator, lparenTokenType, text, fileType);

  if (lparenthOffset < 0) {
    if (braceMatcher instanceof NontrivialBraceMatcher) {
      for (IElementType t : ((NontrivialBraceMatcher)braceMatcher).getOppositeBraceTokenTypes(tokenType)) {
        if (t == lparenTokenType) continue;
        lparenthOffset = BraceMatchingUtil.findLeftmostLParen(iterator, t, text, fileType);
        if (lparenthOffset >= 0) break;
      }
    }
    if (lparenthOffset < 0) return false;
  }

  iterator = ((EditorEx)editor).getHighlighter().createIterator(lparenthOffset);
  boolean matched = BraceMatchingUtil.matchBrace(text, fileType, iterator, true, true);

  if (!matched) return false;

  EditorModificationUtil.moveCaretRelatively(editor, 1);
  return true;
}
 
Example 17
Source File: BraceMatchingUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean findStructuralLeftBrace(@Nonnull FileType fileType, @Nonnull HighlighterIterator iterator, @Nonnull CharSequence fileText) {
  final Stack<IElementType> braceStack = new Stack<IElementType>();
  final Stack<String> tagNameStack = new Stack<String>();

  BraceMatcher matcher = getBraceMatcher(fileType, iterator);

  while (!iterator.atEnd()) {
    if (isStructuralBraceToken(fileType, iterator, fileText)) {
      if (isRBraceToken(iterator, fileText, fileType)) {
        braceStack.push(iterator.getTokenType());
        tagNameStack.push(getTagName(matcher, fileText, iterator));
      }
      if (isLBraceToken(iterator, fileText, fileType)) {
        if (braceStack.isEmpty()) return true;

        final int group = matcher.getBraceTokenGroupId(iterator.getTokenType());

        final IElementType topTokenType = braceStack.pop();
        final IElementType tokenType = iterator.getTokenType();

        boolean isStrict = isStrictTagMatching(matcher, fileType, group);
        boolean isCaseSensitive = areTagsCaseSensitive(matcher, fileType, group);

        String topTagName = null;
        String tagName = null;
        if (isStrict) {
          topTagName = tagNameStack.pop();
          tagName = getTagName(matcher, fileText, iterator);
        }

        if (!isPairBraces(topTokenType, tokenType, fileType)
            || isStrict && !Comparing.equal(topTagName, tagName, isCaseSensitive)) {
          return false;
        }
      }
    }

    iterator.retreat();
  }

  return false;
}
 
Example 18
Source File: TypedHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean handleQuote(@Nonnull Editor editor, char quote, @Nonnull PsiFile file) {
  if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE) return false;
  final QuoteHandler quoteHandler = getQuoteHandler(file, editor);
  if (quoteHandler == null) return false;

  int offset = editor.getCaretModel().getOffset();

  final Document document = editor.getDocument();
  CharSequence chars = document.getCharsSequence();
  int length = document.getTextLength();
  if (isTypingEscapeQuote(editor, quoteHandler, offset)) return false;

  if (offset < length && chars.charAt(offset) == quote) {
    if (isClosingQuote(editor, quoteHandler, offset)) {
      EditorModificationUtil.moveCaretRelatively(editor, 1);
      return true;
    }
  }

  HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset);

  if (!iterator.atEnd()) {
    IElementType tokenType = iterator.getTokenType();
    if (quoteHandler instanceof JavaLikeQuoteHandler) {
      try {
        if (!((JavaLikeQuoteHandler)quoteHandler).isAppropriateElementTypeForLiteral(tokenType)) return false;
      }
      catch (AbstractMethodError incompatiblePluginErrorThatDoesNotInterestUs) {
        // ignore
      }
    }
  }

  type(editor, quote);
  offset = editor.getCaretModel().getOffset();

  if (quoteHandler instanceof MultiCharQuoteHandler) {
    CharSequence closingQuote = getClosingQuote(editor, (MultiCharQuoteHandler)quoteHandler, offset);
    if (closingQuote != null && hasNonClosedLiterals(editor, quoteHandler, offset - 1)) {
      if (offset == document.getTextLength() || !Character.isUnicodeIdentifierPart(document.getCharsSequence().charAt(offset))) { //any better heuristic or an API?
        ((MultiCharQuoteHandler)quoteHandler).insertClosingQuote(editor, offset, file, closingQuote);
        return true;
      }
    }
  }

  if (offset > 0 && isOpeningQuote(editor, quoteHandler, offset - 1) && hasNonClosedLiterals(editor, quoteHandler, offset - 1)) {
    if (offset == document.getTextLength() || !Character.isUnicodeIdentifierPart(document.getCharsSequence().charAt(offset))) { //any better heuristic or an API?
      document.insertString(offset, String.valueOf(quote));
      TabOutScopesTracker.getInstance().registerEmptyScope(editor, offset);
    }
  }

  return true;
}
 
Example 19
Source File: HaskellTypedHandler.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
/**
 * this is almost complete c'n'p from TypedHandler,
 * This code should be generalized into BraceMatchingUtil to support custom matching braces for plugin developers
 *
 * @see com.intellij.codeInsight.editorActions.TypedHandler
 * @see BraceMatchingUtil
 */
private static void insertMatchedEndComment(Project project, Editor editor, PsiFile file, char c) {
    if (!(file instanceof HaskellFile)) return;

    PsiDocumentManager.getInstance(project).commitAllDocuments();

    FileType fileType = file.getFileType();
    int offset = editor.getCaretModel().getOffset();
    HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
    boolean atEndOfDocument = offset == editor.getDocument().getTextLength();

    if (!atEndOfDocument) iterator.retreat();
    if (iterator.atEnd()) return;
    BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
    if (iterator.atEnd()) return;
    IElementType braceTokenType = iterator.getTokenType();
    final CharSequence fileText = editor.getDocument().getCharsSequence();
    if (!braceMatcher.isLBraceToken(iterator, fileText, fileType)) return;

    if (!iterator.atEnd()) {
        iterator.advance();

        if (!iterator.atEnd()) {
            if (!BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType(braceTokenType, iterator.getTokenType(), fileType)) {
                return;
            }
            if (BraceMatchingUtil.isLBraceToken(iterator, fileText, fileType)) {
                return;
            }
        }

        iterator.retreat();
    }

    int lparenOffset = BraceMatchingUtil.findLeftmostLParen(iterator, braceTokenType, fileText, fileType);
    if (lparenOffset < 0) lparenOffset = 0;

    iterator = ((EditorEx) editor).getHighlighter().createIterator(lparenOffset);

    if (!BraceMatchingUtil.matchBrace(fileText, fileType, iterator, true, true)) {
        // Some other mechanism has put the closing '}' in the document already.
        editor.getDocument().insertString(offset, new CharArrayCharSequence(c));
    }
}
 
Example 20
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 3 votes vote down vote up
private void highlightRightBrace(@Nonnull HighlighterIterator iterator, @Nonnull FileType fileType) {
  TextRange brace1 = TextRange.create(iterator.getStart(), iterator.getEnd());

  boolean matched = BraceMatchingUtil.matchBrace(myDocument.getCharsSequence(), fileType, iterator, false);

  TextRange brace2 = iterator.atEnd() ? null : TextRange.create(iterator.getStart(), iterator.getEnd());

  highlightBraces(brace2, brace1, matched, false, fileType);
}