Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,54 @@
/*
* 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> {
logAnnotationArrayValue(resolver, "JavaAnnotated")
logAnnotationArrayValue(resolver, "KotlinAnnotated")
return emptyList()
}

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

private fun logAnnotationArrayValue(resolver: Resolver, className: String) {
val annotated = resolver.getClassDeclarationByName(className)!!
val annotation = annotated.annotations.single { it.shortName.asString() == "JavaAnnotation" }
val argument = annotation.arguments.single()
val value = argument.value
val argumentName = argument.name?.asString()
results.add("$className $argumentName is Array<*>: ${value is Array<*>}")
results.add("$className $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
40 changes: 40 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,40 @@
/*
* 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 args is Array<*>: true
// JavaAnnotated args size: 2
// KotlinAnnotated args is Array<*>: true
// KotlinAnnotated args size: 2
// END
// FILE: JavaAnnotation.java
public @interface JavaAnnotation {
NestedAnnotation[] args();
}
Comment thread
jaschdoc marked this conversation as resolved.

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

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

// FILE: KotlinAnnotated.kt
@JavaAnnotation(args = [NestedAnnotation(value = "one"), NestedAnnotation(value = "two")])
class KotlinAnnotated