001package arez.annotations; 002 003import java.lang.annotation.Documented; 004import java.lang.annotation.ElementType; 005import java.lang.annotation.Target; 006 007/** 008 * Methods and fields annotated by this annotation should be disposed when the component is disposed. 009 * The dispose occurs after the {@link PreDispose} method. 010 * 011 * <p>It should be noted that it is preferable for the field that defines the contained component is marked 012 * with this annotation rather than the method accessor. The reason is that the annotation processor 013 * will issue a warning if a field that the processor identifies as a potential contained component if it is 014 * not annotated with {@link AutoObserve}, {@link CascadeDispose} or {@link ComponentDependency}.</p> 015 * 016 * <p>If the element annotated is a method then the method must comply with the additional constraints:</p> 017 * <ul> 018 * <li>Must not be annotated with any other arez annotation other than {@link Reference} or {@link Observable}</li> 019 * <li>Must have 0 parameters</li> 020 * <li>The type of the field must implement {@link arez.Disposable} or must be annotated by {@link ArezComponent}</li> 021 * <li>Must not be private</li> 022 * <li>Must not be static</li> 023 * <li>Must not be abstract unless the method is annotated with {@link Reference} or {@link Observable} in which case it MUST be abstract</li> 024 * <li>Must not throw exceptions</li> 025 * <li>Must be accessible to the class annotated by the {@link ArezComponent} annotation.</li> 026 * </ul> 027 * 028 * <p>If the element annotated is a field then the field must comply with the additional constraints:</p> 029 * <ul> 030 * <li>Must not be private</li> 031 * <li>Must not be static</li> 032 * <li>The type of the field must implement {@link arez.Disposable} or must be annotated by {@link ArezComponent}</li> 033 * <li>Must be accessible to the class annotated by the {@link ArezComponent} annotation.</li> 034 * <li>Should not be public. A warning will be generated but can be suppressed by the {@link SuppressWarnings} or {@link SuppressArezWarnings} annotations with a key "Arez:PublicField".</li> 035 * <li> 036 * Should not be protected if in the class annotated with the {@link ArezComponent} annotation as the field is not 037 * expected to be accessed outside the component. A warning will be generated but can be suppressed by the 038 * {@link SuppressWarnings} or {@link SuppressArezWarnings} annotations with a key "Arez:ProtectedField". 039 * </li> 040 * </ul> 041 * 042 * <p>This annotation is only supported on elements contained within a type annotated by 043 * {@link ArezComponent} or {@link ArezComponentLike}. Other usages will fail compilation.</p> 044 */ 045@Documented 046@Target( { ElementType.METHOD, ElementType.FIELD } ) 047public @interface CascadeDispose 048{ 049}