Skip to content

Commit 5c993b1

Browse files
jiangjunxiangRicardoJiang
jiangjunxiang
authored andcommitted
ADD: code review check
1 parent 3404056 commit 5c993b1

36 files changed

+253
-63
lines changed

.github/workflows/build.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
concurrency:
12+
group: build-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 60
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- name: Validate Gradle Wrapper
25+
uses: gradle/wrapper-validation-action@v1
26+
27+
- name: Set up JDK 8
28+
uses: actions/setup-java@v3
29+
with:
30+
distribution: 'zulu'
31+
java-version: 8
32+
33+
- name: Setup Gradle
34+
uses: gradle/gradle-build-action@v2
35+
36+
- name: Check spotless
37+
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
38+
39+
- name: Run local tests
40+
run: ./gradlew :kace-compiler:test

gradle/init.gradle.kts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2022 KanYun
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
val ktlintVersion = "0.43.0"
18+
19+
initscript {
20+
val spotlessVersion = "6.11.0"
21+
22+
repositories {
23+
mavenCentral()
24+
}
25+
26+
dependencies {
27+
classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion")
28+
}
29+
}
30+
31+
rootProject {
32+
subprojects {
33+
apply<com.diffplug.gradle.spotless.SpotlessPlugin>()
34+
extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
35+
kotlin {
36+
target("**/*.kt")
37+
targetExclude("**/build/**/*.kt")
38+
ktlint(ktlintVersion).userData(
39+
mapOf(
40+
"android" to "true",
41+
"max_line_length" to "200"
42+
)
43+
)
44+
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
45+
}
46+
format("kts") {
47+
target("**/*.kts")
48+
targetExclude("**/build/**/*.kts")
49+
// Look for the first line that doesn't have a block comment (assumed to be the license)
50+
licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)")
51+
}
52+
format("xml") {
53+
target("**/*.xml")
54+
targetExclude("**/build/**/*.xml")
55+
// Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
56+
licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])")
57+
}
58+
}
59+
}
60+
}

kace-compiler/build.gradle.kts

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2022 KanYun
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
217

318
plugins {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ class KaceCommandLineProcessor : CommandLineProcessor {
3636
value: String,
3737
configuration: CompilerConfiguration
3838
) = Options.processOption(option, value, configuration)
39-
40-
}
39+
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,3 @@ class KaceComponentRegistrar : ComponentRegistrar {
3939
SyntheticResolveExtension.registerExtension(project, KaceSyntheticResolveExtension())
4040
}
4141
}
42-
43-

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ class KaceIrGenerationExtension : IrGenerationExtension {
2525
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
2626
moduleFragment.transformChildrenVoid(KaceIrTransformer(pluginContext))
2727
}
28-
}
28+
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ class KaceIrTransformer(private val context: IrPluginContext) : IrElementTransfo
105105
irGet(irValueParameter.type, irValueParameter.symbol)
106106
)
107107
}
108-
})
108+
}
109+
)
109110
}.doBuild()
110111
}
111112
}
112113
}
113114
return super.visitClass(declaration)
114115
}
115-
}
116+
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
package com.kanyun.kace.compiler
1818

19-
import com.kanyun.kace.compiler.utils.*
19+
import com.kanyun.kace.compiler.utils.ANDROID_EXTENSIONS_CLASS_NAME
20+
import com.kanyun.kace.compiler.utils.ANDROID_EXTENSIONS_FQNAME
21+
import com.kanyun.kace.compiler.utils.ANDROID_EXTENSIONS_FULL_NAME
22+
import com.kanyun.kace.compiler.utils.ANDROID_EXTENSIONS_PACKAGE_NAME
23+
import com.kanyun.kace.compiler.utils.IMPLICIT_ANDROID_EXTENSIONS_TYPES
2024
import org.jetbrains.kotlin.descriptors.ClassDescriptor
2125
import org.jetbrains.kotlin.descriptors.ClassKind
2226
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
@@ -43,7 +47,7 @@ class KaceSyntheticResolveExtension : SyntheticResolveExtension {
4347
}
4448

4549
var shouldAddSuperType = false
46-
for(superTypeName in superTypeNames) {
50+
for (superTypeName in superTypeNames) {
4751
if (superTypeName == ANDROID_EXTENSIONS_FULL_NAME) return
4852
if (!shouldAddSuperType && superTypeName in IMPLICIT_ANDROID_EXTENSIONS_TYPES) {
4953
shouldAddSuperType = true
@@ -69,5 +73,4 @@ class KaceSyntheticResolveExtension : SyntheticResolveExtension {
6973
)
7074
)
7175
}
72-
73-
}
76+
}

