Skip to content

Commit bb631e0

Browse files
authored
Merge pull request #64 from kanyun-inc/feature/kotlin-2.0.0
Feature/kotlin 2.0.0
2 parents 3d8bcb0 + a0aa5e9 commit bb631e0

12 files changed

+45
-26
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ The Kace currently supports the above four most commonly used types. Other types
7575
| 1.8.20-1.1.0 | 1.8.20 | 4.2.0 | 6.8.3 |
7676
| 1.9.0-1.2.0 | 1.9.0~1.9.20 | 4.2.2 | 6.8.3 |
7777
| 1.9.20-1.2.0 | 1.9.20 | 4.2.2 | 6.8.3 |
78+
| 2.0.0-1.2.0 | 2.0.0 | 7.1.3 | 7.2 |
7879

7980
Since the goal of the Kace is to help developers easily upgrade to Kotlin 1.8, the minimum supported version of Kotlin is relatively high
8081

@@ -104,4 +105,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
104105
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
105106
See the License for the specific language governing permissions and
106107
limitations under the License.
107-
````
108+
````

README_zh.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Kace 目前支持了以上四种最常用的类型,其他 kotlin-android-exten
7474
| 1.8.20-1.1.0 | 1.8.20 | 4.2.0 | 6.8.3 |
7575
| 1.9.0-1.2.0 | 1.9.0~1.9.20 | 4.2.2 | 6.8.3 |
7676
| 1.9.20-1.2.0 | 1.9.20 | 4.2.2 | 6.8.3 |
77+
| 2.0.0-1.2.0 | 2.0.0 | 7.1.3 | 7.2 |
7778

7879
由于 Kace 的目标是帮助开发者更方便地迁移到 Kotlin 1.8,因此 Kotlin 最低支持版本比较高
7980

@@ -103,4 +104,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
103104
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
104105
See the License for the specific language governing permissions and
105106
limitations under the License.
106-
```
107+
```

build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id("com.android.application") version "4.2.2" apply false
4-
id("com.android.library") version "4.2.2" apply false
5-
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
3+
id("com.android.application") version "7.1.3" apply false
4+
id("com.android.library") version "7.1.3" apply false
5+
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
66
id("com.vanniktech.maven.publish") version "0.18.0" apply false
77
id("com.github.gmazzo.buildconfig") version "2.1.0" apply false
88
}

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ kotlin.code.style=official
2323
android.nonTransitiveRClass=true
2424

2525
KOTLIN_PLUGIN_ID=com.kanyun.kace
26-
VERSION_NAME=1.9.20-1.2.0
26+
VERSION_NAME=2.0.0-1.2.0-SNAPSHOT
2727

2828
GROUP=com.kanyun.kace
2929

@@ -44,4 +44,4 @@ POM_DEVELOPER_ID=solar-android
4444
POM_DEVELOPER_NAME=SolarAndroid
4545
POM_DEVELOPER_URL=https://github.com/beijing-kug/
4646

47-
SONATYPE_HOST=S01
47+
SONATYPE_HOST=S01
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Sep 29 08:11:34 CST 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

kace-compiler/build.gradle.kts

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1617
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1718

1819
plugins {
@@ -35,17 +36,16 @@ dependencies {
3536
testImplementation(kotlin("test-junit"))
3637
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
3738

38-
testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:1.9.20-1.3.0")
39+
testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:2.0.0-1.3.0")
3940
}
4041

4142
val compileKotlin: KotlinCompile by tasks
42-
compileKotlin.kotlinOptions.freeCompilerArgs += listOf(
43-
"-opt-in=kotlin.RequiresOptIn",
44-
"-Xcontext-receivers"
45-
)
46-
compileKotlin.kotlinOptions.jvmTarget = "1.8"
43+
compileKotlin.compilerOptions {
44+
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
45+
jvmTarget.set(JvmTarget.JVM_1_8)
46+
}
4747

4848
buildConfig {
4949
packageName("$group")
5050
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${project.property("KOTLIN_PLUGIN_ID")}\"")
51-
}
51+
}

