[Clirr-devel] CVS: clirr/src/java/net/sf/clirr/event ApiDifference.java,1.10,1.11 PlainDiffListener.
Status: Alpha
Brought to you by:
lkuehne
From: <lk...@us...> - 2004-06-27 14:22:16
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2365/src/java/net/sf/clirr/event Modified Files: ApiDifference.java PlainDiffListener.java Severity.java XmlDiffListener.java Log Message: allow differentiating between src and binary compatibility problems Index: ApiDifference.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/ApiDifference.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ApiDifference.java 22 Jun 2004 16:52:10 -0000 1.10 +++ ApiDifference.java 27 Jun 2004 14:21:35 -0000 1.11 @@ -32,8 +32,17 @@ /** human readable change report. */ private String report; - /** severity of the change, as determined by clirr. */ - private Severity severity; + /** + * severity of the change in terms of binary compatibility, + * as determined by clirr. + */ + private Severity binaryCompatibilitySeverity; + + /** + * severity of the change in terms of source compatibility, + * as determined by clirr. + */ + private Severity sourceCompatibilitySeverity; /** The fully qualified class name that is affected by the API change. */ private String affectedClass; @@ -68,9 +77,9 @@ /** * Create a new API differnce representation. * - * @param report a human readable string describing the change that was made. - * @param severity the severity in terms of binary API compatibility. - * @param clazz the fully qualified class name where the change occured + * @param report a human readable string describing the change that was made, must be non-null. + * @param severity the severity in terms of binary and source code compatibility, must be non-null. + * @param clazz the fully qualified class name where the change occured, must be non-null. * @param method the method signature of the method that changed, <code>null</code> * if no method was affected. * @param field the field name where the change occured, <code>null</code> @@ -78,24 +87,80 @@ */ public ApiDifference(String report, Severity severity, String clazz, String method, String field) { + this(report, severity, severity, clazz, method, field); + } + + /** + * Create a new API differnce representation. + * + * @param report a human readable string describing the change that was made, must be non-null. + * @param binarySeverity the severity in terms of binary compatibility, must be non-null. + * @param sourceSeverity the severity in terms of source code compatibility, must be non-null. + * @param clazz the fully qualified class name where the change occured, must be non-null. + * @param method the method signature of the method that changed, <code>null</code> + * if no method was affected. + * @param field the field name where the change occured, <code>null</code> + * if no field was affected. + */ + public ApiDifference(String report, Severity binarySeverity, Severity sourceSeverity, + String clazz, String method, String field) + { + checkNonNull(report); + checkNonNull(binarySeverity); + checkNonNull(sourceSeverity); + checkNonNull(clazz); + this.report = report; - this.severity = severity; + this.binaryCompatibilitySeverity = binarySeverity; + this.sourceCompatibilitySeverity = sourceSeverity; this.affectedClass = clazz; this.affectedField = field; this.affectedMethod = method; } + private void checkNonNull(Object o) + { + if (o == null) + { + throw new IllegalArgumentException(); + } + } + /** - * The Severity of the API difference. ERROR means that clients will - * definately break, WARNING means that clients may break, depending - * on how they use the library. See the eclipse paper for further - * explanation. + * The Severity of the API difference in terms of binary compatibility. + * ERROR means that clients will definitely break, WARNING means that + * clients may break, depending on how they use the library. + * See the eclipse paper for further explanation. * - * @return the severity of the API difference. + * @return the severity of the API difference in terms of binary compatibility. */ - public Severity getSeverity() + public Severity getBinaryCompatibilitySeverity() { - return severity; + return binaryCompatibilitySeverity; + } + + /** + * The Severity of the API difference in terms of source compatibility. + * Sometimes this is different than {@link #getBinaryCompatibilitySeverity + * binary compatibility severity}, for example adding a checked exception + * to a method signature is binary compatible but not source compatible. + * ERROR means that clients will definitely break, WARNING means that + * clients may break, depending on how they use the library. + * See the eclipse paper for further explanation. + * + * @return the severity of the API difference in terms of source code + * compatibility. + */ + public Severity getSourceCompatibilitySeverity() + { + return sourceCompatibilitySeverity; + } + + public Severity getMaximumSeverity() + { + final Severity src = getSourceCompatibilitySeverity(); + final Severity bin = getBinaryCompatibilitySeverity(); + return src.compareTo(bin) < 0 ? bin : src; } /** @@ -140,7 +205,7 @@ */ public String toString() { - return report + " (" + severity + ") - " + return report + " (" + binaryCompatibilitySeverity + ") - " + getAffectedClass() + '[' + getAffectedField() + '/' + getAffectedMethod() + ']'; } @@ -161,18 +226,24 @@ final ApiDifference other = (ApiDifference) o; - if (report != null ? !report.equals(other.report) : other.report != null) + if (!report.equals(other.report)) { return false; } - if (severity != null ? !severity.equals(other.severity) : other.severity != null) + if (!binaryCompatibilitySeverity.equals(other.binaryCompatibilitySeverity)) { return false; } + if (!sourceCompatibilitySeverity.equals(other.sourceCompatibilitySeverity)) + { + return false; + } + + final String otherClass = other.affectedClass; - if (affectedClass != null ? !affectedClass.equals(otherClass) : otherClass != null) + if (!affectedClass.equals(otherClass)) { return false; } @@ -199,10 +270,13 @@ { int result; result = report != null ? report.hashCode() : 0; - result = HASHCODE_MAGIC * result + (severity != null ? severity.hashCode() : 0); - result = HASHCODE_MAGIC * result + (affectedClass != null ? affectedClass.hashCode() : 0); + result = HASHCODE_MAGIC * result + binaryCompatibilitySeverity.hashCode(); + result = HASHCODE_MAGIC * result + sourceCompatibilitySeverity.hashCode(); + result = HASHCODE_MAGIC * result + affectedClass.hashCode(); result = HASHCODE_MAGIC * result + (affectedMethod != null ? affectedMethod.hashCode() : 0); result = HASHCODE_MAGIC * result + (affectedField != null ? affectedField.hashCode() : 0); return result; } + + } Index: PlainDiffListener.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/PlainDiffListener.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- PlainDiffListener.java 22 May 2004 13:26:03 -0000 1.4 +++ PlainDiffListener.java 27 Jun 2004 14:21:35 -0000 1.5 @@ -34,7 +34,7 @@ public void reportDiff(ApiDifference difference) { PrintStream out = getOutputStream(); - out.print(difference.getSeverity().toString()); + out.print(difference.getMaximumSeverity().toString()); out.print(": "); out.println(difference.getReport()); } Index: Severity.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/Severity.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Severity.java 22 May 2004 13:26:03 -0000 1.5 +++ Severity.java 27 Jun 2004 14:21:35 -0000 1.6 @@ -24,28 +24,37 @@ * * @author lkuehne */ -public final class Severity +public final class Severity implements Comparable { private String representation; + private int value; - private Severity(String representation) + private Severity(String representation, int value) { this.representation = representation; + this.value = value; } /** marks an api difference that is binary compatible. */ - public static final Severity INFO = new Severity("INFO"); + public static final Severity INFO = new Severity("INFO", 0); /** marks an api difference that might be binary incompatible. */ - public static final Severity WARNING = new Severity("WARNING"); + public static final Severity WARNING = new Severity("WARNING", 1); /** marks an api difference that is binary incompatible. */ - public static final Severity ERROR = new Severity("ERROR"); + public static final Severity ERROR = new Severity("ERROR", 2); /** @see Object#toString() */ public String toString() { return representation; } + + /** {@inheritDoc} */ + public int compareTo(Object o) + { + Severity other = (Severity) o; + return this.value - other.value; + } } Index: XmlDiffListener.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/XmlDiffListener.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- XmlDiffListener.java 27 May 2004 16:10:50 -0000 1.10 +++ XmlDiffListener.java 27 Jun 2004 14:21:35 -0000 1.11 @@ -43,7 +43,8 @@ { PrintStream out = getOutputStream(); out.print(" <" + DIFFERENCE); - out.print(" severity=\"" + difference.getSeverity() + "\""); + out.print(" binseverity=\"" + difference.getBinaryCompatibilitySeverity() + "\""); + out.print(" srcseverity=\"" + difference.getSourceCompatibilitySeverity() + "\""); out.print(" class=\"" + difference.getAffectedClass() + "\""); if (difference.getAffectedMethod() != null) { |