kace-compiler/src/main/java/com/kanyun/kace/compiler/options/Options.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package com.kanyun.kace.compiler.options
1818

1919
import com.kanyun.kace.compiler.logger
20+
import java.lang.ref.WeakReference
2021
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
2122
import org.jetbrains.kotlin.compiler.plugin.CliOption
2223
import org.jetbrains.kotlin.config.CompilerConfiguration
2324
import org.jetbrains.kotlin.config.CompilerConfigurationKey
24-
import java.lang.ref.WeakReference
2525

2626
object Options {
2727

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

-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ val IMPLICIT_ANDROID_EXTENSIONS_TYPES = setOf(
3636
const val FIND_VIEW_BY_ID_CACHED_NAME = "findViewByIdCached"
3737

3838
const val DELEGATE_FIELD_NAME = "\$\$androidExtensionsImpl"
39-

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,19 @@ import org.jetbrains.kotlin.ir.types.classFqName
2424
import org.jetbrains.kotlin.ir.types.defaultType
2525
import org.jetbrains.kotlin.ir.util.functions
2626

27-
2827
fun IrClass.findViewByIdCached(pluginContext: IrPluginContext): IrSimpleFunction? {
2928
return functions.find {
3029
it.isFindViewByIdCached(pluginContext)
3130
}
3231
}
3332

3433
fun IrFunction.isFindViewByIdCached(pluginContext: IrPluginContext): Boolean {
35-
return name.identifier == FIND_VIEW_BY_ID_CACHED_NAME
36-
&& valueParameters.size == 2
37-
&& valueParameters[0].type == pluginContext.referenceClass(
34+
return name.identifier == FIND_VIEW_BY_ID_CACHED_NAME &&
35+
valueParameters.size == 2 &&
36+
valueParameters[0].type == pluginContext.referenceClass(
3837
ANDROID_EXTENSIONS_BASE_FQNAME
39-
)?.defaultType
40-
&& valueParameters[1].type == pluginContext.symbols.int.defaultType
38+
)?.defaultType &&
39+
valueParameters[1].type == pluginContext.symbols.int.defaultType
4140
}
4241

4342
fun IrClass.isAndroidExtensions(): Boolean {
@@ -51,4 +50,4 @@ fun IrPluginContext.typeOfView() =
5150
referenceClass(ANDROID_VIEW_FQNAME)!!.defaultType
5251

5352
fun IrPluginContext.symbolOfAndroidExtensionImpl() =
54-
referenceClass(ANDROID_EXTENSIONS_IMPL_FQNAME)!!
53+
referenceClass(ANDROID_EXTENSIONS_IMPL_FQNAME)!!

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ fun IrClass.addOverride(
5959
}
6060

6161
fun IrSimpleFunction.overridesFunctionIn(fqName: FqName): Boolean =
62-
parentClassOrNull?.fqNameWhenAvailable == fqName || allOverridden().any { it.parentClassOrNull?.fqNameWhenAvailable == fqName }
62+
parentClassOrNull?.fqNameWhenAvailable == fqName || allOverridden().any {
63+
it.parentClassOrNull?.fqNameWhenAvailable == fqName
64+
}
6365

6466
fun IrFunction.irThis(): IrExpression {
6567
val irDispatchReceiverParameter = dispatchReceiverParameter!!
@@ -68,4 +70,4 @@ fun IrFunction.irThis(): IrExpression {
6870
irDispatchReceiverParameter.type,
6971
irDispatchReceiverParameter.symbol
7072
)
71-
}
73+
}

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class Logger(private val messageCollector: MessageCollector) {
3434
}
3535

3636
fun println(level: CompilerMessageSeverity, message: Any?) {
37-
messageCollector.report(level, "[Kace] ${message.toString()}")
37+
messageCollector.report(level, "[Kace] $message")
3838
}
39-
40-
}
39+
}

kace-compiler/src/test/java/com/kanyun/kace/compiler/KaceTest.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class KaceTest {
2626

2727
@Test
2828
fun basic() {
29-
testBase("basic.kt")
29+
testBase("basic.txt")
3030
}
3131

3232
private fun testBase(fileName: String) {
@@ -45,5 +45,4 @@ class KaceTest {
4545
checkCompilerOutput = true
4646
)
4747
}
48-
49-
}
48+
}
File renamed without changes.

