xref: /aosp_15_r20/external/ksp/test-utils/testData/api/annotatedUtil.kt (revision af87fb4bb8e3042070d2a054e912924f599b22b7)
1 /*
2  * Copyright 2021 Google LLC
3  * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 // TEST PROCESSOR: AnnotatedUtilProcessor
19 // EXPECTED:
20 // Test: OnlyTestAnnotation
21 // Test: ParametersTestAnnotationWithValuesTest
22 // IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation
23 // ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=true, byteValue=5, shortValue=202, charValue=k, doubleValue=5.12, floatValue=123.3, intValue=2, longValue=4, stringValue=someValue, kClassValue=class java.lang.Throwable, enumValue=VALUE1]
24 // Test: ParametersTestAnnotationWithDefaultsTest
25 // IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation
26 // ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=false, byteValue=2, shortValue=3, charValue=b, doubleValue=4.0, floatValue=5.0, intValue=6, longValue=7, stringValue=emptystring, kClassValue=interface com.google.devtools.ksp.processor.ParametersTestAnnotation, enumValue=NONE]
27 // ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=false, byteValue=2, shortValue=3, charValue=b, doubleValue=4.0, floatValue=5.0, intValue=6, longValue=7, stringValue=emptystring, kClassValue=interface com.google.devtools.ksp.processor.ParametersTestAnnotation, enumValue=NONE]
28 // Test: ParametersTestWithNegativeDefaultsAnnotationTest
29 // IsPresent: class com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation
30 // ByType: com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation[byteValue=-2, shortValue=-3, doubleValue=-4.0, floatValue=-5.0, intValue=-6, longValue=-7]
31 // ByType: com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation[byteValue=-2, shortValue=-3, doubleValue=-4.0, floatValue=-5.0, intValue=-6, longValue=-7]
32 // Test: ParameterArraysTestAnnotationWithDefaultTest
33 // IsPresent: class com.google.devtools.ksp.processor.ParameterArraysTestAnnotation
34 // ByType: ParameterArraysTestAnnotation[booleanArrayValue=[true, false],byteArrayValue=[-2, 4],shortArrayValue=[-1, 2, 3],charArrayValue=[a, b, c],doubleArrayValue=[1.1, 2.2, 3.3],floatArrayValue=[1.0, 2.0, 3.3],intArrayValue=[1, 2, 4, 8, 16],longArrayValue=[1, 2, 4, 8, 16, 32],stringArrayValue=[first, second, third],kClassArrayValue=[class kotlin.Throwable, class com.google.devtools.ksp.processor.ParametersTestAnnotation],enumArrayValue=[VALUE1, VALUE2, VALUE1, VALUE2]]
35 // Test: AnnotationWithinAnAnnotationTest
36 // IsPresent: class com.google.devtools.ksp.processor.OuterAnnotation
37 // ByType: com.google.devtools.ksp.processor.OuterAnnotation[innerAnnotation=com.google.devtools.ksp.processor.InnerAnnotation[value=hello from the other side]]
38 // END
39 // MODULE: annotations
40 // FILE: com/google/devtools/ksp/processor/a.kt
41 package com.google.devtools.ksp.processor
42 
43 import kotlin.reflect.KClass
44 import java.lang.Throwable
45 
46 annotation class Test
47 
48 @Suppress("LongParameterList")
49 annotation class ParametersTestAnnotation(
50     val booleanValue: Boolean = false,
51     val byteValue: Byte = 2,
52     val shortValue: Short = 3,
53     val charValue: Char = 'b',
54     val doubleValue: Double = 4.0,
55     val floatValue: Float = 5.0f,
56     val intValue: Int = 6,
57     val longValue: Long = 7L,
58     val stringValue: String = "emptystring",
59     val kClassValue: KClass<*> = ParametersTestAnnotation::class,
60     val enumValue: TestEnum = TestEnum.NONE,
61 )
62 
63 @Suppress("LongParameterList")
64 annotation class ParameterArraysTestAnnotation(
65     val booleanArrayValue: BooleanArray = booleanArrayOf(),
66     val byteArrayValue: ByteArray = byteArrayOf(),
67     val shortArrayValue: ShortArray = shortArrayOf(),
68     val charArrayValue: CharArray = charArrayOf(),
69     val doubleArrayValue: DoubleArray = doubleArrayOf(),
70     val floatArrayValue: FloatArray = floatArrayOf(),
71     val intArrayValue: IntArray = intArrayOf(),
72     val longArrayValue: LongArray = longArrayOf(),
73     val stringArrayValue: Array<String> = emptyArray(),
74     val kClassArrayValue: Array<KClass<*>> = emptyArray(),
75     val enumArrayValue: Array<TestEnum> = emptyArray(),
76 )
77 
78 annotation class ParametersTestWithNegativeDefaultsAnnotation(
79     val byteValue: Byte = -2,
80     val shortValue: Short = -3,
81     val doubleValue: Double = -4.0,
82     val floatValue: Float = -5.0f,
83     val intValue: Int = -6,
84     val longValue: Long = -7L,
85 )
86 
87 enum class TestEnum {
88     NONE, VALUE1, VALUE2
89 }
90 
91 annotation class InnerAnnotation(val value: String = "default")
92 
93 annotation class OuterAnnotation(
94     val innerAnnotation : InnerAnnotation = InnerAnnotation()
95 )
96 
97 /////////////////////////////////////////////////////////
98 // Tests
99 /////////////////////////////////////////////////////////
100 
101 @Test
102 @Test
103 class OnlyTestAnnotation
104 
105 @ParametersTestAnnotation(
106     booleanValue = true,
107     byteValue = 5,
108     shortValue = 202,
109     charValue = 'k',
110     doubleValue = 5.12,
111     floatValue = 123.3f,
112     intValue = 2,
113     longValue = 4L,
114     stringValue = "someValue",
115     java.lang.Throwable::class,
116     TestEnum.VALUE1,
117 )
118 @Test
119 class ParametersTestAnnotationWithValuesTest
120 
121 @ParametersTestAnnotation
122 @ParametersTestAnnotation
123 @Test
124 class ParametersTestAnnotationWithDefaultsTest
125 
126 @ParametersTestWithNegativeDefaultsAnnotation
127 @ParametersTestWithNegativeDefaultsAnnotation
128 @Test
129 class ParametersTestWithNegativeDefaultsAnnotationTest
130 
131 @ParameterArraysTestAnnotation(
132     booleanArrayValue = booleanArrayOf(true, false),
133     byteArrayValue = byteArrayOf(-2, 4),
134     shortArrayValue = shortArrayOf(-1, 2, 3),
135     charArrayValue = charArrayOf('a', 'b', 'c'),
136     doubleArrayValue = doubleArrayOf(1.1, 2.2, 3.3),
137     floatArrayValue = floatArrayOf(1.0f, 2.0f, 3.3f),
138     intArrayValue = intArrayOf(1, 2, 4, 8, 16),
139     longArrayValue = longArrayOf(1L, 2L, 4L, 8L, 16, 32L),
140     stringArrayValue = arrayOf("first", "second", "third"),
141     kClassArrayValue = arrayOf(Throwable::class, ParametersTestAnnotation::class),
142     enumArrayValue = arrayOf(TestEnum.VALUE1, TestEnum.VALUE2, TestEnum.VALUE1, TestEnum.VALUE2),
143 )
144 @Test
145 class ParameterArraysTestAnnotationWithDefaultTest
146 
147 @OuterAnnotation(innerAnnotation = InnerAnnotation("hello from the other side"))
148 @Test
149 class AnnotationWithinAnAnnotationTest
150