Repository: evant/kotlin-inject
Pull request #52 (2020-09-02 02:36:42)

Update ksp and align kotlin versions to 1.4.0


Patch:
diff --git a/README.md b/README.md
index b66c239..4f1dc42c 100644
--- a/README.md
+++ b/README.md
@@ -27,8 +27,8 @@ val repo = appComponent.repo
 
 ```groovy
 plugins {
-    id 'org.jetbrains.kotlin.jvm'
-    id 'org.jetbrains.kotlin.kapt'
+    id 'org.jetbrains.kotlin.jvm' version '1.4.0'
+    id 'org.jetbrains.kotlin.kapt' version '1.4.0'
 }
 
 repositories {
@@ -71,8 +71,8 @@ pluginManagement {
 `build.gradle`
 ```groovy
 plugins {
-    id 'org.jetbrains.kotlin.jvm' version "1.4.0-rc"
-    id 'org.jetbrains.kotlin.ksp' version "1.4.0-rc-dev-experimental-20200814"
+    id 'org.jetbrains.kotlin.jvm' version '1.4.0'
+    id 'org.jetbrains.kotlin.ksp' version '1.4.0-dev-experimental-20200828'
 }
 
 repositories {
diff --git a/build.gradle b/build.gradle
index 5865396..d6bd37a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,7 +1,10 @@
+plugins {
+    id 'org.jetbrains.kotlin.jvm' version '1.4.0' apply false
+}
+
 subprojects {
     repositories {
         google()
-        maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
         mavenCentral()
     }
 }
\ No newline at end of file
diff --git a/kotlin-inject-compiler-core/build.gradle b/kotlin-inject-compiler-core/build.gradle
index ae67e51..5dc3de3 100644
--- a/kotlin-inject-compiler-core/build.gradle
+++ b/kotlin-inject-compiler-core/build.gradle
@@ -1,5 +1,5 @@
 plugins {
-    id 'org.jetbrains.kotlin.jvm' version '1.3.70'
+    id 'org.jetbrains.kotlin.jvm'
 }
 
 dependencies {
diff --git a/kotlin-inject-compiler-kapt/build.gradle b/kotlin-inject-compiler-kapt/build.gradle
index fa555ee..e4df8cb 100644
--- a/kotlin-inject-compiler-kapt/build.gradle
+++ b/kotlin-inject-compiler-kapt/build.gradle
@@ -1,5 +1,5 @@
 plugins {
-    id 'org.jetbrains.kotlin.jvm' version '1.3.70'
+    id 'org.jetbrains.kotlin.jvm'
 }
 
 dependencies {
diff --git a/kotlin-inject-compiler-ksp/build.gradle b/kotlin-inject-compiler-ksp/build.gradle
index e2cf251..c6601cc 100644
--- a/kotlin-inject-compiler-ksp/build.gradle
+++ b/kotlin-inject-compiler-ksp/build.gradle
@@ -1,12 +1,12 @@
 plugins {
-    id 'org.jetbrains.kotlin.jvm' version '1.4.0-rc'
+    id 'org.jetbrains.kotlin.jvm'
 }
 
 dependencies {
     implementation project(':kotlin-inject-runtime')
     implementation project(':kotlin-inject-compiler-core')
     implementation "org.jetbrains.kotlin:kotlin-stdlib"
-    implementation 'org.jetbrains.kotlin:kotlin-symbol-processing-api:1.4.0-rc-dev-experimental-20200814'
+    implementation 'org.jetbrains.kotlin:kotlin-symbol-processing-api:1.4.0-dev-experimental-20200828'
 }
 
 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 5bcda13..1791b10 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
@@ -267,15 +267,13 @@ private class KSAstProperty(provider: KSAstProvider, override val declaration: K
     }
 
     override fun hasAnnotation(className: String): Boolean {
-        // also check the declaration itself https://github.com/android/kotlin/issues/108
         return declaration.getter?.hasAnnotation(className) == true
-                || declaration.hasAnnotation(className)
+                || declaration.hasAnnotation(className, AnnotationUseSiteTarget.GET)
     }
 
     override fun typeAnnotatedWith(className: String): AstClass? {
-        // also check the declaration itself https://github.com/android/kotlin/issues/108
         return (declaration.getter?.typeAnnotatedWith(className)?.declaration as? KSClassDeclaration)?.toAstClass()
-            ?: (declaration.typeAnnotatedWith(className)?.declaration as? KSClassDeclaration)?.toAstClass()
+            ?: (declaration.typeAnnotatedWith(className, AnnotationUseSiteTarget.GET)?.declaration as? KSClassDeclaration)?.toAstClass()
     }
 
     override fun equals(other: Any?): Boolean {
@@ -359,9 +357,7 @@ private class KSAstType(provider: KSAstProvider) : AstType(), KSAstAnnotated, KS
 
     override fun isAssignableFrom(other: AstType): Boolean {
         require(other is KSAstType)
-        // potential bug in isAssignableFrom when using typealises, manually check their underlying type
-        // https://github.com/android/kotlin/issues/106
-        return type.actualType().isAssignableFrom(other.type.actualType())
+        return type.isAssignableFrom(other.type)
     }
 
     override fun equals(other: Any?): Boolean {
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 f5ddc61..78b5204 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
@@ -6,21 +6,37 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
 import com.squareup.kotlinpoet.TypeName
 import com.squareup.kotlinpoet.TypeVariableName
 import org.jetbrains.kotlin.ksp.isAbstract
-import org.jetbrains.kotlin.ksp.symbol.*
+import org.jetbrains.kotlin.ksp.symbol.AnnotationUseSiteTarget
+import org.jetbrains.kotlin.ksp.symbol.KSAnnotated
+import org.jetbrains.kotlin.ksp.symbol.KSClassDeclaration
+import org.jetbrains.kotlin.ksp.symbol.KSDeclaration
+import org.jetbrains.kotlin.ksp.symbol.KSFunctionDeclaration
+import org.jetbrains.kotlin.ksp.symbol.KSNode
+import org.jetbrains.kotlin.ksp.symbol.KSPropertyDeclaration
+import org.jetbrains.kotlin.ksp.symbol.KSType
+import org.jetbrains.kotlin.ksp.symbol.KSTypeAlias
+import org.jetbrains.kotlin.ksp.symbol.KSTypeParameter
+import org.jetbrains.kotlin.ksp.symbol.KSTypeReference
+import org.jetbrains.kotlin.ksp.symbol.Nullability
+import org.jetbrains.kotlin.ksp.symbol.Variance
 import org.jetbrains.kotlin.ksp.visitor.KSDefaultVisitor
 
-fun KSAnnotated.typeAnnotatedWith(className: String): KSType? {
+fun KSAnnotated.typeAnnotatedWith(className: String, useSiteTarget: AnnotationUseSiteTarget? = null): KSType? {
     for (annotation in annotations) {
         val t = annotation.annotationType.resolve()
-        if (t?.declaration?.hasAnnotation(className) == true) {
+        if (t?.declaration?.hasAnnotation(className, useSiteTarget) == true) {
             return t
         }
     }
     return null
 }
 
-fun KSAnnotated.hasAnnotation(className: String): Boolean {
-    return annotations.any { it.annotationType.resolve()?.declaration?.qualifiedName?.asString() == className }
+fun KSAnnotated.hasAnnotation(className: String, useSiteTarget: AnnotationUseSiteTarget? = null): Boolean {
+    return annotations.any {
+        // only check short name until https://github.com/android/kotlin/issues/126 is resolved.
+        it.shortName.asString() == className.substringAfterLast(".") &&
+                useSiteTarget == it.useSiteTarget
+    }
 }
 
 fun KSDeclaration.asClassName(): ClassName {
@@ -32,17 +48,11 @@ fun KSDeclaration.asClassName(): ClassName {
 
 fun KSDeclaration.isAbstract() = when (this) {
     is KSFunctionDeclaration -> isAbstract
-    is KSPropertyDeclaration -> {
-        isAbstractWorkaround()
-    }
+    is KSPropertyDeclaration -> isAbstract()
     is KSClassDeclaration -> isAbstract()
     else -> false
 }
 
-// https://github.com/android/kotlin/issues/107
-fun KSPropertyDeclaration.isAbstractWorkaround() = this.modifiers.contains(Modifier.ABSTRACT) ||
-        ((this.parentDeclaration as? KSClassDeclaration)?.classKind == ClassKind.INTERFACE && getter?.origin == Origin.SYNTHETIC)
-
 fun KSTypeReference.memberOf(enclosingClass: KSClassDeclaration): KSTypeReference {
     val declaration = resolve()!!.declaration
     return if (declaration is KSTypeParameter) {
diff --git a/kotlin-inject-runtime/build.gradle b/kotlin-inject-runtime/build.gradle
index ece4b05..5d80191 100644
--- a/kotlin-inject-runtime/build.gradle
+++ b/kotlin-inject-runtime/build.gradle
@@ -1,5 +1,5 @@
 plugins {
-    id 'org.jetbrains.kotlin.jvm' version '1.3.70'
+    id 'org.jetbrains.kotlin.jvm'
 }
 
 dependencies {
diff --git a/settings.gradle b/settings.gradle
index e2b0e5d..d4a50c3 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,7 +1,6 @@
 pluginManagement {
     repositories {
         google()
-        maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
         mavenCentral()
         gradlePluginPortal()
     }


Test patch:
diff --git a/compiler-tests/build.gradle b/compiler-tests/build.gradle
index e3c639e..b01001f 100644
--- a/compiler-tests/build.gradle
+++ b/compiler-tests/build.gradle
@@ -1,5 +1,5 @@
 plugins {
-    id 'org.jetbrains.kotlin.jvm' version '1.3.70'
+    id 'org.jetbrains.kotlin.jvm'
 }
 
 dependencies {
diff --git a/compiler-tests/src/test/kotlin/me/tatarka/inject/test/ProjectCompiler.kt b/compiler-tests/src/test/kotlin/me/tatarka/inject/test/ProjectCompiler.kt
index 6668171..5115eeb 100644
--- a/compiler-tests/src/test/kotlin/me/tatarka/inject/test/ProjectCompiler.kt
+++ b/compiler-tests/src/test/kotlin/me/tatarka/inject/test/ProjectCompiler.kt
@@ -11,7 +11,7 @@ class ProjectCompiler(private val root: File, private val target: Target) {
     private lateinit var sourceDir: File
 
     fun setup(): ProjectCompiler {
-        val kotlinVersion = if (target == Target.ksp) "1.4.0-rc" else "1.3.70"
+        val kotlinVersion = "1.4.0"
 
         val settingsFile = root.resolve("settings.gradle")
 
@@ -19,7 +19,6 @@ class ProjectCompiler(private val root: File, private val target: Target) {
            pluginManagement {
                repositories {
                    google()
-                   maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
                    mavenCentral()
                    gradlePluginPortal()
                }
@@ -54,10 +53,13 @@ class ProjectCompiler(private val root: File, private val target: Target) {
 
         rootBuildFile.writeText(
             """
+            plugins {
+                id 'org.jetbrains.kotlin.jvm' version '${kotlinVersion}' apply false
+            }
+                
             allprojects {
                 repositories {
                     google()
-                    maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
                     mavenCentral()
                 }
             }
@@ -69,13 +71,11 @@ class ProjectCompiler(private val root: File, private val target: Target) {
 
         val buildFile = dir.resolve("build.gradle")
 
-        val pluginVersion = if (target == Target.ksp) "1.4.0-rc-dev-experimental-20200814" else kotlinVersion
-
         buildFile.writeText(
             """
             plugins {
-                id 'org.jetbrains.kotlin.jvm' version '${kotlinVersion}'
-                id("org.jetbrains.kotlin.$target") version '${pluginVersion}'
+                id 'org.jetbrains.kotlin.jvm'
+                id 'org.jetbrains.kotlin.$target' ${if (target == Target.ksp) " version '1.4.0-dev-experimental-20200828'" else ""}
             }
             
             dependencies {
@@ -86,6 +86,8 @@ class ProjectCompiler(private val root: File, private val target: Target) {
             """.trimIndent()
         )
 
+        println(buildFile.readText())
+
         sourceDir = dir.resolve("src/main/kotlin")
         sourceDir.mkdirs()
 
@@ -106,7 +108,7 @@ class ProjectCompiler(private val root: File, private val target: Target) {
     fun compile() {
         GradleRunner.create()
             .withProjectDir(root)
-            .withArguments("assemble")
+            .withArguments("assemble", "--stacktrace")
             .build()
     }
 }
diff --git a/integration-tests-kapt/build.gradle b/integration-tests-kapt/build.gradle
index 059a053..0e6e2a6 100644
--- a/integration-tests-kapt/build.gradle
+++ b/integration-tests-kapt/build.gradle
@@ -1,6 +1,6 @@
 plugins {
-    id 'org.jetbrains.kotlin.jvm' version '1.3.70'
-    id 'org.jetbrains.kotlin.kapt' version '1.3.70'
+    id 'org.jetbrains.kotlin.jvm'
+    id 'org.jetbrains.kotlin.kapt'
 }
 
 dependencies {
diff --git a/integration-tests-ksp/build.gradle b/integration-tests-ksp/build.gradle
index 60be1e5..704748d 100644
--- a/integration-tests-ksp/build.gradle
+++ b/integration-tests-ksp/build.gradle
@@ -1,6 +1,6 @@
 plugins {
-    id 'org.jetbrains.kotlin.jvm' version '1.4.0-rc'
-    id("org.jetbrains.kotlin.ksp") version "1.4.0-rc-dev-experimental-20200814"
+    id 'org.jetbrains.kotlin.jvm'
+    id("org.jetbrains.kotlin.ksp") version "1.4.0-dev-experimental-20200828"
 }
 
 dependencies {