if i could even get intelliJ to flag something lik...
# tornadofx
g
if i could even get intelliJ to flag something like
resourceBundle.get("MizzspelledKey")
with "this lookup is suspicious" would be a step forward
m
IntelliJ IDEA marks spelling errors inside strings by default, on my system.
g
ah sure but, my keys have funny names, im not talking about a spelling mistake in that the string doesnt map to an english word, im talking about a spelling mistake that doesnt result in a value from the properties file
m
You can make a delegate property class which translates the property name into a resource name using a convention of your choice.
That's cheap.
I just did something like this for me.
Copy code
open class SVGResources(
    val baseName: String
) {
    @OptIn(ExperimentalStdlibApi::class)
    fun propertyNameToResourceName(propertyName: String) =
        baseName + propertyName.splitCamelCaseToList().joinToString("_") { it.toLowerCase() } + ".svg"

    operator fun getValue(thisRef: Any?, property: KProperty<*>) =
        Resource(propertyNameToResourceName(property.name))

    private val svgLoader = SvgLoader()

    private fun loadSvg(resourceName: String): Group =
        svgLoader.loadSvg(javaClass.getResourceAsStream(resourceName))

    inner class Resource(val resourceName: String) {
        fun load() = loadSvg(resourceName)
        operator fun invoke() = load()
    }
}
and then, something like this:
Copy code
object Icons : SVGResources("/x/ay/z/") {
    val play by Icons
    val playSelection by Icons
    val pause by Icons
    val stop by Icons

    val fastRewind by Icons
    val fastForward by Icons
    val skipPrevious by Icons
    val skipNext by Icons

    val zoomIn by Icons
    val zoomOut by Icons

    val folder by Icons

    val add by Icons
    val delete by Icons
    val createNewFolder by Icons

    val volume by Icons
    val closeWindow by Icons

    val refresh by Icons

    val face by Icons
}
then I load the "zoom in" icon resource with
Icons.zoomIn()
.
You can do something similar.
Otherwise you have to do metaprogramming.
g
yeah so thats a very elegant wrapper but it still requires you to manually enumerate all the entries in your resources files. For me there's just too many
I'd really rather have a system that generated the kotlin for me from the properties file, and im kind've suprised this isnt a widely asked for thing
mind you, the java community has never taken to code-generation like microsoft and the dotnet guys have
for better and for worse