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


Java Document.replaceString方法代码示例

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


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

示例1: getCopyWithAnswers

import com.intellij.openapi.editor.Document; //导入方法依赖的package包/类
static Pair<VirtualFile, TaskFile> getCopyWithAnswers(@NotNull final VirtualFile taskDir,
                                                              @NotNull final VirtualFile file,
                                                              @NotNull final TaskFile source) {
  try {
    VirtualFile answerFile = file.copy(taskDir, taskDir, file.getNameWithoutExtension() + EduNames.ANSWERS_POSTFIX + "." + file.getExtension());
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    final Document document = documentManager.getDocument(answerFile);
    if (document != null) {
      TaskFile answerTaskFile = source.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(file));
      if (answerTaskFile == null) {
        return null;
      }
      EduDocumentListener listener = new EduDocumentListener(answerTaskFile);
      document.addDocumentListener(listener);
      for (AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
        final int start = answerPlaceholder.getOffset();
        final int end = start + answerPlaceholder.getRealLength();
        final String text = answerPlaceholder.getPossibleAnswer();
        document.replaceString(start, end, text);
      }
      ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(document));
      return Pair.create(answerFile, answerTaskFile);
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  return null;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:30,代码来源:PyStudySmartChecker.java

示例2: smartCheck

import com.intellij.openapi.editor.Document; //导入方法依赖的package包/类
private static void smartCheck(@NotNull final AnswerPlaceholder placeholder,
                              @NotNull final Project project,
                              @NotNull final VirtualFile answerFile,
                              @NotNull final TaskFile answerTaskFile,
                              @NotNull final TaskFile usersTaskFile,
                              @NotNull final PyStudyTestRunner testRunner,
                              @NotNull final VirtualFile virtualFile,
                              @NotNull final Document usersDocument) {
  VirtualFile fileWindows = null;
  VirtualFile windowCopy = null;
  try {
    final int index = placeholder.getIndex();
    String windowCopyName = answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX + answerFile.getExtension();
    windowCopy = answerFile.copy(project, answerFile.getParent(), windowCopyName);
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    final Document windowDocument = documentManager.getDocument(windowCopy);
    if (windowDocument != null) {
      TaskFile windowTaskFile = answerTaskFile.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(virtualFile));
      if (windowTaskFile == null) {
        return;
      }
      EduDocumentListener listener = new EduDocumentListener(windowTaskFile);
      windowDocument.addDocumentListener(listener);
      int start = placeholder.getOffset();
      int end = start + placeholder.getRealLength();
      final AnswerPlaceholder userAnswerPlaceholder = usersTaskFile.getAnswerPlaceholders().get(placeholder.getIndex());
      int userStart = userAnswerPlaceholder.getOffset();
      int userEnd = userStart + userAnswerPlaceholder.getRealLength();
      String text = usersDocument.getText(new TextRange(userStart, userEnd));
      windowDocument.replaceString(start, end, text);
      ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(windowDocument));
      fileWindows = EduUtils.flushWindows(windowTaskFile, windowCopy);
      Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath());
      final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess, null, windowCopy.getPath());
      final ProcessOutput output = handler.runProcess();
      final Course course = StudyTaskManager.getInstance(project).getCourse();
      if (course != null) {
        boolean res = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive()).isSuccess();
        StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
      }
    }
  }
  catch (ExecutionException | IOException e) {
    LOG.error(e);
  }
  finally {
    StudyUtils.deleteFile(windowCopy);
    StudyUtils.deleteFile(fileWindows);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:51,代码来源:PyStudySmartChecker.java


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