Skip to content

Commit 1ce03fe

Browse files
committed
适配ksp2
1 parent bff5ec2 commit 1ce03fe

4 files changed

Lines changed: 43 additions & 24 deletions

File tree

android-aop-apt/src/main/java/com/flyjingfish/android_aop_ksp/AndroidAopSymbolProcessor.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@ class AndroidAopSymbolProcessor(private val codeGenerator: CodeGenerator,
137137
throw IllegalArgumentException("注意:请给 $symbol 设置 @Target 为 METHOD ")
138138
}
139139
} else if (symbol.origin == Origin.KOTLIN) {
140-
if ("kotlin.annotation.AnnotationTarget.FUNCTION" != s.toString() && "kotlin.annotation.AnnotationTarget.PROPERTY_GETTER" != s.toString() && "kotlin.annotation.AnnotationTarget.PROPERTY_SETTER" != s.toString()) {
140+
val targetType = s.toString()
141+
// if ("kotlin.annotation.AnnotationTarget.FUNCTION" != s.toString()
142+
// && "kotlin.annotation.AnnotationTarget.PROPERTY_GETTER" != s.toString()
143+
// && "kotlin.annotation.AnnotationTarget.PROPERTY_SETTER" != s.toString()) {
144+
if (!targetType.contains("AnnotationTarget.FUNCTION")
145+
&& !targetType.contains("AnnotationTarget.PROPERTY_GETTER")
146+
&& !targetType.contains("AnnotationTarget.PROPERTY_SETTER")) {
141147
throw IllegalArgumentException("注意:$symbol 只可设置 @Target 为 FUNCTION、PROPERTY_SETTER 或 PROPERTY_GETTER")
142148
}
143149
}
@@ -154,7 +160,8 @@ class AndroidAopSymbolProcessor(private val codeGenerator: CodeGenerator,
154160
val retentionMap: MutableMap<String, Any?>? = annotationMap["@Retention"]
155161
if (retentionMap != null) {
156162
val retention = retentionMap["value"]?.toString()
157-
if ((symbol.origin == Origin.JAVA && "RUNTIME" != retention) || (symbol.origin == Origin.KOTLIN && "kotlin.annotation.AnnotationRetention.RUNTIME" != retention)) {
163+
if ((symbol.origin == Origin.JAVA && "RUNTIME" != retention)
164+
|| (symbol.origin == Origin.KOTLIN && retention?.contains("AnnotationRetention.RUNTIME") != true)) {
158165
throw IllegalArgumentException("注意:请给 $symbol 设置 @Retention 为 RUNTIME ")
159166
}
160167
} else {
@@ -428,7 +435,9 @@ class AndroidAopSymbolProcessor(private val codeGenerator: CodeGenerator,
428435

429436
}else if (symbol.origin == Origin.JAVA){
430437
if (symbol is KSFunctionDeclaration){
431-
if (symbol.functionKind != FunctionKind.STATIC){
438+
val modifiers = symbol.modifiers
439+
val isStatic = Modifier.JAVA_STATIC in modifiers
440+
if (!isStatic){
432441
var className = "${symbol.packageName.asString()}."
433442
var parent = symbol.parent
434443
while (parent !is KSFile){
@@ -563,7 +572,9 @@ class AndroidAopSymbolProcessor(private val codeGenerator: CodeGenerator,
563572
}
564573

565574
}else if (symbol.origin == Origin.JAVA){
566-
if (symbol.functionKind != FunctionKind.STATIC){
575+
val modifiers = symbol.modifiers
576+
val isStatic = Modifier.JAVA_STATIC in modifiers
577+
if (!isStatic){
567578
throw IllegalArgumentException("$exceptionJavaHintPreText 必须是静态方法")
568579
}
569580
val isPublic = symbol.modifiers.contains(Modifier.PUBLIC)
@@ -582,8 +593,8 @@ class AndroidAopSymbolProcessor(private val codeGenerator: CodeGenerator,
582593
val isClazz = collectOutClassName == "java.lang.Class"
583594
var collectClassName = if (isClazz){
584595
if (symbol.origin == Origin.KOTLIN){
585-
// logger.error("$exceptionHintPreText---${parameter.type.resolve()}")
586596
val checkType = "${parameter.type.resolve()}"
597+
logger.error("=====$checkType")
587598
if (regexIsEmpty){
588599
if (!checkKotlinType(checkType)){
589600
throw IllegalArgumentException("$exceptionHintPreText 的 参数的泛型设置的不对")
@@ -596,6 +607,7 @@ class AndroidAopSymbolProcessor(private val codeGenerator: CodeGenerator,
596607
}else if (symbol.origin == Origin.JAVA){
597608
// logger.error("$exceptionHintPreText---${parameter.type}")
598609
val checkType = "${parameter.type}"
610+
logger.error("=====$checkType")
599611
if (regexIsEmpty){
600612
if (!checkJavaType(checkType)){
601613
throw IllegalArgumentException("$exceptionJavaHintPreText 的 参数的泛型设置的不对")

android-aop-extra/build.gradle

Lines changed: 0 additions & 16 deletions
This file was deleted.

android-aop-extra/build.gradle.kts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id("com.android.library")
3+
id("org.jetbrains.kotlin.android")
4+
id("com.google.devtools.ksp")
5+
}
6+
7+
// 引入外部 gradle 脚本
8+
apply(from = "$rootDir/gradle/android_base.gradle")
9+
apply(from = "$rootDir/gradle/android_publish.gradle")
10+
11+
android {
12+
namespace = "com.flyjingfish.android_aop_extra"
13+
}
14+
15+
//ksp {
16+
// useKsp2 = true
17+
//}
18+
19+
dependencies {
20+
implementation(project(path = ":android-aop-annotation"))
21+
implementation(project(path = ":android-aop-core"))
22+
ksp(project(":android-aop-apt"))
23+
}

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ buildscript {
99
plugins {
1010
id 'com.android.application' version '8.2.2' apply false
1111
id 'com.android.library' version '8.2.2' apply false
12-
id 'org.jetbrains.kotlin.android' version '1.9.23' apply false
13-
id 'org.jetbrains.kotlin.jvm' version '1.9.23' apply false
12+
id 'org.jetbrains.kotlin.android' version '2.1.20' apply false
13+
id 'org.jetbrains.kotlin.jvm' version '2.1.20' apply false
1414
id "com.vanniktech.maven.publish" version "0.33.0" apply false
15-
id 'com.google.devtools.ksp' version '1.9.23-1.0.20' apply false
15+
id 'com.google.devtools.ksp' version '2.1.20-2.0.0' apply false
1616
id 'io.github.flyjingfish.easyregister' version '1.1.0' apply false
1717
id 'com.gradle.plugin-publish' version '1.2.1' apply false
1818
// id "kotlinx-serialization" version "1.5.0"

0 commit comments

Comments
 (0)