diff --git a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt index 1416ca699a..8ec4704fb9 100644 --- a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt +++ b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt @@ -145,6 +145,18 @@ class KSPAATest : AbstractKSPAATest() { runTest("../test-utils/testData/api/builtInTypes.kt") } + @TestMetadata("A.kt") + @Test + fun testA() { + runTest("../test-utils/testData/api/A.kt") + } + + @TestMetadata("B.kt") + @Test + fun testB() { + runTest("../test-utils/testData/api/B.kt") + } + @Disabled @TestMetadata("checkOverride.kt") @Test diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AProcessor.kt new file mode 100644 index 0000000000..f4d3a4a6bd --- /dev/null +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AProcessor.kt @@ -0,0 +1,22 @@ +package com.google.devtools.ksp.processor + +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.getClassDeclarationByName +import com.google.devtools.ksp.getDeclaredProperties +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated + +open class AProcessor : AbstractTestProcessor() { + val results = mutableListOf() + override fun toResult(): List { + return results + } + + @OptIn(KspExperimental::class) + override fun process(resolver: Resolver): List { + resolver.getClassDeclarationByName("BaseClass")!!.let { cls -> + println(cls.getDeclaredProperties().map { "${it.simpleName.asString()}(${it.hasBackingField})" }.toList()) + } + return emptyList() + } +} diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/BProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/BProcessor.kt new file mode 100644 index 0000000000..c95a81fa5b --- /dev/null +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/BProcessor.kt @@ -0,0 +1,23 @@ +package com.google.devtools.ksp.processor + +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.getClassDeclarationByName +import com.google.devtools.ksp.getDeclaredProperties +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated + +open class BProcessor : AbstractTestProcessor() { + val results = mutableListOf() + override fun toResult(): List { + return results + } + + @OptIn(KspExperimental::class) + override fun process(resolver: Resolver): List { + resolver.getClassDeclarationByName("BaseClass")!!.let { cls -> + println(cls.getDeclaredProperties().map { "${it.simpleName.asString()}(${it.hasBackingField})" }.toList()) + // `hasBackingField` is true when running the test individually but is false when running the whole KSPAATest. + } + return emptyList() + } +} diff --git a/test-utils/testData/api/A.kt b/test-utils/testData/api/A.kt new file mode 100644 index 0000000000..4f91fbef75 --- /dev/null +++ b/test-utils/testData/api/A.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * 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. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AProcessor +// EXPECTED: +// END +// MODULE: lib +// FILE: Test.kt +open class BaseClass(val genericProp : T) { + fun baseMethod(input: T) {} +} +class SubClass(x : Int) : BaseClass(x) { + val subClassProp : String = "abc" +} +// MODULE: main(lib) +// FILE: Main.kt +class Main diff --git a/test-utils/testData/api/B.kt b/test-utils/testData/api/B.kt new file mode 100644 index 0000000000..2f898b3fc1 --- /dev/null +++ b/test-utils/testData/api/B.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * 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. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: BProcessor +// EXPECTED: +// END +// MODULE: lib +// FILE: Test.kt +open class BaseClass( + open val value : List +) +class SubClass( + override val value : MutableList +) : BaseClass(value) +// MODULE: main(lib) +// FILE: Main.kt +class Main