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

The following examples show how to use com.intellij.openapi.editor.highlighter.HighlighterIterator#getDocument() . 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: BuildQuoteHandler.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isOpeningQuote(HighlighterIterator iterator, int offset) {
  if (!myLiteralTokenSet.contains(iterator.getTokenType())) {
    return false;
  }
  int start = iterator.getStart();
  if (offset == start) {
    return true;
  }
  final Document document = iterator.getDocument();
  if (document == null) {
    return false;
  }
  CharSequence text = document.getCharsSequence();
  char theQuote = text.charAt(offset);
  if (offset >= 2
      && text.charAt(offset - 1) == theQuote
      && text.charAt(offset - 2) == theQuote
      && (offset < 3 || text.charAt(offset - 3) != theQuote)) {
    if (super.isOpeningQuote(iterator, offset)) {
      return true;
    }
  }
  return false;
}
 
Example 2
Source File: Brace.java    From HighlightBracketPair with Apache License 2.0 5 votes vote down vote up
public Brace(IElementType elementType, HighlighterIterator iterator) {
    this.elementType = elementType;
    this.offset = iterator.getStart();

    Document document = iterator.getDocument();
    this.text = document.getText(new TextRange(iterator.getStart(),
            iterator.getEnd()));
}
 
Example 3
Source File: BuildQuoteHandler.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isClosingQuote(HighlighterIterator iterator, int offset) {
  final IElementType tokenType = iterator.getTokenType();
  if (!myLiteralTokenSet.contains(tokenType)) {
    return false;
  }
  int start = iterator.getStart();
  int end = iterator.getEnd();
  if (end - start >= 1 && offset == end - 1) {
    return true; // single quote
  }
  if (end - start < 3 || offset < end - 3) {
    return false;
  }
  // check for triple quote
  Document doc = iterator.getDocument();
  if (doc == null) {
    return false;
  }
  CharSequence chars = doc.getCharsSequence();
  char quote = chars.charAt(start);
  boolean tripleQuote = quote == chars.charAt(start + 1) && quote == chars.charAt(start + 2);
  if (!tripleQuote) {
    return false;
  }
  for (int i = offset; i < Math.min(offset + 2, end); i++) {
    if (quote != chars.charAt(i)) {
      return false;
    }
  }
  return true;
}