congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
HighlighterIterator
Code IndexAdd Tabnine to your IDE (free)

How to use
HighlighterIterator
in
com.intellij.openapi.editor.highlighter

Best Java code snippets using com.intellij.openapi.editor.highlighter.HighlighterIterator (Showing top 20 results out of 315)

origin: KronicDeth/intellij-elixir

 @Nullable
 @Override
 public BracePair findPair(boolean left, HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
  BracePair pair = super.findPair(left, iterator, fileText, fileType);

  if (pair == Paired.DO_END || pair == Paired.FN_END) {
   iterator.advance();

   if (!iterator.atEnd()) {
    IElementType tokenType = iterator.getTokenType();

    if (tokenType == ElixirTypes.KEYWORD_PAIR_COLON) {
     pair = null;
    }
   }

   iterator.retreat();
  }

  return pair;
 }
}
origin: KronicDeth/intellij-elixir

@Nullable
@Override
public CharSequence getClosingQuote(HighlighterIterator highlighterIterator, int offset) {
  CharSequence closingQuote = null;
  if (highlighterIterator.getStart() > 0) {
    highlighterIterator.retreat();
    try {
      IElementType tokenType = highlighterIterator.getTokenType();
      if (CLOSING_QUOTE_BY_OPENING_QUOTE.get(tokenType) != null) {
        Document document = highlighterIterator.getDocument();
        if (document != null) {
          String promoter = document.getText(
              new TextRange(highlighterIterator.getStart(), highlighterIterator.getEnd())
          );
          String terminator = StackFrame.TERMINATOR_BY_PROMOTER.get(promoter);
          if (terminator != null) {
            if (terminator.length() >= 3) {
              closingQuote = "\n" + terminator;
            } else {
              closingQuote = terminator;
            }
          }
        }
      }
    } finally {
      highlighterIterator.advance();
    }
  }
  return closingQuote;
}
origin: KronicDeth/intellij-elixir

  @Override
  public boolean isOpeningQuote(HighlighterIterator highlighterIterator, int offset) {
    boolean isOpeningQuote = false;

    if (OPENING_QUOTES.contains(highlighterIterator.getTokenType())){
      int start = highlighterIterator.getStart();
      isOpeningQuote = offset == start;
    }

    return isOpeningQuote;
  }
}
origin: KronicDeth/intellij-elixir

/**
 *
 * @param highlighterIterator
 * @param offset the current offset in the file of the {@code highlighterIterator}
 * @return {@code true} if {@link HighlighterIterator#getTokenType()} is one of {@link #CLOSING_QUOTES} and
 *   {@code offset} is {@link HighlighterIterator#getStart()}
 */
@Override
public boolean isClosingQuote(HighlighterIterator highlighterIterator, int offset) {
  boolean isClosingQuote = false;
  if (CLOSING_QUOTES.contains(highlighterIterator.getTokenType())) {
    int start = highlighterIterator.getStart();
    int end = highlighterIterator.getEnd();
    isClosingQuote = end - start >= 1 && offset == end - 1;
  }
  return isClosingQuote;
}
origin: halirutan/Mathematica-IntelliJ-Plugin

