Skip to content

Commit c1aba45

Browse files
authored
Merge pull request #51 from ForteScarlet/update-to-kt2
Update Kotlin to 2.0.0
2 parents a32307f + 208cd5f commit c1aba45

File tree

34 files changed

+2240
-634
lines changed

34 files changed

+2240
-634
lines changed

Diff for: build.gradle.kts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import love.forte.gradle.common.core.project.setup
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23

34
buildscript {
45
extra["kotlin_plugin_id"] = "love.forte.plugin.suspend-transform"
@@ -23,8 +24,10 @@ allprojects {
2324
options.encoding = "UTF-8"
2425
}
2526
this.tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
26-
kotlinOptions.jvmTarget = "1.8"
27-
kotlinOptions.javaParameters = true
27+
compilerOptions {
28+
jvmTarget.set(JvmTarget.JVM_1_8)
29+
javaParameters.set(true)
30+
}
2831
}
2932
}
3033

Diff for: buildSrc/src/main/kotlin/IProject.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object IProject : ProjectDetail() {
99
const val DESCRIPTION = "Generate platform-compatible functions for Kotlin suspend functions"
1010
const val HOMEPAGE = "https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin"
1111

12-
override val version: Version = version(0, 7, 0) - version("beta2")
12+
override val version: Version = version(0, 8, 0) - version("beta1")
1313

1414
override val homepage: String get() = HOMEPAGE
1515

Diff for: compiler/suspend-transform-plugin/build.gradle.kts

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
12
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23

34
plugins {
@@ -43,12 +44,31 @@ dependencies {
4344
testImplementation(libs.kotlinx.coroutines.core)
4445
}
4546

46-
val compileKotlin: KotlinCompile by tasks
47-
compileKotlin.kotlinOptions.freeCompilerArgs += listOf(
48-
"-Xjvm-default=all",
49-
"-opt-in=kotlin.RequiresOptIn",
50-
"-opt-in=org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI",
51-
)
47+
//val compileKotlin: KotlinCompile by tasks
48+
//compileKotlin.kotlinOptions.freeCompilerArgs += listOf(
49+
// "-Xjvm-default=all",
50+
// "-opt-in=kotlin.RequiresOptIn",
51+
// "-opt-in=org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI",
52+
//)
53+
54+
//tasks.withType<KotlinCompile> {
55+
// kotlinOptions.jvmTarget = "1.8"
56+
//}
57+
58+
kotlin {
59+
compilerOptions {
60+
jvmTarget.set(JvmTarget.JVM_1_8)
61+
optIn.addAll(
62+
"kotlin.RequiresOptIn",
63+
"org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI"
64+
)
65+
freeCompilerArgs.addAll(
66+
"-Xjvm-default=all",
67+
// "-opt-in=kotlin.RequiresOptIn",
68+
// "-opt-in=org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI",
69+
)
70+
}
71+
}
5272

5373
tasks.withType(KotlinCompile::class.java).configureEach {
5474
// see https://youtrack.jetbrains.com/issue/KTIJ-21563
@@ -76,9 +96,7 @@ buildConfig {
7696
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${rootProject.extra["kotlin_plugin_id"]}\"")
7797
}
7898

79-
tasks.withType<KotlinCompile> {
80-
kotlinOptions.jvmTarget = "1.8"
81-
}
99+
82100

83101

84102
sourceSets {

Diff for: compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirTransformer.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import love.forte.plugin.suspendtrans.utils.toClassId
77
import love.forte.plugin.suspendtrans.utils.toInfo
88
import org.jetbrains.kotlin.descriptors.Modality
99
import org.jetbrains.kotlin.fir.FirSession
10-
import org.jetbrains.kotlin.fir.analysis.checkers.collectUpperBounds
1110
import org.jetbrains.kotlin.fir.caches.FirCache
1211
import org.jetbrains.kotlin.fir.caches.firCachesFactory
1312
import org.jetbrains.kotlin.fir.caches.getValue
13+
import org.jetbrains.kotlin.fir.collectUpperBounds
1414
import org.jetbrains.kotlin.fir.copy
1515
import org.jetbrains.kotlin.fir.declarations.*
1616
import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
@@ -339,6 +339,7 @@ class SuspendTransformFirTransformer(
339339
// println("RAW AnnoData: ${anno.argumentMapping.mapping}")
340340

341341
val annoData = TransformAnnotationData.of(
342+
this.session,
342343
firAnnotation = anno,
343344
annotationBaseNamePropertyName = markAnnotation.baseNameProperty,
344345
annotationSuffixPropertyName = markAnnotation.suffixProperty,
@@ -453,12 +454,13 @@ class SuspendTransformFirTransformer(
453454

454455
private fun FirAnnotationArgumentMappingBuilder.includeGeneratedArguments(function: FirSimpleFunction) {
455456
fun MutableList<FirExpression>.addString(value: String) {
456-
val expression = buildConstExpression(
457+
val expression = buildLiteralExpression(
457458
source = null,
458459
kind = ConstantValueKind.String,
459460
value = value,
460461
setType = false
461462
)
463+
462464
add(expression)
463465
}
464466

Diff for: compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/ir/SuspendTransformTransformer.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ class SuspendTransformTransformer(
267267

268268
private fun IrFunction.reportLocation(): IrMessageLogger.Location? {
269269
return when (val sourceLocation =
270-
getSourceLocation(runCatching { fileEntry }.getOrNull())) {
270+
// getSourceLocation(runCatching { fileEntry }.getOrNull())) {
271+
getSourceLocation(file)) {
271272
is SourceLocation.Location -> {
272273
IrMessageLogger.Location(
273274
filePath = sourceLocation.file,

Diff for: compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/utils/AnnotationDescriptorUtils.kt

+34-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import love.forte.plugin.suspendtrans.toJvmBlockingAnnotationName
77
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
88
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
99
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
10+
import org.jetbrains.kotlin.fir.FirSession
11+
import org.jetbrains.kotlin.fir.declarations.findArgumentByName
1012
import org.jetbrains.kotlin.fir.declarations.getBooleanArgument
1113
import org.jetbrains.kotlin.fir.declarations.getStringArgument
1214
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
15+
import org.jetbrains.kotlin.fir.expressions.FirLiteralExpression
1316
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
1417
import org.jetbrains.kotlin.ir.builders.irCall
1518
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
@@ -89,6 +92,7 @@ data class TransformAnnotationData(
8992
}
9093

9194
fun of(
95+
session: FirSession,
9296
firAnnotation: FirAnnotation,
9397
annotationBaseNamePropertyName: String = "baseName",
9498
annotationSuffixPropertyName: String = "suffix",
@@ -97,13 +101,13 @@ data class TransformAnnotationData(
97101
defaultSuffix: String,
98102
defaultAsProperty: Boolean,
99103
): TransformAnnotationData {
100-
101-
val baseName = firAnnotation.getStringArgument(Name.identifier(annotationBaseNamePropertyName))
104+
val baseName = firAnnotation.getStringArgument0(Name.identifier(annotationBaseNamePropertyName), session)
102105
?.takeIf { it.isNotEmpty() }
103106

104-
val suffix = firAnnotation.getStringArgument(Name.identifier(annotationSuffixPropertyName))
107+
val suffix = firAnnotation.getStringArgument0(Name.identifier(annotationSuffixPropertyName), session)
105108

106-
val rawAsProperty = firAnnotation.getBooleanArgument(Name.identifier(annotationAsPropertyPropertyName))
109+
val rawAsProperty =
110+
firAnnotation.getBooleanArgument0(Name.identifier(annotationAsPropertyPropertyName), session)
107111

108112
val functionName = "${baseName ?: defaultBaseName}${suffix ?: defaultSuffix}"
109113

@@ -116,8 +120,34 @@ data class TransformAnnotationData(
116120
)
117121
}
118122
}
123+
}
124+
125+
private fun FirAnnotation.getStringArgument0(
126+
name: Name,
127+
session: FirSession
128+
): String? {
129+
val arg = getStringArgument(name, session)
130+
if (arg != null) {
131+
return arg
132+
}
119133

134+
// If not found, try to use `findArgumentByName`
135+
val argByName = findArgumentByName(name, returnFirstWhenNotFound = false)
136+
return (argByName as? FirLiteralExpression<*>)?.value as? String
137+
}
138+
139+
private fun FirAnnotation.getBooleanArgument0(
140+
name: Name,
141+
session: FirSession
142+
): Boolean? {
143+
val arg = getBooleanArgument(name, session)
144+
if (arg != null) {
145+
return arg
146+
}
120147

148+
// If not found, try to use `findArgumentByName`
149+
val argByName = findArgumentByName(name, returnFirstWhenNotFound = false)
150+
return (argByName as? FirLiteralExpression<*>)?.value as? Boolean
121151
}
122152

123153

Diff for: compiler/suspend-transform-plugin/src/test-gen/love/forte/plugin/suspendtrans/runners/CodeGenTestRunnerGenerated.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,32 @@
1515
@TestMetadata("src/testData/codegen")
1616
@TestDataPath("$PROJECT_ROOT")
1717
public class CodeGenTestRunnerGenerated extends AbstractCodeGenTestRunner {
18-
@Test
19-
public void testAllFilesPresentInCodegen() throws Exception {
20-
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/codegen"), Pattern.compile("^(.+)\\.kt$"), null, true);
21-
}
22-
23-
@Test
24-
@TestMetadata("asProperty.kt")
25-
public void testAsProperty() throws Exception {
26-
runTest("src/testData/codegen/asProperty.kt");
27-
}
28-
29-
@Test
30-
@TestMetadata("basic.kt")
31-
public void testBasic() throws Exception {
32-
runTest("src/testData/codegen/basic.kt");
33-
}
34-
35-
@Test
36-
@TestMetadata("override.kt")
37-
public void testOverride() throws Exception {
38-
runTest("src/testData/codegen/override.kt");
39-
}
40-
41-
@Test
42-
@TestMetadata("typeAttr.kt")
43-
public void testTypeAttr() throws Exception {
44-
runTest("src/testData/codegen/typeAttr.kt");
45-
}
18+
@Test
19+
public void testAllFilesPresentInCodegen() {
20+
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/codegen"), Pattern.compile("^(.+)\\.kt$"), null, true);
21+
}
22+
23+
@Test
24+
@TestMetadata("asProperty.kt")
25+
public void testAsProperty() {
26+
runTest("src/testData/codegen/asProperty.kt");
27+
}
28+
29+
@Test
30+
@TestMetadata("basic.kt")
31+
public void testBasic() {
32+
runTest("src/testData/codegen/basic.kt");
33+
}
34+
35+
@Test
36+
@TestMetadata("override.kt")
37+
public void testOverride() {
38+
runTest("src/testData/codegen/override.kt");
39+
}
40+
41+
@Test
42+
@TestMetadata("typeAttr.kt")
43+
public void testTypeAttr() {
44+
runTest("src/testData/codegen/typeAttr.kt");
45+
}
4646
}

0 commit comments

Comments
 (0)