kace-compiler/src/main/java/com/kanyun/kace/compiler/KaceFirSupertypeGenerationExtension.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ class KaceFirSupertypeGenerationExtension(
4646
session: FirSession,
4747
) : FirSupertypeGenerationExtension(session) {
4848

49-
context(TypeResolveServiceContainer) override fun computeAdditionalSupertypes(
49+
override fun computeAdditionalSupertypes(
5050
classLikeDeclaration: FirClassLikeDeclaration,
5151
resolvedSupertypes: List<FirResolvedTypeRef>,
52+
typeResolver: TypeResolveService
5253
): List<FirResolvedTypeRef> {
5354
var shouldAddSuperType = false
5455
OUTER@ for (superTypeRef in resolvedSupertypes) {

kace-compiler/src/main/java/com/kanyun/kace/compiler/KaceIrTransformer.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.ir.builders.irGetField
4242
import org.jetbrains.kotlin.ir.builders.irReturn
4343
import org.jetbrains.kotlin.ir.declarations.IrClass
4444
import org.jetbrains.kotlin.ir.types.defaultType
45-
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
4645
import org.jetbrains.kotlin.ir.types.makeNullable
4746
import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
4847
import org.jetbrains.kotlin.ir.util.constructors
@@ -78,8 +77,7 @@ class KaceIrTransformer(private val context: IrPluginContext) : IrElementTransfo
7877
// override fun <T> findViewByIdCached(owner, id) = ...
7978
declaration.addOverride(
8079
ANDROID_EXTENSIONS_FQNAME,
81-
FIND_VIEW_BY_ID_CACHED_NAME,
82-
IrUninitializedType,
80+
FIND_VIEW_BY_ID_CACHED_NAME
8381
).apply {
8482
val parameterT = addTypeParameter("T", context.typeOfView())
8583
returnType = parameterT.defaultType.makeNullable()

kace-compiler/src/main/java/com/kanyun/kace/compiler/utils/IrCommon.kt

+20-2
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@
1717
package com.kanyun.kace.compiler.utils
1818

1919
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
20+
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
2021
import org.jetbrains.kotlin.descriptors.Modality
22+
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
2123
import org.jetbrains.kotlin.ir.builders.declarations.addFunction
2224
import org.jetbrains.kotlin.ir.declarations.IrClass
25+
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
2326
import org.jetbrains.kotlin.ir.declarations.IrFunction
2427
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
2528
import org.jetbrains.kotlin.ir.expressions.IrExpression
2629
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
2730
import org.jetbrains.kotlin.ir.types.IrType
2831
import org.jetbrains.kotlin.ir.types.classOrNull
2932
import org.jetbrains.kotlin.ir.util.allOverridden
33+
import org.jetbrains.kotlin.ir.util.copyTo
3034
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
3135
import org.jetbrains.kotlin.ir.util.functions
36+
import org.jetbrains.kotlin.ir.util.parentAsClass
3237
import org.jetbrains.kotlin.ir.util.parentClassOrNull
3338
import org.jetbrains.kotlin.name.FqName
39+
import org.jetbrains.kotlin.name.Name
3440

3541
fun IrClass.isSubclassOfFqName(fqName: String): Boolean =
3642
fqNameWhenAvailable?.asString() == fqName || superTypes.any {
@@ -42,9 +48,21 @@ fun IrClass.isSubclassOfFqName(fqName: String): Boolean =
4248
fun IrClass.addOverride(
4349
baseFqName: FqName,
4450
name: String,
45-
returnType: IrType,
4651
modality: Modality = Modality.FINAL,
47-
): IrSimpleFunction = addFunction(name, returnType, modality).apply {
52+
): IrSimpleFunction = addFunction {
53+
this.name = Name.identifier(name)
54+
this.modality = modality
55+
this.startOffset = UNDEFINED_OFFSET
56+
this.endOffset = UNDEFINED_OFFSET
57+
this.visibility = DescriptorVisibilities.PUBLIC
58+
this.isFakeOverride = false
59+
this.isSuspend = false
60+
this.isInline = false
61+
this.origin = IrDeclarationOrigin.DEFINED
62+
}.apply {
63+
val thisReceiver = parentAsClass.thisReceiver!!
64+
dispatchReceiverParameter = thisReceiver.copyTo(this, type = thisReceiver.type)
65+
4866
overriddenSymbols = superTypes.mapNotNull { superType ->
4967
superType.classOrNull?.owner?.takeIf { superClass ->
5068
superClass.isSubclassOfFqName(

kace-compiler/testData/expect.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class SixthActivity
1717
7
1818
// FILE: Main.kt.ir
1919
class MainActivity : AndroidExtensions {
20+
private val $$delegate_0: AndroidExtensionsImpl = AndroidExtensionsImpl()
2021
override fun <T: View?> findViewByIdCached(owner: AndroidExtensionsBase, id: Int, viewClass: Class<T>): T? {
2122
return <this>.$$delegate_0.findViewByIdCached(owner, id, viewClass)
2223
}
23-
private val $$delegate_0: AndroidExtensionsImpl = AndroidExtensionsImpl()
2424
}
2525
class SecondActivity : AndroidExtensions {
2626
private var $$androidExtensionsImpl: AndroidExtensionsImpl = AndroidExtensionsImpl()

kace-sample/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
plugins {
33
id("com.android.application") apply false
44
id("com.android.library") apply false
5-
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
5+
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
66
id("com.kanyun.kace") version "0.0.0-SNAPSHOT" apply false
77
}
88

@@ -19,4 +19,4 @@ allprojects {
1919
google()
2020
mavenCentral()
2121
}
22-
}
22+
}

test_agp.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function testUnderAGPVersion() {
1616

1717
cd kace-sample
1818

19-
setGradleVersion 6.8.3
20-
testUnderAGPVersion 4.2.2
19+
setGradleVersion 7.2
20+
testUnderAGPVersion 7.1.3
2121

2222
setGradleVersion 7.3.3
2323
testUnderAGPVersion 7.2.0

0 commit comments

Comments
 (0)