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