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 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 = "checkName")
019 public @interface OnlyThreadWithName {
020 /**
021 * Name of the thread. If the regex member is true, then this is treated as a regular expression.
022 * @return name or regular expression for the 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 name is equal to the
039 * 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 = "checkName")
045 public static @interface InField {
046 /**
047 * The class that contains the field specifying the 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 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 name is equal to the
065 * string in the field specified by class name and field name.
066 */
067 @Retention(RetentionPolicy.RUNTIME)
068 @Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE})
069
070 @PredicateLink(value = ReflectionThreadCheckPredicates.class, method = "checkNameByName")
071 public static @interface ByName {
072 /**
073 * The name of the class that contains the field specifying the name of threads allowed to run.
074 * @return class containing the field
075 */
076 String fieldClassName();
077
078 /**
079 * The name of the field specifying the name of threads allowed to run.
080 * @return name of the field
081 */
082 String fieldName();
083
084
085 //
086 // nested interfaces
087 //
088
089 /**
090 * Annotation used to designate methods that are only allowed to be run by a thread whose name
091 * is equal to the string in one of the fields provided, i.e. the individual
092 * @OnlyThreadWithName.InField.ByName annotations are combined using OR.
093 */
094 @Retention(RetentionPolicy.RUNTIME)
095 @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
096
097 @Combine(Combine.Mode.OR)
098 public static @interface Any {
099 OnlyThreadWithName.InField.ByName[] value();
100 }
101 }
102
103 /**
104 * Annotation used to designate methods that are only allowed to be run by a thread whose name
105 * is equal to the string in one of the fields provided, i.e. the individual
106 * @OnlyThreadWithName.InField annotations are combined using OR.
107 */
108 @Retention(RetentionPolicy.RUNTIME)
109 @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
110
111 @Combine(Combine.Mode.OR)
112 public static @interface Any {
113 OnlyThreadWithName.InField[] value();
114 }
115 }
116
117 /**
118 * Annotation used to designate methods that are only allowed to be run by a thread whose name
119 * is equal to one of the names provided, i.e. the individual @OnlyThreadWithName annotations
120 * are combined using OR.
121 */
122 @Retention(RetentionPolicy.RUNTIME)
123 @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
124
125 @Combine(Combine.Mode.OR)
126 public static @interface Any {
127 OnlyThreadWithName[] value();
128 }
129 }