From 3db4ff47491cabd6510e36f916f114f96404b2f9 Mon Sep 17 00:00:00 2001
From: Konstantin Kopper <s8kokopp@stud.uni-saarland.de>
Date: Sat, 2 Oct 2021 14:49:59 +0200
Subject: [PATCH] Various minor improvements

---
 src/main/kotlin/com/pseuco/api/PseuCoShare.kt          |  7 +++++--
 src/main/kotlin/fxGui/PseucoAlert.kt                   |  1 +
 .../kotlin/fxGui/debugger/channels/ChannelElement.kt   |  7 +++----
 src/main/kotlin/fxGui/debugger/channels/ChannelPane.kt | 10 ++++++----
 src/main/kotlin/properties/AboutProperties.kt          |  2 +-
 src/main/kotlin/properties/BuildProperties.kt          |  2 +-
 src/main/kotlin/util/ZipUtilities.kt                   |  1 +
 src/main/kotlin/webapp/CompanionWebApp.kt              |  3 ++-
 8 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/src/main/kotlin/com/pseuco/api/PseuCoShare.kt b/src/main/kotlin/com/pseuco/api/PseuCoShare.kt
index b2703ae..74b59ee 100644
--- a/src/main/kotlin/com/pseuco/api/PseuCoShare.kt
+++ b/src/main/kotlin/com/pseuco/api/PseuCoShare.kt
@@ -8,6 +8,7 @@ import io.ktor.client.features.json.JsonFeature
 import io.ktor.client.features.json.serializer.KotlinxSerializer
 import io.ktor.client.request.accept
 import io.ktor.client.request.get
+import io.ktor.client.request.parameter
 import io.ktor.client.request.post
 import io.ktor.client.statement.HttpStatement
 import io.ktor.http.ContentType
@@ -62,6 +63,8 @@ object PseuCoShare : FileSharer {
     @Throws(PseuCoShareException::class)
     override suspend fun uploadFile(file: PseuCoComFile): URI = shareFile(file, true)
 
+    private val jsonAllowingStructuredMapKeys = Json { allowStructuredMapKeys = true }
+
     /**
      * Uploads [file] to the [pseuCo.com](https://pseuco.com) sharing API.
      *
@@ -92,7 +95,7 @@ object PseuCoShare : FileSharer {
 
         return try {
             URI(
-                Json { allowStructuredMapKeys = true }.parseToJsonElement(
+                jsonAllowingStructuredMapKeys.parseToJsonElement(
                     c.content.toInputStream().reader().use { it.readText() }).jsonObject["url"]!!.jsonPrimitive.content
             )
         } catch (e: SerializationException) {
@@ -119,7 +122,7 @@ object PseuCoShare : FileSharer {
                 host = "pseuco.com"
                 port = protocol.defaultPort
                 path("api", "paste", "get")
-                parameters["id"] = id
+                parameter("id", id)
             }
             accept(ContentType.Application.Json.withCharset(Charsets.UTF_8))
         }.execute()
diff --git a/src/main/kotlin/fxGui/PseucoAlert.kt b/src/main/kotlin/fxGui/PseucoAlert.kt
index 0b33b88..2de95bc 100644
--- a/src/main/kotlin/fxGui/PseucoAlert.kt
+++ b/src/main/kotlin/fxGui/PseucoAlert.kt
@@ -52,6 +52,7 @@ internal open class PseucoAlert(alertType: Alert.AlertType) : Alert(alertType) {
          * @author Konstantin Kopper
          * @since 2.0.0
          */
+        @Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
         private val STYLESHEET = PseucoAlert::class.java.getResource("/fxGui/css/alert.css").toExternalForm()
     }
 }
diff --git a/src/main/kotlin/fxGui/debugger/channels/ChannelElement.kt b/src/main/kotlin/fxGui/debugger/channels/ChannelElement.kt
index fa7bdc5..2c5dd0d 100644
--- a/src/main/kotlin/fxGui/debugger/channels/ChannelElement.kt
+++ b/src/main/kotlin/fxGui/debugger/channels/ChannelElement.kt
@@ -2,11 +2,10 @@ package fxGui.debugger.channels
 
 import javafx.scene.control.Label
 
