Skip to content

Commit dce5333

Browse files
Prepare release Kotlin 2.2.20 (#254)
* Prepare release Kotlin 2.2.20 * Fixed breaking changes of kotlin 2.2.20
1 parent c9e5aa3 commit dce5333

File tree

20 files changed

+73
-2271
lines changed

20 files changed

+73
-2271
lines changed
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
package tech.mappie.fir.analysis
22

33
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
4-
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies.WHOLE_ELEMENT
5-
import org.jetbrains.kotlin.diagnostics.error1
64
import org.jetbrains.kotlin.diagnostics.reportOn
75
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
86
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
97
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirAnonymousObjectChecker
108
import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
11-
import org.jetbrains.kotlin.psi.KtElement
9+
import tech.mappie.fir.analysis.MappieErrors.INVALID_ANONYMOUS_OBJECT
1210
import tech.mappie.fir.util.isSubclassOfAnMappie
1311

1412
class AnonymousMappieObjectChecker : FirAnonymousObjectChecker(MppCheckerKind.Common) {
1513

1614
context(context: CheckerContext, reporter: DiagnosticReporter)
1715
override fun check(declaration: FirAnonymousObject) {
1816
if (declaration.symbol.isSubclassOfAnMappie()) {
19-
reporter.reportOn(declaration.source, INVALID_ANONYMOUS_OBJECT, INVALID_ANONYMOUS_OBJECT_MESSAGE)
17+
reporter.reportOn(declaration.source, INVALID_ANONYMOUS_OBJECT)
2018
}
2119
}
22-
23-
companion object {
24-
private val INVALID_ANONYMOUS_OBJECT by error1<KtElement, String>(WHOLE_ELEMENT)
25-
private const val INVALID_ANONYMOUS_OBJECT_MESSAGE = "Anonymous Mappie objects are not supported"
26-
}
2720
}
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package tech.mappie.fir.analysis
22

33
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
4-
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies.WHOLE_ELEMENT
5-
import org.jetbrains.kotlin.diagnostics.error1
64
import org.jetbrains.kotlin.diagnostics.reportOn
75
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
86
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
97
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirFunctionCallChecker
108
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
119
import org.jetbrains.kotlin.fir.types.classId
1210
import org.jetbrains.kotlin.fir.types.resolvedType
13-
import org.jetbrains.kotlin.name.Name
14-
import org.jetbrains.kotlin.psi.KtElement
11+
import tech.mappie.fir.analysis.MappieErrors.COMPILE_TIME_EXTENSION_RECEIVER
12+
import tech.mappie.fir.analysis.MappieErrors.COMPILE_TIME_RECEIVER
1513
import tech.mappie.util.ALL_MAPPING_FUNCTIONS
1614
import tech.mappie.util.CLASS_ID_OBJECT_MAPPING_CONSTRUCTOR
1715

@@ -25,36 +23,11 @@ class CompileTimeDslReceiverChecker : FirFunctionCallChecker(MppCheckerKind.Comm
2523
}
2624

2725
if (expression.dispatchReceiver?.resolvedType?.classId == CLASS_ID_OBJECT_MAPPING_CONSTRUCTOR) {
28-
reporter.reportOn(
29-
expression.source,
30-
COMPILE_TIME_RECEIVER,
31-
buildString {
32-
append("The function $name was called on the mapping dsl which does not exist after compilation")
33-
specify(name)
34-
},
35-
)
26+
reporter.reportOn(expression.source, COMPILE_TIME_RECEIVER, name)
3627
}
3728

3829
if (expression.extensionReceiver?.resolvedType?.classId == CLASS_ID_OBJECT_MAPPING_CONSTRUCTOR) {
39-
reporter.reportOn(
40-
expression.source,
41-
COMPILE_TIME_RECEIVER,
42-
buildString {
43-
append("The function $name was called as an extension method on the mapping dsl which does not exist after compilation")
44-
specify(name)
45-
}
46-
)
30+
reporter.reportOn(expression.source, COMPILE_TIME_EXTENSION_RECEIVER, name)
4731
}
4832
}
49-
50-
private fun StringBuilder.specify(name: Name) =
51-
if (name == Name.identifier("run")) {
52-
append(". Did you mean to use kotlin.run?")
53-
} else {
54-
this
55-
}
56-
57-
companion object {
58-
private val COMPILE_TIME_RECEIVER by error1<KtElement, String>(WHOLE_ELEMENT)
59-
}
6033
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package tech.mappie.fir.analysis
2+
3+
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
4+
import org.jetbrains.kotlin.diagnostics.KtDiagnosticsContainer
5+
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies.WHOLE_ELEMENT
6+
import org.jetbrains.kotlin.diagnostics.error0
7+
import org.jetbrains.kotlin.diagnostics.error1
8+
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
9+
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers
10+
import org.jetbrains.kotlin.diagnostics.warning0
11+
import org.jetbrains.kotlin.diagnostics.warning1
12+
import org.jetbrains.kotlin.name.Name
13+
import org.jetbrains.kotlin.psi.KtElement
14+
15+
object MappieErrors : KtDiagnosticsContainer() {
16+
val INVALID_ANONYMOUS_OBJECT by error0<KtElement>(WHOLE_ELEMENT)
17+
val COMPILE_TIME_RECEIVER by error1<KtElement, Name>(WHOLE_ELEMENT)
18+
val COMPILE_TIME_EXTENSION_RECEIVER by error1<KtElement, Name>(WHOLE_ELEMENT)
19+
val NON_CONSTANT_ERROR by error0<KtElement>(WHOLE_ELEMENT)
20+
val UNKNOWN_NAME_ERROR by error1<KtElement, String>(WHOLE_ELEMENT)
21+
val ANNOTATION_USE_DEFAULT_ARGUMENTS_NOT_APPLICABLE by warning0<KtElement>(WHOLE_ELEMENT)
22+
val ANNOTATION_USE_STRICT_ENUMS_NOT_APPLICABLE by warning0<KtElement>(WHOLE_ELEMENT)
23+
val ANNOTATION_USE_STRICT_VISIBILITY_NOT_APPLICABLE by warning0<KtElement>(WHOLE_ELEMENT)
24+
val UNNECESSARY_EXPLICIT_MAPPING by warning1<KtElement, String>(WHOLE_ELEMENT)
25+
26+
override fun getRendererFactory(): BaseDiagnosticRendererFactory = DefaultErrorMessageMappie
27+
}
28+
29+
object DefaultErrorMessageMappie : BaseDiagnosticRendererFactory() {
30+
override val MAP: KtDiagnosticFactoryToRendererMap by KtDiagnosticFactoryToRendererMap("Mappie") { map ->
31+
map.put(MappieErrors.INVALID_ANONYMOUS_OBJECT, "Anonymous Mappie objects are not supported")
32+
map.put(MappieErrors.COMPILE_TIME_RECEIVER, "The function ''{0}'' was called on the mapping dsl which does not exist after compilation", CommonRenderers.NAME)
33+
map.put(MappieErrors.COMPILE_TIME_EXTENSION_RECEIVER, "The function ''{0}'' was called as an extension method on the mapping dsl which does not exist after compilation", CommonRenderers.NAME)
34+
map.put(MappieErrors.NON_CONSTANT_ERROR, "Argument must be a compile-time constant")
35+
map.put(MappieErrors.UNKNOWN_NAME_ERROR, "Identifier ''{0}'' does not occur as as setter or as a parameter in constructor", CommonRenderers.STRING)
36+
map.put(MappieErrors.ANNOTATION_USE_DEFAULT_ARGUMENTS_NOT_APPLICABLE, "Annotation @UseDefaultArguments has no effect on subclass of EnumMappie")
37+
map.put(MappieErrors.ANNOTATION_USE_STRICT_ENUMS_NOT_APPLICABLE, "Annotation @UseStrictEnums has no effect on subclass of ObjectMappie")
38+
map.put(MappieErrors.ANNOTATION_USE_STRICT_VISIBILITY_NOT_APPLICABLE, "Annotation @UseStrictVisibility has no effect on subclass of EnumMappie")
39+
map.put(MappieErrors.UNNECESSARY_EXPLICIT_MAPPING, "Unnecessary explicit mapping of source ''{0}''", CommonRenderers.STRING)
40+
}
41+
}

