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


Java DocumentUtil类代码示例

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


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

示例1: saveIndent

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
private static void saveIndent(AnswerPlaceholder placeholder, CCState state, boolean visible) {
  Document document = state.getEditor().getDocument();
  int offset = placeholder.getOffset();
  int lineNumber = document.getLineNumber(offset);
  int nonSpaceCharOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
  int newOffset = offset;
  int endOffset = offset + placeholder.getRealLength();
  if (!visible && nonSpaceCharOffset == offset) {
    newOffset = document.getLineStartOffset(lineNumber);
  }
  if (visible) {
    newOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, offset, endOffset);
  }
  placeholder.setOffset(newOffset);
  int delta = offset - newOffset;
  placeholder.setPossibleAnswer(document.getText(TextRange.create(newOffset, newOffset + delta + placeholder.getRealLength())));
  String oldTaskText = placeholder.getTaskText();
  if (delta >= 0) {
    placeholder.setTaskText(StringUtil.repeat(" ", delta) + oldTaskText);
  }
  else {
    String newTaskText = oldTaskText.substring(Math.abs(delta));
    placeholder.setTaskText(newTaskText);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:26,代码来源:CCChangePlaceholderVisibility.java

示例2: actionPerformed

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
public void actionPerformed(AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return;
  }
  DebuggerManagerEx debugManager = DebuggerManagerEx.getInstanceEx(project);
  if (debugManager == null) {
    return;
  }
  final BreakpointManager manager = debugManager.getBreakpointManager();
  final PlaceInDocument place = getPlace(e);
  if(place != null && DocumentUtil.isValidOffset(place.getOffset(), place.getDocument())) {
    Breakpoint breakpoint = manager.findBreakpoint(place.getDocument(), place.getOffset(), MethodBreakpoint.CATEGORY);
    if(breakpoint == null) {
      manager.addMethodBreakpoint(place.getDocument(), place.getDocument().getLineNumber(place.getOffset()));
    }
    else {
      manager.removeBreakpoint(breakpoint);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ToggleMethodBreakpointAction.java

示例3: getFirstElementOnTheLine

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Nullable
public static PsiElement getFirstElementOnTheLine(PsiLambdaExpression lambda, Document document, int line) {
  ApplicationManager.getApplication().assertReadAccessAllowed();
  TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
  if (!intersects(lineRange, lambda)) return null;
  PsiElement body = lambda.getBody();
  if (body == null || !intersects(lineRange, body)) return null;
  if (body instanceof PsiCodeBlock) {
    for (PsiStatement statement : ((PsiCodeBlock)body).getStatements()) {
      if (intersects(lineRange, statement)) {
        return statement;
      }
    }
    return null;
  }
  return body;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:DebuggerUtilsEx.java

示例4: createLineMarker

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@NotNull
public static List<RangeHighlighter> createLineMarker(@NotNull final Editor editor, int line, @NotNull final SeparatorPlacement placement,
                                                      @Nullable TextDiffType type, @NotNull LineSeparatorRenderer renderer, boolean applied) {
  // We won't use addLineHighlighter as it will fail to add marker into empty document.
  //RangeHighlighter highlighter = editor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.SELECTION - 1, null);

  int offset = DocumentUtil.getFirstNonSpaceCharOffset(editor.getDocument(), line);
  RangeHighlighter highlighter = editor.getMarkupModel()
    .addRangeHighlighter(offset, offset, LINE_MARKER_LAYER, null, HighlighterTargetArea.LINES_IN_RANGE);

  highlighter.setLineSeparatorPlacement(placement);
  highlighter.setLineSeparatorRenderer(renderer);

  if (type == null || applied) return Collections.singletonList(highlighter);

  TextAttributes stripeAttributes = getStripeTextAttributes(type, editor);
  RangeHighlighter stripeHighlighter = editor.getMarkupModel()
    .addRangeHighlighter(offset, offset, STRIPE_LAYER, stripeAttributes, HighlighterTargetArea.LINES_IN_RANGE);

  return ContainerUtil.list(highlighter, stripeHighlighter);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DiffDrawUtil.java

示例5: visit

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
/**
 * Read action will be taken automatically
 */
public static <RESULT> RESULT visit(@NotNull XSourcePosition position, @NotNull Project project, @NotNull Visitor<RESULT> visitor, RESULT defaultResult) {
  AccessToken token = ReadAction.start();
  try {
    Document document = FileDocumentManager.getInstance().getDocument(position.getFile());
    PsiFile file = document == null || document.getTextLength() == 0 ? null : PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (file == null) {
      return defaultResult;
    }

    int positionOffset;
    int column = position instanceof SourceInfo ? Math.max(((SourceInfo)position).getColumn(), 0) : 0;
    try {
      positionOffset = column == 0 ? DocumentUtil.getFirstNonSpaceCharOffset(document, position.getLine()) : document.getLineStartOffset(position.getLine()) + column;
    }
    catch (IndexOutOfBoundsException ignored) {
      return defaultResult;
    }

    PsiElement element = file.findElementAt(positionOffset);
    return element == null ? defaultResult : visitor.visit(element, positionOffset, document);
  }
  finally {
    token.finish();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PsiVisitors.java

示例6: changedUpdateImpl

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Override
protected void changedUpdateImpl(@NotNull DocumentEvent e) {
  // todo Denis Zhdanov
  DocumentEventImpl event = (DocumentEventImpl)e;
  final boolean shouldTranslateViaDiff = isValid() && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, this);
  boolean wasTranslatedViaDiff = shouldTranslateViaDiff;
  if (shouldTranslateViaDiff) {
    wasTranslatedViaDiff = translatedViaDiff(e, event);
  }
  if (!wasTranslatedViaDiff) {
    super.changedUpdateImpl(e);
    if (isValid()) {
      myLine = getDocument().getLineNumber(getStartOffset());
      int endLine = getDocument().getLineNumber(getEndOffset());
      if (endLine != myLine) {
        setIntervalEnd(getDocument().getLineEndOffset(myLine));
      }
    }
  }
  if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
    setIntervalStart(DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), myLine));
    setIntervalEnd(getDocument().getLineEndOffset(myLine));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:PersistentRangeHighlighterImpl.java

示例7: executeWriteAction

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  if (editor.getSelectionModel().hasSelection()) {
    int selStart = editor.getSelectionModel().getSelectionStart();
    int selEnd = editor.getSelectionModel().getSelectionEnd();
    if (selEnd > selStart && DocumentUtil.isAtLineStart(selEnd, editor.getDocument())) {
      selEnd--;
    }
    VisualPosition rangeStart = editor.offsetToVisualPosition(Math.min(selStart, selEnd));
    VisualPosition rangeEnd = editor.offsetToVisualPosition(Math.max(selStart, selEnd));
    final Couple<Integer> copiedRange =
      DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), rangeStart, rangeEnd);
    if (copiedRange != null) {
      editor.getSelectionModel().setSelection(copiedRange.first, copiedRange.second);
    }
  }
  else {
    VisualPosition caretPos = editor.getCaretModel().getVisualPosition();
    DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), caretPos, caretPos);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DuplicateLinesAction.java

示例8: updateTextElement

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
private void updateTextElement(final PsiElement elt) {
  final String newText = getNewText(elt);
  if (newText == null || Comparing.strEqual(newText, myEditor.getDocument().getText())) return;
  DocumentUtil.writeInRunUndoTransparentAction(new Runnable() {
    @Override
    public void run() {
      Document fragmentDoc = myEditor.getDocument();
      fragmentDoc.setReadOnly(false);

      fragmentDoc.replaceString(0, fragmentDoc.getTextLength(), newText);
      fragmentDoc.setReadOnly(true);
      myEditor.getCaretModel().moveToOffset(0);
      myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ImplementationViewComponent.java

示例9: 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

示例10: addToHistoryInner

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@NotNull
protected String addToHistoryInner(@NotNull final TextRange textRange, @NotNull final EditorEx editor, boolean erase, final boolean preserveMarkup) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  String result = addTextRangeToHistory(textRange, editor, preserveMarkup);
  if (erase) {
    DocumentUtil.writeInRunUndoTransparentAction(new Runnable() {
      @Override
      public void run() {
        editor.getDocument().deleteString(textRange.getStartOffset(), textRange.getEndOffset());
      }
    });
  }
  // always scroll to end on user input
  scrollToEnd();
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:LanguageConsoleImpl.java

示例11: updateText

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
public void updateText(@NotNull final Producer<String> contentProducer) {
  myAlarm.cancelAllRequests();
  myAlarm.addRequest(new Runnable() {
    @Override
    public void run() {
      if (!isDisposed) {
        final String newText = contentProducer.produce();
        if (StringUtil.isEmpty(newText)) {
          hide();
        }
        else if (!myEditor.getDocument().getText().equals(newText)) {
          DocumentUtil.writeInRunUndoTransparentAction(new Runnable() {
            @Override
            public void run() {
              myEditor.getDocument().setText(newText);
            }
          });
        }
      }
    }
  }, 100);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:EmmetPreviewHint.java

示例12: invokeOnTheFlyImportOptimizer

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
public static void invokeOnTheFlyImportOptimizer(@NotNull final Runnable runnable,
                                                 @NotNull final PsiFile file,
                                                 @NotNull final Editor editor) {
  final long stamp = editor.getDocument().getModificationStamp();
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      if (file.getProject().isDisposed() || editor.isDisposed() || editor.getDocument().getModificationStamp() != stamp) return;
      //no need to optimize imports on the fly during undo/redo
      final UndoManager undoManager = UndoManager.getInstance(editor.getProject());
      if (undoManager.isUndoInProgress() || undoManager.isRedoInProgress()) return;
      PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
      String beforeText = file.getText();
      final long oldStamp = editor.getDocument().getModificationStamp();
      DocumentUtil.writeInRunUndoTransparentAction(runnable);
      if (oldStamp != editor.getDocument().getModificationStamp()) {
        String afterText = file.getText();
        if (Comparing.strEqual(beforeText, afterText)) {
          String path = file.getViewProvider().getVirtualFile().getPath();
          LOG.error("Import optimizer  hasn't optimized any imports", new Attachment(path, afterText));
        }
      }
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GroovyOptimizeImportsFix.java

示例13: reset

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
public void reset() {
  myDisplayName = myCopyrightProfile.getName();
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      DocumentUtil.writeInRunUndoTransparentAction(new Runnable() {
        @Override
        public void run() {
          myEditor.getDocument().setText(EntityUtil.decode(myCopyrightProfile.getNotice()));
        }
      });
    }
  });
  myKeywordTf.setText(myCopyrightProfile.getKeyword());
  myAllowReplaceTextField.setText(myCopyrightProfile.getAllowReplaceKeyword());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CopyrightConfigurable.java

示例14: done

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Nonnull
public List<RangeHighlighter> done() {
  // We won't use addLineHighlighter as it will fail to add marker into empty document.
  //RangeHighlighter highlighter = editor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.SELECTION - 1, null);

  int offset = DocumentUtil.getFirstNonSpaceCharOffset(editor.getDocument(), line);
  RangeHighlighter highlighter = editor.getMarkupModel()
          .addRangeHighlighter(offset, offset, LINE_MARKER_LAYER, null, HighlighterTargetArea.LINES_IN_RANGE);

  highlighter.setLineSeparatorPlacement(placement);
  highlighter.setLineSeparatorRenderer(renderer);
  highlighter.setLineMarkerRenderer(gutterRenderer);

  if (type == null || resolved) return Collections.singletonList(highlighter);

  TextAttributes stripeAttributes = getStripeTextAttributes(type, editor);
  RangeHighlighter stripeHighlighter = editor.getMarkupModel()
          .addRangeHighlighter(offset, offset, STRIPE_LAYER, stripeAttributes, HighlighterTargetArea.LINES_IN_RANGE);

  return ContainerUtil.list(highlighter, stripeHighlighter);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:DiffDrawUtil.java

示例15: executeWriteCommand

import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@RequiredDispatchThread
public static void executeWriteCommand(@javax.annotation.Nullable Project project,
                                       @Nonnull Document document,
                                       @javax.annotation.Nullable String commandName,
                                       @javax.annotation.Nullable String commandGroupId,
                                       @Nonnull UndoConfirmationPolicy confirmationPolicy,
                                       boolean underBulkUpdate,
                                       @Nonnull Runnable task) {
  if (!makeWritable(project, document)) {
    VirtualFile file = FileDocumentManager.getInstance().getFile(document);
    LOG.warn("Document is read-only" + (file != null ? ": " + file.getPresentableName() : ""));
    return;
  }

  ApplicationManager.getApplication().runWriteAction(() -> {
    CommandProcessor.getInstance().executeCommand(project, () -> {
      if (underBulkUpdate) {
        DocumentUtil.executeInBulk(document, true, task);
      }
      else {
        task.run();
      }
    }, commandName, commandGroupId, confirmationPolicy, document);
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:26,代码来源:DiffUtil.java


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