Java Code Examples for com.intellij.util.text.CharArrayUtil#regionMatches()

The following examples show how to use com.intellij.util.text.CharArrayUtil#regionMatches() . 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: MinusculeMatcherImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private FList<TextRange> matchBySubstring(@Nonnull String name) {
  boolean infix = isPatternChar(0, '*');
  char[] patternWithoutWildChar = filterWildcard(myPattern);
  if (name.length() < patternWithoutWildChar.length) {
    return null;
  }
  if (infix) {
    int index = StringUtil.indexOfIgnoreCase(name, new CharArrayCharSequence(patternWithoutWildChar, 0, patternWithoutWildChar.length), 0);
    if (index >= 0) {
      return FList.<TextRange>emptyList().prepend(TextRange.from(index, patternWithoutWildChar.length - 1));
    }
    return null;
  }
  if (CharArrayUtil.regionMatches(patternWithoutWildChar, 0, patternWithoutWildChar.length, name)) {
    return FList.<TextRange>emptyList().prepend(new TextRange(0, patternWithoutWildChar.length));
  }
  return null;
}
 
Example 2
Source File: ZipEntryMap.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isTheOne(@Nonnull ArchiveHandler.EntryInfo entry, @Nonnull CharSequence relativePath) {
  int endIndex = relativePath.length();
  for (ArchiveHandler.EntryInfo e = entry; e != null; e = e.parent) {
    CharSequence shortName = e.shortName;
    if (!CharArrayUtil.regionMatches(relativePath, endIndex - shortName.length(), relativePath.length(), shortName)) {
      return false;
    }

    endIndex -= shortName.length();
    if (e.parent != null && e.parent.shortName.length() != 0 && endIndex != 0) {
      // match "/"
      if (relativePath.charAt(endIndex-1) == '/') {
        endIndex -= 1;
      }
      else {
        return false;
      }
    }

  }
  return endIndex==0;
}
 
Example 3
Source File: CommentByLineCommentHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void uncommentRange(Document document, int startOffset, int endOffset, @Nonnull Commenter commenter) {
  final String commentedSuffix = commenter.getCommentedBlockCommentSuffix();
  final String commentedPrefix = commenter.getCommentedBlockCommentPrefix();
  final String prefix = commenter.getBlockCommentPrefix();
  final String suffix = commenter.getBlockCommentSuffix();
  if (prefix == null || suffix == null) {
    return;
  }
  if (endOffset >= suffix.length() && CharArrayUtil.regionMatches(document.getCharsSequence(), endOffset - suffix.length(), suffix)) {
    document.deleteString(endOffset - suffix.length(), endOffset);
    endOffset -= suffix.length();
  }
  if (commentedPrefix != null && commentedSuffix != null) {
    CommentByBlockCommentHandler.commentNestedComments(document, new TextRange(startOffset, endOffset), commenter);
  }
  document.deleteString(startOffset, startOffset + prefix.length());
}
 
Example 4
Source File: JsonInsertValueHandler.java    From intellij-swagger with MIT License 5 votes vote down vote up
private void handleEndingQuote(final InsertionContext insertionContext) {
  final int caretOffset = insertionContext.getEditor().getCaretModel().getOffset();
  final CharSequence chars = insertionContext.getDocument().getCharsSequence();

  final boolean hasEndingQuote = CharArrayUtil.regionMatches(chars, caretOffset, "\"");
  if (!hasEndingQuote) {
    insertionContext.getDocument().insertString(caretOffset, "\"");
    EditorModificationUtil.moveCaretRelatively(insertionContext.getEditor(), 1);
  }
}
 
Example 5
Source File: JsonInsertFieldHandler.java    From intellij-swagger with MIT License 5 votes vote down vote up
private void handleEndingQuote(final InsertionContext insertionContext) {
  final int caretOffset = insertionContext.getEditor().getCaretModel().getOffset();
  final CharSequence chars = insertionContext.getDocument().getCharsSequence();

  final boolean hasEndingQuote = CharArrayUtil.regionMatches(chars, caretOffset, "\"");
  if (!hasEndingQuote) {
    insertionContext.getDocument().insertString(caretOffset, "\"");
  }
  EditorModificationUtil.moveCaretRelatively(insertionContext.getEditor(), 1);
}
 