compiler-plugin/src/main/kotlin/tech/mappie/fir/analysis/ToCallChecker.kt

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package tech.mappie.fir.analysis
22

33
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
4-
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
5-
import org.jetbrains.kotlin.diagnostics.error1
64
import org.jetbrains.kotlin.diagnostics.reportOn
75
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
86
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
@@ -19,7 +17,8 @@ import org.jetbrains.kotlin.fir.types.resolvedType
1917
import org.jetbrains.kotlin.fir.types.type
2018
import org.jetbrains.kotlin.name.CallableId
2119
import org.jetbrains.kotlin.name.Name
22-
import org.jetbrains.kotlin.psi.KtElement
20+
import tech.mappie.fir.analysis.MappieErrors.NON_CONSTANT_ERROR
21+
import tech.mappie.fir.analysis.MappieErrors.UNKNOWN_NAME_ERROR
2322
import tech.mappie.fir.util.toConstant
2423
import tech.mappie.fir.util.hasCallableId
2524
import tech.mappie.fir.util.isJavaGetter
@@ -35,11 +34,7 @@ class ToCallChecker : FirFunctionCallChecker(MppCheckerKind.Common) {
3534
val name = expression.arguments.first().toConstant()?.value as? String?
3635

3736
if (name == null) {
38-
reporter.reportOn(
39-
expression.source,
40-
NON_CONSTANT_ERROR,
41-
"Argument must be a compile-time constant",
42-
)
37+
reporter.reportOn(expression.source, NON_CONSTANT_ERROR)
4338
} else {
4439
val target = expression.getTargetRegularClassSymbol()
4540
if (target != null) {
@@ -61,11 +56,7 @@ class ToCallChecker : FirFunctionCallChecker(MppCheckerKind.Common) {
6156
}
6257

6358
if (targets.none { it.asString().removePrefix("_") == name }) {
64-
reporter.reportOn(
65-
expression.source,
66-
UNKNOWN_NAME_ERROR,
67-
"Identifier $name does not occur as as setter or as a parameter in constructor",
68-
)
59+
reporter.reportOn(expression.source, UNKNOWN_NAME_ERROR, name)
6960
}
7061
}
7162
}
@@ -75,9 +66,4 @@ class ToCallChecker : FirFunctionCallChecker(MppCheckerKind.Common) {
7566
context (context: CheckerContext)
7667
private fun FirFunctionCall.getTargetRegularClassSymbol() =
7768
dispatchReceiver?.resolvedType?.typeArguments?.last()?.type?.toRegularClassSymbol(context.session)
78-
79-
companion object {
80-
private val NON_CONSTANT_ERROR by error1<KtElement, String>(SourceElementPositioningStrategies.WHOLE_ELEMENT)
81-
private val UNKNOWN_NAME_ERROR by error1<KtElement, String>(SourceElementPositioningStrategies.WHOLE_ELEMENT)
82-
}
8369
}

compiler-plugin/src/main/kotlin/tech/mappie/fir/analysis/UnnecessaryExplicitEnumMappingChecker.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.fir.references.FirNamedReference
1212
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
1313
import org.jetbrains.kotlin.fir.symbols.impl.FirEnumEntrySymbol
1414
import org.jetbrains.kotlin.name.CallableId
15-
import org.jetbrains.kotlin.psi.KtElement
15+
import tech.mappie.fir.analysis.MappieErrors.UNNECESSARY_EXPLICIT_MAPPING
1616
import tech.mappie.fir.util.hasCallableId
1717
import tech.mappie.util.CLASS_ID_ENUM_MAPPING_CONSTRUCTOR
1818
import tech.mappie.util.IDENTIFIER_FROM_ENUM_ENTRY
@@ -32,11 +32,7 @@ class UnnecessaryExplicitEnumMappingChecker : FirFunctionCallChecker(MppCheckerK
3232
if (lhsReference.name == rhsReference.name) {
3333
val name = "${className(rhsReference)?.let { "$it." }}${rhsReference.name}"
3434

35-
reporter.reportOn(
36-
expression.source,
37-
UNNECESSARY_EXPLICIT_MAPPING,
38-
"Unnecessary explicit mapping of source $name",
39-
)
35+
reporter.reportOn(expression.source, UNNECESSARY_EXPLICIT_MAPPING, name)
4036
}
4137
}
4238
}
@@ -46,8 +42,4 @@ class UnnecessaryExplicitEnumMappingChecker : FirFunctionCallChecker(MppCheckerK
4642
(reference as? FirResolvedNamedReference)
4743
?.let { it.resolvedSymbol as? FirEnumEntrySymbol }
4844
?.let { it.callableId.className?.shortName() }
49-
50-
companion object {
51-
private val UNNECESSARY_EXPLICIT_MAPPING by warning1<KtElement, String>(WHOLE_ELEMENT)
52-
}
5345
}
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package tech.mappie.fir.analysis
22

