Package com.intellij.openapi.editor.highlighter

Examples of com.intellij.openapi.editor.highlighter.HighlighterIterator


    if (offset == 0) return false;
    CharSequence chars = editor.getDocument().getCharsSequence();
    if (chars.charAt(offset - 1) != '>') return false;

    EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
    HighlighterIterator iterator = highlighter.createIterator(offset - 1);
    if (iterator.getTokenType() != CfmlTokenTypes.R_ANGLEBRACKET) return false;
    iterator.retreat();

    int retrieveCount = 1;
    while (!iterator.atEnd()) {
      final IElementType tokenType = iterator.getTokenType();
      if (tokenType == CfmlTokenTypes.LSLASH_ANGLEBRACKET) return false;
      if (tokenType == CfmlTokenTypes.OPENER) break;
      ++retrieveCount;
      iterator.retreat();
    }
    for (int i = 0; i < retrieveCount; ++i) iterator.advance();
    iterator.advance();
    return !iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.LSLASH_ANGLEBRACKET;
  }
View Full Code Here


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

    if (c == '{') {
      CfmlBraceMatcher braceMatcher = new CfmlBraceMatcher();
      HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset);
      if (!braceMatcher.isLBraceToken(iterator, editor.getDocument().getCharsSequence(), fileType)) {
        EditorModificationUtil.insertStringAtCaret(editor, "}", true, 0);
        // return Result.STOP;
      }
      return Result.CONTINUE;
