Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JLLeitschuh/ktlint-gradle
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6e353b71f9ccbeac82b7bca5bb2f9a2d1627f61c
Choose a base ref
..
head repository: JLLeitschuh/ktlint-gradle
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2689b698f972477e624198c8c848ff52f3b4e4db
Choose a head ref
Showing with 57 additions and 26 deletions.
  1. +57 −26 plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation.kt
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import com.pinterest.ktlint.core.LintError
import com.pinterest.ktlint.core.api.FeatureInAlphaState
import java.io.File
import kotlin.reflect.KFunction
import kotlin.reflect.KParameter
import kotlin.reflect.full.findParameterByName
import kotlin.reflect.full.instanceParameter
import kotlin.reflect.full.memberFunctions
@@ -91,23 +92,34 @@ internal class ExperimentalParamsInvocation(
)
}

private val ctor: KFunction<*> by lazy {
experimentalParamsClass?.kotlin?.primaryConstructor!!
}
private val fileNameParam: KParameter by lazy { ctor.findParameterByName("fileName")!! }
private val textParam: KParameter by lazy { ctor.findParameterByName("text")!! }
private val ruleSetsParam: KParameter by lazy { ctor.findParameterByName("ruleSets")!! }
private val cbParam: KParameter by lazy { ctor.findParameterByName("cb")!! }
private val scriptParam: KParameter by lazy { ctor.findParameterByName("script")!! }
private val editorConfigPathParam: KParameter by lazy { ctor.findParameterByName("editorConfigPath")!! }
private val debugParam: KParameter by lazy { ctor.findParameterByName("debug")!! }
private val editorConfigOverrideParam: KParameter by lazy { ctor.findParameterByName("editorConfigOverride")!! }

private fun buildParams(
file: File,
cb: (LintError, Boolean) -> Unit
): com.pinterest.ktlint.core.KtLint.ExperimentalParams {
val script = !file.name.endsWith(".kt", ignoreCase = true)
val ctor = experimentalParamsClass!!.kotlin.primaryConstructor
val editorConfigOverride = userDataToEditorConfigOverride(userData)
return ctor!!.callBy(
return ctor.callBy(
mapOf(
ctor.findParameterByName("fileName")!! to file.absolutePath,
ctor.findParameterByName("text")!! to file.readText(),
ctor.findParameterByName("ruleSets")!! to ruleSets,
ctor.findParameterByName("cb")!! to cb,
ctor.findParameterByName("script")!! to script,
ctor.findParameterByName("editorConfigPath")!! to editorConfigPath,
ctor.findParameterByName("debug")!! to debug,
ctor.findParameterByName("editorConfigOverride")!! to editorConfigOverride
fileNameParam to file.absolutePath,
textParam to file.readText(),
ruleSetsParam to ruleSets,
cbParam to cb,
scriptParam to script,
editorConfigPathParam to editorConfigPath,
debugParam to debug,
editorConfigOverrideParam to editorConfigOverride
)
) as com.pinterest.ktlint.core.KtLint.ExperimentalParams
}
@@ -184,23 +196,34 @@ internal class ExperimentalParamsProviderInvocation(
ExperimentalParamsProviderInvocation(editorConfigPath, ruleProviders, userData, debug)
}

private val ctor: KFunction<*> by lazy {
experimentalParamsClass?.kotlin?.primaryConstructor!!
}
private val fileNameParam: KParameter by lazy { ctor.findParameterByName("fileName")!! }
private val textParam: KParameter by lazy { ctor.findParameterByName("text")!! }
private val ruleProvidersParam: KParameter by lazy { ctor.findParameterByName("ruleProviders")!! }
private val cbParam: KParameter by lazy { ctor.findParameterByName("cb")!! }
private val scriptParam: KParameter by lazy { ctor.findParameterByName("script")!! }
private val editorConfigPathParam: KParameter by lazy { ctor.findParameterByName("editorConfigPath")!! }
private val debugParam: KParameter by lazy { ctor.findParameterByName("debug")!! }
private val editorConfigOverrideParam: KParameter by lazy { ctor.findParameterByName("editorConfigOverride")!! }

private fun buildParams(
file: File,
cb: (LintError, Boolean) -> Unit
): com.pinterest.ktlint.core.KtLint.ExperimentalParams {
val script = !file.name.endsWith(".kt", ignoreCase = true)
val ctor = experimentalParamsClass!!.kotlin.primaryConstructor
val editorConfigOverride = userDataToEditorConfigOverride(userData)
return ctor!!.callBy(
return ctor.callBy(
mapOf(
ctor.findParameterByName("fileName")!! to file.absolutePath,
ctor.findParameterByName("text")!! to file.readText(),
ctor.findParameterByName("ruleProviders")!! to ruleProviders,
ctor.findParameterByName("cb")!! to cb,
ctor.findParameterByName("script")!! to script,
ctor.findParameterByName("editorConfigPath")!! to editorConfigPath,
ctor.findParameterByName("debug")!! to debug,
ctor.findParameterByName("editorConfigOverride")!! to editorConfigOverride
fileNameParam to file.absolutePath,
textParam to file.readText(),
ruleProvidersParam to ruleProviders,
cbParam to cb,
scriptParam to script,
editorConfigPathParam to editorConfigPath,
debugParam to debug,
editorConfigOverrideParam to editorConfigOverride
)
) as com.pinterest.ktlint.core.KtLint.ExperimentalParams
}
@@ -244,24 +267,32 @@ internal class RuleEngineInvocation(
}
}

private val lintCodeParam: KParameter by lazy { lintMethod.findParameterByName("code")!! }
private val lintFilePathParam: KParameter by lazy { lintMethod.findParameterByName("filePath")!! }
private val lintCallbackParam: KParameter by lazy { lintMethod.findParameterByName("callback")!! }

override fun invokeLint(file: File, cb: (LintError, Boolean) -> Unit) {
lintMethod.callBy(
mapOf(
lintMethod.instanceParameter!! to engine,
lintMethod.findParameterByName("code")!! to file.readText(),
lintMethod.findParameterByName("filePath")!! to file.absoluteFile.toPath(),
lintMethod.findParameterByName("callback")!! to { le: LintError -> cb.invoke(le, false) }
lintCodeParam to file.readText(),
lintFilePathParam to file.absoluteFile.toPath(),
lintCallbackParam to { le: LintError -> cb.invoke(le, false) }
)
)
}

private val formatCodeParam: KParameter by lazy { formatMethod.findParameterByName("code")!! }
private val formatFilePathParam: KParameter by lazy { formatMethod.findParameterByName("filePath")!! }
private val formatCallbackParam: KParameter by lazy { formatMethod.findParameterByName("callback")!! }

override fun invokeFormat(file: File, cb: (LintError, Boolean) -> Unit): String {
return formatMethod.callBy(
mapOf(
formatMethod.instanceParameter!! to engine,
formatMethod.findParameterByName("code")!! to file.readText(),
formatMethod.findParameterByName("filePath")!! to file.absoluteFile.toPath(),
formatMethod.findParameterByName("callback")!! to cb
formatCodeParam to file.readText(),
formatFilePathParam to file.absoluteFile.toPath(),
formatCallbackParam to cb
)
) as String
}