Example 6
Source File: ApiCommenter.java    From ApiDebugger with Apache License 2.0 5 votes vote down vote up
@Override
public void uncommentLine(final int line, final int offset, @NotNull final Document document, @NotNull final CommenterDataHolder data) {
    if (document == null) {
        $$$reportNull$$$0(6);
    }
    if (data == null) {
        $$$reportNull$$$0(7);
    }
    if (CharArrayUtil.regionMatches(document.getCharsSequence(), offset, LINE_COMMENT_PREFIX)) {
        document.deleteString(offset, offset + LINE_COMMENT_PREFIX.length());
    }
}
 
Example 7
Source File: ApiCommenter.java    From ApiDebugger with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isLineCommented(final int line, final int offset, @NotNull final Document document, @NotNull final CommenterDataHolder data) {
    if (document == null) {
        $$$reportNull$$$0(8);
    }
    if (data == null) {
        $$$reportNull$$$0(9);
    }
    return CharArrayUtil.regionMatches(document.getCharsSequence(), offset, LINE_COMMENT_PREFIX);
}
 
Example 8
Source File: ApiCommenter.java    From ApiDebugger with Apache License 2.0 5 votes vote down vote up
@Override
public void uncommentBlockComment(final int startOffset, final int endOffset, final Document document, final CommenterDataHolder data) {
    if (CharArrayUtil.regionMatches(document.getCharsSequence(), startOffset, BLOCK_COMMENT_PREFIX) && CharArrayUtil.regionMatches(document.getCharsSequence(), endOffset - BLOCK_COMMENT_SUFFIX.length(), BLOCK_COMMENT_SUFFIX)) {
        document.deleteString(startOffset, BLOCK_COMMENT_PREFIX.length());
        document.deleteString(endOffset - BLOCK_COMMENT_SUFFIX.length(), endOffset);
    }
}
 
Example 9
Source File: DiffTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean textMatch(OT oldChild, NT newChild) {
  int oldStart = myOldTree.getStartOffset(oldChild) - myOldTreeStart;
  int oldEnd = myOldTree.getEndOffset(oldChild) - myOldTreeStart;
  int newStart = myNewTree.getStartOffset(newChild) - myNewTreeStart;
  int newEnd = myNewTree.getEndOffset(newChild) - myNewTreeStart;
  // drill down only if node texts match, but when they do, match all the way down unconditionally
  return CharArrayUtil.regionMatches(myOldText, oldStart, oldEnd, myNewText, newStart, newEnd);
}
 
Example 10
Source File: CommentByLineCommentHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int getCommentStart(Editor editor, PsiFile psiFile, int line) {
  int offset = editor.getDocument().getLineStartOffset(line);
  CharSequence chars = editor.getDocument().getCharsSequence();
  offset = CharArrayUtil.shiftForward(chars, offset, " \t");
  final Commenter commenter = findCommenter(editor, psiFile, line);
  if (commenter == null) return -1;
  String prefix = commenter.getLineCommentPrefix();
  if (prefix == null) prefix = commenter.getBlockCommentPrefix();
  if (prefix == null) return -1;
  return CharArrayUtil.regionMatches(chars, offset, prefix) ? offset : -1;
}
 
Example 11
Source File: CodeDocumentationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
static CommentContext tryParseCommentContext(@Nullable Commenter langCommenter, @Nonnull CharSequence chars, int lineStartOffset) {
  final boolean isInsideCommentLikeCode = langCommenter instanceof CodeDocumentationAwareCommenter;
  if (!isInsideCommentLikeCode) {
    return new CommentContext();
  }
  final CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter)langCommenter;
  int commentStartOffset = CharArrayUtil.shiftForward(chars, lineStartOffset, " \t");

  boolean docStart = commenter.getDocumentationCommentPrefix() != null && CharArrayUtil.regionMatches(chars, commentStartOffset, commenter.getDocumentationCommentPrefix());
  boolean docAsterisk = commenter.getDocumentationCommentLinePrefix() != null && CharArrayUtil.regionMatches(chars, commentStartOffset, commenter.getDocumentationCommentLinePrefix());
  return new CommentContext(commenter, docStart, docAsterisk, commentStartOffset);
}
 
Example 12
Source File: YamlValueInsertHandler.java    From intellij-spring-assistant with MIT License 4 votes vote down vote up
private boolean hasEndingQuote(final InsertionContext insertionContext, final int caretOffset,
    final char quoteType) {
  final CharSequence chars = insertionContext.getDocument().getCharsSequence();

  return CharArrayUtil.regionMatches(chars, caretOffset, String.valueOf(quoteType));
}
 
