001package arez.annotations; 002 003import java.lang.annotation.Documented; 004import java.lang.annotation.ElementType; 005import java.lang.annotation.Target; 006import javax.annotation.Nonnull; 007 008/** 009 * Annotate the method that will be overridden to return true if the component is in the specified state. 010 * This is useful when the component must validate methods are only called in certain states or to change 011 * behaviour based on state (i.e. Avoid causing side-effects when disposing). 012 * 013 * <p>The method that is annotated with this component must comply with the constraints:</p> 014 * <ul> 015 * <li>May appear zero or more times on a component</li> 016 * <li>Must not be annotated with any other arez annotation</li> 017 * <li>Must have 0 parameters</li> 018 * <li>Must return a boolean</li> 019 * <li>Must be abstract</li> 020 * <li>Must not throw exceptions</li> 021 * <li>Must be accessible to the class annotated by the {@link ArezComponent} annotation.</li> 022 * <li> 023 * Should not be public as not expected to be invoked outside the component. A warning will be generated but can 024 * be suppressed by the {@link SuppressWarnings} or {@link SuppressArezWarnings} annotations with a key 025 * "Arez:PublicRefMethod". This warning is also suppressed by the annotation processor if it is implementing 026 * an interface method. 027 * </li> 028 * <li> 029 * Should not be protected if in the class annotated with the {@link ArezComponent} annotation as the method is not 030 * expected to be invoked outside the component. A warning will be generated but can be suppressed by the 031 * {@link SuppressWarnings} or {@link SuppressArezWarnings} annotations with a key "Arez:ProtectedMethod". 032 * </li> 033 * </ul> 034 */ 035@Documented 036@Target( ElementType.METHOD ) 037public @interface ComponentStateRef 038{ 039 /** 040 * Return the component state which will cause the annotated method to return true. 041 * 042 * @return the component state which will cause annotated method to return true. 043 */ 044 @Nonnull 045 State value() default State.READY; 046}