diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-11-08 21:35:20 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-11-08 21:35:20 +0000 |
| commit | eeca4f5a304de644a6a9ffbfddf7f18ff857ca63 (patch) | |
| tree | 69bf91d37e7b126dbc4596d98a5055c3e2ec1f97 | |
| parent | d5c7fb6cdfe341b6930207ca4c218d02e4009589 (diff) | |
| parent | 041d90b23e7895c05c528f34019907495b4f4ff3 (diff) | |
Merge "Add Inspector annotations"
| -rw-r--r-- | Android.bp | 10 | ||||
| -rw-r--r-- | core/java/android/view/inspector/InspectableChildren.java | 46 | ||||
| -rw-r--r-- | core/java/android/view/inspector/InspectableNodeName.java | 49 | ||||
| -rw-r--r-- | core/java/android/view/inspector/InspectableProperty.java | 50 |
4 files changed, 155 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp index 10b92f3189b3..93e696312696 100644 --- a/Android.bp +++ b/Android.bp @@ -766,6 +766,16 @@ java_library { ], } +// A host library containing the inspector annotations for inspector-annotation-processor. +java_library_host { + name: "inspector-annotation", + srcs: [ + "core/java/android/view/inspector/InspectableChildren.java", + "core/java/android/view/inspector/InspectableNodeName.java", + "core/java/android/view/inspector/InspectableProperty.java", + ], +} + // A host library including just UnsupportedAppUsage.java so that the annotation // processor can also use this annotation. java_library_host { diff --git a/core/java/android/view/inspector/InspectableChildren.java b/core/java/android/view/inspector/InspectableChildren.java new file mode 100644 index 000000000000..de8fa296e8c5 --- /dev/null +++ b/core/java/android/view/inspector/InspectableChildren.java @@ -0,0 +1,46 @@ +/* + * Copyright 2018 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 android.view.inspector; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Marks a getter for an inspectable node's inspectable children. + * + * This annotation can be applied to any getter that returns a collection of objects, either an + * array, an {@link Iterable} or a {@link java.util.Iterator}. The getter may return null, which + * will be treated as an empty collection. Additionally, the inspector will discard any null + * entries in the collection. + * + * By default, this annotation is inherited. At runtime, the inspector introspects on the class + * hierachy and uses the annotated getter from the bottommost class, if different from any + * annoated getters of the parent class. If a class inherits from a parent class with an annotated + * getter, but does not include this annotation, the child class will be traversed using the + * getter annotated on the parent. This holds true even if the child class overrides the getter. + * + * @see InspectionHelper#traverseChildren(Object, ChildTraverser) + * @see InspectionHelper#hasChildTraversal() + * @hide + */ +@Target({METHOD}) +@Retention(SOURCE) +public @interface InspectableChildren { +} diff --git a/core/java/android/view/inspector/InspectableNodeName.java b/core/java/android/view/inspector/InspectableNodeName.java new file mode 100644 index 000000000000..716409c9af3a --- /dev/null +++ b/core/java/android/view/inspector/InspectableNodeName.java @@ -0,0 +1,49 @@ +/* + * Copyright 2018 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 android.view.inspector; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Marks the node name to display to a developer in the inspection tree. + * + * This annotation is optional to marking a class as inspectable. If it is omitted, the node name + * will be inferred using the semantics of {@link Class#getSimpleName()}. The fully qualified class + * name is always available in the tree, this is for display purposes only. If a class is inflated + * from XML and the tag it inflates from does not match its simple name, this annotation should be + * used to inform the inspector to display the XML tag name in the inspection tree view. + * + * This annotation does not inherit. If a class extends an annotated parent class, but does not + * annotate itself, its node name will be inferred from its Java name. + * + * @see InspectionHelper#getNodeName() + * @hide + */ +@Target({TYPE}) +@Retention(SOURCE) +public @interface InspectableNodeName { + /** + * The display name for nodes of this type. + * + * @return The name for nodes of this type + */ + String value(); +} diff --git a/core/java/android/view/inspector/InspectableProperty.java b/core/java/android/view/inspector/InspectableProperty.java new file mode 100644 index 000000000000..b0fd5032ba56 --- /dev/null +++ b/core/java/android/view/inspector/InspectableProperty.java @@ -0,0 +1,50 @@ +/* + * Copyright 2018 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 android.view.inspector; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Marks a getter of a property on an inspectable node. + * + * This annotation is inherited by default. If a child class doesn't add it to a getter, but a + * parent class does, the property will be inspected, even if the child overrides the definition + * of the getter. If a child class defines a property of the same name of a property on the parent + * but on a different getter, the inspector will use the child's getter when inspecting instances + * of the child, and the parent's otherwise. + * + * @see InspectionHelper#mapProperties(PropertyMapper) + * @see InspectionHelper#readProperties(Object, PropertyReader) + * @hide + */ +@Target({METHOD}) +@Retention(SOURCE) +public @interface InspectableProperty { + /** + * The name of the property. + * + * If left empty (the default), the property name will be inferred from the name of the getter + * method. + * + * @return The name of the property. + */ + String value() default ""; +} |
