Repository: evant/kotlin-inject
Pull request #78 (2020-10-10 20:37:29)

Update ksp


Patch:
diff --git a/build.gradle b/build.gradle
index 034e88f..c98d631 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,6 @@
 plugins {
     id 'org.jetbrains.kotlin.jvm' version '1.4.0' apply false
-    id 'symbol-processing' version "1.4.10-dev-experimental-20200924" apply false
+    id 'symbol-processing' version "$ksp_version" apply false
 }
 
 subprojects {
diff --git a/gradle.properties b/gradle.properties
index f97ebb7..9309ad7 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,1 +1,2 @@
+ksp_version=1.4.10-dev-experimental-20201009
 org.gradle.parallel=true
diff --git a/kotlin-inject-compiler-kapt/src/main/kotlin/me/tatarka/inject/compiler/kapt/Util.kt b/kotlin-inject-compiler-kapt/src/main/kotlin/me/tatarka/inject/compiler/kapt/Util.kt
index 36d64ec..a57e4c1 100644
--- a/kotlin-inject-compiler-kapt/src/main/kotlin/me/tatarka/inject/compiler/kapt/Util.kt
+++ b/kotlin-inject-compiler-kapt/src/main/kotlin/me/tatarka/inject/compiler/kapt/Util.kt
@@ -236,8 +236,10 @@ fun KmType.asTypeName(): TypeName? {
     }.copy(nullable = isNullable)
 }
 
+private val FUNCTION = Regex("kotlin/Function[0-9]+")
+
 fun KmType.isFunction(): Boolean {
-    return classifier.name?.matches(Regex("kotlin/Function[0-9]+")) == true
+    return classifier.name?.matches(FUNCTION) == true
 }
 
 private fun KmType.isSuspendFunction(): Boolean {
diff --git a/kotlin-inject-compiler-ksp/build.gradle b/kotlin-inject-compiler-ksp/build.gradle
index b15f98d..4f9df72 100644
--- a/kotlin-inject-compiler-ksp/build.gradle
+++ b/kotlin-inject-compiler-ksp/build.gradle
@@ -8,7 +8,7 @@ dependencies {
     implementation "org.jetbrains.kotlin:kotlin-stdlib"
     // for access to CompilationErrorException until ksp properly fails on errors
     implementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.0'
-    implementation 'com.google.devtools.ksp:symbol-processing-api:1.4.10-dev-experimental-20200924'
+    implementation "com.google.devtools.ksp:symbol-processing-api:$ksp_version"
 }
 
 sourceCompatibility = 1.8
diff --git a/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/KSAst.kt b/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/KSAst.kt
index ee43abe..3ab5ec3 100644
--- a/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/KSAst.kt
+++ b/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/KSAst.kt
@@ -37,7 +37,7 @@ import com.google.devtools.ksp.symbol.KSPropertyDeclaration
 import com.google.devtools.ksp.symbol.KSType
 import com.google.devtools.ksp.symbol.KSTypeAlias
 import com.google.devtools.ksp.symbol.KSTypeReference
-import com.google.devtools.ksp.symbol.KSVariableParameter
+import com.google.devtools.ksp.symbol.KSValueParameter
 import com.google.devtools.ksp.symbol.Variance
 import org.jetbrains.kotlin.analyzer.AnalysisResult
 import kotlin.reflect.KClass
@@ -261,7 +261,7 @@ private class KSAstFunction(provider: KSAstProvider, override val declaration: K
 
     override fun overrides(other: AstMethod): Boolean {
         if (other !is KSAstFunction) return false
-        return declaration.overrides(other.declaration)
+        return resolver.overrides(declaration, other.declaration)
     }
 
     override val returnType: AstType
@@ -301,7 +301,7 @@ private class KSAstProperty(provider: KSAstProvider, override val declaration: K
 
     override fun overrides(other: AstMethod): Boolean {
         if (other !is KSAstProperty) return false
-        return declaration.overrides(other.declaration)
+        return resolver.overrides(declaration, other.declaration)
     }
 
     override val returnType: AstType
@@ -434,7 +434,7 @@ private class KSAstParam(
     provider: KSAstProvider,
     val parentClass: KSClassDeclaration?,
     val parent: KSDeclaration,
-    override val declaration: KSVariableParameter
+    override val declaration: KSValueParameter
 ) : AstParam(),
     KSAstAnnotated, KSAstProvider by provider {
 
diff --git a/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/Util.kt b/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/Util.kt
index 69a8c45..a711080 100644
--- a/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/Util.kt
+++ b/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/Util.kt
@@ -159,13 +159,15 @@ fun KSTypeReference.eqvHashCode(collector: HashCollector): Int = collectHash(col
     resolve().eqvHashCode(collector)
 }
 
+private val FUNCTION = Regex("Function[0-9]+")
+private val SUSPEND_FUNCTION = Regex("SuspendFunction[0-9]+")
 
 fun KSType.isFunction(): Boolean {
     val name = declaration.qualifiedName ?: return false
-    return name.getQualifier() == "kotlin" && name.getShortName().matches(Regex("Function[0-9]+"))
+    return name.getQualifier() == "kotlin" && name.getShortName().matches(FUNCTION)
 }
 
 fun KSType.isSuspendingFunction(): Boolean {
     val name = declaration.qualifiedName ?: return false
-    return name.getQualifier() == "kotlin.coroutines" && name.getShortName().matches(Regex("SuspendFunction[0-9]+"))
+    return name.getQualifier() == "kotlin.coroutines" && name.getShortName().matches(SUSPEND_FUNCTION)
 }


Test patch:
diff --git a/compiler-tests/build.gradle b/compiler-tests/build.gradle
index 95d4dfb..f5120c8 100644
--- a/compiler-tests/build.gradle
+++ b/compiler-tests/build.gradle
@@ -11,7 +11,8 @@ dependencies {
 
     implementation 'com.github.tschuchortdev:kotlin-compile-testing-ksp:1.3.1'
     implementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.0'
-    implementation 'com.google.devtools.ksp:symbol-processing-api:1.4.10-dev-experimental-20200924'
+    implementation "com.google.devtools.ksp:symbol-processing:$ksp_version"
+    implementation "com.google.devtools.ksp:symbol-processing-api:$ksp_version"
 
     testImplementation "org.jetbrains.kotlin:kotlin-test"
     testImplementation "org.jetbrains.kotlin:kotlin-test-junit"