diff --git a/buildSrc/src/main/kotlin/PklFormatterSpotless.kt b/buildSrc/src/main/kotlin/PklFormatterSpotless.kt index 852aefb5..cd050901 100644 --- a/buildSrc/src/main/kotlin/PklFormatterSpotless.kt +++ b/buildSrc/src/main/kotlin/PklFormatterSpotless.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2025-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,20 +47,11 @@ class PklFormatterFunc(@Transient private val configuration: Configuration) : 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 formatMethod by lazy { formatterClass.getMethod("format", String::class.java) } private val formatterInstance by lazy { formatterClass.getConstructor().newInstance() } override fun apply(input: String): String { - val latestGrammarVersion = grammarVersionLatestMethod(null) - return formatMethod(formatterInstance, input, latestGrammarVersion) as String + return formatMethod(formatterInstance, input) as String } } diff --git a/pkl-formatter/src/main/kotlin/org/pkl/formatter/Formatter.kt b/pkl-formatter/src/main/kotlin/org/pkl/formatter/Formatter.kt index 9daa1c67..fbe26678 100644 --- a/pkl-formatter/src/main/kotlin/org/pkl/formatter/Formatter.kt +++ b/pkl-formatter/src/main/kotlin/org/pkl/formatter/Formatter.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2025-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ class Formatter { * @return the formatted Pkl source code as a string * @throws java.io.IOException if the file cannot be read */ + @JvmOverloads fun format(path: Path, grammarVersion: GrammarVersion = GrammarVersion.latest()): String { return format(Files.readString(path), grammarVersion) } @@ -42,6 +43,7 @@ class Formatter { * @param grammarVersion grammar compatibility version * @return the formatted Pkl source code as a string */ + @JvmOverloads fun format(text: String, grammarVersion: GrammarVersion = GrammarVersion.latest()): String { val parser = GenericParser() val builder = Builder(text, grammarVersion) @@ -60,7 +62,6 @@ enum class GrammarVersion(val version: Int, val versionSpan: String) { V2(2, "0.30+"); companion object { - @JvmStatic - fun latest(): GrammarVersion = entries.maxBy { it.version } + @JvmStatic fun latest(): GrammarVersion = entries.maxBy { it.version } } }