33
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
4-
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies.WHOLE_ELEMENT
54
import org.jetbrains.kotlin.diagnostics.reportOn
6-
import org.jetbrains.kotlin.diagnostics.warning1
75
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
86
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
97
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirAnnotationCallChecker
108
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
119
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
1210
import org.jetbrains.kotlin.fir.types.classId
1311
import org.jetbrains.kotlin.fir.types.resolvedType
14-
import org.jetbrains.kotlin.psi.KtElement
12+
import tech.mappie.fir.analysis.MappieErrors.ANNOTATION_USE_DEFAULT_ARGUMENTS_NOT_APPLICABLE
1513
import tech.mappie.fir.util.isSubclassOfEnumMappie
1614
import tech.mappie.util.CLASS_ID_USE_DEFAULT_ARGUMENTS
1715

@@ -22,13 +20,8 @@ class UseDefaultArgumentsAnnotationChecker : FirAnnotationCallChecker(MppChecker
2220
if (expression.resolvedType.classId == CLASS_ID_USE_DEFAULT_ARGUMENTS) {
2321
val symbol = expression.containingDeclarationSymbol
2422
if (symbol is FirClassSymbol && symbol.isSubclassOfEnumMappie()) {
25-
reporter.reportOn(expression.source, ANNOTATION_NOT_APPLICABLE, NOT_APPLICABLE_MESSAGE)
23+
reporter.reportOn(expression.source, ANNOTATION_USE_DEFAULT_ARGUMENTS_NOT_APPLICABLE)
2624
}
2725
}
2826
}
29-
30-
companion object {
31-
private val ANNOTATION_NOT_APPLICABLE by warning1<KtElement, String>(WHOLE_ELEMENT)
32-
private const val NOT_APPLICABLE_MESSAGE = "Annotation @UseDefaultArguments has no effect on subclass of EnumMappie"
33-
}
3427
}
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package tech.mappie.fir.analysis
22

