Skip to content

Commit

Permalink
Update kotlin monorepo to v1.9.0 (#2113)
Browse files Browse the repository at this point in the history
* Update kotlin monorepo to v1.9.0

* Remove registration of class "org.jetbrains.kotlin.com.intellij.treeCopyHandler" as extension point for the compiler as this is not supported in the embedded Kotlin compiler version 1.9. Also remove Ktlint CLI command line flag `disable-kotlin-extension-point`, and parameter `enableKotlinCompilerExtensionPoint` from `KtLintRuleEngine` to disable the kotlin extension point. Update public API.

Closes #2061

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: paul-dingemans <paul-dingemans@users.noreply.github.com>
  • Loading branch information
renovate[bot] and paul-dingemans authored Aug 17, 2023
1 parent 1220bc0 commit 6b528cd
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 51 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
| NO_BLANK_LINE_IN_LIST_RULE_ID | NoBlankLineInListKt | NoBlankLineInListRuleKt |
| NO_EMPTY_FILE_RULE_ID | (not applicable) | NoEmptyFileRuleKt |

#### Custom rule providers

Class "org.jetbrains.kotlin.com.intellij.treeCopyHandler" is no longer registered as extension point for the compiler as this is not supported in Kotlin 1.9. Please test your custom rules. In case of unexpected exceptions during formatting of code, see [#2044](https://github.com/pinterest/ktlint/pull/2044) for possible remediation.

### Added

* Add experimental rule `class-signature`. This rule rewrites the class header to a consistent format. In code style `ktlint_official`, super types are always wrapped to a separate line. In other code styles, super types are only wrapped in classes having multiple super types. Especially for code style `ktlint_official` the class headers are rewritten in a more consistent format. See [examples in documentation](https://pinterest.github.io/ktlint/latest/rules/experimental/#class-signature). `class-signature` [#875](https://github.com/pinterest/ktlint/issues/1349), [#1349](https://github.com/pinterest/ktlint/issues/875)
Expand Down Expand Up @@ -45,6 +49,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Do not wrap a single line enum class `statement-wrapping` [#2177](https://github.com/pinterest/ktlint/issues/2177)
* Fix alignment of type constraints after `where` keyword in function signature `indent` [#2175](https://github.com/pinterest/ktlint/issues/2175)
* Fix wrapping of multiline postfix expression `multiline-expression-wrapping` [#2183](https://github.com/pinterest/ktlint/issues/2183)
* Remove registration of class "org.jetbrains.kotlin.com.intellij.treeCopyHandler" as extension point for the compiler as this is not supported in the embedded Kotlin compiler version 1.9. Also remove Ktlint CLI command line flag `disable-kotlin-extension-point`, and parameter `enableKotlinCompilerExtensionPoint` from `KtLintRuleEngine` to disable the kotlin extension point [#2061](https://github.com/pinterest/ktlint/issues/2061)

### Changed

Expand All @@ -56,6 +61,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Update dependency `org.junit.jupiter:junit-jupiter` to `v5.10.0` ([#2148](https://github.com/pinterest/ktlint/pull/2148))
* Build the project with Java 20, run test on Java 8, 11, 17 and 20 ([#1888](https://github.com/pinterest/ktlint/issues/1888))
* Update dependency `io.github.oshai:kotlin-logging-jvm` to `v5.1.0` ([#2174](https://github.com/pinterest/ktlint/pull/2174))
* Update kotlin monorepo to v1.9.0 [#2113](https://github.com/pinterest/ktlint/issues/2113)

## [0.50.0] - 2023-06-29

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
java-compilation = "20"
# The java-target version is the lowest supported LTS version of Java. Jar's produced are bytecode compatible with this version.
java-target = "8"
kotlin = "1.8.22"
kotlin = "1.9.0"
kotlinDev = "1.9.0"

[plugins]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public final class com/pinterest/ktlint/cli/reporter/baseline/Baseline$Status :
public static final field INVALID Lcom/pinterest/ktlint/cli/reporter/baseline/Baseline$Status;
public static final field NOT_FOUND Lcom/pinterest/ktlint/cli/reporter/baseline/Baseline$Status;
public static final field VALID Lcom/pinterest/ktlint/cli/reporter/baseline/Baseline$Status;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/cli/reporter/baseline/Baseline$Status;
public static fun values ()[Lcom/pinterest/ktlint/cli/reporter/baseline/Baseline$Status;
}
Expand Down
1 change: 1 addition & 0 deletions ktlint-cli-reporter-core/api/ktlint-cli-reporter-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class com/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Sta
public static final field KTLINT_RULE_ENGINE_EXCEPTION Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;
public static final field LINT_CAN_BE_AUTOCORRECTED Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;
public static final field LINT_CAN_NOT_BE_AUTOCORRECTED Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;
public static fun values ()[Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class com/pinterest/ktlint/cli/reporter/format/Color : java/lang/En
public static final field WHITE Lcom/pinterest/ktlint/cli/reporter/format/Color;
public static final field YELLOW Lcom/pinterest/ktlint/cli/reporter/format/Color;
public final fun getCode ()I
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/cli/reporter/format/Color;
public static fun values ()[Lcom/pinterest/ktlint/cli/reporter/format/Color;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class com/pinterest/ktlint/cli/reporter/plain/Color : java/lang/Enu
public static final field WHITE Lcom/pinterest/ktlint/cli/reporter/plain/Color;
public static final field YELLOW Lcom/pinterest/ktlint/cli/reporter/plain/Color;
public final fun getCode ()I
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/cli/reporter/plain/Color;
public static fun values ()[Lcom/pinterest/ktlint/cli/reporter/plain/Color;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@ internal class KtlintCommandLine {
)
private var minLogLevel: Level = Level.INFO

@Option(
hidden = true,
names = ["--disable-kotlin-extension-point"],
)
var disableKotlinExtensionPoint: Boolean = false

private val tripped = AtomicBoolean()
private val fileNumber = AtomicInteger()
private val errorNumber = AtomicInteger()
Expand Down Expand Up @@ -280,7 +274,6 @@ internal class KtlintCommandLine {
editorConfigDefaults = editorConfigDefaults(ruleProviders),
editorConfigOverride = editorConfigOverride,
isInvokedFromCli = true,
enableKotlinCompilerExtensionPoint = !disableKotlinExtensionPoint,
)

val baseline =
Expand Down
4 changes: 4 additions & 0 deletions ktlint-rule-engine-core/api/ktlint-rule-engine-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ public final class com/pinterest/ktlint/rule/engine/core/api/IndentConfig$Compan
public final class com/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle : java/lang/Enum {
public static final field SPACE Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle;
public static final field TAB Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle;
public static fun values ()[Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle;
}
Expand Down Expand Up @@ -419,6 +420,7 @@ public final class com/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifie
public final class com/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode : java/lang/Enum {
public static final field ONLY_WHEN_RUN_AFTER_RULE_IS_LOADED_AND_ENABLED Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;
public static final field REGARDLESS_WHETHER_RUN_AFTER_RULE_IS_LOADED_OR_DISABLED Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;
public static fun values ()[Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;
}
Expand Down Expand Up @@ -480,6 +482,7 @@ public final class com/pinterest/ktlint/rule/engine/core/api/editorconfig/CodeSt
public static final field android_studio Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/CodeStyleValue;
public static final field intellij_idea Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/CodeStyleValue;
public static final field ktlint_official Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/CodeStyleValue;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/CodeStyleValue;
public static fun values ()[Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/CodeStyleValue;
}
Expand Down Expand Up @@ -542,6 +545,7 @@ public final class com/pinterest/ktlint/rule/engine/core/api/editorconfig/MaxLin
public final class com/pinterest/ktlint/rule/engine/core/api/editorconfig/RuleExecution : java/lang/Enum {
public static final field disabled Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/RuleExecution;
public static final field enabled Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/RuleExecution;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/RuleExecution;
public static fun values ()[Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/RuleExecution;
}
Expand Down
5 changes: 2 additions & 3 deletions ktlint-rule-engine/api/ktlint-rule-engine.api
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ public final class com/pinterest/ktlint/rule/engine/api/KtLintRuleEngine {
public static final field Companion Lcom/pinterest/ktlint/rule/engine/api/KtLintRuleEngine$Companion;
public static final field STDIN_FILE Ljava/lang/String;
public fun <init> ()V
public fun <init> (Ljava/util/Set;Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults;Lcom/pinterest/ktlint/rule/engine/api/EditorConfigOverride;ZZLjava/nio/file/FileSystem;)V
public synthetic fun <init> (Ljava/util/Set;Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults;Lcom/pinterest/ktlint/rule/engine/api/EditorConfigOverride;ZZLjava/nio/file/FileSystem;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/util/Set;Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults;Lcom/pinterest/ktlint/rule/engine/api/EditorConfigOverride;ZLjava/nio/file/FileSystem;)V
public synthetic fun <init> (Ljava/util/Set;Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults;Lcom/pinterest/ktlint/rule/engine/api/EditorConfigOverride;ZLjava/nio/file/FileSystem;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun editorConfigFilePaths (Ljava/nio/file/Path;)Ljava/util/List;
public final fun format (Lcom/pinterest/ktlint/rule/engine/api/Code;Lkotlin/jvm/functions/Function2;)Ljava/lang/String;
public static synthetic fun format$default (Lcom/pinterest/ktlint/rule/engine/api/KtLintRuleEngine;Lcom/pinterest/ktlint/rule/engine/api/Code;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/lang/String;
public final fun generateKotlinEditorConfigSection (Ljava/nio/file/Path;)Ljava/lang/String;
public final fun getEditorConfigDefaults ()Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults;
public final fun getEditorConfigOverride ()Lcom/pinterest/ktlint/rule/engine/api/EditorConfigOverride;
public final fun getEnableKotlinCompilerExtensionPoint ()Z
public final fun getFileSystem ()Ljava/nio/file/FileSystem;
public final fun getRuleProviders ()Ljava/util/Set;
public final fun isInvokedFromCli ()Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ public class KtLintRuleEngine(
* property being set in any other way.
*/
public val editorConfigOverride: EditorConfigOverride = EMPTY_EDITOR_CONFIG_OVERRIDE,
/**
* Temporary flag to indicate that kotlin embeddable compiler is to be executed with (default) or without the extension point
* 'org.jetbrains.kotlin.com.intellij.treeCopyHandler'. This extension point is not (yet) supported in the preview of Kotlin 1.9. Some
* rules might no longer work and throw exceptions at runtime.
* It is unclear whether the extension point will be supported. Disabling this flag on the Kotlin 1.8 compiler has the same effect. As
* of that it can be used to assess the impact, and to fix rules before release of the Ktlint version which will be based on Kotlin 1.9.
*/
public val enableKotlinCompilerExtensionPoint: Boolean = true,
/**
* **For internal use only**: indicates that linting was invoked from KtLint CLI tool. It enables some internals workarounds for Kotlin
* Compiler initialization. This property is likely to be removed in any of next versions without further notice.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.pinterest.ktlint.rule.engine.internal

import com.pinterest.ktlint.logger.api.initKtLintKLogger
import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine
import io.github.oshai.kotlinlogging.KotlinLogging
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.com.intellij.mock.MockProject
import org.jetbrains.kotlin.com.intellij.openapi.diagnostic.DefaultLogger
import org.jetbrains.kotlin.com.intellij.openapi.extensions.ExtensionPoint
import org.jetbrains.kotlin.com.intellij.openapi.extensions.Extensions.getRootArea
import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer
import org.jetbrains.kotlin.com.intellij.openapi.util.UserDataHolderBase
import org.jetbrains.kotlin.com.intellij.pom.PomModel
Expand All @@ -19,15 +15,12 @@ import org.jetbrains.kotlin.com.intellij.pom.PomTransaction
import org.jetbrains.kotlin.com.intellij.pom.impl.PomTransactionBase
import org.jetbrains.kotlin.com.intellij.pom.tree.TreeAspect
import org.jetbrains.kotlin.com.intellij.psi.PsiFileFactory
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeCopyHandler
import org.jetbrains.kotlin.config.CompilerConfiguration
import sun.reflect.ReflectionFactory
import java.nio.file.Files
import java.nio.file.Path
import org.jetbrains.kotlin.com.intellij.openapi.diagnostic.Logger as DiagnosticLogger

private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger()

internal class KotlinPsiFileFactoryProvider {
private lateinit var psiFileFactory: PsiFileFactory

Expand Down Expand Up @@ -67,18 +60,6 @@ internal fun initPsiFileFactory(ktLintRuleEngine: KtLintRuleEngine): PsiFileFact
compilerConfiguration,
EnvironmentConfigFiles.JVM_CONFIG_FILES,
).project as MockProject
if (ktLintRuleEngine.enableKotlinCompilerExtensionPoint) {
project.enableASTMutations()
} else {
LOGGER.info {
"""
*** Kotlin extension points are disabled to investigate the impact of Kotlin 1.9 in a future release.
*** If runtime exceptions are throw because extension point 'org.jetbrains.kotlin.com.intellij.treeCopyHandler'
*** is not registered then your rules will fail when ktlint starts using Kotlin 1.9 unless the extension point
*** will be fully supported by Jetbrains.
""".trimIndent()
}
}
project.registerFormatPomModel()

return PsiFileFactory.getInstance(project)
Expand Down Expand Up @@ -128,19 +109,6 @@ private class LoggerFactory : DiagnosticLogger.Factory {
}
}

/**
* Enables AST mutations (`ktlint -F ...`).
*/
private fun MockProject.enableASTMutations() {
val extensionPoint = "org.jetbrains.kotlin.com.intellij.treeCopyHandler"
val extensionClassName = TreeCopyHandler::class.java.name
for (area in arrayOf(extensionArea, getRootArea())) {
if (!area.hasExtensionPoint(extensionPoint)) {
area.registerExtensionPoint(extensionPoint, extensionClassName, ExtensionPoint.Kind.INTERFACE)
}
}
}

private fun MockProject.registerFormatPomModel() {
registerService(PomModel::class.java, FormatPomModel())
}
Expand Down
1 change: 1 addition & 0 deletions ktlint-ruleset-standard/api/ktlint-ruleset-standard.api
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionSignature
public static final field always Lcom/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule$FunctionBodyExpressionWrapping;
public static final field default Lcom/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule$FunctionBodyExpressionWrapping;
public static final field multiline Lcom/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule$FunctionBodyExpressionWrapping;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule$FunctionBodyExpressionWrapping;
public static fun values ()[Lcom/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule$FunctionBodyExpressionWrapping;
}
Expand Down

0 comments on commit 6b528cd

Please sign in to comment.