Example 13
Source File: DotEnvCommenter.java    From idea-php-dotenv-plugin with MIT License 4 votes vote down vote up
@Override
public boolean isLineCommented(int line, int offset, @NotNull Document document, @NotNull CommenterDataHolder data) {
    return CharArrayUtil.regionMatches(document.getCharsSequence(), offset, HASH_COMMENT_PREFIX);
}
 
Example 14
Source File: YamlInsertValueHandler.java    From intellij-swagger with MIT License 4 votes vote down vote up
private boolean hasEndingQuote(
    final InsertionContext insertionContext, final int caretOffset, final char quoteType) {
  final CharSequence chars = insertionContext.getDocument().getCharsSequence();

  return CharArrayUtil.regionMatches(chars, caretOffset, String.valueOf(quoteType));
}
 
Example 15
Source File: CommentByLineCommentHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isLineCommented(Block block, final int line, final Commenter commenter) {
  boolean commented;
  int lineEndForBlockCommenting = -1;
  Document document = block.editor.getDocument();
  int lineStart = document.getLineStartOffset(line);
  CharSequence chars = document.getCharsSequence();
  lineStart = CharArrayUtil.shiftForward(chars, lineStart, " \t");

  if (commenter instanceof SelfManagingCommenter) {
    final SelfManagingCommenter selfManagingCommenter = (SelfManagingCommenter)commenter;
    commented = selfManagingCommenter.isLineCommented(line, lineStart, document, block.commenterStateMap.get(selfManagingCommenter));
  }
  else {
    String prefix = commenter.getLineCommentPrefix();

    if (prefix != null) {
      commented = CharArrayUtil.regionMatches(chars, lineStart, StringUtil.trimTrailing(prefix));
    }
    else {
      prefix = commenter.getBlockCommentPrefix();
      String suffix = commenter.getBlockCommentSuffix();
      final int textLength = document.getTextLength();
      lineEndForBlockCommenting = document.getLineEndOffset(line);
      if (lineEndForBlockCommenting == textLength) {
        final int shifted = CharArrayUtil.shiftBackward(chars, textLength - 1, " \t");
        if (shifted < textLength - 1) lineEndForBlockCommenting = shifted;
      }
      else {
        lineEndForBlockCommenting = CharArrayUtil.shiftBackward(chars, lineEndForBlockCommenting, " \t");
      }
      commented = lineStart == lineEndForBlockCommenting && block.startLine != block.endLine ||
                  CharArrayUtil.regionMatches(chars, lineStart, prefix) && CharArrayUtil.regionMatches(chars, lineEndForBlockCommenting - suffix.length(), suffix);
    }
  }

  if (commented) {
    block.startOffsets[line - block.startLine] = lineStart;
    block.endOffsets[line - block.startLine] = lineEndForBlockCommenting;
  }

  return commented;
}
 
Example 16
Source File: PrefixSuffixStripperLexer.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void locateToken() {
  if (myTokenType != null || myState == 3) return;

  if (myState == 0) {
    myTokenEnd = myTokenStart + myPrefix.length();
    myTokenType = myPrefixType;
    myState = myTokenEnd < myBufferEnd ? 1 : 3;
    return;
  }

  if (myState == 1) {
    myTokenStart = myTokenEnd;
    final int suffixStart = myBufferEnd - mySuffix.length();
    myTokenType = myMiddleTokenType;
    if ( (myBufferArray != null && CharArrayUtil.regionMatches(myBufferArray, suffixStart, myBufferEnd, mySuffix)) ||
         (myBufferArray == null && CharArrayUtil.regionMatches(myBuffer, suffixStart, myBufferEnd, mySuffix))
       ) {
      myTokenEnd = suffixStart;
      if (myTokenStart < myTokenEnd) {
        myState = 2;
      }
      else {
        myState = 3;
        myTokenType = mySuffixType;
        myTokenEnd = myBufferEnd;
      }
    }
    else {
      myTokenEnd = myBufferEnd;
      myState = 3;
    }

    return;
  }

  if (myState == 2) {
    myTokenStart = myTokenEnd;
    myTokenEnd = myBufferEnd;
    myTokenType = mySuffixType;
    myState = 3;
  }
}