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
013     * method argument indexed by value is null.
014     * @author Mathias Ricken
015     */
016    @Retention(RetentionPolicy.RUNTIME)
017    @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
018    
019    @PredicateLink(value = ThreadCheckPredicates.class, method = "checkNumberBoundedArgument", arguments = true)
020    public @interface NumberBoundedArgument {
021        /**
022         * Mode of bounding.
023         */
024        public static enum Mode {
025            /**
026             * Number must be less than bound.
027             */
028            LESS,
029    
030            /**
031             * Number must be less than or equal to bound.
032             */
033            LESS_EQ,
034    
035            /**
036             * Number must be greater than bound.
037             */
038            GREATER,
039    
040            /**
041             * Number must be greater than or bound.
042             */
043            GREATER_EQ,
044    
045            /**
046             * Number must be less than or equal to upperBound and greater than or equal to bound.
047             */
048            IN_EQ,
049    
050            /**
051             * Number must be less than upperBound and less than bound.
052             */
053            IN,
054    
055            /**
056             * Number must be greater than or equal to upperBound or less than or equal to bound.
057             */
058            OUT_EQ,
059    
060            /**
061             * Number must be greater than upperBbound or less than bound.
062             */
063            OUT
064        }
065    
066        /**
067         * Class containing the predicate method.
068         * @return class containing the predicate method.
069         */
070        Mode mode();
071    
072        /**
073         * Index of the method argument.
074         * @return index of the method argument to be bounded
075         */
076        int index();
077    
078        /**
079         * Lower bound.
080         * @return the lower bound for the comparison.
081         */
082        double bound();
083    
084        /**
085         * Upper bound.
086         * @return the upper bound for the comparison, only used for IN_EQ, IN, OUT_EQ and OUT
087         */
088        double upperBound() default 0;
089    
090    
091        //
092        // nested interfaces
093        //
094    
095        /**
096         * Annotation used to designate methods that are only allowed to be run if
097         * one or more of the bounds are met, i.e. the individual
098         * @NumberBoundedArgument annotations are combined using OR.
099         */
100        @Retention(RetentionPolicy.RUNTIME)
101        @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
102    
103        @Combine(Combine.Mode.OR)
104        public static @interface Any {
105            NumberBoundedArgument[] value();
106        }
107    
108        /**
109         * Annotation used to designate methods that are only allowed to be run if
110         * all of the bounds are met, i.e. the individual
111         * @NumberBoundedArgument annotations are combined using ALL.
112         */
113        @Retention(RetentionPolicy.RUNTIME)
114        @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
115    
116        @Combine(Combine.Mode.AND)
117        public static @interface All {
118            NumberBoundedArgument[] value();
119        }
120    
121        /**
122         * Annotation used to designate methods that are only allowed to be run if
123         * none of the bounds are met, i.e. the individual
124         * @NumberBoundedArgument annotations are combined using NOT.
125         */
126        @Retention(RetentionPolicy.RUNTIME)
127        @Target({ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.TYPE})
128    
129        @Combine(Combine.Mode.NOT)
130        public static @interface None {
131            NumberBoundedArgument[] value();
132        }
133    }