Java Code Examples for com.intellij.openapi.editor.highlighter.HighlighterIterator

The following examples show how to use com.intellij.openapi.editor.highlighter.HighlighterIterator. These examples are extracted from open source projects. 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 Project: HighlightBracketPair   Source File: BraceHighlighter.java    License: Apache License 2.0 6 votes vote down vote up
public BracePair findClosetBracePairInBraceTokens(int offset) {
    EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter();
    boolean isBlockCaret = this.isBlockCaret();
    List<Pair<IElementType, IElementType>> braceTokens = this.getSupportedBraceToken();
    for (Pair<IElementType, IElementType> braceTokenPair :
            braceTokens) {
        HighlighterIterator leftTraverseIterator = editorHighlighter.createIterator(offset);
        HighlighterIterator rightTraverseIterator = editorHighlighter.createIterator(offset);
        int leftBraceOffset = BraceMatchingUtilAdapter.findLeftLParen(
                leftTraverseIterator, braceTokenPair.getLeft(), this.fileText, this.fileType, isBlockCaret);
        int rightBraceOffset = BraceMatchingUtilAdapter.findRightRParen(
                rightTraverseIterator, braceTokenPair.getRight(), this.fileText, this.fileType, isBlockCaret);
        if (leftBraceOffset != NON_OFFSET && rightBraceOffset != NON_OFFSET) {
            return new BracePair.BracePairBuilder().
                    leftType(braceTokenPair.getLeft()).
                    rightType(braceTokenPair.getRight()).
                    leftIterator(leftTraverseIterator).
                    rightIterator(rightTraverseIterator).build();


        }
    }
    return EMPTY_BRACE_PAIR;
}
 
Example 2
Source Project: idea-php-typo3-plugin   Source File: FluidQuoteHandler.java    License: MIT License 6 votes vote down vote up
public boolean hasNonClosedLiteral(@NotNull Editor editor, @NotNull HighlighterIterator iterator, int offset) {
    Document document = editor.getDocument();
    int lineEndOffset = document.getLineEndOffset(document.getLineNumber(offset));
    if (offset < lineEndOffset) {
        CharSequence charSequence = document.getCharsSequence();
        char openQuote = charSequence.charAt(offset);
        int nextCharOffset = offset + 1;
        if (nextCharOffset < lineEndOffset && charSequence.charAt(nextCharOffset) == openQuote) {
            return true;
        }

        for (int i = nextCharOffset + 1; i < lineEndOffset; ++i) {
            if (charSequence.charAt(i) == openQuote) {
                return false;
            }
        }
    }

    return true;
}
 
Example 3
private int findCodeConstructStartLine(int startLine) {
  DocumentEx document = myEditor.getDocument();
  CharSequence text = document.getImmutableCharSequence();
  int lineStartOffset = document.getLineStartOffset(startLine);
  int firstNonWsOffset = CharArrayUtil.shiftForward(text, lineStartOffset, " \t");
  FileType type = PsiUtilBase.getPsiFileAtOffset(myFile, firstNonWsOffset).getFileType();
  Language language = PsiUtilCore.getLanguageAtOffset(myFile, firstNonWsOffset);
  BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(type, language);
  HighlighterIterator iterator = myEditor.getHighlighter().createIterator(firstNonWsOffset);
  if (braceMatcher.isLBraceToken(iterator, text, type)) {
    int codeConstructStart = braceMatcher.getCodeConstructStart(myFile, firstNonWsOffset);
    return document.getLineNumber(codeConstructStart);
  }
  else {
    return startLine;
  }
}
 
Example 4
Source Project: intellij   Source File: BuildQuoteHandler.java    License: 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 5
Source Project: intellij   Source File: BuildQuoteHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected boolean isNonClosedLiteral(HighlighterIterator iterator, CharSequence chars) {
  int end = iterator.getEnd();
  if (getLiteralStartOffset(chars, iterator.getStart()) >= end - 1) {
    return true;
  }
  char endSymbol = chars.charAt(end - 1);
  if (endSymbol != '"' && endSymbol != '\'') {
    return true;
  }

  //for triple quoted string
  if (end >= 3
      && (endSymbol == chars.charAt(end - 2))
      && (chars.charAt(end - 2) == chars.charAt(end - 3))
      && (end < 4 || chars.charAt(end - 4) != endSymbol)) {
    return true;
  }

  return false;
}
 
