@@ -5,6 +5,7 @@ import com.intellij.reference.SoftReference
55import org.jetbrains.annotations.PropertyKey
66import java.lang.ref.Reference
77import java.util.*
8+ import java.lang.ref.SoftReference as JavaSoftReference
89
910/* *
1011 * @author Edoardo Luppi
@@ -13,25 +14,25 @@ public object CCBundle {
1314 private const val BUNDLE = " messages.ConventionalCommitBundle"
1415
1516 private var bundleReference: Reference <ResourceBundle >? = null
16- private val bundle: ResourceBundle by lazy {
17- SoftReference .dereference(bundleReference)
18- ? : ResourceBundle .getBundle(BUNDLE ).also {
19- bundleReference = java.lang.ref.SoftReference (it)
20- }
21- }
17+ private val bundle: ResourceBundle
18+ get() = derefBundle()
2219
2320 @JvmStatic
2421 public operator fun get (@PropertyKey(resourceBundle = BUNDLE ) key : String , vararg params : Any ): String =
25- /* We cannot use anything else but BundleBase to be compatible
26- * with all IDE versions and to avoid deprecated methods */
2722 BundleBase .message(bundle, key, * params)
2823
2924 @JvmStatic
30- @Suppress(" SameParameterValue" )
31- public fun getWithDefault (
32- @PropertyKey(resourceBundle = BUNDLE ) key : String ,
33- defaultValue : String? = null,
34- vararg params : Any ,
35- ): String =
25+ public fun getOrDefault (@PropertyKey(resourceBundle = BUNDLE ) key : String , defaultValue : String , vararg params : Any ): String =
3626 BundleBase .messageOrDefault(bundle, key, defaultValue, * params)
27+
28+ private fun derefBundle (): ResourceBundle {
29+ var ref = SoftReference .dereference(bundleReference)
30+
31+ if (ref == null ) {
32+ ref = ResourceBundle .getBundle(BUNDLE )
33+ bundleReference = JavaSoftReference (ref)
34+ }
35+
36+ return ref
37+ }
3738}
0 commit comments