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