mirror of
https://github.com/apple/pkl.git
synced 2026-07-09 22:52:44 +02:00
Fix Pkl spotless formatting (#1278)
This commit is contained in:
@@ -40,17 +40,27 @@ class PklFormatterFunc(@Transient private val configuration: Configuration) :
|
|||||||
@Serial private const val serialVersionUID: Long = 1L
|
@Serial private const val serialVersionUID: Long = 1L
|
||||||
}
|
}
|
||||||
|
|
||||||
private val formatterClass by lazy {
|
private val classLoader by lazy {
|
||||||
val urls = configuration.files.map { it.toURI().toURL() }
|
val urls = configuration.files.map { it.toURI().toURL() }
|
||||||
val classLoader = URLClassLoader(urls.toTypedArray())
|
URLClassLoader(urls.toTypedArray())
|
||||||
classLoader.loadClass("org.pkl.formatter.Formatter")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val formatMethod by lazy { formatterClass.getMethod("format", String::class.java) }
|
private val formatterClass by lazy { classLoader.loadClass("org.pkl.formatter.Formatter") }
|
||||||
|
|
||||||
|
private val grammarVersionClass by lazy {
|
||||||
|
classLoader.loadClass("org.pkl.formatter.GrammarVersion")
|
||||||
|
}
|
||||||
|
|
||||||
|
private val grammarVersionLatestMethod by lazy { grammarVersionClass.getMethod("latest") }
|
||||||
|
|
||||||
|
private val formatMethod by lazy {
|
||||||
|
formatterClass.getMethod("format", String::class.java, grammarVersionClass)
|
||||||
|
}
|
||||||
|
|
||||||
private val formatterInstance by lazy { formatterClass.getConstructor().newInstance() }
|
private val formatterInstance by lazy { formatterClass.getConstructor().newInstance() }
|
||||||
|
|
||||||
override fun apply(input: String): String {
|
override fun apply(input: String): String {
|
||||||
return formatMethod(formatterInstance, input) as String
|
val latestGrammarVersion = grammarVersionLatestMethod(grammarVersionClass)
|
||||||
|
return formatMethod(formatterInstance, input, latestGrammarVersion) as String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user