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 when the monitor of
013 * the field specified by class and field name is owned by some thread, regardless which it is.
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 = "checkSynchronizedFieldByAnyThread")
021 public @interface AnySynchronizedField {
022 /**
023 * The class that contains the field whose monitor some 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 sine 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 when the monitor of
042 * the field specified by class name and field name is owned by some thread, regardless which it is.
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 = "checkSynchronizedFieldByAnyThreadByName")
050 public static @interface ByName {
051 /**
052 * The name of the class that contains the field whose monitor some 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 some to own.
060 *
061 * @return name of the field
062 */
063 String fieldName();
064
065 //
066 // nested interfaces
067 //
068
069 /**
070 * An annotation used to designate methods that are only allowed to be run when one or more of the
071 * monitors of the fields specified are owned by some thread, regardless which it is, i.e. the individual
072 * @AnySynchronizedField.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 AnySynchronizedField.ByName[] value();
080 }
081
082 /**
083 * An annotation used to designate methods that are only allowed to be run when all of the
084 * monitors of the fields specified are owned by some thread, regardless which it is, i.e. the individual
085 * @AnySynchronizedField.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 AnySynchronizedField.ByName[] value();
093 }
094 }
095
096 /**
097 * An annotation used to designate methods that are only allowed to be run when one or more of the
098 * monitors of the fields specified are owned by some thread, regardless which it is, i.e. the individual
099 * @AnySynchronizedField 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 AnySynchronizedField[] value();
107 }
108
109 /**
110 * An annotation used to designate methods that are only allowed to be run when all of the
111 * monitors of the fields specified are owned by some thread, regardless which it is, i.e. the individual
112 * @AnySynchronizedField annotations are combined using AND.
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 AnySynchronizedField[] value();
120 }
121 }