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);
 }
 public static void showTestResultPopUp(
     final String text, Color color, @NotNull final Project project) {
   BalloonBuilder balloonBuilder =
       JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text, null, color, null);
   final Balloon balloon = balloonBuilder.createBalloon();
   StudyUtils.showCheckPopUp(project, balloon);
 }
 @Override
 public void actionPerformed(AnActionEvent e) {
   Project project = e.getProject();
   if (project == null) {
     return;
   }
   for (StudyActionListener listener : Extensions.getExtensions(StudyActionListener.EP_NAME)) {
     listener.beforeCheck(e);
   }
   final AnswerPlaceholder answerPlaceholder = getAnswerPlaceholder(e);
   if (answerPlaceholder == null) {
     return;
   }
   StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
   final StudyState studyState = new StudyState(studyEditor);
   if (answerPlaceholder.getTaskFile().getTask().hasSubtasks()) {
     StudySubtaskUtils.refreshPlaceholder(studyState.getEditor(), answerPlaceholder);
     return;
   }
   Document patternDocument =
       StudyUtils.getPatternDocument(
           answerPlaceholder.getTaskFile(), studyState.getVirtualFile().getName());
   if (patternDocument == null) {
     return;
   }
   AnswerPlaceholder.MyInitialState initialState = answerPlaceholder.getInitialState();
   int startOffset = initialState.getOffset();
   final String text =
       patternDocument.getText(new TextRange(startOffset, startOffset + initialState.getLength()));
   CommandProcessor.getInstance()
       .executeCommand(
           project,
           () ->
               ApplicationManager.getApplication()
                   .runWriteAction(
                       () -> {
                         Document document = studyState.getEditor().getDocument();
                         int offset = answerPlaceholder.getOffset();
                         document.deleteString(offset, offset + answerPlaceholder.getRealLength());
                         document.insertString(offset, text);
                       }),
           NAME,
           null);
 }
 @Override
 public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement element) {
   PsiFile file = element.getContainingFile();
   if (file == null) {
     return true;
   }
   VirtualFile virtualFile = file.getVirtualFile();
   if (virtualFile == null) {
     return true;
   }
   TaskFile taskFile = StudyUtils.getTaskFile(element.getProject(), virtualFile);
   return taskFile == null || taskFile.isHighlightErrors();
 }
 @Nullable
 private static AnswerPlaceholder getAnswerPlaceholder(AnActionEvent e) {
   final Project project = e.getProject();
   if (project == null) {
     return null;
   }
   StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
   final StudyState studyState = new StudyState(studyEditor);
   if (studyEditor == null || !studyState.isValid()) {
     return null;
   }
   final Editor editor = studyState.getEditor();
   final TaskFile taskFile = studyState.getTaskFile();
   return taskFile.getAnswerPlaceholder(editor.getCaretModel().getOffset());
 }
 public static void drawAllPlaceholders(
     @NotNull final Project project,
     @NotNull final Task task,
     @NotNull final VirtualFile taskDir) {
   for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
     String name = entry.getKey();
     TaskFile taskFile = entry.getValue();
     VirtualFile virtualFile = taskDir.findChild(name);
     if (virtualFile == null) {
       continue;
     }
     FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
     if (fileEditor instanceof StudyEditor) {
       StudyEditor studyEditor = (StudyEditor) fileEditor;
       StudyUtils.drawAllWindows(studyEditor.getEditor(), taskFile);
     }
   }
 }
 @NotNull
 @Override
 public Collection<AbstractTreeNode> modify(
     @NotNull AbstractTreeNode parent,
     @NotNull Collection<AbstractTreeNode> children,
     ViewSettings settings) {
   if (!isCourseBasedProject(parent)) {
     return children;
   }
   Collection<AbstractTreeNode> nodes = new ArrayList<AbstractTreeNode>();
   for (AbstractTreeNode node : children) {
     final Project project = node.getProject();
     if (project != null) {
       if (node.getValue() instanceof PsiDirectory) {
         final PsiDirectory nodeValue = (PsiDirectory) node.getValue();
         if (!nodeValue.getName().contains(EduNames.USER_TESTS)
             && !nodeValue.getName().equals(".idea")) {
           StudyDirectoryNode newNode = new StudyDirectoryNode(project, nodeValue, settings);
           nodes.add(newNode);
         }
       } else {
         if (parent instanceof StudyDirectoryNode && node instanceof PsiFileNode) {
           final PsiFileNode psiFileNode = (PsiFileNode) node;
           final VirtualFile virtualFile = psiFileNode.getVirtualFile();
           if (virtualFile == null) {
             return nodes;
           }
           final TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
           if (taskFile != null) {
             nodes.add(node);
           }
           final String parentName = parent.getName();
           if (parentName != null) {
             if (parentName.equals(EduNames.SANDBOX_DIR)) {
               nodes.add(node);
             }
           }
         }
       }
     }
   }
   return nodes;
 }
Esempio n. 8
0
 @Override
 public void createToolWindowContent(
     @NotNull final Project project, @NotNull final ToolWindow toolWindow) {
   toolWindow.setIcon(InteractiveLearningIcons.TaskDescription);
   StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
   final Course course = taskManager.getCourse();
   if (course != null) {
     final StudyToolWindow studyToolWindow;
     if (StudyUtils.hasJavaFx() && StudyTaskManager.getInstance(project).shouldUseJavaFx()) {
       studyToolWindow = new StudyJavaFxToolWindow();
     } else {
       studyToolWindow = new StudySwingToolWindow();
     }
     studyToolWindow.init(project);
     final ContentManager contentManager = toolWindow.getContentManager();
     final Content content =
         contentManager.getFactory().createContent(studyToolWindow, null, false);
     contentManager.addContent(content);
     Disposer.register(project, studyToolWindow);
   }
 }