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

The following examples show how to use com.intellij.util.text.CharArrayUtil#containLineBreaks() . 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: CodeEditUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void replaceChild(ASTNode parent, @Nonnull ASTNode oldChild, @Nonnull ASTNode newChild) {
  saveWhitespacesInfo(oldChild);
  saveWhitespacesInfo(newChild);
  checkForOuters(oldChild);
  checkForOuters(newChild);

  LeafElement oldFirst = TreeUtil.findFirstLeaf(oldChild);

  parent.replaceChild(oldChild, newChild);
  final LeafElement firstLeaf = TreeUtil.findFirstLeaf(newChild);
  final ASTNode prevToken = TreeUtil.prevLeaf(newChild);
  if (firstLeaf != null) {
    final ASTNode nextLeaf = TreeUtil.nextLeaf(newChild);
    makePlaceHolderBetweenTokens(prevToken, firstLeaf, isFormattingRequired(prevToken, newChild), false);
    if (nextLeaf != null && !CharArrayUtil.containLineBreaks(nextLeaf.getText())) {
      makePlaceHolderBetweenTokens(TreeUtil.prevLeaf(nextLeaf), nextLeaf, false, false);
    }
  }
  else {
    if (oldFirst != null && prevToken == null) {
      ASTNode whitespaceNode = newChild.getTreeNext();
      if (whitespaceNode != null && whitespaceNode.getElementType() == TokenType.WHITE_SPACE) {
        // Replacing non-empty prefix to empty shall remove whitespace
        parent.removeChild(whitespaceNode);
      }
    }

    makePlaceHolderBetweenTokens(prevToken, TreeUtil.nextLeaf(newChild), isFormattingRequired(prevToken, newChild), false);
  }
}
 
Example 2
Source File: SemanticEditorPosition.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if there are line breaks strictly after the given offset till the end of the current element.
 *
 * @param offset The offset to search line breaks after.
 * @return True if there are line breaks after the given offset.
 */
public boolean hasLineBreaksAfter(int offset) {
  if (!myIterator.atEnd() && offset >= 0) {
    int offsetAfter = offset + 1;
    if (offsetAfter < myIterator.getEnd()) {
      return CharArrayUtil.containLineBreaks(myChars, offsetAfter, myIterator.getEnd());
    }
  }
  return false;
}
 
Example 3
Source File: DesktopCaretImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean needToShiftWhiteSpaces(final DocumentEvent e) {
  return e.getOffset() > 0 &&
         Character.isWhitespace(e.getDocument().getImmutableCharSequence().charAt(e.getOffset() - 1)) &&
         CharArrayUtil.containsOnlyWhiteSpaces(e.getNewFragment()) &&
         !CharArrayUtil.containLineBreaks(e.getNewFragment());
}
 
Example 4
Source File: LineSet.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean isSingleLineChange(int start, int end, @Nonnull CharSequence replacement) {
  if (start == 0 && end == myLength && replacement.length() == 0) return false;

  int startLine = findLineIndex(start);
  return startLine == findLineIndex(end) && !CharArrayUtil.containLineBreaks(replacement) && !isLastEmptyLine(startLine);
}
 
Example 5
Source File: SemanticEditorPosition.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean isAtMultiline() {
  if (!myIterator.atEnd()) {
    return CharArrayUtil.containLineBreaks(myChars, myIterator.getStart(), myIterator.getEnd());
  }
  return false;
}
 
Example 6
Source File: SemanticEditorPosition.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean isAtMultiline(SyntaxElement... elements) {
  return isAtAnyOf(elements) && CharArrayUtil.containLineBreaks(myChars, myIterator.getStart(), myIterator.getEnd());
}