View Full Code Here

    EditorModificationUtil.moveCaretRelatively(editor, 1);
    ++offset;
    if (DocumentUtils.getCharAt(document, offset - 2) == '/') {
      return false;
    }
    HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset - 2);

    while (!iterator.atEnd() && !iterator.getTokenType().equals(CfmlTokenTypes.CF_TAG_NAME)) {
      if (CfmlUtil.isControlToken(iterator.getTokenType())) {
        return false;
      }
      iterator.retreat();
    }
    if (!iterator.atEnd()) {
      iterator.retreat();
      if (!iterator.atEnd() && iterator.getTokenType().equals(CfmlTokenTypes.LSLASH_ANGLEBRACKET)) {
        return false;
      }
      iterator.advance();
    }
    if (iterator.atEnd()) {
      return false;
    }
    String tagName = document.getCharsSequence().subSequence(iterator.getStart(), iterator.getEnd()).toString();
    if (CfmlUtil.isSingleCfmlTag(tagName, project) || CfmlUtil.isUserDefined(tagName)) {
      return false;
    }
    PsiElement tagElement = file.findElementAt(iterator.getStart());
    while (tagElement != null && !(tagElement instanceof CfmlTag)) {
      tagElement = tagElement.getParent();
    }
    if (tagElement == null) {
      return false;
    }
    boolean doInsertion = false;
    if (tagElement.getLastChild() instanceof PsiErrorElement) {
      doInsertion = true;
    }
    else {
      iterator = ((EditorEx)editor).getHighlighter().createIterator(0);
      while (!iterator.atEnd() && iterator.getStart() < offset) {
        if (iterator.getTokenType() == CfmlTokenTypes.CF_TAG_NAME) {
          String currentTagName = document.getCharsSequence().subSequence(iterator.getStart(), iterator.getEnd()).toString();
          if (tagName.equals(currentTagName)) {
            PsiElement currentTagElement = file.findElementAt(iterator.getStart());
            currentTagElement = PsiTreeUtil.getParentOfType(currentTagElement, CfmlTag.class);
            if (currentTagElement.getLastChild() instanceof PsiErrorElement) {
              doInsertion = true;
              break;
            }
          }
        }
        iterator.advance();
      }
    }
    if (doInsertion && CfmlUtil.isEndTagRequired(((CfmlTag)tagElement).getTagName(), project)) {
      EditorModificationUtil.insertStringAtCaret(editor, "</" + ((CfmlTag)tagElement).getTagName() + ">", true, 0);
      return true;
View Full Code Here

    if (offset == 0) return false;
    CharSequence chars = editor.getDocument().getCharsSequence();
    if (chars.charAt(offset - 1) != '}') return false;

    EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
    HighlighterIterator iterator = highlighter.createIterator(offset - 1);

    final PsiElement openerElement = file.findElementAt(iterator.getStart());

    PsiElement openTag = HbPsiUtil.findParentOpenTagElement(openerElement);

    if (openTag == null) {
      return false;
    }

    iterator.advance();

    if (iterator.atEnd()) {
      // no more tokens, so certainly no close tag
      return false;
    }

    final PsiElement closerElement = file.findElementAt(iterator.getStart());

    PsiElement closeTag = HbPsiUtil.findParentCloseTagElement(closerElement);

    // if we got this far, we're between open and close tags iff this is a close tag
    return closeTag != null;
View Full Code Here

  private void doTest() throws Throwable {
    final int pairOffset = configureByTestFile(getTestName(false));
    int offset = myFixture.getEditor().getCaretModel().getOffset();
    EditorHighlighter editorHighlighter = ((EditorEx)myFixture.getEditor()).getHighlighter();
    HighlighterIterator iterator = editorHighlighter.createIterator(offset);
    boolean forward = offset < pairOffset;
    boolean matched = BraceMatchingUtil
      .matchBrace(myFixture.getEditor().getDocument().getCharsSequence(), myFixture.getFile().getFileType(), iterator, forward);

    assertTrue(matched);
    assertEquals(pairOffset, iterator.getStart());
  }
View Full Code Here

*/
public class CfmlEditorUtil {
  public static int countSharpsBalance(Editor editor) {
    int sharpsCounter = 0;
    // count balance
    HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(0);
    while (!iterator.atEnd()) {
      if (iterator.getTokenType() == CfscriptTokenTypes.OPENSHARP ||
          iterator.getTokenType() == CfmlTokenTypes.START_EXPRESSION) {
        sharpsCounter++;
      }
      else if (iterator.getTokenType() == CfscriptTokenTypes.CLOSESHARP ||
               iterator.getTokenType() == CfmlTokenTypes.END_EXPRESSION) {
        sharpsCounter--;
      }
      iterator.advance();
    }
    return sharpsCounter;
  }
View Full Code Here

*/
public class CfmlTailType extends TailType {
  public static final TailType PARENTHS = new CfmlTailType();

  public int processTail(Editor editor, int tailOffset) {
    HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(tailOffset);
    if (iterator.getTokenType() != CfscriptTokenTypes.L_BRACKET) {
      editor.getDocument().insertString(tailOffset, "()");
    }
    return moveCaret(editor, tailOffset, 1);
  }
View Full Code Here

        continue;
      }
      result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s.getName()).
        withCaseSensitivity(false), new TailType() {
        public int processTail(Editor editor, int tailOffset) {
          HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(tailOffset);
          if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.WHITE_SPACE) iterator.advance();
          if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.ASSIGN) {
            iterator.advance();
          }
          else {
            editor.getDocument().insertString(tailOffset, "=\"\"");
            return moveCaret(editor, tailOffset, 2);
          }
          int offset = iterator.getStart();
          if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.WHITE_SPACE) iterator.advance();
          if (!iterator.atEnd() && CfmlTokenTypes.STRING_ELEMENTS.contains(iterator.getTokenType())) {
            return tailOffset;
          }

          editor.getDocument().insertString(offset, "\"\"");
          return moveCaret(editor, tailOffset, offset - tailOffset + 1);
View Full Code Here

    if (!(file instanceof ErlangFile)) return false;

    PsiDocumentManager.getInstance(project).commitAllDocuments();

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

    if (offset == 0) return false;
    if (!atEndOfDocument) iterator.retreat();
    if (iterator.atEnd()) return false;

    PsiElement elementAt = file.findElementAt(offset - 1);
    if (elementAt == null || elementAt.getNode().getElementType() != ErlangTypes.ERL_SEMI) return false;
    ASTNode sibling = FormatterUtil.getPreviousNonWhitespaceSibling(elementAt.getNode());
    if (sibling == null) return false;
View Full Code Here

    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();
    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;
View Full Code Here

TOP

Related Classes of com.intellij.openapi.editor.highlighter.HighlighterIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.