Minor Cleanup
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Fri, 22 Jul 2016 12:04:21 +0000 (15:04 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Fri, 22 Jul 2016 18:43:00 +0000 (21:43 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/stepic/EduAdaptiveStepicConnector.java
python/educational-core/student/src/com/jetbrains/edu/learning/ui/StudyHint.kt

index d867774a22c3b7538850d9b2b4fee377e3b24104..6bb89c8bd3d76f3edb359c62c9cbe2e8b5c7b082 100644 (file)
@@ -7,6 +7,7 @@ import com.intellij.ide.projectView.ProjectView;
 import com.intellij.lang.Language;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
@@ -122,7 +123,6 @@ public class EduAdaptiveStepicConnector {
           StudyUtils.showCheckPopUp(project, balloon);
         }
       });
-      
     }
     catch (URISyntaxException e) {
       LOG.warn(e.getMessage());
@@ -212,8 +212,8 @@ public class EduAdaptiveStepicConnector {
       final StepicUser user = StudyTaskManager.getInstance(project).getUser();
 
       final boolean recommendationReaction =
-        user != null && postRecommendationReaction(project, String.valueOf(editor.getTaskFile().getTask().getLesson().getId()),
-                                                   String.valueOf(user.getId()), reaction);
+        postRecommendationReaction(project, String.valueOf(editor.getTaskFile().getTask().getLesson().getId()),
+                                   String.valueOf(user.getId()), reaction);
       if (recommendationReaction) {
         final Task task = getNextRecommendation(project, course);
 
@@ -234,13 +234,12 @@ public class EduAdaptiveStepicConnector {
             if (taskFiles.size() == 1) {
               final TaskFile taskFile = editor.getTaskFile();
               taskFile.text = ((TaskFile)taskFiles.values().toArray()[0]).text;
-              ApplicationManager.getApplication().invokeLater(() ->
-                                                                ApplicationManager.getApplication().runWriteAction(() ->
-                                                                                                                     editor.getEditor()
-                                                                                                                       .getDocument()
-                                                                                                                       .setText(
-                                                                                                                         taskFiles.get(
-                                                                                                                           EduStepicNames.DEFAULT_TASKFILE_NAME).text)));
+
+              ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
+                final Document document = editor.getEditor().getDocument();
+                final String taskFileText = taskFiles.get(EduStepicNames.DEFAULT_TASKFILE_NAME).text;
+                document.setText(taskFileText);
+              }));
             }
             else {
               LOG.warn("Got task without unexpected number of task files: " + taskFiles.size());
@@ -289,7 +288,7 @@ public class EduAdaptiveStepicConnector {
       }
       else {
         LOG.warn("Recommendation reactions weren't posted");
-        ApplicationManager.getApplication().invokeLater(() -> StudyUtils.showErrorPopupOnToolbar(project));        
+        ApplicationManager.getApplication().invokeLater(() -> StudyUtils.showErrorPopupOnToolbar(project));
       }
     }
   }
@@ -388,7 +387,6 @@ public class EduAdaptiveStepicConnector {
 
   private static String getCodeTemplateForTask(@Nullable StepicWrappers.CodeTemplatesWrapper codeTemplates,
                                                @NotNull final Task task, @NotNull final Project project) {
-
     if (codeTemplates != null) {
       final String languageString = getLanguageString(task, project);
       if (languageString != null) {
@@ -416,19 +414,14 @@ public class EduAdaptiveStepicConnector {
         StepicWrappers.ResultSubmissionWrapper wrapper = postResultsForCheck(client, attemptId, language, editor.getDocument().getText());
 
         final StepicUser user = StudyTaskManager.getInstance(project).getUser();
-        if (user != null) {
-          final int id = user.getId();
-          wrapper = getCheckResults(attemptId, id, client, wrapper);
-          if (wrapper.submissions.length == 1) {
-            final boolean isSolved = !wrapper.submissions[0].status.equals("wrong");
-            return Pair.create(isSolved, wrapper.submissions[0].hint);
-          }
-          else {
-            LOG.warn("Got a submission wrapper with incorrect submissions number: " + wrapper.submissions.length);
-          }
+        final int id = user.getId();
+        wrapper = getCheckResults(attemptId, id, client, wrapper);
+        if (wrapper.submissions.length == 1) {
+          final boolean isSolved = !wrapper.submissions[0].status.equals("wrong");
+          return Pair.create(isSolved, wrapper.submissions[0].hint);
         }
         else {
-          LOG.warn("User is null");
+          LOG.warn("Got a submission wrapper with incorrect submissions number: " + wrapper.submissions.length);
         }
       }
     }
index b587efea6622190c59f1eda6428158781d31bda2..760c0ef1f78d69a3d3458edee63100f2460ac7cb 100644 (file)
@@ -163,7 +163,6 @@ class StudyHint(private val myPlaceholder: AnswerPlaceholder?, project: Project)
   }
 
   companion object {
-
     private val OUR_WARNING_MESSAGE = "Put the caret in the answer placeholder to get hint"
   }
 }