Example 6
Source Project: consulo-csharp   Source File: CSharpQuoteHandler.java    License: 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 7
Source Project: consulo   Source File: SelectWordAtCaretAction.java    License: Apache License 2.0 6 votes vote down vote up
private static void selectWithGuide(Editor editor, IndentGuideDescriptor guide) {
  final Document doc = editor.getDocument();
  int startOffset = editor.logicalPositionToOffset(new LogicalPosition(guide.startLine, 0));
  int endOffset = guide.endLine >= doc.getLineCount() ? doc.getTextLength() : doc.getLineStartOffset(guide.endLine);

  final VirtualFile file = ((EditorEx)editor).getVirtualFile();
  if (file != null) {
    // Make sure selection contains closing matching brace.

    final CharSequence chars = doc.getCharsSequence();
    int nonWhitespaceOffset = CharArrayUtil.shiftForward(chars, endOffset, " \t\n");
    HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(nonWhitespaceOffset);
    if (BraceMatchingUtil.isRBraceToken(iterator, chars, file.getFileType())) {
      if (editor.offsetToLogicalPosition(iterator.getStart()).column == guide.indentLevel) {
        endOffset = iterator.getEnd();
        endOffset = CharArrayUtil.shiftForward(chars, endOffset, " \t");
        if (endOffset < chars.length() && chars.charAt(endOffset) == '\n') endOffset++;
      }
    }
  }

  editor.getSelectionModel().setSelection(startOffset, endOffset);
}
 
Example 8
Source Project: consulo   Source File: LexerEditorHighlighter.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public HighlighterIterator createIterator(int startOffset) {
  synchronized (this) {
    if (!isInSyncWithDocument()) {
      final Document document = getDocument();
      assert document != null;
      if (document.isInBulkUpdate()) {
        document.setInBulkUpdate(false); // bulk mode failed
      }
      doSetText(document.getImmutableCharSequence());
    }

    final int latestValidOffset = mySegments.getLastValidOffset();
    return new HighlighterIteratorImpl(startOffset <= latestValidOffset ? startOffset : latestValidOffset);
  }
}
 
Example 9
Source Project: consulo   Source File: ToggleCaseAction.java    License: 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 10
Source Project: consulo   Source File: HTMLTextPainter.java    License: Apache License 2.0 6 votes vote down vote up
private void writeStyles(@NonNls final Writer writer) throws IOException {
  writer.write("<style type=\"text/css\">\n");
  writer.write(".ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }\n");
  HighlighterIterator hIterator = myHighlighter.createIterator(myOffset);
  while(!hIterator.atEnd()) {
    TextAttributes textAttributes = hIterator.getTextAttributes();
    if (!myStyleMap.containsKey(textAttributes)) {
      @NonNls String styleName = "s" + myStyleMap.size();
      myStyleMap.put(textAttributes, styleName);
      writer.write("." + styleName + " { ");
      final Color foreColor = textAttributes.getForegroundColor();
      if (foreColor != null) {
        writer.write("color: rgb(" + foreColor.getRed() + "," + foreColor.getGreen() + "," + foreColor.getBlue() + "); ");
      }
      if ((textAttributes.getFontType() & Font.BOLD) != 0) {
        writer.write("font-weight: bold; ");
      }
      if ((textAttributes.getFontType() & Font.ITALIC) != 0) {
        writer.write("font-style: italic; ");
      }
      writer.write("}\n");
    }
    hIterator.advance();
  }
  writer.write("</style>\n");
}
 