-internal class ChannelElement(private val element: String, private val type: ChannelType) : Label(element) {
+@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
+internal class ChannelElement(element: String, type: ChannelType) : Label(element) {
 
-    internal constructor(element: Int, type: ChannelType) : this(element.toString(), type)
-
-    internal constructor(element: Boolean, type: ChannelType) : this(element.toString(), type)
+    internal constructor(element: Any, type: ChannelType) : this(element.toString(), type)
 
     init {
         stylesheets += this::class.java.getResource("/fxGui/css/general.css").toExternalForm()
diff --git a/src/main/kotlin/fxGui/debugger/channels/ChannelPane.kt b/src/main/kotlin/fxGui/debugger/channels/ChannelPane.kt
index e154df6..38fc358 100644
--- a/src/main/kotlin/fxGui/debugger/channels/ChannelPane.kt
+++ b/src/main/kotlin/fxGui/debugger/channels/ChannelPane.kt
@@ -7,7 +7,8 @@ import javafx.scene.layout.AnchorPane
 import javafx.scene.layout.HBox
 import java.util.concurrent.BlockingQueue
 
-internal class ChannelPane<T>(internal val queue: BlockingQueue<T>, internal val type: ChannelType) : AnchorPane() {
+internal class ChannelPane<T : Any>(internal val queue: BlockingQueue<T>, internal val type: ChannelType) :
+    AnchorPane() {
 
     /**
      * The label indicating the capacity of this channel.
@@ -64,9 +65,10 @@ internal class ChannelPane<T>(internal val queue: BlockingQueue<T>, internal val
 
     internal fun update() {
         elements.children.clear()
-        queue.takeIf { it.isNotEmpty() }?.forEach { elements.children += ChannelElement(it.toString(), this.type) }
-                ?: { elements.children += ChannelElement("Channel is empty!", ChannelType.NONE) }()
+        queue.takeIf { it.isNotEmpty() }?.forEach { elements.children += ChannelElement(it, this.type) }
+            ?: run { elements.children += ChannelElement("Channel is empty!", ChannelType.NONE) }
 
-        channelPane.style = if (queue.remainingCapacity() == 0) "-fx-border-width: 3px; -fx-border-color: indianred;" else ""
+        channelPane.style =
+            if (queue.remainingCapacity() == 0) "-fx-border-width: 3px; -fx-border-color: indianred;" else ""
     }
 }
diff --git a/src/main/kotlin/properties/AboutProperties.kt b/src/main/kotlin/properties/AboutProperties.kt
index b6815d1..019366c 100644
--- a/src/main/kotlin/properties/AboutProperties.kt
+++ b/src/main/kotlin/properties/AboutProperties.kt
@@ -56,7 +56,7 @@ object AboutProperties : Properties() {
 
     init {
         try {
-            load(this::class.java.getResourceAsStream("/about.properties"))
+            this::class.java.getResourceAsStream("/about.properties").use { load(it) }
         } catch (e: IOException) {
             System.err.println("Could not read properties. Using some default values.")
             if (Main.DEBUG)
diff --git a/src/main/kotlin/properties/BuildProperties.kt b/src/main/kotlin/properties/BuildProperties.kt
index 377a6a3..16287f7 100644
--- a/src/main/kotlin/properties/BuildProperties.kt
+++ b/src/main/kotlin/properties/BuildProperties.kt
@@ -38,7 +38,7 @@ object BuildProperties : Properties() {
 
     init {
         try {
-            load(this::class.java.getResourceAsStream("/build.properties"))
+            this::class.java.getResourceAsStream("/build.properties").use { load(it) }
         } catch (e: IOException) {
             System.err.println("Reading build properties failed.")
             if (Main.DEBUG)
diff --git a/src/main/kotlin/util/ZipUtilities.kt b/src/main/kotlin/util/ZipUtilities.kt
index 0b61eb7..77dbe78 100644
--- a/src/main/kotlin/util/ZipUtilities.kt
+++ b/src/main/kotlin/util/ZipUtilities.kt
@@ -32,6 +32,7 @@ object ZipUtilities {
 
         val buffer = ByteArray(1024)
 
+        @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
         val inputStream = ZipInputStream(ZipUtilities::class.java.getResourceAsStream(name))
 
         try {
diff --git a/src/main/kotlin/webapp/CompanionWebApp.kt b/src/main/kotlin/webapp/CompanionWebApp.kt
index 65cdc2d..6c6c9a5 100644
--- a/src/main/kotlin/webapp/CompanionWebApp.kt
+++ b/src/main/kotlin/webapp/CompanionWebApp.kt
@@ -22,6 +22,7 @@ import io.ktor.routing.post
 import io.ktor.routing.routing
 import io.ktor.server.engine.embeddedServer
 import io.ktor.server.netty.Netty
+import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
 import java.awt.Desktop
 import java.net.URI
@@ -117,7 +118,7 @@ object CompanionWebApp {
                 Config.file.deleteOnExit()
                 launch {
                     // Wait for response to be sent and kill IDE afterwards.
-                    Thread.sleep(250)
+                    delay(250)
                     exitProcess(0)
                 }
                 call.respond(HttpStatusCode.OK, "Success. Please close this tab and restart the IDE.")
-- 
GitLab