Ashley Rose | 041d90b | 2018-11-07 17:35:19 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | package android.view.inspector; |
| 18 | |
| 19 | import static java.lang.annotation.ElementType.METHOD; |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 20 | import static java.lang.annotation.ElementType.TYPE; |
Ashley Rose | 041d90b | 2018-11-07 17:35:19 -0500 | [diff] [blame] | 21 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 22 | |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 23 | import android.annotation.TestApi; |
Aurimas Liutikas | d8ebfef | 2019-01-16 12:46:42 -0800 | [diff] [blame] | 24 | import android.content.res.Resources; |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 25 | |
Ashley Rose | 041d90b | 2018-11-07 17:35:19 -0500 | [diff] [blame] | 26 | import java.lang.annotation.Retention; |
| 27 | import java.lang.annotation.Target; |
| 28 | |
| 29 | /** |
| 30 | * Marks a getter of a property on an inspectable node. |
| 31 | * |
| 32 | * This annotation is inherited by default. If a child class doesn't add it to a getter, but a |
| 33 | * parent class does, the property will be inspected, even if the child overrides the definition |
| 34 | * of the getter. If a child class defines a property of the same name of a property on the parent |
| 35 | * but on a different getter, the inspector will use the child's getter when inspecting instances |
| 36 | * of the child, and the parent's otherwise. |
| 37 | * |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 38 | * @see InspectionCompanion#mapProperties(PropertyMapper) |
| 39 | * @see InspectionCompanion#readProperties(Object, PropertyReader) |
Ashley Rose | 041d90b | 2018-11-07 17:35:19 -0500 | [diff] [blame] | 40 | * @hide |
| 41 | */ |
| 42 | @Target({METHOD}) |
| 43 | @Retention(SOURCE) |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 44 | @TestApi |
Ashley Rose | 041d90b | 2018-11-07 17:35:19 -0500 | [diff] [blame] | 45 | public @interface InspectableProperty { |
| 46 | /** |
| 47 | * The name of the property. |
| 48 | * |
| 49 | * If left empty (the default), the property name will be inferred from the name of the getter |
| 50 | * method. |
| 51 | * |
| 52 | * @return The name of the property. |
| 53 | */ |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 54 | String name() default ""; |
| 55 | |
| 56 | /** |
| 57 | * If the property is inflated from XML, the resource ID of its XML attribute. |
| 58 | * |
| 59 | * If left as {ID_NULL}, and {@link #hasAttributeId()} is true, the attribute ID will be |
| 60 | * inferred from {@link #name()}. |
| 61 | * |
Aurimas Liutikas | d8ebfef | 2019-01-16 12:46:42 -0800 | [diff] [blame] | 62 | * @return The attribute ID of the property or {@link Resources#ID_NULL} |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 63 | */ |
Aurimas Liutikas | d8ebfef | 2019-01-16 12:46:42 -0800 | [diff] [blame] | 64 | int attributeId() default Resources.ID_NULL; |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * If this property has an attribute ID. |
| 68 | * |
| 69 | * Set to false if the annotated property does not have an attribute ID, that is, it is not |
| 70 | * inflated from an XML attribute. This will prevent the automatic inference of the attribute |
Aurimas Liutikas | d8ebfef | 2019-01-16 12:46:42 -0800 | [diff] [blame] | 71 | * ID if {@link #attributeId()} is set to {@link Resources#ID_NULL}. |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 72 | * |
| 73 | * @return Whether to infer an attribute ID if not supplied |
| 74 | */ |
| 75 | boolean hasAttributeId() default true; |
| 76 | |
| 77 | /** |
| 78 | * Specify how to interpret a value type packed into a primitive integer. |
| 79 | * |
| 80 | * @return A {@link ValueType} |
| 81 | */ |
| 82 | ValueType valueType() default ValueType.INFERRED; |
| 83 | |
| 84 | /** |
| 85 | * For enumerations packed into primitive {int} properties, map the values to string names. |
| 86 | * |
| 87 | * Note that {@link #enumMapping()} cannot be used simultaneously with {@link #flagMapping()}. |
| 88 | * |
| 89 | * @return An array of {@link EnumMap}, empty if not applicable |
| 90 | * @see android.annotation.IntDef |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 91 | */ |
| 92 | EnumMap[] enumMapping() default {}; |
| 93 | |
| 94 | /** |
| 95 | * For flags packed into primitive {int} properties, model the string names of the flags. |
| 96 | * |
| 97 | * Note that {@link #flagMapping()} cannot be used simultaneously with {@link #enumMapping()}. |
| 98 | * |
| 99 | * @return An array of {@link FlagMap}, empty if not applicable |
| 100 | * @see android.annotation.IntDef |
| 101 | * @see IntFlagMapping |
| 102 | */ |
| 103 | FlagMap[] flagMapping() default {}; |
| 104 | |
| 105 | |
| 106 | /** |
| 107 | * One entry in an enumeration packed into a primitive {int}. |
| 108 | * |
Ashley Rose | a61e7cd | 2019-01-23 14:37:42 -0500 | [diff] [blame] | 109 | * @see IntEnumMapping |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 110 | * @hide |
| 111 | */ |
| 112 | @Target({TYPE}) |
| 113 | @Retention(SOURCE) |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 114 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 115 | @interface EnumMap { |
| 116 | /** |
| 117 | * The string name of this enumeration value. |
| 118 | * |
| 119 | * @return A string name |
| 120 | */ |
| 121 | String name(); |
| 122 | |
| 123 | /** |
| 124 | * The integer value of this enumeration value. |
| 125 | * |
| 126 | * @return An integer value |
| 127 | */ |
| 128 | int value(); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * One flag value of many that may be packed into a primitive {int}. |
| 133 | * |
| 134 | * @see IntFlagMapping |
| 135 | * @hide |
| 136 | */ |
| 137 | @Target({TYPE}) |
| 138 | @Retention(SOURCE) |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 139 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 140 | @interface FlagMap { |
| 141 | /** |
| 142 | * The string name of this flag. |
| 143 | * |
| 144 | * @return A string name |
| 145 | */ |
| 146 | String name(); |
| 147 | |
| 148 | /** |
| 149 | * A target value that the property's value must equal after masking. |
| 150 | * |
| 151 | * If a mask is not supplied (i.e., {@link #mask()} is 0), the target will be reused as the |
| 152 | * mask. This handles the common case where no flags mutually exclude each other. |
| 153 | * |
| 154 | * @return The target value to compare against |
| 155 | */ |
| 156 | int target(); |
| 157 | |
| 158 | /** |
| 159 | * A mask that the property will be bitwise anded with before comparing to the target. |
| 160 | * |
| 161 | * If set to 0 (the default), the value of {@link #target()} will be used as a mask. Zero |
| 162 | * was chosen as the default since bitwise and with zero is always zero. |
| 163 | * |
| 164 | * @return A mask, or 0 to use the target as a mask |
| 165 | */ |
| 166 | int mask() default 0; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * The type of value packed into a primitive {int}. |
| 171 | * |
| 172 | * @hide |
| 173 | */ |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 174 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 175 | enum ValueType { |
| 176 | /** |
| 177 | * No special handling, property is considered to be a numeric value. |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 178 | * |
| 179 | * @hide |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 180 | */ |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 181 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 182 | NONE, |
| 183 | |
| 184 | /** |
| 185 | * The default the annotation processor infers the value type from context. |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 186 | * |
| 187 | * @hide |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 188 | */ |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 189 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 190 | INFERRED, |
| 191 | |
| 192 | /** |
| 193 | * Value packs an enumeration. |
| 194 | * |
| 195 | * This is inferred if {@link #enumMapping()} is specified. |
| 196 | * |
| 197 | * @see EnumMap |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 198 | * @hide |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 199 | */ |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 200 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 201 | INT_ENUM, |
| 202 | |
| 203 | /** |
| 204 | * Value packs flags, of which many may be enabled at once. |
| 205 | * |
| 206 | * This is inferred if {@link #flagMapping()} is specified. |
| 207 | * |
| 208 | * @see FlagMap |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 209 | * @hide |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 210 | */ |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 211 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 212 | INT_FLAG, |
| 213 | |
| 214 | /** |
| 215 | * Value packs color information. |
| 216 | * |
| 217 | * This is inferred from {@link android.annotation.ColorInt}, or |
| 218 | * {@link android.annotation.ColorLong} on the getter method. |
| 219 | * |
| 220 | * @see android.graphics.Color |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 221 | * @hide |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 222 | */ |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 223 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 224 | COLOR, |
| 225 | |
| 226 | /** |
| 227 | * Value packs gravity information. |
| 228 | * |
| 229 | * This type is not inferred, and is non-trivial to represent using {@link FlagMap}. |
| 230 | * |
| 231 | * @see android.view.Gravity |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 232 | * @hide |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 233 | */ |
Ashley Rose | c1a4dec | 2018-12-13 18:06:30 -0500 | [diff] [blame] | 234 | @TestApi |
Ashley Rose | d2c5f45 | 2018-11-29 15:40:10 -0500 | [diff] [blame] | 235 | GRAVITY |
| 236 | } |
Ashley Rose | 041d90b | 2018-11-07 17:35:19 -0500 | [diff] [blame] | 237 | } |