Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Comment thread
jaschdoc marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2026 Google LLC
* Copyright 2010-2026 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.
*/

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

class AnnotationArrayValueTypeProcessor : AbstractTestProcessor() {
private val results = mutableListOf<String>()

override fun process(resolver: Resolver): List<KSAnnotated> {
logAnnotationArrayValues(resolver, "JavaAnnotated")
logAnnotationArrayValues(resolver, "KotlinAnnotated")
return emptyList()
}

override fun toResult(): List<String> {
return results
}

private fun logAnnotationArrayValues(resolver: Resolver, className: String) {
val annotated = resolver.getClassDeclarationByName(className)!!
listOf("JavaAnnotation", "KotlinAnnotation").forEach { annotationName ->
val annotation = annotated.annotations.single { it.shortName.asString() == annotationName }
val argument = annotation.arguments.single()
val value = argument.value
val argumentName = argument.name?.asString()
results.add("$className $annotationName $argumentName is Array<*>: ${value is Array<*>}")
results.add("$className $annotationName $argumentName size: ${value.sizeOrNull()}")
}
}

private fun Any?.sizeOrNull(): Int? {
return when (this) {
is Array<*> -> size
is Collection<*> -> size
else -> null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class AAConfiguredUnitTestSuite : KSPUnitTestSuite(experimentalPsiResolution = f
runTest("$AA_PATH/getSymbolsWithAnnotation/aliasedAnnotation.kt")
}

@TestMetadata("annotationArrayValueType.kt")
@Test
override fun testAnnotationArrayValueType() {
runFailingTest("$AA_PATH/annotationArrayValueType.kt")
}

@TestMetadata("allUseSiteTargetAppliedToAnnotationList.kt")
@Test
override fun testAllUseSiteTargetAppliedToAnnotationList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ abstract class KSPUnitTestSuite(
runTest("$AA_PATH/annotationWithArrayValue.kt")
}

@Bug("https://github.com/google/ksp/issues/3008", BugState.OPEN)
abstract fun testAnnotationArrayValueType()

@TestMetadata("annotationWithDefault.kt")
@Test
fun testAnnotationWithDefault() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class PsiConfiguredUnitTestSuite : KSPUnitTestSuite(experimentalPsiResolution =
runFailingTest("$AA_PATH/getSymbolsWithAnnotation/aliasedAnnotation.kt")
}

@TestMetadata("annotationArrayValueType.kt")
@Test
override fun testAnnotationArrayValueType() {
runFailingTest("$AA_PATH/annotationArrayValueType.kt")
}

@TestMetadata("allUseSiteTargetAppliedToAnnotationList.kt")
@Test
override fun testAllUseSiteTargetAppliedToAnnotationList() {
Expand Down
50 changes: 50 additions & 0 deletions kotlin-analysis-api/testData/annotationArrayValueType.kt
Comment thread
jaschdoc marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2026 Google LLC
* Copyright 2010-2026 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.
*/
// TEST PROCESSOR: AnnotationArrayValueTypeProcessor
// EXPECTED:
// JavaAnnotated JavaAnnotation args is Array<*>: true
// JavaAnnotated JavaAnnotation args size: 2
// JavaAnnotated KotlinAnnotation args is Array<*>: true
// JavaAnnotated KotlinAnnotation args size: 2
// KotlinAnnotated JavaAnnotation args is Array<*>: true
// KotlinAnnotated JavaAnnotation args size: 2
// KotlinAnnotated KotlinAnnotation args is Array<*>: true
// KotlinAnnotated KotlinAnnotation args size: 2
// END
// FILE: JavaAnnotation.java
public @interface JavaAnnotation {
NestedAnnotation[] args();
}

// FILE: NestedAnnotation.java
public @interface NestedAnnotation {
String value();
}

// FILE: JavaAnnotated.java
@JavaAnnotation(args = {@NestedAnnotation(value = "one"), @NestedAnnotation(value = "two")})
@KotlinAnnotation(args = {@KotlinNestedAnnotation(value = "one"), @KotlinNestedAnnotation(value = "two")})
class JavaAnnotated {}

// FILE: KotlinAnnotated.kt
annotation class KotlinAnnotation(val args: Array<KotlinNestedAnnotation>)

annotation class KotlinNestedAnnotation(val value: String)

@JavaAnnotation(args = [NestedAnnotation(value = "one"), NestedAnnotation(value = "two")])
@KotlinAnnotation(args = [KotlinNestedAnnotation(value = "one"), KotlinNestedAnnotation(value = "two")])
class KotlinAnnotated
Loading