001 package edu.rice.cs.cunit.instrumentors.threadCheck;
002
003 import edu.rice.cs.cunit.classFile.attributes.AAnnotationsAttributeInfo;
004 import edu.rice.cs.cunit.classFile.MethodInfo;
005 import edu.rice.cs.cunit.threadCheck.Combine;
006
007 import java.io.Serializable;
008 import java.util.HashMap;
009 import java.util.ArrayList;
010 import java.util.List;
011 import java.util.HashSet;
012
013 /**
014 * Class that keeps track of an annotation and the predicate class and method linked to it.
015 */
016 public class PredicateAnnotationRecord implements Serializable {
017 /**
018 * The annotation on the method or class.
019 */
020 public AAnnotationsAttributeInfo.Annotation annotation;
021
022 /**
023 * Hashmap with the parameter name as the key and the parameter descriptors as value, ignoring the first Object.
024 * Used for both @PredicateLink- and @Combine-type annotations.
025 */
026 public HashMap<String, String> paramTypes;
027
028 //
029 // @PredicateLink section
030 //
031
032 /**
033 * Name of the predicate class, or null if @PredicateLink was not specified.
034 */
035 public String predicateClass;
036
037 /**
038 * Name of the predicate method, or null if @PredicateLink was not specified.
039 */
040 public MethodInfo predicateMI;
041
042 /**
043 * The parameter names in the order they appear in the predicate method, ignoring the first Object.
044 */
045 public ArrayList<String> paramNames;
046
047 /**
048 * The values from the annotation, including default values if a value was not specified at
049 * the usage site and a default value was defined, in the order of the parameters in the predicate method.
050 */
051 public ArrayList<AAnnotationsAttributeInfo.Annotation.AMemberValue> valueList;
052
053 /**
054 * Whether method arguments should be passed.
055 */
056 public boolean passArguments;
057
058 //
059 // @Combine section
060 //
061
062 /**
063 * Combine mode, or null if @Combine was not specified.
064 */
065 public Combine.Mode combineMode;
066
067 /**
068 * Hashmap from member name to a list of other predicates that should be combined.
069 */
070 public HashMap<String, ArrayList<PredicateAnnotationRecord>> combinedPredicates;
071
072 public PredicateAnnotationRecord(AAnnotationsAttributeInfo.Annotation annotation,
073 String predicateClass,
074 MethodInfo predicateMI,
075 List<String> paramNames,
076 HashMap<String, String> paramTypes,
077 ArrayList<AAnnotationsAttributeInfo.Annotation.AMemberValue> valueList,
078 boolean passArguments,
079 Combine.Mode combineMode,
080 HashMap<String, ArrayList<PredicateAnnotationRecord>> combinedPredicates) {
081 this.annotation = annotation;
082 this.predicateClass = predicateClass;
083 this.predicateMI = predicateMI;
084 this.combineMode = combineMode;
085 this.paramNames = new ArrayList<String>(paramNames);
086 this.paramTypes = new HashMap<String, String>(paramTypes);
087 this.valueList = new ArrayList<AAnnotationsAttributeInfo.Annotation.AMemberValue>(valueList);
088 this.passArguments = passArguments;
089 this.combinedPredicates = new HashMap<String,ArrayList<PredicateAnnotationRecord>>();
090 HashSet<PredicateAnnotationRecord> allSet = new HashSet<PredicateAnnotationRecord>();
091 for(String key: combinedPredicates.keySet()) {
092 ArrayList<PredicateAnnotationRecord> set = combinedPredicates.get(key);
093 ArrayList<PredicateAnnotationRecord> copy = new ArrayList<PredicateAnnotationRecord>();
094 for(PredicateAnnotationRecord par: set) {
095 allSet.add(par);
096 copy.add(par);
097 }
098 this.combinedPredicates.put(key, copy);
099 }
100 }
101
102 public PredicateAnnotationRecord(PredicateAnnotationRecord otherPAR) {
103 this(otherPAR.annotation,
104 otherPAR.predicateClass,
105 otherPAR.predicateMI,
106 new ArrayList<String>(otherPAR.paramNames),
107 new HashMap<String, String>(otherPAR.paramTypes),
108 new ArrayList<AAnnotationsAttributeInfo.Annotation.AMemberValue>(otherPAR.valueList),
109 otherPAR.passArguments,
110 otherPAR.combineMode,
111 otherPAR.combinedPredicates);
112 }
113
114 // public boolean equals(Object o) {
115 // if (this == o) {
116 // return true;
117 // }
118 // if (o == null || getClass() != o.getClass()) {
119 // return false;
120 // }
121 //
122 // PredicateAnnotationRecord that = (PredicateAnnotationRecord)o;
123 //
124 // if (annotation != null ? !annotation.equals(that.annotation) : that.annotation != null) {
125 // return false;
126 // }
127 // if (combineMode != that.combineMode) {
128 // return false;
129 // }
130 // if (combinedPredicates != null ? !combinedPredicates.equals(that.combinedPredicates) :
131 // that.combinedPredicates != null) {
132 // return false;
133 // }
134 // if (paramNames != null ? !paramNames.equals(that.paramNames) : that.paramNames != null) {
135 // return false;
136 // }
137 // if (paramTypes != null ? !paramTypes.equals(that.paramTypes) : that.paramTypes != null) {
138 // return false;
139 // }
140 // if (predicateClass != null ? !predicateClass.equals(that.predicateClass) : that.predicateClass != null) {
141 // return false;
142 // }
143 // if (predicateMI != null ? !predicateMI.equals(that.predicateMI) : that.predicateMI != null) {
144 // return false;
145 // }
146 // if (valueList != null ? !valueList.equals(that.valueList) : that.valueList != null) {
147 // return false;
148 // }
149 // if (passArguments!=that.passArguments) {
150 // return false;
151 // }
152 //
153 // return true;
154 // }
155 //
156 // public int hashCode() {
157 // int result;
158 // result = (annotation != null ? annotation.hashCode() : 0);
159 // result = 31 * result + (paramTypes != null ? paramTypes.hashCode() : 0);
160 // result = 31 * result + (predicateClass != null ? predicateClass.hashCode() : 0);
161 // result = 31 * result + (predicateMI != null ? predicateMI.hashCode() : 0);
162 // result = 31 * result + (paramNames != null ? paramNames.hashCode() : 0);
163 // result = 31 * result + (valueList != null ? valueList.hashCode() : 0);
164 // result = 31 * result + (combineMode != null ? combineMode.hashCode() : 0);
165 // result = 31 * result + (combinedPredicates != null ? combinedPredicates.hashCode() : 0);
166 // result = 31 * result + (passArguments?1:0);
167 // return result;
168 // }
169
170
171 public boolean equals(Object o) {
172 if (this == o) {
173 return true;
174 }
175 if (o == null || getClass() != o.getClass()) {
176 return false;
177 }
178
179 PredicateAnnotationRecord that = (PredicateAnnotationRecord)o;
180
181 if (passArguments != that.passArguments) {
182 return false;
183 }
184 if (annotation != null ? !annotation.equals(that.annotation) : that.annotation != null) {
185 return false;
186 }
187 if (combineMode != that.combineMode) {
188 return false;
189 }
190 if (combinedPredicates != null ? !combinedPredicates.equals(that.combinedPredicates) :
191 that.combinedPredicates != null) {
192 return false;
193 }
194 if (paramNames != null ? !paramNames.equals(that.paramNames) : that.paramNames != null) {
195 return false;
196 }
197 if (paramTypes != null ? !paramTypes.equals(that.paramTypes) : that.paramTypes != null) {
198 return false;
199 }
200 if (predicateClass != null ? !predicateClass.equals(that.predicateClass) : that.predicateClass != null) {
201 return false;
202 }
203 if (predicateMI != null ? !predicateMI.equals(that.predicateMI) : that.predicateMI != null) {
204 return false;
205 }
206 if (valueList != null ? !valueList.equals(that.valueList) : that.valueList != null) {
207 return false;
208 }
209
210 return true;
211 }
212
213 public int hashCode() {
214 int result;
215 result = (annotation != null ? annotation.hashCode() : 0);
216 result = 31 * result + (paramTypes != null ? paramTypes.hashCode() : 0);
217 result = 31 * result + (predicateClass != null ? predicateClass.hashCode() : 0);
218 result = 31 * result + (predicateMI != null ? predicateMI.hashCode() : 0);
219 result = 31 * result + (paramNames != null ? paramNames.hashCode() : 0);
220 result = 31 * result + (valueList != null ? valueList.hashCode() : 0);
221 result = 31 * result + (passArguments ? 1 : 0);
222 result = 31 * result + (combineMode != null ? combineMode.hashCode() : 0);
223 result = 31 * result + (combinedPredicates != null ? combinedPredicates.hashCode() : 0);
224 return result;
225 }
226
227 public String toString() {
228 return annotation.toStringJava();
229 }
230 }