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