Example 11
/**
 * 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 12
Source Project: consulo   Source File: ClickNavigator.java    License: Apache License 2.0 5 votes vote down vote up
private void navigate(final Editor editor, boolean select,
                      LogicalPosition pos,
                      final SyntaxHighlighter highlighter,
                      final HighlightData[] data, final boolean isBackgroundImportant) {
  int offset = editor.logicalPositionToOffset(pos);

  if (!isBackgroundImportant && editor.offsetToLogicalPosition(offset).column != pos.column) {
    if (!select) {
      setCursor(editor, Cursor.TEXT_CURSOR);
      return;
    }
  }

  if (data != null) {
    for (HighlightData highlightData : data) {
      if (highlightDataContainsOffset(highlightData, editor.logicalPositionToOffset(pos))) {
        if (!select) setCursor(editor, Cursor.HAND_CURSOR);
        setSelectedItem(highlightData.getHighlightType(), select);
        return;
      }
    }
  }

  if (highlighter != null) {
    HighlighterIterator itr = ((EditorEx)editor).getHighlighter().createIterator(offset);
    boolean selection = selectItem(select, itr, highlighter);
    if (!select && selection) {
      setCursor(editor, Cursor.HAND_CURSOR);
    }
    else {
      setCursor(editor, Cursor.TEXT_CURSOR);
    }
  }
}
 
Example 13
Source Project: consulo   Source File: BraceHighlightingHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
static EditorHighlighter getLazyParsableHighlighterIfAny(Project project, Editor editor, PsiFile psiFile) {
  if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
    return ((EditorEx)editor).getHighlighter();
  }
  PsiElement elementAt = psiFile.findElementAt(editor.getCaretModel().getOffset());
  for (PsiElement e : SyntaxTraverser.psiApi().parents(elementAt).takeWhile(Conditions.notEqualTo(psiFile))) {
    if (!(PsiUtilCore.getElementType(e) instanceof ILazyParseableElementType)) continue;
    Language language = ILazyParseableElementType.LANGUAGE_KEY.get(e.getNode());
    if (language == null) continue;
    TextRange range = e.getTextRange();
    final int offset = range.getStartOffset();
    SyntaxHighlighter syntaxHighlighter =
            SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, psiFile.getVirtualFile());
    LexerEditorHighlighter highlighter = new LexerEditorHighlighter(syntaxHighlighter, editor.getColorsScheme()) {
      @Nonnull
      @Override
      public HighlighterIterator createIterator(int startOffset) {
        return new HighlighterIteratorWrapper(super.createIterator(Math.max(startOffset - offset, 0))) {
          @Override
          public int getStart() {
            return super.getStart() + offset;
          }

          @Override
          public int getEnd() {
            return super.getEnd() + offset;
          }
        };
      }
    };
    highlighter.setText(editor.getDocument().getText(range));
    return highlighter;
  }
  return ((EditorEx)editor).getHighlighter();
}
 
Example 14
Source Project: idea-php-typo3-plugin   Source File: FluidQuoteHandler.java    License: MIT License 5 votes vote down vote up
public boolean isOpeningQuote(HighlighterIterator iterator, int offset) {
    if (this.isInsideLiteral(iterator)) {
        int start = iterator.getStart();
        return offset == start;
    } else {
        IElementType tokenType = iterator.getTokenType();
        return tokenType == FluidTypes.DOUBLE_QUOTE || tokenType == FluidTypes.SINGLE_QUOTE;
    }
}
 
Example 15
Source Project: idea-php-typo3-plugin   Source File: FluidQuoteHandler.java    License: MIT License 5 votes vote down vote up
public boolean isClosingQuote(HighlighterIterator iterator, int offset) {
    if (this.isInsideLiteral(iterator)) {
        int start = iterator.getStart();
        int end = iterator.getEnd();
        return end - start >= 1 && offset == end - 1;
    } else {
        IElementType tokenType = iterator.getTokenType();
        return tokenType == FluidTypes.DOUBLE_QUOTE || tokenType == FluidTypes.SINGLE_QUOTE;
    }
}
 
Example 16
Source Project: intellij   Source File: BuildQuoteHandler.java    License: 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;
}
 
Example 17
Source Project: intellij   Source File: BuildQuoteHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public CharSequence getClosingQuote(HighlighterIterator iterator, int offset) {
  char theQuote = iterator.getDocument().getCharsSequence().charAt(offset - 1);
  if (super.isOpeningQuote(iterator, offset - 1)) {
    return String.valueOf(theQuote);
  }
  if (super.isOpeningQuote(iterator, offset - 3)) {
    return StringUtil.repeat(String.valueOf(theQuote), 3);
  }
  return null;
}
 
Example 18
Source Project: consulo   Source File: CustomFileTypeQuoteHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isOpeningQuote(HighlighterIterator iterator, int offset) {
  final IElementType tokenType = iterator.getTokenType();

  if (tokenType == CustomHighlighterTokenType.STRING ||
      tokenType == CustomHighlighterTokenType.SINGLE_QUOTED_STRING ||
      tokenType == CustomHighlighterTokenType.CHARACTER){
    int start = iterator.getStart();
    return offset == start;
  }
  return false;
}
 
Example 19
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);
}
 
Example 20
Source Project: BashSupport   Source File: BashAnnotatorHighlightingTest.java    License: Apache License 2.0 5 votes vote down vote up
private List<TextAttributes> collectComments() {
    List<TextAttributes> result = Lists.newArrayList();

    HighlighterIterator iterator = ((EditorEx) myFixture.getEditor()).getHighlighter().createIterator(0);
    while (!iterator.atEnd()) {
        if (iterator.getTokenType() == BashTokenTypes.COMMENT) {
            result.add(iterator.getTextAttributes());
        }
        iterator.advance();
    }
    return result;
}
 
Example 21
Source Project: consulo   Source File: BraceHighlightingHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void highlightLeftBrace(@Nonnull HighlighterIterator iterator, boolean scopeHighlighting, @Nonnull FileType fileType) {
  TextRange brace1Start = TextRange.create(iterator.getStart(), iterator.getEnd());
  boolean matched = BraceMatchingUtil.matchBrace(myDocument.getCharsSequence(), fileType, iterator, true);

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

  highlightBraces(brace1Start, brace2End, matched, scopeHighlighting, fileType);
}
 
Example 22
Source Project: consulo-csharp   Source File: CSharpDocBraceMatcher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isLBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType)
{
	final IElementType tokenType = iterator.getTokenType();

	return tokenType == CSharpDocTokenType.XML_START_TAG_START ||
			tokenType == CSharpDocTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER;
}
 
Example 23
Source Project: consulo   Source File: TypedHandler.java    License: 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 24
Source Project: consulo   Source File: TypedHandler.java    License: 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 25
Source Project: consulo   Source File: BraceHighlightingHandler.java    License: 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 26
Source Project: consulo   Source File: CommentByBlockCommentHandler.java    License: Apache License 2.0 5 votes vote down vote up
private TextRange getBlockCommentAt(int offset) {
  CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter)myCommenter;
  HighlighterIterator it = ((EditorEx)myEditor).getHighlighter().createIterator(offset);
  if (it.getTokenType() == commenter.getBlockCommentTokenType()) {
    return new TextRange(it.getStart(), it.getEnd());
  }
  if (docCommentIsBlockComment(commenter)) {
    PsiComment comment = getCommentAtOffset(offset);
    if (comment != null && commenter.isDocumentationComment(comment)) {
      return comment.getTextRange();
    }
  }
  return null;
}
 
Example 27
Source Project: consulo   Source File: SimpleEditorPreview.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static String selectItem(HighlighterIterator itr, SyntaxHighlighter highlighter) {
  IElementType tokenType = itr.getTokenType();
  if (tokenType == null) return null;

  TextAttributesKey[] highlights = highlighter.getTokenHighlights(tokenType);
  String s = null;
  for (int i = highlights.length - 1; i >= 0; i--) {
    if (highlights[i] != HighlighterColors.TEXT) {
      s = highlights[i].getExternalName();
      break;
    }
  }
  return s == null ? HighlighterColors.TEXT.getExternalName() : s;
}
 
Example 28
Source Project: intellij-xquery   Source File: XQueryQuoteHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isOpeningQuote(HighlighterIterator iterator, int offset) {
    if (OPENINGQUOT == iterator.getTokenType() || OPENINGAPOS == iterator.getTokenType()){
        int start = iterator.getStart();
        return offset == start;
    }

    return false;
}
 
Example 29
Source Project: consulo   Source File: SimpleTokenSetQuoteHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isOpeningQuote(HighlighterIterator iterator, int offset) {
  if (myLiteralTokenSet.contains(iterator.getTokenType())){
    int start = iterator.getStart();
    return offset == start;
  }

  return false;
}
 
Example 30
public void restart(@Nonnull CharSequence text) {
  lexer.start(text);

  if (lexer instanceof LexerEditorHighlighterLexer) {
    HighlighterIterator iterator = ((LexerEditorHighlighterLexer)lexer).getHighlighterIterator();
    if (iterator instanceof LayeredHighlighterIterator) {
      layeredHighlighterIterator = (LayeredHighlighterIterator)iterator;
    } else {
      layeredHighlighterIterator = null;
    }
  }
}