Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: ./gradlew publishToMavenLocal -PVERSION_NAME=0.0.0-SNAPSHOT

- name: Check spotless
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
run: ./gradlew spotlessCheck --init-script gradle/init.gradle --no-configuration-cache

- name: Test AGP compatibility
run: chmod +x ./test_agp.sh && ./test_agp.sh
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ The Kace currently supports the above four most commonly used types. Other types
| 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 |
| 2.0.20-1.2.0 | 2.0.20 | 7.1.3 | 7.2 |
| 2.1.0-1.2.0 | 2.1.0 | 7.3.1 | 7.6.3 |
| 2.1.0-1.2.0 | 2.1.0 | 7.3.1 | 7.6.3 |
| 2.2.0-1.2.0 | 2.2.0 | 7.3.1 | 7.6.3 |

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
33 changes: 33 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false

// Use Kotlin 2.0.0 to build gradle plugin and compiler plugin for 2.1.0
// to avoid incompatible issue with gradle build.
id 'org.jetbrains.kotlin.android' version '2.2.0' apply false
id 'org.jetbrains.kotlin.jvm' version '2.2.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
}

allprojects {
repositories {
mavenCentral()
google()
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
}

apply plugin: "com.vanniktech.maven.publish"

plugins.withId("java") {
project.extensions.getByType(org.gradle.api.plugins.JavaPluginExtension).sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
}
plugins.withId("org.jetbrains.kotlin.jvm") {
project.extensions.getByType(org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension).compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
}
plugins.withId("org.jetbrains.kotlin.android") {
project.extensions.getByType(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension).compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
}
}
37 changes: 0 additions & 37 deletions build.gradle.kts

This file was deleted.

2 changes: 1 addition & 1 deletion 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=2.1.0-1.2.0
VERSION_NAME=2.2.0-1.2.0-SNAPSHOT

GROUP=com.kanyun.kace

Expand Down
46 changes: 46 additions & 0 deletions gradle/init.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ext.ktlintVersion = "0.49.1"

initscript {
def spotlessVersion = "6.19.0"

repositories {
mavenCentral()
}

dependencies {
classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion"
}
}

rootProject {
subprojects {
apply plugin: com.diffplug.gradle.spotless.SpotlessPlugin
spotless {
kotlin {
target '**/*.kt'
targetExclude '**/build/**/*.kt'
ktlint(ktlintVersion).userData(
[
"android" : "true",
"max_line_length" : "200",
"ij_kotlin_allow_trailing_comma" : "false",
"ij_kotlin_allow_trailing_comma_on_call_site": "false"
]
)
licenseHeaderFile rootProject.file("spotless/copyright.kt")
}
format 'kts', {
target '**/*.kts'
targetExclude '**/build/**/*.kts'
// Look for the first line that doesn't have a block comment (assumed to be the license)
licenseHeaderFile rootProject.file("spotless/copyright.kts"), "(^(?![\\\\/ ]\\\\*).*\$)"
}
format 'xml', {
target '**/*.xml'
targetExclude '**/build/**/*.xml'
// Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
licenseHeaderFile rootProject.file("spotless/copyright.xml"), "(<[^!?])"
}
}
}
}
62 changes: 0 additions & 62 deletions gradle/init.gradle.kts

This file was deleted.

52 changes: 52 additions & 0 deletions kace-compiler/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2022 KanYun
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* 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.
*/

plugins {
id 'org.jetbrains.kotlin.jvm'
id 'java'
id 'org.jetbrains.kotlin.kapt'
id 'com.github.gmazzo.buildconfig'
id 'com.vanniktech.maven.publish'
id 'maven-publish'
}

// Build this project with Kotlin 2.0.0 for compatibility reason.
// But we should depend on libs for Kotlin 2.1.0.
def kotlinVersion = "2.2.0"

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlinVersion}"

kapt "com.google.auto.service:auto-service:1.0.1"
compileOnly "com.google.auto.service:auto-service-annotations:1.0.1"

testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
testImplementation "com.bennyhuo.kotlin:kotlin-compile-testing-extensions:2.2.0-1.3.0"
}

tasks.named('compileKotlin', org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
compilerOptions {
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
}
}

buildConfig {
packageName = project.group
buildConfigField "String", "KOTLIN_PLUGIN_ID", "\"${project.property('KOTLIN_PLUGIN_ID')}\""
}
53 changes: 0 additions & 53 deletions kace-compiler/build.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.jetbrains.kotlin.ir.types.defaultType
import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.ir.util.nonDispatchParameters
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid

class KaceIrTransformer(private val context: IrPluginContext) : IrElementTransformerVoid() {
Expand Down Expand Up @@ -99,11 +100,9 @@ class KaceIrTransformer(private val context: IrPluginContext) : IrElementTransfo
).apply {
dispatchReceiver = androidExtensionsValue

valueParameters.forEachIndexed { index, irValueParameter ->
putValueArgument(
index,
irGet(irValueParameter.type, irValueParameter.symbol),
)
nonDispatchParameters.forEachIndexed { index, irValueParameter ->
arguments[index + 1] =
irGet(irValueParameter.type, irValueParameter.symbol)
}
},
)
Expand Down
10 changes: 6 additions & 4 deletions kace-compiler/src/main/java/com/kanyun/kace/compiler/utils/Ir.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.kanyun.kace.compiler.utils
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrParameterKind
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.types.classFqName
import org.jetbrains.kotlin.ir.types.classifierOrNull
Expand All @@ -32,12 +33,13 @@ fun IrClass.findViewByIdCached(pluginContext: IrPluginContext): IrSimpleFunction
}

fun IrFunction.isFindViewByIdCached(pluginContext: IrPluginContext): Boolean {
val regularParameter = parameters.filter { it.kind === IrParameterKind.Regular }
return name.identifier == FIND_VIEW_BY_ID_CACHED_NAME &&
valueParameters.size == 3 &&
valueParameters[0].type == pluginContext.typeOfAndroidExtensionsBase() &&
valueParameters[1].type == pluginContext.symbols.int.defaultType &&
regularParameter.size == 3 &&
regularParameter[0].type == pluginContext.typeOfAndroidExtensionsBase() &&
regularParameter[1].type == pluginContext.symbols.int.defaultType &&
// java.lang.Class<T> -> java.lang.Class
valueParameters[2].type.classifierOrNull?.defaultType == pluginContext.typeOfJavaClass()
regularParameter[2].type.classifierOrNull?.defaultType == pluginContext.typeOfJavaClass()
}

fun IrClass.isAndroidExtensions(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

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
Expand All @@ -30,8 +29,10 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
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.erasedUpperBound
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.functions
import org.jetbrains.kotlin.ir.util.nonDispatchParameters
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.parentClassOrNull
import org.jetbrains.kotlin.name.FqName
Expand Down Expand Up @@ -60,7 +61,7 @@ fun IrClass.addOverride(
this.origin = IrDeclarationOrigin.DEFINED
}.apply {
val thisReceiver = parentAsClass.thisReceiver!!
dispatchReceiverParameter = thisReceiver.copyTo(this, type = thisReceiver.type)
parameters = listOf(thisReceiver.copyTo(this, type = thisReceiver.type)) + nonDispatchParameters

overriddenSymbols = superTypes.mapNotNull { superType ->
superType.classOrNull?.owner?.takeIf { superClass ->
Expand Down
Loading
Loading