当前位置: 首页>>代码示例>>Java>>正文


Java DocumentUtil.executeInBulk方法代码示例

本文整理汇总了Java中com.intellij.util.DocumentUtil.executeInBulk方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentUtil.executeInBulk方法的具体用法?Java DocumentUtil.executeInBulk怎么用?Java DocumentUtil.executeInBulk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.util.DocumentUtil的用法示例。


在下文中一共展示了DocumentUtil.executeInBulk方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reformatBlock

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private static void reformatBlock(final Project project, final Editor editor, final int startOffset, final int endOffset) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();
  Runnable task = new Runnable() {
    @Override
    public void run() {
      PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
      try {
        CodeStyleManager.getInstance(project).reformatRange(file, startOffset, endOffset, true);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  };

  if (endOffset - startOffset > 1000) {
    DocumentUtil.executeInBulk(editor.getDocument(), true, task);
  }
  else {
    task.run();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PasteHandler.java

示例2: executeChanges

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private void executeChanges(@Nonnull List<TemplateDocumentChange> changes) {
  if (isDisposed() || changes.isEmpty()) {
    return;
  }
  if (changes.size() > 1) {
    ContainerUtil.sort(changes, (o1, o2) -> {
      int startDiff = o2.startOffset - o1.startOffset;
      return startDiff != 0 ? startDiff : o2.endOffset - o1.endOffset;
    });
  }
  DocumentUtil.executeInBulk(myDocument, true, () -> {
    for (TemplateDocumentChange change : changes) {
      replaceString(change.newValue, change.startOffset, change.endOffset, change.segmentNumber);
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:17,代码来源:TemplateState.java

示例3: restoreEmptyVariables

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private void restoreEmptyVariables(IntArrayList indices) {
  List<TextRange> rangesToRemove = ContainerUtil.newArrayList();
  for (int i = 0; i < indices.size(); i++) {
    int index = indices.get(i);
    rangesToRemove.add(TextRange.create(mySegments.getSegmentStart(index), mySegments.getSegmentEnd(index)));
  }
  Collections.sort(rangesToRemove, (o1, o2) -> {
    int startDiff = o2.getStartOffset() - o1.getStartOffset();
    return startDiff != 0 ? startDiff : o2.getEndOffset() - o1.getEndOffset();
  });
  DocumentUtil.executeInBulk(myDocument, true, () -> {
    if (isDisposed()) {
      return;
    }
    for (TextRange range : rangesToRemove) {
      myDocument.deleteString(range.getStartOffset(), range.getEndOffset());
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:TemplateState.java

示例4: doDefaultCommenting

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
public void doDefaultCommenting(final Block block) {
  final Document document = block.editor.getDocument();
  DocumentUtil.executeInBulk(
    document, block.endLine - block.startLine >= Registry.intValue("comment.by.line.bulk.lines.trigger"), new Runnable() {
    @Override
    public void run() {
      for (int line = block.endLine; line >= block.startLine; line--) {
        int offset = document.getLineStartOffset(line);
        commentLine(block, line, offset);
      }
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:CommentByLineCommentHandler.java

示例5: doIndentCommenting

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private void doIndentCommenting(final Block block) {
  final Document document = block.editor.getDocument();
  final CharSequence chars = document.getCharsSequence();
  final FileType fileType = block.psiFile.getFileType();
  final Indent minIndent = computeMinIndent(block.editor, block.psiFile, block.startLine, block.endLine, fileType);

  DocumentUtil.executeInBulk(
    document, block.endLine - block.startLine > Registry.intValue("comment.by.line.bulk.lines.trigger"), new Runnable() {
      @Override
      public void run() {
        for (int line = block.endLine; line >= block.startLine; line--) {
          int lineStart = document.getLineStartOffset(line);
          int offset = lineStart;
          final StringBuilder buffer = new StringBuilder();
          while (true) {
            String space = buffer.toString();
            Indent indent = myCodeStyleManager.getIndent(space, fileType);
            if (indent.isGreaterThan(minIndent) || indent.equals(minIndent)) break;
            char c = chars.charAt(offset);
            if (c != ' ' && c != '\t') {
              String newSpace = myCodeStyleManager.fillIndent(minIndent, fileType);
              document.replaceString(lineStart, offset, newSpace);
              offset = lineStart + newSpace.length();
              break;
            }
            buffer.append(c);
            offset++;
          }
          commentLine(block, line, offset);
        }
      }
    });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:CommentByLineCommentHandler.java

示例6: doDefaultCommenting

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
public void doDefaultCommenting(final Commenter commenter) {
  DocumentUtil.executeInBulk(
    myDocument, myEndLine - myStartLine >= Registry.intValue("comment.by.line.bulk.lines.trigger"), new Runnable() {
    @Override
    public void run() {
      for (int line = myEndLine; line >= myStartLine; line--) {
        int offset = myDocument.getLineStartOffset(line);
        commentLine(line, offset, commenter);
      }
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:13,代码来源:CommentByLineCommentHandler.java

示例7: doIndentCommenting

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private void doIndentCommenting(final Commenter commenter) {
  final CharSequence chars = myDocument.getCharsSequence();
  final FileType fileType = myFile.getFileType();
  final Indent minIndent = computeMinIndent(myStartLine, myEndLine, chars, myCodeStyleManager, fileType);

  DocumentUtil.executeInBulk(
    myDocument, myEndLine - myStartLine > Registry.intValue("comment.by.line.bulk.lines.trigger"), new Runnable() {
    @Override
    public void run() {
      for (int line = myEndLine; line >= myStartLine; line--) {
        int lineStart = myDocument.getLineStartOffset(line);
        int offset = lineStart;
        final StringBuilder buffer = new StringBuilder();
        while (true) {
          String space = buffer.toString();
          Indent indent = myCodeStyleManager.getIndent(space, fileType);
          if (indent.isGreaterThan(minIndent) || indent.equals(minIndent)) break;
          char c = chars.charAt(offset);
          if (c != ' ' && c != '\t') {
            String newSpace = myCodeStyleManager.fillIndent(minIndent, fileType);
            myDocument.replaceString(lineStart, offset, newSpace);
            offset = lineStart + newSpace.length();
            break;
          }
          buffer.append(c);
          offset++;
        }
        commentLine(line, offset, commenter);
      }
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:33,代码来源:CommentByLineCommentHandler.java

示例8: doIndent

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
static void doIndent(final int endIndex, final int startIndex, final Document document, final Project project, final Editor editor,
                     final int blockIndent) {
  final int[] caretOffset = {editor.getCaretModel().getOffset()};

  boolean bulkMode = endIndex - startIndex > 50;
  DocumentUtil.executeInBulk(document, bulkMode, ()-> {
    List<Integer> nonModifiableLines = new ArrayList<>();
    if (project != null) {
      PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
      IndentStrategy indentStrategy = LanguageIndentStrategy.getIndentStrategy(file);
      if (!LanguageIndentStrategy.isDefault(indentStrategy)) {
        for (int i = startIndex; i <= endIndex; i++) {
          if (!canIndent(document, file, i, indentStrategy)) {
            nonModifiableLines.add(i);
          }
        }
      }
    }
    for(int i=startIndex; i<=endIndex; i++) {
      if (!nonModifiableLines.contains(i)) {
        caretOffset[0] = EditorActionUtil.indentLine(project, editor, i, blockIndent, caretOffset[0]);
      }
    }
  });

  editor.getCaretModel().moveToOffset(caretOffset[0]);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:28,代码来源:IndentSelectionAction.java

示例9: processIndents

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private static int processIndents(Document document, int tabSize, TextRange textRange, IndentBuilder indentBuilder) {
  int[] changedLines = {0};
  DocumentUtil.executeInBulk(document, true, () -> {
    int startLine = document.getLineNumber(textRange.getStartOffset());
    int endLine = document.getLineNumber(textRange.getEndOffset());
    for (int line = startLine; line <= endLine; line++) {
      int indent = 0;
      final int lineStart = document.getLineStartOffset(line);
      final int lineEnd = document.getLineEndOffset(line);
      int indentEnd = lineEnd;
      for(int offset = Math.max(lineStart, textRange.getStartOffset()); offset < lineEnd; offset++) {
        char c = document.getCharsSequence().charAt(offset);
        if (c == ' ') {
          indent++;
        }
        else if (c == '\t') {
          indent = ((indent / tabSize) + 1) * tabSize;
        }
        else {
          indentEnd = offset;
          break;
        }
      }
      if (indent > 0) {
        String oldIndent = document.getCharsSequence().subSequence(lineStart, indentEnd).toString();
        String newIndent = indentBuilder.buildIndent(indent, tabSize);
        if (!oldIndent.equals(newIndent)) {
          document.replaceString(lineStart, indentEnd, newIndent);
          changedLines[0]++;
        }
      }
    }
  });
  return changedLines[0];
}
 
开发者ID:consulo,项目名称:consulo,代码行数:36,代码来源:ConvertIndentsActionBase.java

示例10: doDefaultCommenting

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
public void doDefaultCommenting(final Block block) {
  final Document document = block.editor.getDocument();
  DocumentUtil.executeInBulk(document, block.endLine - block.startLine >= Registry.intValue("comment.by.line.bulk.lines.trigger"), () -> {
    for (int line = block.endLine; line >= block.startLine; line--) {
      int offset = document.getLineStartOffset(line);
      commentLine(block, line, offset);
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:10,代码来源:CommentByLineCommentHandler.java

示例11: doIndentCommenting

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private void doIndentCommenting(final Block block) {
  final Document document = block.editor.getDocument();
  final CharSequence chars = document.getCharsSequence();
  final FileType fileType = block.psiFile.getFileType();
  final Indent minIndent = computeMinIndent(block.editor, block.psiFile, block.startLine, block.endLine, fileType);

  DocumentUtil.executeInBulk(document, block.endLine - block.startLine > Registry.intValue("comment.by.line.bulk.lines.trigger"), () -> {
    for (int line = block.endLine; line >= block.startLine; line--) {
      int lineStart = document.getLineStartOffset(line);
      int offset = lineStart;
      final StringBuilder buffer = new StringBuilder();
      while (true) {
        String space = buffer.toString();
        Indent indent = myCodeStyleManager.getIndent(space, fileType);
        if (indent.isGreaterThan(minIndent) || indent.equals(minIndent)) break;
        char c = chars.charAt(offset);
        if (c != ' ' && c != '\t') {
          String newSpace = myCodeStyleManager.fillIndent(minIndent, fileType);
          document.replaceString(lineStart, offset, newSpace);
          offset = lineStart + newSpace.length();
          break;
        }
        buffer.append(c);
        offset++;
      }
      commentLine(block, line, offset);
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:30,代码来源:CommentByLineCommentHandler.java

示例12: smartIndent

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private void smartIndent(int startOffset, int endOffset) {
  int startLineNum = myDocument.getLineNumber(startOffset);
  int endLineNum = myDocument.getLineNumber(endOffset);
  if (endLineNum == startLineNum) {
    return;
  }

  int selectionIndent = -1;
  int selectionStartLine = -1;
  int selectionEndLine = -1;
  int selectionSegment = myTemplate.getVariableSegmentNumber(TemplateImpl.SELECTION);
  if (selectionSegment >= 0) {
    int selectionStart = myTemplate.getSegmentOffset(selectionSegment);
    selectionIndent = 0;
    String templateText = myTemplate.getTemplateText();
    while (selectionStart > 0 && templateText.charAt(selectionStart - 1) == ' ') {
      // TODO handle tabs
      selectionIndent++;
      selectionStart--;
    }
    selectionStartLine = myDocument.getLineNumber(mySegments.getSegmentStart(selectionSegment));
    selectionEndLine = myDocument.getLineNumber(mySegments.getSegmentEnd(selectionSegment));
  }

  int indentLineNum = startLineNum;

  int lineLength = 0;
  for (; indentLineNum >= 0; indentLineNum--) {
    lineLength = myDocument.getLineEndOffset(indentLineNum) - myDocument.getLineStartOffset(indentLineNum);
    if (lineLength > 0) {
      break;
    }
  }
  if (indentLineNum < 0) {
    return;
  }
  StringBuilder buffer = new StringBuilder();
  CharSequence text = myDocument.getCharsSequence();
  for (int i = 0; i < lineLength; i++) {
    char ch = text.charAt(myDocument.getLineStartOffset(indentLineNum) + i);
    if (ch != ' ' && ch != '\t') {
      break;
    }
    buffer.append(ch);
  }
  if (buffer.length() == 0 && selectionIndent <= 0 || startLineNum >= endLineNum) {
    return;
  }
  String stringToInsert = buffer.toString();
  int finalSelectionStartLine = selectionStartLine;
  int finalSelectionEndLine = selectionEndLine;
  int finalSelectionIndent = selectionIndent;
  DocumentUtil.executeInBulk(myDocument, true, () -> {
    for (int i = startLineNum + 1; i <= endLineNum; i++) {
      if (i > finalSelectionStartLine && i <= finalSelectionEndLine) {
        myDocument.insertString(myDocument.getLineStartOffset(i), StringUtil.repeatSymbol(' ', finalSelectionIndent));
      }
      else {
        myDocument.insertString(myDocument.getLineStartOffset(i), stringToInsert);
      }
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:64,代码来源:TemplateState.java


注:本文中的com.intellij.util.DocumentUtil.executeInBulk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。