diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt index 196e1fe3e7..5ff23c2788 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt @@ -323,6 +323,8 @@ internal fun KtAnnotated.annotations( parent: KSNode? = null, candidates: List = kaAnnotated.annotations ): Sequence { + if (candidates.isEmpty()) + return emptySequence() return annotationEntries.filter { !it.isUseSiteTargetAnnotation() }.asSequence().map { annotationEntry -> KSAnnotationImpl.getCached(annotationEntry, parent) { candidates.single { it.psi == annotationEntry } 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 962d75df61..cff122e393 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 @@ -97,13 +97,13 @@ class KSPAATest : AbstractKSPAATest() { @TestMetadata("annotationValue_java.kt") @Test fun testAnnotationValue_java() { - runTest("../kotlin-analysis-api/testData/annotationValue/java.kt") + runTest("../kotlin-analysis-api/testData/annotationValue/annotationValue_java.kt") } @TestMetadata("annotationValue_kt.kt") @Test fun testAnnotationValue_kt() { - runTest("../kotlin-analysis-api/testData/annotationValue/kotlin.kt") + runTest("../kotlin-analysis-api/testData/annotationValue/annotationValue_kt.kt") } @TestMetadata("annotationWithArrayValue.kt") diff --git a/kotlin-analysis-api/testData/annotationValue/java.kt b/kotlin-analysis-api/testData/annotationValue/annotationValue_java.kt similarity index 100% rename from kotlin-analysis-api/testData/annotationValue/java.kt rename to kotlin-analysis-api/testData/annotationValue/annotationValue_java.kt diff --git a/kotlin-analysis-api/testData/annotationValue/kotlin.kt b/kotlin-analysis-api/testData/annotationValue/annotationValue_kt.kt similarity index 99% rename from kotlin-analysis-api/testData/annotationValue/kotlin.kt rename to kotlin-analysis-api/testData/annotationValue/annotationValue_kt.kt index 277f593625..b06d9b8ee0 100644 --- a/kotlin-analysis-api/testData/annotationValue/kotlin.kt +++ b/kotlin-analysis-api/testData/annotationValue/annotationValue_kt.kt @@ -106,6 +106,8 @@ fun Fun() { class Local } +data class DataClass + // FILE: JavaEnum.java enum JavaEnum { ONE, TWO, THREE } diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AnnotationArgumentProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AnnotationArgumentProcessor.kt index 54366407cb..fdb9ad78e6 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AnnotationArgumentProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AnnotationArgumentProcessor.kt @@ -19,10 +19,7 @@ package com.google.devtools.ksp.processor import com.google.devtools.ksp.getClassDeclarationByName import com.google.devtools.ksp.processing.Resolver -import com.google.devtools.ksp.symbol.KSAnnotated -import com.google.devtools.ksp.symbol.KSType -import com.google.devtools.ksp.symbol.KSValueArgument -import com.google.devtools.ksp.symbol.KSVisitorVoid +import com.google.devtools.ksp.symbol.* class AnnotationArgumentProcessor : AbstractTestProcessor() { val results = mutableListOf() @@ -37,6 +34,14 @@ class AnnotationArgumentProcessor : AbstractTestProcessor() { } } + resolver.getClassDeclarationByName("DataClass")?.let { cls -> + cls.declarations.filterIsInstance().single { + it.simpleName.asString() == "copy" + }.annotations.forEach { + it.arguments + } + } + resolver.getSymbolsWithAnnotation("Bar", true).forEach { it.annotations.forEach { it.arguments.forEach { it.accept(visitor, Unit) } } }