kace-gradle-plugin/build.gradle.kts

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2022 KanYun
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
plugins {
217
id("java-gradle-plugin")
318
kotlin("jvm")

kace-gradle-plugin/src/main/java/com/kanyun/kace/gradle/KaceExtension.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ open class KaceExtension {
2020
var whiteList: List<String> = listOf()
2121
var blackList: List<String> = listOf()
2222
var customVariant: Map<String, List<String>> = emptyMap()
23-
}
23+
}

kace-gradle-plugin/src/main/java/com/kanyun/kace/gradle/KaceGenerateAction.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import com.kanyun.kace.BuildConfig
2020
import com.kanyun.kace.gradle.utils.appendLine
2121
import com.kanyun.kace.gradle.utils.initSAX
2222
import com.kanyun.kace.gradle.utils.parseXml
23+
import java.io.File
24+
import javax.xml.parsers.SAXParser
2325
import org.gradle.api.file.DirectoryProperty
2426
import org.gradle.api.file.RegularFileProperty
2527
import org.gradle.api.provider.Property
2628
import org.gradle.workers.WorkAction
2729
import org.gradle.workers.WorkParameters
2830
import org.slf4j.LoggerFactory
29-
import java.io.File
30-
import javax.xml.parsers.SAXParser
3131

3232
abstract class KaceGenerateAction : WorkAction<KaceGenerateAction.Parameters> {
3333
interface Parameters : WorkParameters {
@@ -66,7 +66,7 @@ abstract class KaceGenerateAction : WorkAction<KaceGenerateAction.Parameters> {
6666
writer.appendLine("import ${BuildConfig.KOTLIN_PLUGIN_GROUP}.AndroidExtensionsBase")
6767
writer.appendLine("import android.app.Activity")
6868
writer.appendLine("import androidx.fragment.app.Fragment")
69-
writer.appendLine("import ${namespace}.R")
69+
writer.appendLine("import $namespace.R")
7070
writer.newLine()
7171

7272
layoutNodeItems.forEach { item ->
@@ -93,7 +93,7 @@ abstract class KaceGenerateAction : WorkAction<KaceGenerateAction.Parameters> {
9393
writer.appendLine("package ${item.targetFilePackageName}.view")
9494
writer.newLine()
9595
writer.appendLine("import android.view.View")
96-
writer.appendLine("import ${namespace}.R")
96+
writer.appendLine("import $namespace.R")
9797
writer.newLine()
9898

9999
layoutNodeItems.forEach { item ->
@@ -104,4 +104,3 @@ abstract class KaceGenerateAction : WorkAction<KaceGenerateAction.Parameters> {
104104
}
105105
}
106106
}
107-

kace-gradle-plugin/src/main/java/com/kanyun/kace/gradle/KaceGenerateTask.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.kanyun.kace.gradle
1818

19+
import java.io.File
20+
import javax.inject.Inject
1921
import org.gradle.api.DefaultTask
2022
import org.gradle.api.file.ConfigurableFileCollection
2123
import org.gradle.api.file.DirectoryProperty
@@ -35,8 +37,6 @@ import org.gradle.work.Incremental
3537
import org.gradle.work.InputChanges
3638
import org.gradle.workers.WorkerExecutor
3739
import org.jetbrains.kotlin.incremental.ChangedFiles
38-
import java.io.File
39-
import javax.inject.Inject
4040

4141
abstract class KaceGenerateTask : DefaultTask() {
4242

@@ -153,4 +153,4 @@ abstract class KaceGenerateTask : DefaultTask() {
153153
ChangedFiles.Known(first, second)
154154
}
155155
}
156-
}
156+
}

kace-gradle-plugin/src/main/java/com/kanyun/kace/gradle/KaceGradlePlugin.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import com.kanyun.kace.gradle.utils.addSourceSetLayoutDir
2626
import com.kanyun.kace.gradle.utils.configSourceSetDir
2727
import com.kanyun.kace.gradle.utils.getApplicationPackage
2828
import com.kanyun.kace.gradle.utils.withAllPlugins
29+
import java.io.File
2930
import org.gradle.api.Plugin
3031
import org.gradle.api.Project
31-
import java.io.File
3232

3333
class KaceGradlePlugin : Plugin<Project> {
3434
override fun apply(target: Project) {

kace-gradle-plugin/src/main/java/com/kanyun/kace/gradle/KaceSubPlugin.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ class KaceSubPlugin : KotlinCompilerPluginSupportPlugin {
4242
emptyList()
4343
}
4444
}
45-
}
45+
}

0 commit comments

Comments
 (0)