Reapply "Add support for tests using androidx keep annotations"

This reverts commit 809cceb4534e1a1f1ca446a32bfa9fef13656cd2.

Reapply "Change the keep annotations in the androidx namespace to Kotlin source"

This reverts commit 8c2c3b1010ec081f0af519b8f8903d90229acde0.

With additional fix for SanityCheck.

Bug: b/392865072
Change-Id: I0d5dc671c4a7ea08960d92c28b5edf30e0e89627
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepCondition.kt b/src/keepanno/java/androidx/annotation/keep/KeepCondition.kt
new file mode 100644
index 0000000..a4fcddc
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepCondition.kt
@@ -0,0 +1,801 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * 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.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep
+
+import kotlin.annotation.Retention
+import kotlin.annotation.Target
+import kotlin.reflect.KClass
+
+/**
+ * A condition for a keep edge.
+ *
+ * <p>
+ * The condition denotes an item used as a precondition of a rule. An item can be:
+ * <ul>
+ * <li>a pattern on classes;
+ * <li>a pattern on methods; or
+ * <li>a pattern on fields.
+ * </ul>
+ */
+@Retention(AnnotationRetention.BINARY)
+@Target(AnnotationTarget.ANNOTATION_CLASS)
+annotation class KeepCondition(
+
+  /**
+   * Define the class pattern by reference to a binding.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining class:
+   * <ul>
+   * <li>className
+   * <li>classConstant
+   * <li>classNamePattern
+   * <li>instanceOfClassName
+   * <li>instanceOfClassNameExclusive
+   * <li>instanceOfClassConstant
+   * <li>instanceOfClassConstantExclusive
+   * <li>instanceOfPattern
+   * <li>classAnnotatedByClassName
+   * <li>classAnnotatedByClassConstant
+   * <li>classAnnotatedByClassNamePattern
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class.
+   *
+   * @return The name of the binding that defines the class.
+   */
+  val classFromBinding: String = "",
+
+  /**
+   * Define the class-name pattern by fully qualified class name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining class-name:
+   * <ul>
+   * <li>classConstant
+   * <li>classNamePattern
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class name.
+   *
+   * @return The qualified class name that defines the class.
+   */
+  val className: String = "",
+
+  /**
+   * Define the class-name pattern by reference to a Class constant.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining class-name:
+   * <ul>
+   * <li>className
+   * <li>classNamePattern
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class name.
+   *
+   * @return The class-constant that defines the class.
+   */
+  val classConstant: KClass<*> = Object::class,
+
+  /**
+   * Define the class-name pattern by reference to a class-name pattern.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining class-name:
+   * <ul>
+   * <li>className
+   * <li>classConstant
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class name.
+   *
+   * @return The class-name pattern that defines the class.
+   */
+  val classNamePattern: ClassNamePattern = ClassNamePattern(unqualifiedName = ""),
+
+  /**
+   * Define the instance-of pattern as classes that are instances of the fully qualified class name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining instance-of:
+   * <ul>
+   * <li>instanceOfClassNameExclusive
+   * <li>instanceOfClassConstant
+   * <li>instanceOfClassConstantExclusive
+   * <li>instanceOfPattern
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class instance.
+   *
+   * @return The qualified class name that defines what instance-of the class must be.
+   */
+  val instanceOfClassName: String = "",
+
+  /**
+   * Define the instance-of pattern as classes that are instances of the fully qualified class name.
+   *
+   * <p>
+   * The pattern is exclusive in that it does not match classes that are instances of the pattern,
+   * but only those that are instances of classes that are subclasses of the pattern.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining instance-of:
+   * <ul>
+   * <li>instanceOfClassName
+   * <li>instanceOfClassConstant
+   * <li>instanceOfClassConstantExclusive
+   * <li>instanceOfPattern
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class instance.
+   *
+   * @return The qualified class name that defines what instance-of the class must be.
+   */
+  val instanceOfClassNameExclusive: String = "",
+
+  /**
+   * Define the instance-of pattern as classes that are instances the referenced Class constant.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining instance-of:
+   * <ul>
+   * <li>instanceOfClassName
+   * <li>instanceOfClassNameExclusive
+   * <li>instanceOfClassConstantExclusive
+   * <li>instanceOfPattern
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class instance.
+   *
+   * @return The class constant that defines what instance-of the class must be.
+   */
+  val instanceOfClassConstant: KClass<*> = Object::class,
+
+  /**
+   * Define the instance-of pattern as classes that are instances the referenced Class constant.
+   *
+   * <p>
+   * The pattern is exclusive in that it does not match classes that are instances of the pattern,
+   * but only those that are instances of classes that are subclasses of the pattern.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining instance-of:
+   * <ul>
+   * <li>instanceOfClassName
+   * <li>instanceOfClassNameExclusive
+   * <li>instanceOfClassConstant
+   * <li>instanceOfPattern
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class instance.
+   *
+   * @return The class constant that defines what instance-of the class must be.
+   */
+  val instanceOfClassConstantExclusive: KClass<*> = Object::class,
+
+  /**
+   * Define the instance-of with a pattern.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining instance-of:
+   * <ul>
+   * <li>instanceOfClassName
+   * <li>instanceOfClassNameExclusive
+   * <li>instanceOfClassConstant
+   * <li>instanceOfClassConstantExclusive
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class instance.
+   *
+   * @return The pattern that defines what instance-of the class must be.
+   */
+  val instanceOfPattern: InstanceOfPattern = InstanceOfPattern(),
+
+  /**
+   * Define the class-annotated-by pattern by fully qualified class name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining class-annotated-by:
+   * <ul>
+   * <li>classAnnotatedByClassConstant
+   * <li>classAnnotatedByClassNamePattern
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class regardless of what the class is
+   * annotated by.
+   *
+   * @return The qualified class name that defines the annotation.
+   */
+  val classAnnotatedByClassName: String = "",
+
+  /**
+   * Define the class-annotated-by pattern by reference to a Class constant.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining class-annotated-by:
+   * <ul>
+   * <li>classAnnotatedByClassName
+   * <li>classAnnotatedByClassNamePattern
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class regardless of what the class is
+   * annotated by.
+   *
+   * @return The class-constant that defines the annotation.
+   */
+  val classAnnotatedByClassConstant: KClass<*> = Object::class,
+
+  /**
+   * Define the class-annotated-by pattern by reference to a class-name pattern.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining class-annotated-by:
+   * <ul>
+   * <li>classAnnotatedByClassName
+   * <li>classAnnotatedByClassConstant
+   * <li>classFromBinding
+   * </ul>
+   *
+   * <p>
+   * If none are specified the default is to match any class regardless of what the class is
+   * annotated by.
+   *
+   * @return The class-name pattern that defines the annotation.
+   */
+  val classAnnotatedByClassNamePattern: ClassNamePattern = ClassNamePattern(unqualifiedName = ""),
+
+  /**
+   * Define the member pattern in full by a reference to a binding.
+   *
+   * <p>
+   * Mutually exclusive with all other class and member pattern properties. When a member binding is
+   * referenced this item is defined to be that item, including its class and member patterns.
+   *
+   * @return The binding name that defines the member.
+   */
+  val memberFromBinding: String = "",
+
+  /**
+   * Define the member-annotated-by pattern by fully qualified class name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining member-annotated-by:
+   * <ul>
+   * <li>memberAnnotatedByClassConstant
+   * <li>memberAnnotatedByClassNamePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all field and method properties as use restricts the match to both
+   * types of members.
+   *
+   * <p>
+   * If none are specified the default is to match any member regardless of what the member is
+   * annotated by.
+   *
+   * @return The qualified class name that defines the annotation.
+   */
+  val memberAnnotatedByClassName: String = "",
+
+  /**
+   * Define the member-annotated-by pattern by reference to a Class constant.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining member-annotated-by:
+   * <ul>
+   * <li>memberAnnotatedByClassName
+   * <li>memberAnnotatedByClassNamePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all field and method properties as use restricts the match to both
+   * types of members.
+   *
+   * <p>
+   * If none are specified the default is to match any member regardless of what the member is
+   * annotated by.
+   *
+   * @return The class-constant that defines the annotation.
+   */
+  val memberAnnotatedByClassConstant: KClass<*> = Object::class,
+
+  /**
+   * Define the member-annotated-by pattern by reference to a class-name pattern.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining member-annotated-by:
+   * <ul>
+   * <li>memberAnnotatedByClassName
+   * <li>memberAnnotatedByClassConstant
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all field and method properties as use restricts the match to both
+   * types of members.
+   *
+   * <p>
+   * If none are specified the default is to match any member regardless of what the member is
+   * annotated by.
+   *
+   * @return The class-name pattern that defines the annotation.
+   */
+  val memberAnnotatedByClassNamePattern: ClassNamePattern = ClassNamePattern(unqualifiedName = ""),
+
+  /**
+   * Define the member-access pattern by matching on access flags.
+   *
+   * <p>
+   * Mutually exclusive with all field and method properties as use restricts the match to both
+   * types of members.
+   *
+   * <p>
+   * Mutually exclusive with the property `memberFromBinding` also defining member-access.
+   *
+   * @return The member access-flag constraints that must be met.
+   */
+  val memberAccess: Array<MemberAccessFlags> = [],
+
+  /**
+   * Define the method-annotated-by pattern by fully qualified class name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining method-annotated-by:
+   * <ul>
+   * <li>methodAnnotatedByClassConstant
+   * <li>methodAnnotatedByClassNamePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none are specified the default is to match any method regardless of what the method is
+   * annotated by.
+   *
+   * @return The qualified class name that defines the annotation.
+   */
+  val methodAnnotatedByClassName: String = "",
+
+  /**
+   * Define the method-annotated-by pattern by reference to a Class constant.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining method-annotated-by:
+   * <ul>
+   * <li>methodAnnotatedByClassName
+   * <li>methodAnnotatedByClassNamePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none are specified the default is to match any method regardless of what the method is
+   * annotated by.
+   *
+   * @return The class-constant that defines the annotation.
+   */
+  val methodAnnotatedByClassConstant: KClass<*> = Object::class,
+
+  /**
+   * Define the method-annotated-by pattern by reference to a class-name pattern.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining method-annotated-by:
+   * <ul>
+   * <li>methodAnnotatedByClassName
+   * <li>methodAnnotatedByClassConstant
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none are specified the default is to match any method regardless of what the method is
+   * annotated by.
+   *
+   * @return The class-name pattern that defines the annotation.
+   */
+  val methodAnnotatedByClassNamePattern: ClassNamePattern = ClassNamePattern(unqualifiedName = ""),
+
+  /**
+   * Define the method-access pattern by matching on access flags.
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a method, the default matches any
+   * method-access flags.
+   *
+   * <p>
+   * Mutually exclusive with the property `memberFromBinding` also defining method-access.
+   *
+   * @return The method access-flag constraints that must be met.
+   */
+  val methodAccess: Array<MethodAccessFlags> = [],
+
+  /**
+   * Define the method-name pattern by an exact method name.
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a method, the default matches any method
+   * name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining method-name:
+   * <ul>
+   * <li>methodNamePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The exact method name of the method.
+   */
+  val methodName: String = "",
+
+  /**
+   * Define the method-name pattern by a string pattern.
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a method, the default matches any method
+   * name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining method-name:
+   * <ul>
+   * <li>methodName
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The string pattern of the method name.
+   */
+  val methodNamePattern: StringPattern = StringPattern(exact = ""),
+
+  /**
+   * Define the method return-type pattern by a fully qualified type or 'void'.
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a method, the default matches any return
+   * type.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining return-type:
+   * <ul>
+   * <li>methodReturnTypeConstant
+   * <li>methodReturnTypePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The qualified type name of the method return type.
+   */
+  val methodReturnType: String = "",
+
+  /**
+   * Define the method return-type pattern by a class constant.
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a method, the default matches any return
+   * type.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining return-type:
+   * <ul>
+   * <li>methodReturnType
+   * <li>methodReturnTypePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return A class constant denoting the type of the method return type.
+   */
+  val methodReturnTypeConstant: KClass<*> = Object::class,
+
+  /**
+   * Define the method return-type pattern by a type pattern.
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a method, the default matches any return
+   * type.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining return-type:
+   * <ul>
+   * <li>methodReturnType
+   * <li>methodReturnTypeConstant
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The pattern of the method return type.
+   */
+  val methodReturnTypePattern: TypePattern = TypePattern(name = ""),
+
+  /**
+   * Define the method parameters pattern by a list of fully qualified types.
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a method, the default matches any parameters.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining parameters:
+   * <ul>
+   * <li>methodParameterTypePatterns
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The list of qualified type names of the method parameters.
+   */
+  val methodParameters: Array<String> = [""],
+
+  /**
+   * Define the method parameters pattern by a list of patterns on types.
+   *
+   * <p>
+   * Mutually exclusive with all field properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a method, the default matches any parameters.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining parameters:
+   * <ul>
+   * <li>methodParameters
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The list of type patterns for the method parameters.
+   */
+  val methodParameterTypePatterns: Array<TypePattern> = [TypePattern(name = "")],
+
+  /**
+   * Define the field-annotated-by pattern by fully qualified class name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining field-annotated-by:
+   * <ul>
+   * <li>fieldAnnotatedByClassConstant
+   * <li>fieldAnnotatedByClassNamePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none are specified the default is to match any field regardless of what the field is
+   * annotated by.
+   *
+   * @return The qualified class name that defines the annotation.
+   */
+  val fieldAnnotatedByClassName: String = "",
+
+  /**
+   * Define the field-annotated-by pattern by reference to a Class constant.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining field-annotated-by:
+   * <ul>
+   * <li>fieldAnnotatedByClassName
+   * <li>fieldAnnotatedByClassNamePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none are specified the default is to match any field regardless of what the field is
+   * annotated by.
+   *
+   * @return The class-constant that defines the annotation.
+   */
+  val fieldAnnotatedByClassConstant: KClass<*> = Object::class,
+
+  /**
+   * Define the field-annotated-by pattern by reference to a class-name pattern.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining field-annotated-by:
+   * <ul>
+   * <li>fieldAnnotatedByClassName
+   * <li>fieldAnnotatedByClassConstant
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none are specified the default is to match any field regardless of what the field is
+   * annotated by.
+   *
+   * @return The class-name pattern that defines the annotation.
+   */
+  val fieldAnnotatedByClassNamePattern: ClassNamePattern = ClassNamePattern(unqualifiedName = ""),
+
+  /**
+   * Define the field-access pattern by matching on access flags.
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a field, the default matches any field-access
+   * flags.
+   *
+   * <p>
+   * Mutually exclusive with the property `memberFromBinding` also defining field-access.
+   *
+   * @return The field access-flag constraints that must be met.
+   */
+  val fieldAccess: Array<FieldAccessFlags> = [],
+
+  /**
+   * Define the field-name pattern by an exact field name.
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a field, the default matches any field name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining field-name:
+   * <ul>
+   * <li>fieldNamePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The exact field name of the field.
+   */
+  val fieldName: String = "",
+
+  /**
+   * Define the field-name pattern by a string pattern.
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a field, the default matches any field name.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining field-name:
+   * <ul>
+   * <li>fieldName
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The string pattern of the field name.
+   */
+  val fieldNamePattern: StringPattern = StringPattern(exact = ""),
+
+  /**
+   * Define the field-type pattern by a fully qualified type.
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a field, the default matches any type.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining field-type:
+   * <ul>
+   * <li>fieldTypeConstant
+   * <li>fieldTypePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The qualified type name for the field type.
+   */
+  val fieldType: String = "",
+
+  /**
+   * Define the field-type pattern by a class constant.
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a field, the default matches any type.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining field-type:
+   * <ul>
+   * <li>fieldType
+   * <li>fieldTypePattern
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The class constant for the field type.
+   */
+  val fieldTypeConstant: KClass<*> = Object::class,
+
+  /**
+   * Define the field-type pattern by a pattern on types.
+   *
+   * <p>
+   * Mutually exclusive with all method properties.
+   *
+   * <p>
+   * If none, and other properties define this item as a field, the default matches any type.
+   *
+   * <p>
+   * Mutually exclusive with the following other properties defining field-type:
+   * <ul>
+   * <li>fieldType
+   * <li>fieldTypeConstant
+   * <li>memberFromBinding
+   * </ul>
+   *
+   * @return The type pattern for the field type.
+   */
+  val fieldTypePattern: TypePattern = TypePattern(name = ""),
+)