1 20 package net.sf.clirr.core; 21 22 23 28 public final class ApiDifference 29 { 30 private static final int HASHCODE_MAGIC = 29; 31 32 36 private Message message = null; 37 38 39 private String report; 40 41 45 private Severity binaryCompatibilitySeverity; 46 47 51 private Severity sourceCompatibilitySeverity; 52 53 54 private String affectedClass; 55 56 68 private String affectedMethod; 69 70 81 private String affectedField; 82 83 88 private String [] extraInfo; 89 90 93 public ApiDifference( 94 Message message, 95 Severity severity, 96 String clazz, 97 String method, 98 String field, 99 String [] args) 100 { 101 this(message, severity, severity, clazz, method, field, args); 102 } 103 104 129 public ApiDifference( 130 Message message, 131 Severity binarySeverity, Severity sourceSeverity, 132 String clazz, String method, String field, 133 String [] args) 134 { 135 checkNonNull(message); 136 checkNonNull(binarySeverity); 137 checkNonNull(sourceSeverity); 138 checkNonNull(clazz); 139 140 this.message = message; 141 this.binaryCompatibilitySeverity = binarySeverity; 142 this.sourceCompatibilitySeverity = sourceSeverity; 143 this.affectedClass = clazz; 144 this.affectedField = field; 145 this.affectedMethod = method; 146 this.extraInfo = args; 147 } 148 149 152 private void checkNonNull(Object o) 153 { 154 if (o == null) 155 { 156 throw new IllegalArgumentException (); 157 } 158 } 159 160 166 public Message getMessage() 167 { 168 return message; 169 } 170 171 179 public Severity getBinaryCompatibilitySeverity() 180 { 181 return binaryCompatibilitySeverity; 182 } 183 184 196 public Severity getSourceCompatibilitySeverity() 197 { 198 return sourceCompatibilitySeverity; 199 } 200 201 204 public Severity getMaximumSeverity() 205 { 206 final Severity src = getSourceCompatibilitySeverity(); 207 final Severity bin = getBinaryCompatibilitySeverity(); 208 return src.compareTo(bin) < 0 ? bin : src; 209 } 210 211 216 public String getReport(MessageTranslator translator) 217 { 218 if (report != null) 219 { 220 return report; 221 } 222 223 String desc = translator.getDesc(message); 224 int nArgs = 0; 225 if (extraInfo != null) 226 { 227 nArgs = extraInfo.length; 228 } 229 String [] strings = new String [nArgs + 3]; 230 strings[0] = affectedClass; 231 strings[1] = affectedMethod; 232 strings[2] = affectedField; 233 for (int i = 0; i < nArgs; ++i) 234 { 235 strings[i + 3] = extraInfo[i]; 236 } 237 238 return java.text.MessageFormat.format(desc, strings); 239 } 240 241 245 public String getAffectedClass() 246 { 247 return affectedClass; 248 } 249 250 254 public String getAffectedMethod() 255 { 256 return affectedMethod; 257 } 258 259 263 public String getAffectedField() 264 { 265 return affectedField; 266 } 267 268 271 public String toString() 272 { 273 StringBuffer buf = new StringBuffer (); 274 buf.append(message.getId()); 275 appendCommonData(buf); 276 return buf.toString(); 277 } 278 279 283 public String toString(MessageTranslator translator) 284 { 285 StringBuffer buf = new StringBuffer (); 286 buf.append(getReport(translator)); 287 appendCommonData(buf); 288 return buf.toString(); 289 } 290 291 296 private void appendCommonData(StringBuffer buf) 297 { 298 buf.append(" ("); 299 buf.append(binaryCompatibilitySeverity); 300 301 if (sourceCompatibilitySeverity != binaryCompatibilitySeverity) 302 { 303 buf.append(","); 304 buf.append(sourceCompatibilitySeverity); 305 } 306 307 buf.append(") - "); 308 buf.append(affectedClass); 309 buf.append("["); 310 buf.append(affectedField); 311 buf.append("/"); 312 buf.append(affectedMethod); 313 buf.append("]"); 314 } 315 } 316 | Popular Tags |