33
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
4-
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies.WHOLE_ELEMENT
54
import org.jetbrains.kotlin.diagnostics.reportOn
6-
import org.jetbrains.kotlin.diagnostics.warning1
75
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
86
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
97
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirAnnotationCallChecker
108
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
119
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
1210
import org.jetbrains.kotlin.fir.types.classId
1311
import org.jetbrains.kotlin.fir.types.resolvedType
14-
import org.jetbrains.kotlin.psi.KtElement
12+
import tech.mappie.fir.analysis.MappieErrors.ANNOTATION_USE_STRICT_ENUMS_NOT_APPLICABLE
1513
import tech.mappie.fir.util.isSubclassOfAnObjectMappie
1614
import tech.mappie.util.CLASS_ID_USE_STRICT_ENUMS
1715

@@ -22,13 +20,8 @@ class UseStrictEnumsAnnotationChecker : FirAnnotationCallChecker(MppCheckerKind.
2220
if (expression.resolvedType.classId == CLASS_ID_USE_STRICT_ENUMS) {
2321
val symbol = expression.containingDeclarationSymbol
2422
if (symbol is FirClassSymbol && symbol.isSubclassOfAnObjectMappie()) {
25-
reporter.reportOn(expression.source, ANNOTATION_NOT_APPLICABLE, NOT_APPLICABLE_MESSAGE)
23+
reporter.reportOn(expression.source, ANNOTATION_USE_STRICT_ENUMS_NOT_APPLICABLE)
2624
}
2725
}
2826
}
29-
30-
companion object {
31-
private val ANNOTATION_NOT_APPLICABLE by warning1<KtElement, String>(WHOLE_ELEMENT)
32-
private const val NOT_APPLICABLE_MESSAGE = "Annotation @UseStrictEnums has no effect on subclass of ObjectMappie"
33-
}
3427
}
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package tech.mappie.fir.analysis
22

