Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5766bd5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Support for @InspectableProperty on public fields"

parents fffdfbe1 89d6bce3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3033,7 +3033,7 @@ package android.view.inspector {
    method public abstract String value();
  }

  @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD}) public @interface InspectableProperty {
  @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.FIELD}) public @interface InspectableProperty {
    method public abstract int attributeId() default android.content.res.Resources.ID_NULL;
    method public abstract android.view.inspector.InspectableProperty.EnumMap[] enumMapping() default {};
    method public abstract android.view.inspector.InspectableProperty.FlagMap[] flagMapping() default {};
+2 −2
Original line number Diff line number Diff line
@@ -18589,7 +18589,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            @FlagMap(target = FADING_EDGE_VERTICAL, name = "vertical"),
            @FlagMap(target = FADING_EDGE_HORIZONTAL, name = "horizontal")
    })
    int getFadingEdge() {
    public int getFadingEdge() {
        return mViewFlags & FADING_EDGE_MASK;
    }
@@ -18600,7 +18600,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @hide
     */
    @InspectableProperty
    int getFadingEdgeLength() {
    public int getFadingEdgeLength() {
        if (mScrollCache != null && (mViewFlags & FADING_EDGE_MASK) != FADING_EDGE_NONE) {
            return mScrollCache.fadingEdgeLength;
        }
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view.inspector;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -39,7 +40,7 @@ import java.lang.annotation.Target;
 * @see InspectionCompanion#readProperties(Object, PropertyReader)
 * @hide
 */
@Target({METHOD})
@Target({METHOD, FIELD})
@Retention(SOURCE)
@TestApi
public @interface InspectableProperty {
+84 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;

@@ -85,21 +86,99 @@ public final class InspectableClassModel {
        return mPropertyMap.values();
    }

    /**
     * Represents a way to access a property, either a getter or a field.
     */
    public static final class Accessor {
        private final String mName;
        private final Type mType;

        /**
         * Construct an accessor for a field.
         *
         * @param name The name of the field
         * @return The new accessor
         * @see Type#FIELD
         */
        static Accessor ofField(String name) {
            return new Accessor(name, Type.FIELD);
        }

        /**
         * Construct an accessor for a getter.
         *
         * @param name The name of the getter
         * @return The new accessor
         * @see Type#GETTER
         */
        static Accessor ofGetter(String name) {
            return new Accessor(name, Type.GETTER);
        }

        public Accessor(String name, Type type) {
            mName = Objects.requireNonNull(name, "Accessor name must not be null");
            mType = Objects.requireNonNull(type, "Accessor type must not be null");
        }

        public String getName() {
            return mName;
        }

        public Type getType() {
            return mType;
        }

        /**
         * Get the invocation of this accessor.
         *
         * Example: {@code "getValue()"} for a getter or {@code "valueField"} for a field.
         *
         * @return A string representing the invocation of this accessor
         */
        public String invocation() {
            switch (mType) {
                case FIELD:
                    return mName;
                case GETTER:
                    return String.format("%s()", mName);
                default:
                    throw new NoSuchElementException(
                            String.format("No such accessor type %s", mType));
            }
        }

        public enum Type {
            /**
             * A property accessed by a public field.
             *
             * @see #ofField(String)
             */
            FIELD,

            /**
             * A property accessed by a public getter method.
             *
             * @see #ofGetter(String)
             */
            GETTER
        }
    }

    /**
     * Model an inspectable property
     */
    public static final class Property {
        private final String mName;
        private final String mGetter;
        private final Accessor mAccessor;
        private final Type mType;
        private boolean mAttributeIdInferrableFromR = true;
        private int mAttributeId = 0;
        private List<IntEnumEntry> mIntEnumEntries;
        private List<IntFlagEntry> mIntFlagEntries;

        public Property(String name, String getter, Type type) {
        public Property(String name, Accessor accessor, Type type) {
            mName = Objects.requireNonNull(name, "Name must not be null");
            mGetter = Objects.requireNonNull(getter, "Getter must not be null");
            mAccessor = Objects.requireNonNull(accessor, "Accessor must not be null");
            mType = Objects.requireNonNull(type, "Type must not be null");
        }

@@ -129,8 +208,8 @@ public final class InspectableClassModel {
            return mName;
        }

        public String getGetter() {
            return mGetter;
        public Accessor getAccessor() {
            return mAccessor;
        }

        public Type getType() {
+169 −113

File changed.

Preview size limit exceeded, changes collapsed.

Loading