001package arez.spy;
002
003import arez.Arez;
004import arez.ObservableValue;
005import grim.annotations.OmitSymbol;
006import java.util.List;
007import javax.annotation.Nonnull;
008import javax.annotation.Nullable;
009
010/**
011 * A representation of an ObservableValue instance exposed to spy framework.
012 */
013public interface ObservableValueInfo
014  extends ElementInfo
015{
016  /**
017   * Return true if the Observable is a ComputableValue.
018   *
019   * @return true if the Observable is a ComputableValue.
020   */
021  boolean isComputableValue();
022
023  /**
024   * Convert the Observable to a ComputableValue.
025   * This method should only be called if {@link #isComputableValue()} returns true.
026   *
027   * @return the ComputableValue instance.
028   */
029  ComputableValueInfo asComputableValue();
030
031  /**
032   * Return the list of observers for the Observable.
033   * The list is an immutable copy of the observers of the {@link ObservableValue}.
034   *
035   * @return the list of observers for Observable.
036   */
037  @Nonnull
038  List<ObserverInfo> getObservers();
039
040  /**
041   * Return the component for the Observable.
042   * This method should not be invoked if {@link Arez#areNativeComponentsEnabled()} returns false.
043   *
044   * @return the component that contains Observable if any.
045   */
046  @Nullable
047  ComponentInfo getComponent();
048
049  /**
050   * Return true if the specified Observable has an accessor.
051   * This method should not be invoked if {@link Arez#arePropertyIntrospectorsEnabled()} returns false.
052   *
053   * @return true if an accessor is available.
054   */
055  @OmitSymbol( unless = "arez.enable_property_introspection" )
056  boolean hasAccessor();
057
058  /**
059   * Return the value of the specified Observable.
060   * This method should only be invoked if {@link Arez#arePropertyIntrospectorsEnabled()} returns true
061   * and {@link #hasAccessor()} for the same element returns true.
062   *
063   * @return the value of the observable.
064   * @throws Throwable if the property accessor throws an exception.
065   */
066  @OmitSymbol( unless = "arez.enable_property_introspection" )
067  @Nullable
068  Object getValue()
069    throws Throwable;
070
071  /**
072   * Return true if the specified Observable has a mutator.
073   * This method should not be invoked if {@link Arez#arePropertyIntrospectorsEnabled()} returns false.
074   *
075   * @return true if a mutator is available.
076   */
077  @OmitSymbol( unless = "arez.enable_property_introspection" )
078  boolean hasMutator();
079
080  /**
081   * Set the value of the specified Observable.
082   * This method should only be invoked if {@link Arez#arePropertyIntrospectorsEnabled()} returns true
083   * and {@link #hasMutator()} for the same element returns true.
084   *
085   * @param value the value to set
086   * @throws Throwable if the property accessor throws an exception.
087   */
088  @OmitSymbol( unless = "arez.enable_property_introspection" )
089  void setValue( @Nullable Object value )
090    throws Throwable;
091}