33
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
4-
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies.WHOLE_ELEMENT
54
import org.jetbrains.kotlin.diagnostics.reportOn
6-
import org.jetbrains.kotlin.diagnostics.warning1
75
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
86
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
97
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirAnnotationCallChecker
108
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
119
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
1210
import org.jetbrains.kotlin.fir.types.classId
1311
import org.jetbrains.kotlin.fir.types.resolvedType
14-
import org.jetbrains.kotlin.psi.KtElement
12+
import tech.mappie.fir.analysis.MappieErrors.ANNOTATION_USE_STRICT_VISIBILITY_NOT_APPLICABLE
1513
import tech.mappie.fir.util.isSubclassOfEnumMappie
1614
import tech.mappie.util.CLASS_ID_USE_STRICT_VISIBILITY
1715

@@ -22,13 +20,8 @@ class UseStrictVisibilityAnnotationChecker : FirAnnotationCallChecker(MppChecker
2220
if (expression.resolvedType.classId == CLASS_ID_USE_STRICT_VISIBILITY) {
2321
val symbol = expression.containingDeclarationSymbol
2422
if (symbol is FirClassSymbol && symbol.isSubclassOfEnumMappie()) {
25-
reporter.reportOn(expression.source, ANNOTATION_NOT_APPLICABLE, NOT_APPLICABLE_MESSAGE)
23+
reporter.reportOn(expression.source, ANNOTATION_USE_STRICT_VISIBILITY_NOT_APPLICABLE)
2624
}
2725
}
2826
}
29-
30-
companion object {
31-
private val ANNOTATION_NOT_APPLICABLE by warning1<KtElement, String>(WHOLE_ELEMENT)
32-
private const val NOT_APPLICABLE_MESSAGE = "Annotation @UseStrictVisibility has no effect on subclass of EnumMappie"
33-
}
3427
}

compiler-plugin/src/test/kotlin/tech/mappie/testing/enums/EnumMapperWrongConfigTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import org.junit.jupiter.api.io.TempDir
55
import tech.mappie.testing.compilation.compile
66
import java.io.File
77

8-
@Suppress("unused")
98
class EnumMapperWrongConfigTest {
109

1110
enum class Input { A, B }
@@ -42,7 +41,7 @@ class EnumMapperWrongConfigTest {
4241
import tech.mappie.testing.enums.EnumMapperWrongConfigTest.*
4342
import tech.mappie.api.config.UseDefaultArguments
4443
45-
@Suppress("ANNOTATION_NOT_APPLICABLE")
44+
@Suppress("ANNOTATION_USE_DEFAULT_ARGUMENTS_NOT_APPLICABLE")
4645
@UseDefaultArguments
4746
class Mapper : EnumMappie<Input, Output>()
4847
"""
@@ -81,7 +80,7 @@ class EnumMapperWrongConfigTest {
8180
import tech.mappie.testing.enums.EnumMapperWrongConfigTest.*
8281
import tech.mappie.api.config.UseStrictVisibility
8382
84-
@Suppress("ANNOTATION_NOT_APPLICABLE")
83+
@Suppress("ANNOTATION_USE_STRICT_VISIBILITY_NOT_APPLICABLE")
8584
@UseStrictVisibility
8685
class Mapper : EnumMappie<Input, Output>()
8786
"""

compiler-plugin/src/test/kotlin/tech/mappie/testing/enums/EnumToEnumWithSameEntriesTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class EnumToEnumWithSameEntriesTest {
6060
)
6161
} satisfies {
6262
isOk()
63-
hasWarningMessage(6, "Unnecessary explicit mapping of source Input.SOME")
63+
hasWarningMessage(6, "Unnecessary explicit mapping of source 'Input.SOME'")
6464

6565
val mapper = classLoader
6666
.loadEnumMappieClass<Input, Output>("Mapper")

0 commit comments

Comments
 (0)