From: Lars K?h. <lk...@us...> - 2003-12-27 19:15:26
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/event In directory sc8-pr-cvs1:/tmp/cvs-serv6028/src/java/net/sf/clirr/event Modified Files: ApiDifference.java FileDiffListener.java XmlDiffListener.java Log Message: added information about affected class/method/field to ApiDifference This is a first step towards filtering diffs to let the user specify changes that are OK Index: ApiDifference.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/ApiDifference.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ApiDifference.java 5 Oct 2003 17:56:31 -0000 1.4 +++ ApiDifference.java 27 Dec 2003 19:08:42 -0000 1.5 @@ -21,32 +21,63 @@ /** - * TODO: Add structure. - * E.g. - * - origfile, newfile - * - Class-/MethodName + * Describes an API change. + * * @author Lars */ public final class ApiDifference { + private static final int HASHCODE_MAGIC = 29; + /** human readable change report. */ private String report; + /** severity of the change, as determined by clirr. */ private Severity severity; - //private boolean expected; + /** The fully qualified class name that is affected by the API change. */ + private String affectedClass; + + /** + * The method that is affected, if any. + * <p/> + * The content is the method name plus the fully qualified + * parameter types separated by comma and space and enclosed in + * brackets, e.g. "doStuff(java.lang.String, int)". + * <p/> + * This value is <code>null</code> if no single method is + * affected, i.e. if the + * api change affects a field or is global + * (like "class is now final"). + */ + private String affectedMethod; + + /** + * The field that is affected, if any. + * <p/> + * The content is the field name, e.g. "someValue". + * Type information for the field is not available. + * <p/> + * This value is <code>null</code> if no single field is + * affected, i.e. if the + * api change affects a method or is global + * (like "class is now final"). + */ + private String affectedField; /** * Create a new API differnce representation. - * - * @param report a human readable string describing the change that was made. + * + * @param report a human readable string describing the change that was made. * @param severity the severity in terms of binary API compatibility. */ - public ApiDifference(String report, Severity severity /*, boolean expected*/) + public ApiDifference(String report, Severity severity, String clazz, String method, String field) { this.report = report; this.severity = severity; -// this.expected = expected; + this.affectedClass = clazz; + this.affectedField = field; + this.affectedMethod = method; } /** @@ -54,7 +85,7 @@ * definately 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. */ public Severity getSeverity() @@ -62,25 +93,42 @@ return severity; } + /** + * Human readable api change description. + * + * @return a human readable description of this API difference. + */ public String getReport() { return report; } - /* - public boolean isExpected() + public String getAffectedClass() + { + return affectedClass; + } + + public String getAffectedMethod() + { + return affectedMethod; + } + + public String getAffectedField() { - return expected; + return affectedField; } - */ - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public String toString() { - return report + " (" + severity + ")"; + return report + " (" + severity + ')'; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public boolean equals(Object o) { if (this == o) @@ -93,13 +141,25 @@ return false; } - final ApiDifference apiDifference = (ApiDifference) o; + final ApiDifference other = (ApiDifference) o; - if (report != null ? !report.equals(apiDifference.report) : apiDifference.report != null) + if (report != null ? !report.equals(other.report) : other.report != null) + { + return false; + } + if (severity != null ? !severity.equals(other.severity) : other.severity != null) + { + return false; + } + if (affectedClass != null ? !affectedClass.equals(other.affectedClass) : other.affectedClass != null) + { + return false; + } + if (affectedMethod != null ? !affectedMethod.equals(other.affectedMethod) : other.affectedMethod != null) { return false; } - if (severity != null ? !severity.equals(apiDifference.severity) : apiDifference.severity != null) + if (affectedField != null ? !affectedField.equals(other.affectedField) : other.affectedField != null) { return false; } @@ -110,8 +170,11 @@ public int hashCode() { int result; - result = (report != null ? report.hashCode() : 0); - result = 29 * result + (severity != null ? severity.hashCode() : 0); + 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 + (affectedMethod != null ? affectedMethod.hashCode() : 0); + result = HASHCODE_MAGIC * result + (affectedField != null ? affectedField.hashCode() : 0); return result; } } Index: FileDiffListener.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/FileDiffListener.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- FileDiffListener.java 27 Sep 2003 05:28:43 -0000 1.5 +++ FileDiffListener.java 27 Dec 2003 19:08:42 -0000 1.6 @@ -43,12 +43,12 @@ { if (outFile == null) { - this.outputStream = System.out; + outputStream = System.out; } else { final OutputStream out = new FileOutputStream(outFile); - this.outputStream = new PrintStream(out); + outputStream = new PrintStream(out); } } Index: XmlDiffListener.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/XmlDiffListener.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XmlDiffListener.java 27 Dec 2003 17:43:53 -0000 1.5 +++ XmlDiffListener.java 27 Dec 2003 19:08:42 -0000 1.6 @@ -26,7 +26,7 @@ * A DiffListener that reports any detected difference to * an XML file. That file can be used by subsequent processing steps * to create nice looking reports in HTML, PDF, etc. - * + * * @author lkuehne */ public final class XmlDiffListener extends FileDiffListener @@ -44,12 +44,22 @@ PrintStream out = getOutputStream(); out.print(" <" + DIFFERENCE); out.print(" severity=\"" + difference.getSeverity() + "\">"); + out.print(" class=\"" + difference.getAffectedClass() + "\""); + if (difference.getAffectedMethod() != null) + { + out.print(" method=\"" + difference.getAffectedMethod() + "\""); + } + if (difference.getAffectedField() != null) + { + out.print(" field=\"" + difference.getAffectedField() + "\""); + } out.print(difference.getReport()); // TODO: XML escapes?? out.println("</" + DIFFERENCE + '>'); } /** * Writes an XML header and toplevel tag to the xml stream. + * * @see DiffListener#start() */ public void start() @@ -70,6 +80,7 @@ /** * Closes the toplevel tag that was opened in start. + * * @see DiffListener#stop() */ protected void writeFooter() |