コード例 #1
0
 public static void runSmartTestProcess(
     @NotNull final VirtualFile taskDir,
     @NotNull final StudyTestRunner testRunner,
     final String taskFileName,
     @NotNull final TaskFile taskFile,
     @NotNull final Project project) {
   final TaskFile answerTaskFile = new TaskFile();
   answerTaskFile.name = taskFileName;
   final VirtualFile virtualFile = taskDir.findChild(taskFileName);
   if (virtualFile == null) {
     return;
   }
   final VirtualFile answerFile =
       getCopyWithAnswers(taskDir, virtualFile, taskFile, answerTaskFile);
   for (final AnswerPlaceholder answerPlaceholder : answerTaskFile.getAnswerPlaceholders()) {
     final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
     if (document == null) {
       continue;
     }
     StudySmartChecker.smartCheck(
         answerPlaceholder,
         project,
         answerFile,
         answerTaskFile,
         taskFile,
         testRunner,
         virtualFile,
         document);
   }
   StudyUtils.deleteFile(answerFile);
 }
コード例 #2
0
  private static VirtualFile getCopyWithAnswers(
      @NotNull final VirtualFile taskDir,
      @NotNull final VirtualFile file,
      @NotNull final TaskFile source,
      @NotNull final TaskFile target) {
    VirtualFile copy = null;
    try {

      copy =
          file.copy(
              taskDir,
              taskDir,
              file.getNameWithoutExtension()
                  + EduNames.ANSWERS_POSTFIX
                  + "."
                  + file.getExtension());
      final FileDocumentManager documentManager = FileDocumentManager.getInstance();
      final Document document = documentManager.getDocument(copy);
      if (document != null) {
        TaskFile.copy(source, target);
        EduDocumentListener listener = new EduDocumentListener(target);
        document.addDocumentListener(listener);
        for (AnswerPlaceholder answerPlaceholder : target.getAnswerPlaceholders()) {
          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));
      }
    } catch (IOException e) {
      LOG.error(e);
    }
    return copy;
  }