001    package edu.rice.cs.cunit.threadCheck.predicates;
002    
003    import edu.rice.cs.cunit.threadCheck.PredicateLink;
004    import edu.rice.cs.cunit.threadCheck.Combine;
005    
006    import java.lang.annotation.Retention;
007    import java.lang.annotation.RetentionPolicy;
008    import java.lang.annotation.Target;
009    import java.lang.annotation.ElementType;
010    
011    /**
012     * An annotation used to designate methods that are only allowed to run if they own the monitor of the field specified
013     * by class and field name.
014     *
015     * @author Mathias Ricken
016     */
017    @Retention(RetentionPolicy.RUNTIME)
018    @Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE})
019    
020    @PredicateLink(value = ReflectionThreadCheckPredicates.class, method = "checkSynchronizedField")
021    public @interface OnlySynchronizedField {
022        /**
023         * The class that contains the field whose monitor the thread has to own.
024         *
025         * @return class containing the field
026         */
027        Class fieldClass();
028    
029        /**
030         * The name of the field whose monitor the thread has to own.
031         *
032         * @return name of the field
033         */
034        String fieldName();
035    
036        //
037        // nested interfaces
038        //
039    
040        /**
041         * An annotation used to designate methods that are only allowed to be run by the thread in the field specified
042         * by class name and field name.
043         *
044         * @author Mathias Ricken
045         */
046        @Retention(RetentionPolicy.RUNTIME)
047        @Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE})
048    
049        @PredicateLink(value = ReflectionThreadCheckPredicates.class, method = "checkSynchronizedFieldByName")
050        public static @interface ByName {
051            /**
052             * The name of the class that contains the field whose monitor the thread has to own.
053             *
054             * @return class containing the field
055             */
056            String fieldClassName();
057    
058            /**
059             * The name of the field whose monitor the thread has to own.
060             *
061             * @return name of the field
062             */
063            String fieldName();
064    
065            //
066            // nested interfaces
067            //
068    
069            /**
070             * Annotation used to designate methods that are only allowed to be run if they own
071             * one or more of the monitors specified in the fields, i.e. the individual
072             * @OnlySynchronizedField.ByName annotations are combined using OR.
073             */
074            @Retention(RetentionPolicy.RUNTIME)
075            @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
076    
077            @Combine(Combine.Mode.OR)
078            public static @interface Any {
079                OnlySynchronizedField.ByName[] value();
080            }
081    
082            /**
083             * Annotation used to designate methods that are only allowed to be run if they own
084             * one or more of the monitors specified in the fields, i.e. the individual
085             * @OnlySynchronizedField.ByName annotations are combined using AND.
086             */
087            @Retention(RetentionPolicy.RUNTIME)
088            @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
089    
090            @Combine(Combine.Mode.AND)
091            public static @interface All {
092                OnlySynchronizedField.ByName[] value();
093            }
094        }
095    
096        /**
097         * Annotation used to designate methods that are only allowed to be run if they own
098         * one or more of the monitors specified in the fields, i.e. the individual
099         * @OnlySynchronizedField annotations are combined using OR.
100         */
101        @Retention(RetentionPolicy.RUNTIME)
102        @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
103    
104        @Combine(Combine.Mode.OR)
105        public static @interface Any {
106            OnlySynchronizedField[] value();
107        }
108    
109        /**
110         * Annotation used to designate methods that are only allowed to be run if they own
111         * all of the monitors specified in the fields, i.e. the individual
112         * @OnlySynchronizedField annotations are combined using ALL.
113         */
114        @Retention(RetentionPolicy.RUNTIME)
115        @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
116    
117        @Combine(Combine.Mode.AND)
118        public static @interface All {
119            OnlySynchronizedField[] value();
120        }
121    }