blob: 7cf8b09560cc7679b112157eadb1f725482d0b1a [file] [log] [blame]
Christoffer Adamsen8c2c3b12025-02-21 01:34:15 -08001/*
2 * Copyright 2025 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// ***********************************************************************************
18// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
19// ***********************************************************************************
20
21// ***********************************************************************************
22// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
23// ***********************************************************************************
24
25package androidx.annotation.keep;
26
27import java.lang.annotation.ElementType;
28import java.lang.annotation.Retention;
29import java.lang.annotation.RetentionPolicy;
30import java.lang.annotation.Target;
31
32/**
33 * Annotation to mark a class, field or method as being accessed reflectively.
34 *
35 * <p>Note: Before using this annotation, consider if instead you can annotate the code that is
36 * doing reflection with {@link UsesReflection}. Annotating the reflecting code is generally more
37 * clear and maintainable, and it also naturally gives rise to edges that describe just the
38 * reflected aspects of the program. The {@link UsedByReflection} annotation is suitable for cases
39 * where the reflecting code is not under user control, or in migrating away from rules.
40 *
41 * <p>When a class is annotated, member patterns can be used to define which members are to be kept.
42 * When no member patterns are specified the default pattern is to match just the class.
43 *
44 * <p>When a member is annotated, the member patterns cannot be used as the annotated member itself
45 * fully defines the item to be kept (i.e., itself).
46 */
47@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
48@Retention(RetentionPolicy.CLASS)
49public @interface UsedByReflection {
50
51 /**
52 * Optional description to document the reason for this annotation.
53 *
54 * @return The descriptive message. Defaults to no description.
55 */
56 String description() default "";
57
58 /**
59 * Conditions that should be satisfied for the annotation to be in effect.
60 *
61 * @return The list of preconditions. Defaults to no conditions, thus trivially/unconditionally
62 * satisfied.
63 */
64 KeepCondition[] preconditions() default {};
65
66 /**
67 * Additional targets to be kept in addition to the annotated class/members.
68 *
69 * @return List of additional target consequences. Defaults to no additional target consequences.
70 */
71 KeepTarget[] additionalTargets() default {};
72
73 /**
74 * Specify the kind of this item pattern.
75 *
76 * <p>If unspecified the default kind depends on the annotated item.
77 *
78 * <p>When annotating a class the default kind is:
79 *
80 * <ul>
81 * <li>{@link KeepItemKind#ONLY_CLASS} if no member patterns are defined;
82 * <li>{@link KeepItemKind#CLASS_AND_METHODS} if method patterns are defined;
83 * <li>{@link KeepItemKind#CLASS_AND_FIELDS} if field patterns are defined;
84 * <li>{@link KeepItemKind#CLASS_AND_MEMBERS} otherwise.
85 * </ul>
86 *
87 * <p>When annotating a method the default kind is: {@link KeepItemKind#ONLY_METHODS}
88 *
89 * <p>When annotating a field the default kind is: {@link KeepItemKind#ONLY_FIELDS}
90 *
91 * <p>It is not possible to use {@link KeepItemKind#ONLY_CLASS} if annotating a member.
92 *
93 * @return The kind for this pattern.
94 */
95 KeepItemKind kind() default KeepItemKind.DEFAULT;
96
97 /**
98 * Define the usage constraints of the target.
99 *
100 * <p>The specified constraints must remain valid for the target.
101 *
102 * <p>The default constraints depend on the kind of the target. For all targets the default
103 * constraints include:
104 *
105 * <ul>
106 * <li>{@link KeepConstraint#LOOKUP}
107 * <li>{@link KeepConstraint#NAME}
108 * <li>{@link KeepConstraint#VISIBILITY_RELAX}
109 * </ul>
110 *
111 * <p>For classes the default constraints also include:
112 *
113 * <ul>
114 * <li>{@link KeepConstraint#CLASS_INSTANTIATE}
115 * </ul>
116 *
117 * <p>For methods the default constraints also include:
118 *
119 * <ul>
120 * <li>{@link KeepConstraint#METHOD_INVOKE}
121 * </ul>
122 *
123 * <p>For fields the default constraints also include:
124 *
125 * <ul>
126 * <li>{@link KeepConstraint#FIELD_GET}
127 * <li>{@link KeepConstraint#FIELD_SET}
128 * </ul>
129 *
130 * <p>Mutually exclusive with the property `constraintAdditions` also defining constraints.
131 *
132 * @return Usage constraints for the target.
133 */
134 KeepConstraint[] constraints() default {};
135
136 /**
137 * Add additional usage constraints of the target.
138 *
139 * <p>The specified constraints must remain valid for the target in addition to the default
140 * constraints.
141 *
142 * <p>The default constraints are documented in {@link #constraints}
143 *
144 * <p>Mutually exclusive with the property `constraints` also defining constraints.
145 *
146 * @return Additional usage constraints for the target.
147 */
148 KeepConstraint[] constraintAdditions() default {};
149
150 /**
151 * Patterns for annotations that must remain on the item.
152 *
153 * <p>The annotations matching any of the patterns must remain on the item if the annotation types
154 * remain in the program.
155 *
156 * <p>Note that if the annotation types themselves are unused/removed, then their references on
157 * the item will be removed too. If the annotation types themselves are used reflectively then
158 * they too need a keep annotation or rule to ensure they remain in the program.
159 *
160 * <p>By default no annotation patterns are defined and no annotations are required to remain.
161 *
162 * @return Annotation patterns
163 */
164 AnnotationPattern[] constrainAnnotations() default {};
165
166 /**
167 * Define the member-annotated-by pattern by fully qualified class name.
168 *
169 * <p>Mutually exclusive with the following other properties defining member-annotated-by:
170 *
171 * <ul>
172 * <li>memberAnnotatedByClassConstant
173 * <li>memberAnnotatedByClassNamePattern
174 * </ul>
175 *
176 * <p>Mutually exclusive with all field and method properties as use restricts the match to both
177 * types of members.
178 *
179 * <p>If none are specified the default is to match any member regardless of what the member is
180 * annotated by.
181 *
182 * @return The qualified class name that defines the annotation.
183 */
184 String memberAnnotatedByClassName() default "";
185
186 /**
187 * Define the member-annotated-by pattern by reference to a Class constant.
188 *
189 * <p>Mutually exclusive with the following other properties defining member-annotated-by:
190 *
191 * <ul>
192 * <li>memberAnnotatedByClassName
193 * <li>memberAnnotatedByClassNamePattern
194 * </ul>
195 *
196 * <p>Mutually exclusive with all field and method properties as use restricts the match to both
197 * types of members.
198 *
199 * <p>If none are specified the default is to match any member regardless of what the member is
200 * annotated by.
201 *
202 * @return The class-constant that defines the annotation.
203 */
204 Class<?> memberAnnotatedByClassConstant() default Object.class;
205
206 /**
207 * Define the member-annotated-by pattern by reference to a class-name pattern.
208 *
209 * <p>Mutually exclusive with the following other properties defining member-annotated-by:
210 *
211 * <ul>
212 * <li>memberAnnotatedByClassName
213 * <li>memberAnnotatedByClassConstant
214 * </ul>
215 *
216 * <p>Mutually exclusive with all field and method properties as use restricts the match to both
217 * types of members.
218 *
219 * <p>If none are specified the default is to match any member regardless of what the member is
220 * annotated by.
221 *
222 * @return The class-name pattern that defines the annotation.
223 */
224 ClassNamePattern memberAnnotatedByClassNamePattern() default
225 @ClassNamePattern(unqualifiedName = "");
226
227 /**
228 * Define the member-access pattern by matching on access flags.
229 *
230 * <p>Mutually exclusive with all field and method properties as use restricts the match to both
231 * types of members.
232 *
233 * @return The member access-flag constraints that must be met.
234 */
235 MemberAccessFlags[] memberAccess() default {};
236
237 /**
238 * Define the method-annotated-by pattern by fully qualified class name.
239 *
240 * <p>Mutually exclusive with the following other properties defining method-annotated-by:
241 *
242 * <ul>
243 * <li>methodAnnotatedByClassConstant
244 * <li>methodAnnotatedByClassNamePattern
245 * </ul>
246 *
247 * <p>Mutually exclusive with all field properties.
248 *
249 * <p>If none are specified the default is to match any method regardless of what the method is
250 * annotated by.
251 *
252 * @return The qualified class name that defines the annotation.
253 */
254 String methodAnnotatedByClassName() default "";
255
256 /**
257 * Define the method-annotated-by pattern by reference to a Class constant.
258 *
259 * <p>Mutually exclusive with the following other properties defining method-annotated-by:
260 *
261 * <ul>
262 * <li>methodAnnotatedByClassName
263 * <li>methodAnnotatedByClassNamePattern
264 * </ul>
265 *
266 * <p>Mutually exclusive with all field properties.
267 *
268 * <p>If none are specified the default is to match any method regardless of what the method is
269 * annotated by.
270 *
271 * @return The class-constant that defines the annotation.
272 */
273 Class<?> methodAnnotatedByClassConstant() default Object.class;
274
275 /**
276 * Define the method-annotated-by pattern by reference to a class-name pattern.
277 *
278 * <p>Mutually exclusive with the following other properties defining method-annotated-by:
279 *
280 * <ul>
281 * <li>methodAnnotatedByClassName
282 * <li>methodAnnotatedByClassConstant
283 * </ul>
284 *
285 * <p>Mutually exclusive with all field properties.
286 *
287 * <p>If none are specified the default is to match any method regardless of what the method is
288 * annotated by.
289 *
290 * @return The class-name pattern that defines the annotation.
291 */
292 ClassNamePattern methodAnnotatedByClassNamePattern() default
293 @ClassNamePattern(unqualifiedName = "");
294
295 /**
296 * Define the method-access pattern by matching on access flags.
297 *
298 * <p>Mutually exclusive with all field properties.
299 *
300 * <p>If none, and other properties define this item as a method, the default matches any
301 * method-access flags.
302 *
303 * @return The method access-flag constraints that must be met.
304 */
305 MethodAccessFlags[] methodAccess() default {};
306
307 /**
308 * Define the method-name pattern by an exact method name.
309 *
310 * <p>Mutually exclusive with all field properties.
311 *
312 * <p>If none, and other properties define this item as a method, the default matches any method
313 * name.
314 *
315 * <p>Mutually exclusive with the property `methodNamePattern` also defining method-name.
316 *
317 * @return The exact method name of the method.
318 */
319 String methodName() default "";
320
321 /**
322 * Define the method-name pattern by a string pattern.
323 *
324 * <p>Mutually exclusive with all field properties.
325 *
326 * <p>If none, and other properties define this item as a method, the default matches any method
327 * name.
328 *
329 * <p>Mutually exclusive with the property `methodName` also defining method-name.
330 *
331 * @return The string pattern of the method name.
332 */
333 StringPattern methodNamePattern() default @StringPattern(exact = "");
334
335 /**
336 * Define the method return-type pattern by a fully qualified type or 'void'.
337 *
338 * <p>Mutually exclusive with all field properties.
339 *
340 * <p>If none, and other properties define this item as a method, the default matches any return
341 * type.
342 *
343 * <p>Mutually exclusive with the following other properties defining return-type:
344 *
345 * <ul>
346 * <li>methodReturnTypeConstant
347 * <li>methodReturnTypePattern
348 * </ul>
349 *
350 * @return The qualified type name of the method return type.
351 */
352 String methodReturnType() default "";
353
354 /**
355 * Define the method return-type pattern by a class constant.
356 *
357 * <p>Mutually exclusive with all field properties.
358 *
359 * <p>If none, and other properties define this item as a method, the default matches any return
360 * type.
361 *
362 * <p>Mutually exclusive with the following other properties defining return-type:
363 *
364 * <ul>
365 * <li>methodReturnType
366 * <li>methodReturnTypePattern
367 * </ul>
368 *
369 * @return A class constant denoting the type of the method return type.
370 */
371 Class<?> methodReturnTypeConstant() default Object.class;
372
373 /**
374 * Define the method return-type pattern by a type pattern.
375 *
376 * <p>Mutually exclusive with all field properties.
377 *
378 * <p>If none, and other properties define this item as a method, the default matches any return
379 * type.
380 *
381 * <p>Mutually exclusive with the following other properties defining return-type:
382 *
383 * <ul>
384 * <li>methodReturnType
385 * <li>methodReturnTypeConstant
386 * </ul>
387 *
388 * @return The pattern of the method return type.
389 */
390 TypePattern methodReturnTypePattern() default @TypePattern(name = "");
391
392 /**
393 * Define the method parameters pattern by a list of fully qualified types.
394 *
395 * <p>Mutually exclusive with all field properties.
396 *
397 * <p>If none, and other properties define this item as a method, the default matches any
398 * parameters.
399 *
400 * <p>Mutually exclusive with the property `methodParameterTypePatterns` also defining parameters.
401 *
402 * @return The list of qualified type names of the method parameters.
403 */
404 String[] methodParameters() default {""};
405
406 /**
407 * Define the method parameters pattern by a list of patterns on types.
408 *
409 * <p>Mutually exclusive with all field properties.
410 *
411 * <p>If none, and other properties define this item as a method, the default matches any
412 * parameters.
413 *
414 * <p>Mutually exclusive with the property `methodParameters` also defining parameters.
415 *
416 * @return The list of type patterns for the method parameters.
417 */
418 TypePattern[] methodParameterTypePatterns() default {@TypePattern(name = "")};
419
420 /**
421 * Define the field-annotated-by pattern by fully qualified class name.
422 *
423 * <p>Mutually exclusive with the following other properties defining field-annotated-by:
424 *
425 * <ul>
426 * <li>fieldAnnotatedByClassConstant
427 * <li>fieldAnnotatedByClassNamePattern
428 * </ul>
429 *
430 * <p>Mutually exclusive with all method properties.
431 *
432 * <p>If none are specified the default is to match any field regardless of what the field is
433 * annotated by.
434 *
435 * @return The qualified class name that defines the annotation.
436 */
437 String fieldAnnotatedByClassName() default "";
438
439 /**
440 * Define the field-annotated-by pattern by reference to a Class constant.
441 *
442 * <p>Mutually exclusive with the following other properties defining field-annotated-by:
443 *
444 * <ul>
445 * <li>fieldAnnotatedByClassName
446 * <li>fieldAnnotatedByClassNamePattern
447 * </ul>
448 *
449 * <p>Mutually exclusive with all method properties.
450 *
451 * <p>If none are specified the default is to match any field regardless of what the field is
452 * annotated by.
453 *
454 * @return The class-constant that defines the annotation.
455 */
456 Class<?> fieldAnnotatedByClassConstant() default Object.class;
457
458 /**
459 * Define the field-annotated-by pattern by reference to a class-name pattern.
460 *
461 * <p>Mutually exclusive with the following other properties defining field-annotated-by:
462 *
463 * <ul>
464 * <li>fieldAnnotatedByClassName
465 * <li>fieldAnnotatedByClassConstant
466 * </ul>
467 *
468 * <p>Mutually exclusive with all method properties.
469 *
470 * <p>If none are specified the default is to match any field regardless of what the field is
471 * annotated by.
472 *
473 * @return The class-name pattern that defines the annotation.
474 */
475 ClassNamePattern fieldAnnotatedByClassNamePattern() default
476 @ClassNamePattern(unqualifiedName = "");
477
478 /**
479 * Define the field-access pattern by matching on access flags.
480 *
481 * <p>Mutually exclusive with all method properties.
482 *
483 * <p>If none, and other properties define this item as a field, the default matches any
484 * field-access flags.
485 *
486 * @return The field access-flag constraints that must be met.
487 */
488 FieldAccessFlags[] fieldAccess() default {};
489
490 /**
491 * Define the field-name pattern by an exact field name.
492 *
493 * <p>Mutually exclusive with all method properties.
494 *
495 * <p>If none, and other properties define this item as a field, the default matches any field
496 * name.
497 *
498 * <p>Mutually exclusive with the property `fieldNamePattern` also defining field-name.
499 *
500 * @return The exact field name of the field.
501 */
502 String fieldName() default "";
503
504 /**
505 * Define the field-name pattern by a string pattern.
506 *
507 * <p>Mutually exclusive with all method properties.
508 *
509 * <p>If none, and other properties define this item as a field, the default matches any field
510 * name.
511 *
512 * <p>Mutually exclusive with the property `fieldName` also defining field-name.
513 *
514 * @return The string pattern of the field name.
515 */
516 StringPattern fieldNamePattern() default @StringPattern(exact = "");
517
518 /**
519 * Define the field-type pattern by a fully qualified type.
520 *
521 * <p>Mutually exclusive with all method properties.
522 *
523 * <p>If none, and other properties define this item as a field, the default matches any type.
524 *
525 * <p>Mutually exclusive with the following other properties defining field-type:
526 *
527 * <ul>
528 * <li>fieldTypeConstant
529 * <li>fieldTypePattern
530 * </ul>
531 *
532 * @return The qualified type name for the field type.
533 */
534 String fieldType() default "";
535
536 /**
537 * Define the field-type pattern by a class constant.
538 *
539 * <p>Mutually exclusive with all method properties.
540 *
541 * <p>If none, and other properties define this item as a field, the default matches any type.
542 *
543 * <p>Mutually exclusive with the following other properties defining field-type:
544 *
545 * <ul>
546 * <li>fieldType
547 * <li>fieldTypePattern
548 * </ul>
549 *
550 * @return The class constant for the field type.
551 */
552 Class<?> fieldTypeConstant() default Object.class;
553
554 /**
555 * Define the field-type pattern by a pattern on types.
556 *
557 * <p>Mutually exclusive with all method properties.
558 *
559 * <p>If none, and other properties define this item as a field, the default matches any type.
560 *
561 * <p>Mutually exclusive with the following other properties defining field-type:
562 *
563 * <ul>
564 * <li>fieldType
565 * <li>fieldTypeConstant
566 * </ul>
567 *
568 * @return The type pattern for the field type.
569 */
570 TypePattern fieldTypePattern() default @TypePattern(name = "");
571}