Create @AppCompatShadowedAttributes

This annotation is restricted to intra-androidx library usage. When
applied to a View in AppCompat, it will direct the annotation processor
to infer shadowed attributes for the View based on what interfaces from
Core it implements, e.g.: TintableBackgroundView.

Test: N/A
Relnote: Improved AppCompat support
Bug: 188446121
Change-Id: I2d7387a017585bcea14a8d8a857b9b60930bc1c5
diff --git a/resourceinspection/resourceinspection-annotation/api/restricted_current.txt b/resourceinspection/resourceinspection-annotation/api/restricted_current.txt
index 2962da1..5be0bd5 100644
--- a/resourceinspection/resourceinspection-annotation/api/restricted_current.txt
+++ b/resourceinspection/resourceinspection-annotation/api/restricted_current.txt
@@ -1,6 +1,9 @@
 // Signature format: 4.0
 package androidx.resourceinspection.annotation {
 
+  @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE) public @interface AppCompatShadowedAttributes {
+  }
+
   @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface Attribute {
     method public abstract androidx.resourceinspection.annotation.Attribute.IntMap[] intMapping() default {};
     method public abstract String value();
diff --git a/resourceinspection/resourceinspection-annotation/src/main/java/androidx/resourceinspection/annotation/AppCompatShadowedAttributes.java b/resourceinspection/resourceinspection-annotation/src/main/java/androidx/resourceinspection/annotation/AppCompatShadowedAttributes.java
new file mode 100644
index 0000000..2ec1183
--- /dev/null
+++ b/resourceinspection/resourceinspection-annotation/src/main/java/androidx/resourceinspection/annotation/AppCompatShadowedAttributes.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2021 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.
+ */
+
+package androidx.resourceinspection.annotation;
+
+import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import androidx.annotation.RestrictTo;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a view within AppCompat that shadows platform attributes.
+ * <p>
+ * Many AppCompat views shadow a platform attribute in order to provide backwards compatibility
+ * for older API levels. This means that a developer might set
+ * {@code androidx.appcompat:backgroundTint} instead of {@code android:backgroundTint} to get a
+ * background tint with support for API < 21. On more recent versions of the platform, this has
+ * the effect of storing the resolution stack in the {@code androidx.appcompat} namespace but
+ * reading the set value from the platform inspection companion in the {@code android} namespace,
+ * causing the resolution stack to get lost in the inspector.
+ * <p>
+ * Ordinarily, this behavior could be overridden by an {@link Attribute} annotation on the getter,
+ * but it is infeasible to override a platform getter that doesn't exist on older supported API
+ * levels. It results in worse performance at load time on those devices.
+ * <p>
+ * This annotation instructs the processor to include a list of shadowed attributes with
+ * API-level appropriate accessors in the view's inspection companion. It infers the attributes
+ * to include from the interfaces on the annotated view. For example, a view that implements
+ * {@link androidx.core.view.TintableBackgroundView} will report
+ * {@code androidx.appcompat:backgroundTint} directly from the platform
+ * {@link android.view.View.getBackgroundTintList()} getter. This approach allows views within
+ * AppCompat to mix shadowed attributes and regular attribute annotations on the same view
+ * without hand-written inspection companions.
+ * <p>
+ * @hide
+ */
+@Target(TYPE)
+@Retention(SOURCE)
+@RestrictTo(LIBRARY_GROUP_PREFIX)
+public @interface AppCompatShadowedAttributes {
+}