Verified Commit c1b1486e authored by Konstantin Kopper's avatar Konstantin Kopper
Browse files

Replace gson with kotlinx serialization for replacement parsing

parent c6d20547
package fxGui.completion
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import fxGui.main.PseuCoArea
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
/**
* Singleton providing hints for auto completion.
......@@ -29,10 +27,8 @@ internal object Hints {
* @author Konstantin Kopper
* @since 2.0.0
*/
private val hints: Map<String, @JvmSuppressWildcards List<Replacement>> = Gson().fromJson(
BufferedReader(InputStreamReader(jsonHints)),
object : TypeToken<Map<String, @JvmSuppressWildcards List<Replacement>>>() {}.type
)
private val hints =
Json.decodeFromString<Map<String, List<Replacement>>>(jsonHints.bufferedReader().use { it.readText() })
/**
* Map of keywords to a list of replacements.
......
package fxGui.completion
import kotlinx.serialization.Serializable
/**
* Data class providing information on placeholders needed for auto completion.
* Placeholders are usually encapsulated within replacements.
......@@ -13,7 +15,12 @@ package fxGui.completion
* @property text The text to be inserted at offset [position].
* @constructor Create a new placeholder.
*/
internal data class Placeholder(internal val position: Int, internal val expand: Boolean, internal val text: String) {
@Serializable
internal data class Placeholder(
internal val position: Int,
internal val expand: Boolean = false,
internal val text: String
) {
/**
* Create a new unexpandable placeholder.
......
package fxGui.completion
import kotlinx.serialization.Serializable
/**
* Data class providing information on replacements during auto completion.
*
......@@ -12,11 +14,12 @@ package fxGui.completion
* @property placeholders A list of possible placeholders to be inserted into [template].
* @constructor Create a new replacement.
*/
@Serializable
internal data class Replacement(
internal val displayText: String,
internal val template: String,
internal val hasContinuation: Boolean,
internal val placeholders: List<Placeholder>
internal val hasContinuation: Boolean = false,
internal val placeholders: List<Placeholder> = emptyList()
) {
/**
......
package fxGui.main
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import fxGui.completion.Hints
import javafx.application.Platform
import javafx.scene.control.ContextMenu
import javafx.scene.control.MenuItem
import javafx.scene.input.KeyCode
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import org.apache.commons.lang3.StringUtils
import org.fxmisc.richtext.CodeArea
import org.fxmisc.richtext.LineNumberFactory
......@@ -18,8 +18,6 @@ import org.fxmisc.richtext.model.TwoDimensional
import org.fxmisc.wellbehaved.event.EventPattern
import org.fxmisc.wellbehaved.event.InputMap
import org.fxmisc.wellbehaved.event.Nodes
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.ArrayDeque
import java.util.Queue
import java.util.regex.Pattern
......@@ -438,10 +436,9 @@ internal class PseuCoArea : CodeArea() {
* @author Konstantin Kopper
* @since 2.0.0
*/
internal val PSEUCO_TOKEN: List<String> = Gson().fromJson(
BufferedReader(InputStreamReader(this::class.java.getResourceAsStream("/pseucoKeywords.json"))),
object : TypeToken<List<String>>() {}.type
)
internal val PSEUCO_TOKEN =
Json.decodeFromString<List<String>>(
this::class.java.getResourceAsStream("/pseucoKeywords.json").bufferedReader().use { it.readText() })
// Regular expressions used for syntax highlighting
private val KEYWORD_PATTERN = "\\b(${PSEUCO_TOKEN.joinToString("|")})\\b".toRegex()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment