comparison src/main/kotlin/name/blackcap/passman/Main.kt @ 8:698c4a3d758d

Some code clean-up.
author David Barts <n5jrn@me.com>
date Fri, 23 Sep 2022 20:59:52 -0700
parents eafa3779aef8
children ea65ab890f66
comparison
equal deleted inserted replaced
7:f245b9a53495 8:698c4a3d758d
30 fun getClassForSubcommand(name: String): Class<Subcommand>? = try { 30 fun getClassForSubcommand(name: String): Class<Subcommand>? = try {
31 val shortName = name.replace('-', '_') 31 val shortName = name.replace('-', '_')
32 .lowercase() 32 .lowercase()
33 .replaceFirstChar { it.titlecase(Locale.getDefault()) } 33 .replaceFirstChar { it.titlecase(Locale.getDefault()) }
34 Class.forName("$MAIN_PACKAGE.${shortName}Subcommand") as? Class<Subcommand> 34 Class.forName("$MAIN_PACKAGE.${shortName}Subcommand") as? Class<Subcommand>
35 /* val ret = Class.forName("$MAIN_PACKAGE.$shortName")
36 if (ret.isInstance(Subcommand::class.java)) { ret as Class<Subcommand> } else { null } */
37 } catch (e: ClassNotFoundException) { 35 } catch (e: ClassNotFoundException) {
38 null 36 null
39 } 37 }
40 38
41 fun getInstanceForClass(klass: Class<Subcommand>?) = try { 39 fun getInstanceForClass(klass: Class<Subcommand>?) = try {