From 7733f671291c84603494ed7a2adbed6ff99102d0 Mon Sep 17 00:00:00 2001 From: "Maxim.Kolmakov" Date: Fri, 6 Oct 2017 17:18:28 +0200 Subject: [PATCH] [gui-tests] Greenify --- .../testGuiFramework/recorder/Writer.kt | 6 ++-- .../recorder/actions/UpdateEditorAction.kt | 2 +- .../recorder/compile/LocalCompiler.kt | 20 +++++------ .../components/GuiRecorderComponent.kt | 35 ++++--------------- .../recorder/ui/GuiScriptEditorFrame.kt | 2 +- .../testGuiFramework/recorder/ui/Notifier.kt | 4 +-- 6 files changed, 23 insertions(+), 46 deletions(-) diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Writer.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Writer.kt index effbe9d0affd..2b45d14f51d7 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Writer.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Writer.kt @@ -38,15 +38,15 @@ object Writer { private fun write(str: String) { print(str) - if (GuiRecorderComponent.getFrame() != null && GuiRecorderComponent.getFrame()!!.isSyncToEditor()) + if (GuiRecorderComponent.frame != null && GuiRecorderComponent.frame!!.isSyncToEditor()) writeToEditor(str) else scriptBuffer.append(str) } private fun writeToEditor(str: String) { - if (GuiRecorderComponent.getFrame() != null && GuiRecorderComponent.getFrame()!!.getEditor() != null) { - val editor = GuiRecorderComponent.getFrame()!!.getEditor() + if (GuiRecorderComponent.frame != null && GuiRecorderComponent.frame!!.getEditor() != null) { + val editor = GuiRecorderComponent.frame!!.getEditor() val document = editor.document WriteCommandAction.runWriteCommandAction(null, { document.insertString(document.textLength, str) }) } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UpdateEditorAction.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UpdateEditorAction.kt index ae74145267d5..35493ef2532f 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UpdateEditorAction.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UpdateEditorAction.kt @@ -14,7 +14,7 @@ import com.intellij.testGuiFramework.recorder.ui.Notifier class UpdateEditorAction : AnAction(null, "Update GUI Script Editor (get recorded from buffer)", AllIcons.Actions.NextOccurence) { override fun actionPerformed(actionEvent: AnActionEvent?) { - val editor = GuiRecorderComponent.getFrame()!!.getEditor() + val editor = GuiRecorderComponent.frame!!.getEditor() ApplicationManager.getApplication().runWriteAction { editor.document.setText(getGuiScriptBuffer()) } Notifier.updateStatus("GUI script updated") } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/compile/LocalCompiler.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/compile/LocalCompiler.kt index 95c29e4514b7..a133e4cd6023 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/compile/LocalCompiler.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/compile/LocalCompiler.kt @@ -76,7 +76,7 @@ class LocalCompiler { LOG.error(ce.message) } }) - GuiRecorderComponent.setCurrentTask(taskFuture) + GuiRecorderComponent.currentTask = taskFuture } @@ -99,14 +99,14 @@ class LocalCompiler { "Unable to load by pluginClassLoader $TEST_CLASS_NAME.class file") val testCase = currentTest.newInstance() val testMethod = currentTest.getMethod(ScriptWrapper.TEST_METHOD_NAME) - GuiRecorderComponent.setState(GuiRecorderComponent.States.RUNNING) + GuiRecorderComponent.state = GuiRecorderComponent.States.RUNNING try { testMethod.invoke(testCase) Notifier.updateStatus("Script stopped") - GuiRecorderComponent.setState(GuiRecorderComponent.States.IDLE) + GuiRecorderComponent.state = GuiRecorderComponent.States.IDLE } catch (throwable: Throwable) { - GuiRecorderComponent.setState(GuiRecorderComponent.States.RUNNING_ERROR) + GuiRecorderComponent.state = GuiRecorderComponent.States.RUNNING_ERROR Notifier.updateStatus("Running error, please see idea.log") throw throwable } @@ -132,15 +132,15 @@ class LocalCompiler { val setUpMethod = currentTest.getMethod("setUp") val testMethod = currentTest.getMethod(ScriptWrapper.TEST_METHOD_NAME) Notifier.updateStatus("${Notifier.LONG_OPERATION_PREFIX}Script running...") - GuiRecorderComponent.setState(GuiRecorderComponent.States.RUNNING) + GuiRecorderComponent.state = GuiRecorderComponent.States.RUNNING try { setUpMethod.invoke(testCase) testMethod.invoke(testCase) Notifier.updateStatus("Script stopped") - GuiRecorderComponent.setState(GuiRecorderComponent.States.IDLE) + GuiRecorderComponent.state = GuiRecorderComponent.States.IDLE } catch (throwable: Throwable) { - GuiRecorderComponent.setState(GuiRecorderComponent.States.RUNNING_ERROR) + GuiRecorderComponent.state = GuiRecorderComponent.States.RUNNING_ERROR Notifier.updateStatus("Running error, please see idea.log") throw throwable } @@ -164,7 +164,7 @@ class LocalCompiler { val libDirLocation = getApplicationLibDir().parentFile Notifier.updateStatus("${Notifier.LONG_OPERATION_PREFIX}Compiling...") - GuiRecorderComponent.setState(GuiRecorderComponent.States.COMPILING) + GuiRecorderComponent.state = GuiRecorderComponent.States.COMPILING val compilationProcessBuilder = if (SystemInfo.isWindows) @@ -182,12 +182,12 @@ class LocalCompiler { if (process.exitValue() == 1) { LOG.error(BufferedReader(InputStreamReader(process.errorStream)).lines().collect(Collectors.joining("\n"))) Notifier.updateStatus("Compilation error (see idea.log)") - GuiRecorderComponent.setState(GuiRecorderComponent.States.COMPILATION_ERROR) + GuiRecorderComponent.state = GuiRecorderComponent.States.COMPILATION_ERROR throw CompilationException("Compilation error (see idea.log)") } else { Notifier.updateStatus("Compilation is done") - GuiRecorderComponent.setState(GuiRecorderComponent.States.COMPILATION_DONE) + GuiRecorderComponent.state = GuiRecorderComponent.States.COMPILATION_DONE } return wait } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/components/GuiRecorderComponent.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/components/GuiRecorderComponent.kt index 1d71b2dfd6c5..7882b26a3efc 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/components/GuiRecorderComponent.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/components/GuiRecorderComponent.kt @@ -28,32 +28,19 @@ object GuiRecorderComponent : ApplicationComponent, Disposable { enum class States {IDLE, COMPILING, COMPILATION_ERROR, COMPILATION_DONE, RUNNING, RUNNING_ERROR, TEST_INIT } - var myState: States = States.IDLE; + var state: States = States.IDLE + var frame: GuiScriptEditorFrame? = null + var currentTask: Future<*>? = null - override fun dispose() { - } - - private var myFrame: GuiScriptEditorFrame? = null - - private var currentTask: Future<*>? = null + override fun dispose() {} override fun getComponentName() = "GuiRecorderComponent" - fun setCurrentTask(task: Future<*>) { currentTask = task } - fun cancelCurrentTask() { if (currentTask != null && !currentTask!!.isDone) currentTask!!.cancel(true) } - fun getState() = myState - - fun setState(yaState: States) { - myState = yaState - } - - fun getFrame() = myFrame - - fun getEditor() = myFrame!!.getGuiScriptEditorPanel().editor + fun getEditor() = frame!!.getGuiScriptEditorPanel().editor fun placeCaretToEnd() { val caretModel = getEditor().caretModel @@ -61,17 +48,7 @@ object GuiRecorderComponent : ApplicationComponent, Disposable { caretModel.moveToLogicalPosition(LogicalPosition(lineCount + 1, 0)) } - fun registerFrame(frame: GuiScriptEditorFrame) { - myFrame = frame - } - - fun unregisterFrame() { - if (myFrame != null) - myFrame!!.dispose() - } - fun disposeFrame() { - myFrame = null + frame = null } - } \ No newline at end of file diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorFrame.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorFrame.kt index 03ddd27a8b2c..72a387ce6a66 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorFrame.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorFrame.kt @@ -52,7 +52,7 @@ class GuiScriptEditorFrame : Disposable { myFrame.pack() myFrame.isVisible = true - GuiRecorderComponent.registerFrame(this) + GuiRecorderComponent.frame = this myFrame.addWindowListener(object : WindowAdapter() { override fun windowClosing(e: WindowEvent?) { dispose() diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/Notifier.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/Notifier.kt index 489d87b68504..6cd780b4bbe2 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/Notifier.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/Notifier.kt @@ -27,8 +27,8 @@ object Notifier { fun updateStatus(statusMessage: String) { - if (GuiRecorderComponent.getFrame() == null) return - val guiScriptEditorPanel = GuiRecorderComponent.getFrame()!!.getGuiScriptEditorPanel() + if (GuiRecorderComponent.frame == null) return + val guiScriptEditorPanel = GuiRecorderComponent.frame!!.getGuiScriptEditorPanel() val statusHandler: (String) -> Unit = { status -> if (status.startsWith(LONG_OPERATION_PREFIX)) {