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 be run by a thread with the specified group name.
013     * @author Mathias Ricken
014     */
015    @Retention(RetentionPolicy.RUNTIME)
016    @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
017    
018    @PredicateLink(value = ThreadCheckPredicates.class, method = "checkGroup")
019    public @interface OnlyThreadWithGroupName {
020        /**
021         * Group name of the thread. If the regex member is true, then this is treated as a regular expression.
022         * @return group name or regular expression for the group name of the thread allowed to run
023         */
024        String value();
025    
026        /**
027         * Determines if the string in the value member is a regular expression (true) or a plain string (false).
028         * @return true if the string in the value member is a regular expression
029         */
030        boolean regex() default false;
031    
032    
033        //
034        // nested interfaces
035        //
036    
037        /**
038         * An annotation used to designate methods that are only allowed to be run by a thread whose group name is equal
039         * to the string in the field specified by class and field name.
040         */
041        @Retention(RetentionPolicy.RUNTIME)
042        @Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE})
043    
044        @PredicateLink(value = ReflectionThreadCheckPredicates.class, method = "checkGroup")
045        public static @interface InField {
046            /**
047             * The class that contains the field specifying the group name of threads allowed to run.
048             * @return class containing the field
049             */
050            Class fieldClass();
051    
052            /**
053             * The name of the field specifying the group name of threads allowed to run.
054             * @return name of the field
055             */
056            String fieldName();
057    
058    
059            //
060            // nested interfaces
061            //
062    
063            /**
064             * An annotation used to designate methods that are only allowed to be run by a thread whose group name is
065             * equal to the string in the field specified by class name and field name.
066             *
067             * @author Mathias Ricken
068             */
069            @Retention(RetentionPolicy.RUNTIME)
070            @Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE})
071    
072            @PredicateLink(value = ReflectionThreadCheckPredicates.class, method = "checkGroupByName")
073            public static @interface ByName {
074                /**
075                 * The name of the class that contains the field specifying the name of threads allowed to run.
076                 *
077                 * @return class containing the field
078                 */
079                String fieldClassName();
080    
081                /**
082                 * The name of the field specifying the name of threads allowed to run.
083                 *
084                 * @return name of the field
085                 */
086                String fieldName();
087                
088                            
089                //
090                // nested interfaces
091                //
092                
093                /**
094                 * Annotation used to designate methods that are only allowed to be run by a thread whose name
095                 * is equal to the string in one of the fields provided, i.e. the individual
096                 * @OnlyThreadWithName.InField.ByName annotations are combined using OR.
097                 */
098                @Retention(RetentionPolicy.RUNTIME)
099                @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
100                        
101                @Combine(Combine.Mode.OR)
102                public static @interface None {
103                    OnlyThreadWithGroupName.InField.ByName[] value();
104                }
105            }
106    
107                    
108            /**
109             * Annotation used to designate methods that are only allowed to be run by a thread whose name
110             * is equal to the string in one of the fields provided, i.e. the individual
111             * @OnlyThreadWithName.InField annotations are combined using OR.
112             */
113            @Retention(RetentionPolicy.RUNTIME)
114            @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
115                    
116            @Combine(Combine.Mode.OR)
117            public static @interface Any {
118                OnlyThreadWithName.InField[] value();
119            }
120        }
121        
122        /**
123         * Annotation used to designate methods that are only allowed to be run by a thread whose
124         * thread group name is equal to one of the names provided, i.e. the individual
125         * @OnlyThreadWithGroupName annotations are combined using OR.
126         */
127        @Retention(RetentionPolicy.RUNTIME)
128        @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
129    
130        @Combine(Combine.Mode.OR)
131        public static @interface Any {
132            OnlyThreadWithGroupName[] value();
133        }
134    }