@Nullable
private IElementType getNonWhitespaceElementType(final HighlighterIterator iterator, int curLineStart, final int prevLineStartOffset) {
 while (!iterator.atEnd() && iterator.getEnd() >= curLineStart && iterator.getStart() >= prevLineStartOffset) {
  final IElementType tokenType = iterator.getTokenType();
  if (!MathematicaElementTypes.WHITE_SPACE_OR_COMMENTS.contains(tokenType)) {
   return tokenType;
  }
  iterator.retreat();
 }
 return null;
}
origin: qeesung/HighlightBracketPair

               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();
        return iterator.getStart();
      } else {
        break;
    if (isBlockCaret && initOffset == iterator.getStart())
      continue;
    else
      braceStack.push(iterator.getTokenType());
origin: Camelcade/Perl5-IDEA

/**
 * Iterates back until atEnd or non-space token
 */
@NotNull
public static HighlighterIterator moveToPreviousMeaningfulToken(@NotNull HighlighterIterator iterator) {
 while (!iterator.atEnd()) {
  IElementType tokenType = iterator.getTokenType();
  if (tokenType != TokenType.WHITE_SPACE) {
   break;
  }
  iterator.retreat();
 }
 return iterator;
}
origin: Camelcade/Perl5-IDEA

/**
 * @return previous non-space token type
 */
@Nullable
public static IElementType getPreviousTokenType(@NotNull HighlighterIterator iterator) {
 moveToPreviousMeaningfulToken(iterator);
 return iterator.atEnd() ? null : iterator.getTokenType();
}
origin: Camelcade/Perl5-IDEA

HighlighterIterator highlighterIterator = editor.getHighlighter().createIterator(0);
int level = 0;
while (!highlighterIterator.atEnd()) {
 IElementType tokenType = highlighterIterator.getTokenType();
 if (tokenType == leftType) {
  level++;
  return false;
 else if (level == 0 && highlighterIterator.getEnd() > offset) {
  return true;
 highlighterIterator.advance();
origin: BashSupport/BashSupport

protected void doLexerHighlightingTest(String fileContent, IElementType targetElementType) {
  BashSyntaxHighlighter syntaxHighlighter = new BashSyntaxHighlighter();
  TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(targetElementType);
  Assert.assertEquals("Expected one key", 1, keys.length);
  TextAttributesKey attributesKey = keys[0];
  Assert.assertNotNull(attributesKey);
  EditorColorsManager manager = EditorColorsManager.getInstance();
  EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
  manager.addColorsScheme(scheme);
  EditorColorsManager.getInstance().setGlobalScheme(scheme);
  TextAttributes targetAttributes = new TextAttributes(JBColor.RED, JBColor.BLUE, JBColor.GRAY, EffectType.BOXED, Font.BOLD);
  scheme.setAttributes(attributesKey, targetAttributes);
  myFixture.configureByText(BashFileType.BASH_FILE_TYPE, fileContent);
  TextAttributes actualAttributes = null;
  HighlighterIterator iterator = ((EditorImpl) myFixture.getEditor()).getHighlighter().createIterator(0);
  while (!iterator.atEnd()) {
    if (iterator.getTokenType() == targetElementType) {
      actualAttributes = iterator.getTextAttributes();
      break;
    }
    iterator.advance();
  }
  Assert.assertEquals("Expected text attributes for " + attributesKey, targetAttributes, actualAttributes);
}
origin: Camelcade/Perl5-IDEA

/**
 * Iterates forward until atEnd or non-space token
 */
@NotNull
public static HighlighterIterator moveToNextMeaningfulToken(@NotNull HighlighterIterator iterator) {
 iterator.advance();
 while (!iterator.atEnd()) {
  IElementType tokenType = iterator.getTokenType();
  if (tokenType != TokenType.WHITE_SPACE) {
   break;
  }
  iterator.advance();
 }
 return iterator;
}
origin: Camelcade/Perl5-IDEA

IElementType tokenToDelete = iterator.atEnd() ? null : iterator.getTokenType();
if (QUOTE_OPEN_ANY.contains(tokenToDelete)) {
 PerlEditorUtil.moveToNextMeaningfulToken(iterator);
 if (iterator.atEnd()) {
  return;
 IElementType nextTokenType = iterator.getTokenType();
 if (QUOTE_CLOSE_PAIRED.contains(nextTokenType)) {
  int startOffsetToDelete = currentOffset + 1;
   HighlighterIterator preQuoteIterator =
    PerlEditorUtil.moveToPreviousMeaningfulToken(highlighter.createIterator(currentOffset - 1));
   if (!preQuoteIterator.atEnd() && QUOTE_OPEN_ANY.contains(preQuoteIterator.getTokenType())) {
    startOffsetToDelete = preQuoteIterator.getEnd();
    caretModel.moveToOffset(preQuoteIterator.getEnd());
   POST_HANDLER.set(editor, () -> true);
  editor.getDocument().deleteString(startOffsetToDelete, iterator.getEnd());
origin: Camelcade/Perl5-IDEA

if (highlighterIterator.atEnd()) {
 return Result.Continue;
IElementType currentTokenType = highlighterIterator.getTokenType();
int currentTokenStart = highlighterIterator.getStart();
origin: KronicDeth/intellij-elixir

@Override
public boolean isInsideLiteral(HighlighterIterator highlighterIterator) {
  return LITERALS.contains(highlighterIterator.getTokenType());
}
origin: Camelcade/Perl5-IDEA

if (highlighterIterator.atEnd() ||
  StringUtil.containsLineBreak(documentChars.subSequence(highlighterIterator.getStart(), currentOffset))) {
 return Result.Continue;
int openTokenStart = highlighterIterator.getStart();
if (highlighterIterator.atEnd() ||
  StringUtil.containsLineBreak(documentChars.subSequence(currentOffset, highlighterIterator.getEnd()))) {
 return Result.Continue;
origin: qeesung/HighlightBracketPair

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()));
}
origin: halirutan/Mathematica-IntelliJ-Plugin

@Nullable
private IElementType getNonWhitespaceElementType(final HighlighterIterator iterator, int curLineStart, final int prevLineStartOffset) {
 while (!iterator.atEnd() && iterator.getEnd() >= curLineStart && iterator.getStart() >= prevLineStartOffset) {
  final IElementType tokenType = iterator.getTokenType();
  if (!MathematicaElementTypes.WHITE_SPACE_OR_COMMENTS.contains(tokenType)) {
   return tokenType;
  }
  iterator.retreat();
 }
 return null;
}
origin: Camelcade/Perl5-IDEA

IElementType elementTokenType = iterator.getTokenType();
Document document = editor.getDocument();
if (QUOTE_OPEN_ANY.contains(elementTokenType) && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE) {
 iterator.advance();
 IElementType possibleCloseQuoteType = iterator.atEnd() ? null : iterator.getTokenType();
 if (QUOTE_CLOSE_FIRST_ANY.contains(possibleCloseQuoteType) && closeChar == text.charAt(iterator.getStart())) {
  if (COMPLEX_QUOTE_OPENERS.contains(quotePrefixType) && StringUtil.containsChar(HANDLED_BY_BRACE_MATCHER, openChar)) {
   iterator.advance();
   if (iterator.atEnd() || !QUOTE_OPEN_ANY.contains(iterator.getTokenType())) {
    EditorModificationUtil.insertStringAtCaret(editor, Character.toString(closeChar) + openChar, false, false);
origin: Camelcade/Perl5-IDEA

 @Nullable
 @Contract("null -> null")
 public static IElementType getLastOpenMarker(@Nullable Editor editor) {
  if (editor == null) {
   return null;
  }
  int offset = editor.getCaretModel().getOffset();
  HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset);

  while (!iterator.atEnd()) {
   IElementType tokenType = iterator.getTokenType();
   if (TemplateToolkitSyntaxElements.OPEN_TAGS.contains(tokenType)) {
    return tokenType;
   }
   iterator.retreat();
  }

  return null;
 }
}
origin: halirutan/Mathematica-IntelliJ-Plugin

/**
 * Should return true if the current offset is the closing quote of the string. Unfortunately, I'm not quite sure
 * anymore why I had to make the calculations but I remember that something with the removal of an empty string did
 * not work.
 *
 * @param iterator
 *     the iterator to move through the token stream. Here, only used to get the current token type
 * @param offset
 *     current character offset
 * @return true, if the current offset is a closing quote
 */
@Override
public boolean isClosingQuote(HighlighterIterator iterator, int offset) {
 final IElementType tokenType = iterator.getTokenType();
 if (tokenType.equals(STRING_LITERAL_END)) {
  int start = iterator.getStart();
  int end = iterator.getEnd();
  return end - start >= 1 && offset == end - 1;
 }
 return false;
}
com.intellij.openapi.editor.highlighterHighlighterIterator

Most used methods

  • atEnd
  • getTokenType
  • advance
  • retreat
  • getEnd
  • getStart
  • getDocument
  • getTextAttributes

Popular in Java

  • Running tasks concurrently on multiple threads
  • scheduleAtFixedRate (ScheduledExecutorService)
  • setContentView (Activity)
  • addToBackStack (FragmentTransaction)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • 21 Best IntelliJ Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now