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: ParametersTestAnnotationWithIntegerLiteralValuesTest 25*af87fb4bSXin Li // IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation 26*af87fb4bSXin Li // ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=true, byteValue=5, shortValue=202, charValue=k, doubleValue=5.0, floatValue=123.0, intValue=2, longValue=4, stringValue=someValue, kClassValue=class java.lang.Throwable, enumValue=VALUE1] 27*af87fb4bSXin Li // Test: ParametersTestAnnotationWithDefaultsTest 28*af87fb4bSXin Li // IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation 29*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] 30*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] 31*af87fb4bSXin Li // Test: ParametersTestWithNegativeDefaultsAnnotationTest 32*af87fb4bSXin Li // IsPresent: class com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation 33*af87fb4bSXin Li // ByType: com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation[byteValue=-2, shortValue=-3, doubleValue=-4.0, floatValue=-5.0, intValue=-6, longValue=-7] 34*af87fb4bSXin Li // ByType: com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation[byteValue=-2, shortValue=-3, doubleValue=-4.0, floatValue=-5.0, intValue=-6, longValue=-7] 35*af87fb4bSXin Li // Test: ParameterArraysTestAnnotationWithDefaultTest 36*af87fb4bSXin Li // IsPresent: class com.google.devtools.ksp.processor.ParameterArraysTestAnnotation 37*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]] 38*af87fb4bSXin Li // Test: AnnotationWithinAnAnnotationTest 39*af87fb4bSXin Li // IsPresent: class com.google.devtools.ksp.processor.OuterAnnotation 40*af87fb4bSXin Li // ByType: com.google.devtools.ksp.processor.OuterAnnotation[innerAnnotation=com.google.devtools.ksp.processor.InnerAnnotation[value=hello from the other side]] 41*af87fb4bSXin Li // END 42*af87fb4bSXin Li // FILE: com/google/devtools/ksp/processor/A.java 43*af87fb4bSXin Li package com.google.devtools.ksp.processor; 44*af87fb4bSXin Li 45*af87fb4bSXin Li import kotlin.reflect.KClass 46*af87fb4bSXin Li 47*af87fb4bSXin Li public class A {} 48*af87fb4bSXin Li 49*af87fb4bSXin Li 50*af87fb4bSXin Li public @interface Test {} 51*af87fb4bSXin Li 52*af87fb4bSXin Li public @interface ParametersTestAnnotation { 53*af87fb4bSXin Li Boolean booleanValue() default false; 54*af87fb4bSXin Li Byte byteValue() default 2; 55*af87fb4bSXin Li Short shortValue() default 3; 56*af87fb4bSXin Li Char charValue() default 'b'; 57*af87fb4bSXin Li Double doubleValue() default 4.0; 58*af87fb4bSXin Li Float floatValue() default 5.0f; 59*af87fb4bSXin Li Int intValue() default 6; 60*af87fb4bSXin Li Long longValue() default 7L; 61*af87fb4bSXin Li String stringValue() default "emptystring"; 62*af87fb4bSXin Li Class<?> kClassValue() default ParametersTestAnnotation.class; 63*af87fb4bSXin Li TestEnum enumValue() default TestEnum.NONE; 64*af87fb4bSXin Li } 65*af87fb4bSXin Li 66*af87fb4bSXin Li public @interface ParametersTestWithNegativeDefaultsAnnotation { 67*af87fb4bSXin Li Byte byteValue() default -2; 68*af87fb4bSXin Li Short shortValue() default -3; 69*af87fb4bSXin Li Double doubleValue() default -4.0; 70*af87fb4bSXin Li Float floatValue() default -5.0f; 71*af87fb4bSXin Li Int intValue() default -6; 72*af87fb4bSXin Li Long longValue() default -7L; 73*af87fb4bSXin Li } 74*af87fb4bSXin Li 75*af87fb4bSXin Li public @interface ParameterArraysTestAnnotation { 76*af87fb4bSXin Li boolean[] booleanArrayValue(); 77*af87fb4bSXin Li byte[] byteArrayValue() default { }; 78*af87fb4bSXin Li short[] shortArrayValue() default { }; 79*af87fb4bSXin Li char[] charArrayValue() default { }; 80*af87fb4bSXin Li double[] doubleArrayValue() default { }; 81*af87fb4bSXin Li float[] floatArrayValue() default { }; 82*af87fb4bSXin Li int[] intArrayValue() default { }; 83*af87fb4bSXin Li long[] longArrayValue() default { }; 84*af87fb4bSXin Li string[] stringArrayValue() default { }; 85*af87fb4bSXin Li Class[] kClassArrayValue() default { }; 86*af87fb4bSXin Li TestEnum[] enumArrayValue() default { }; 87*af87fb4bSXin Li } 88*af87fb4bSXin Li 89*af87fb4bSXin Li public enum TestEnum { 90*af87fb4bSXin Li NONE, VALUE1, VALUE2; 91*af87fb4bSXin Li } 92*af87fb4bSXin Li 93*af87fb4bSXin Li public @interface InnerAnnotation { 94*af87fb4bSXin Li String value() default "defaultValue"; 95*af87fb4bSXin Li } 96*af87fb4bSXin Li 97*af87fb4bSXin Li public @interface OuterAnnotation { 98*af87fb4bSXin Li InnerAnnotation innerAnnotation() default InnerAnnotation(); 99*af87fb4bSXin Li } 100*af87fb4bSXin Li 101*af87fb4bSXin Li ///////////////////////////////////////////////////////// 102*af87fb4bSXin Li // Tests 103*af87fb4bSXin Li ///////////////////////////////////////////////////////// 104*af87fb4bSXin Li 105*af87fb4bSXin Li @Test 106*af87fb4bSXin Li @Test 107*af87fb4bSXin Li public class OnlyTestAnnotation {} 108*af87fb4bSXin Li 109*af87fb4bSXin Li @ParametersTestAnnotation( 110*af87fb4bSXin Li booleanValue = true, 111*af87fb4bSXin Li byteValue = 5, 112*af87fb4bSXin Li shortValue = 202, 113*af87fb4bSXin Li charValue = 'k', 114*af87fb4bSXin Li doubleValue = 5.12, 115*af87fb4bSXin Li floatValue = 123.3f, 116*af87fb4bSXin Li intValue = 2, 117*af87fb4bSXin Li longValue = 4L, 118*af87fb4bSXin Li stringValue = "someValue", 119*af87fb4bSXin Li kClassValue = java.lang.Throwable.class, 120*af87fb4bSXin Li enumValue = TestEnum.VALUE1 121*af87fb4bSXin Li ) 122*af87fb4bSXin Li @Test 123*af87fb4bSXin Li public class ParametersTestAnnotationWithValuesTest {} 124*af87fb4bSXin Li 125*af87fb4bSXin Li @ParametersTestAnnotation( 126*af87fb4bSXin Li booleanValue = true, 127*af87fb4bSXin Li byteValue = 5, 128*af87fb4bSXin Li shortValue = 202, 129*af87fb4bSXin Li charValue = 'k', 130*af87fb4bSXin Li doubleValue = 5, 131*af87fb4bSXin Li floatValue = 123, 132*af87fb4bSXin Li intValue = 2, 133*af87fb4bSXin Li longValue = 4, 134*af87fb4bSXin Li stringValue = "someValue", 135*af87fb4bSXin Li kClassValue = java.lang.Throwable.class, 136*af87fb4bSXin Li enumValue = TestEnum.VALUE1 137*af87fb4bSXin Li ) 138*af87fb4bSXin Li @Test 139*af87fb4bSXin Li public class ParametersTestAnnotationWithIntegerLiteralValuesTest {} 140*af87fb4bSXin Li 141*af87fb4bSXin Li @ParametersTestAnnotation 142*af87fb4bSXin Li @ParametersTestAnnotation 143*af87fb4bSXin Li @Test 144*af87fb4bSXin Li public class ParametersTestAnnotationWithDefaultsTest {} 145*af87fb4bSXin Li 146*af87fb4bSXin Li @ParametersTestWithNegativeDefaultsAnnotation 147*af87fb4bSXin Li @ParametersTestWithNegativeDefaultsAnnotation 148*af87fb4bSXin Li @Test 149*af87fb4bSXin Li public class ParametersTestWithNegativeDefaultsAnnotationTest {} 150*af87fb4bSXin Li 151*af87fb4bSXin Li @ParameterArraysTestAnnotation( 152*af87fb4bSXin Li booleanArrayValue = {true, false}, 153*af87fb4bSXin Li byteArrayValue = {-2, 4}, 154*af87fb4bSXin Li shortArrayValue = {-1, 2, 3}, 155*af87fb4bSXin Li charArrayValue = {'a', 'b', 'c'}, 156*af87fb4bSXin Li doubleArrayValue = {1.1, 2.2, 3.3}, 157*af87fb4bSXin Li floatArrayValue = {1.0f, 2.0f, 3.3f}, 158*af87fb4bSXin Li intArrayValue = {1, 2, 4, 8, 16}, 159*af87fb4bSXin Li longArrayValue = {1L, 2L, 4L, 8L, 16, 32L}, 160*af87fb4bSXin Li stringArrayValue = {"first", "second", "third"}, 161*af87fb4bSXin Li kClassArrayValue = {java.lang.Throwable.class, ParametersTestAnnotation.class}, 162*af87fb4bSXin Li enumArrayValue = {TestEnum.VALUE1, TestEnum.VALUE2, TestEnum.VALUE1, TestEnum.VALUE2} 163*af87fb4bSXin Li ) 164*af87fb4bSXin Li @Test 165*af87fb4bSXin Li public class ParameterArraysTestAnnotationWithDefaultTest {} 166*af87fb4bSXin Li 167*af87fb4bSXin Li @OuterAnnotation(innerAnnotation = @InnerAnnotation(value = "hello from the other side")) 168*af87fb4bSXin Li @Test 169*af87fb4bSXin Li public class AnnotationWithinAnAnnotationTest {} 170*af87fb4bSXin Li 171*af87fb4bSXin Li // FILE: Annotations.kt 172