Skip to content

Commit

Permalink
Merge pull request #64 from kanyun-inc/feature/kotlin-2.0.0
Browse files Browse the repository at this point in the history
Feature/kotlin 2.0.0
  • Loading branch information
RicardoJiang authored Dec 15, 2024
2 parents 3d8bcb0 + a0aa5e9 commit bb631e0
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 26 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The Kace currently supports the above four most commonly used types. Other types
| 1.8.20-1.1.0 | 1.8.20 | 4.2.0 | 6.8.3 |
| 1.9.0-1.2.0 | 1.9.0~1.9.20 | 4.2.2 | 6.8.3 |
| 1.9.20-1.2.0 | 1.9.20 | 4.2.2 | 6.8.3 |
| 2.0.0-1.2.0 | 2.0.0 | 7.1.3 | 7.2 |

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

Expand Down Expand Up @@ -104,4 +105,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
````
````
3 changes: 2 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Kace 目前支持了以上四种最常用的类型,其他 kotlin-android-exten
| 1.8.20-1.1.0 | 1.8.20 | 4.2.0 | 6.8.3 |
| 1.9.0-1.2.0 | 1.9.0~1.9.20 | 4.2.2 | 6.8.3 |
| 1.9.20-1.2.0 | 1.9.20 | 4.2.2 | 6.8.3 |
| 2.0.0-1.2.0 | 2.0.0 | 7.1.3 | 7.2 |

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

Expand Down Expand Up @@ -103,4 +104,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
```
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "4.2.2" apply false
id("com.android.library") version "4.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
id("com.android.application") version "7.1.3" apply false
id("com.android.library") version "7.1.3" apply false
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
id("com.vanniktech.maven.publish") version "0.18.0" apply false
id("com.github.gmazzo.buildconfig") version "2.1.0" apply false
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ kotlin.code.style=official
android.nonTransitiveRClass=true

KOTLIN_PLUGIN_ID=com.kanyun.kace
VERSION_NAME=1.9.20-1.2.0
VERSION_NAME=2.0.0-1.2.0-SNAPSHOT

GROUP=com.kanyun.kace

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

SONATYPE_HOST=S01
SONATYPE_HOST=S01
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Sep 29 08:11:34 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
14 changes: 7 additions & 7 deletions kace-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

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

testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:1.9.20-1.3.0")
testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:2.0.0-1.3.0")
}

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

buildConfig {
packageName("$group")
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${project.property("KOTLIN_PLUGIN_ID")}\"")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class KaceFirSupertypeGenerationExtension(
session: FirSession,
) : FirSupertypeGenerationExtension(session) {

context(TypeResolveServiceContainer) override fun computeAdditionalSupertypes(
override fun computeAdditionalSupertypes(
classLikeDeclaration: FirClassLikeDeclaration,
resolvedSupertypes: List<FirResolvedTypeRef>,
typeResolver: TypeResolveService
): List<FirResolvedTypeRef> {
var shouldAddSuperType = false
OUTER@ for (superTypeRef in resolvedSupertypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import org.jetbrains.kotlin.ir.builders.irGetField
import org.jetbrains.kotlin.ir.builders.irReturn
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.types.defaultType
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
import org.jetbrains.kotlin.ir.util.constructors
Expand Down Expand Up @@ -78,8 +77,7 @@ class KaceIrTransformer(private val context: IrPluginContext) : IrElementTransfo
// override fun <T> findViewByIdCached(owner, id) = ...
declaration.addOverride(
ANDROID_EXTENSIONS_FQNAME,
FIND_VIEW_BY_ID_CACHED_NAME,
IrUninitializedType,
FIND_VIEW_BY_ID_CACHED_NAME
).apply {
val parameterT = addTypeParameter("T", context.typeOfView())
returnType = parameterT.defaultType.makeNullable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@
package com.kanyun.kace.compiler.utils

import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.declarations.addFunction
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classOrNull
import org.jetbrains.kotlin.ir.util.allOverridden
import org.jetbrains.kotlin.ir.util.copyTo
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.functions
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.parentClassOrNull
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name

fun IrClass.isSubclassOfFqName(fqName: String): Boolean =
fqNameWhenAvailable?.asString() == fqName || superTypes.any {
Expand All @@ -42,9 +48,21 @@ fun IrClass.isSubclassOfFqName(fqName: String): Boolean =
fun IrClass.addOverride(
baseFqName: FqName,
name: String,
returnType: IrType,
modality: Modality = Modality.FINAL,
): IrSimpleFunction = addFunction(name, returnType, modality).apply {
): IrSimpleFunction = addFunction {
this.name = Name.identifier(name)
this.modality = modality
this.startOffset = UNDEFINED_OFFSET
this.endOffset = UNDEFINED_OFFSET
this.visibility = DescriptorVisibilities.PUBLIC
this.isFakeOverride = false
this.isSuspend = false
this.isInline = false
this.origin = IrDeclarationOrigin.DEFINED
}.apply {
val thisReceiver = parentAsClass.thisReceiver!!
dispatchReceiverParameter = thisReceiver.copyTo(this, type = thisReceiver.type)

overriddenSymbols = superTypes.mapNotNull { superType ->
superType.classOrNull?.owner?.takeIf { superClass ->
superClass.isSubclassOfFqName(
Expand Down
2 changes: 1 addition & 1 deletion kace-compiler/testData/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class SixthActivity
7
// FILE: Main.kt.ir
class MainActivity : AndroidExtensions {
private val $$delegate_0: AndroidExtensionsImpl = AndroidExtensionsImpl()
override fun <T: View?> findViewByIdCached(owner: AndroidExtensionsBase, id: Int, viewClass: Class<T>): T? {
return <this>.$$delegate_0.findViewByIdCached(owner, id, viewClass)
}
private val $$delegate_0: AndroidExtensionsImpl = AndroidExtensionsImpl()
}
class SecondActivity : AndroidExtensions {
private var $$androidExtensionsImpl: AndroidExtensionsImpl = AndroidExtensionsImpl()
Expand Down
4 changes: 2 additions & 2 deletions kace-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
plugins {
id("com.android.application") apply false
id("com.android.library") apply false
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
id("com.kanyun.kace") version "0.0.0-SNAPSHOT" apply false
}

Expand All @@ -19,4 +19,4 @@ allprojects {
google()
mavenCentral()
}
}
}
4 changes: 2 additions & 2 deletions test_agp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function testUnderAGPVersion() {

cd kace-sample

setGradleVersion 6.8.3
testUnderAGPVersion 4.2.2
setGradleVersion 7.2
testUnderAGPVersion 7.1.3

setGradleVersion 7.3.3
testUnderAGPVersion 7.2.0
Expand Down

0 comments on commit bb631e0

Please sign in to comment.