Update of /cvsroot/clirr/clirr/core/src/java/net/sf/clirr/core/internal
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6821
Modified Files:
AbstractDiffReporter.java
Log Message:
Added getSeverity methods, used by checks to reduce severity from ERROR
to INFO for diffs due to items of package or private accessibility.
Index: AbstractDiffReporter.java
===================================================================
RCS file: /cvsroot/clirr/clirr/core/src/java/net/sf/clirr/core/internal/AbstractDiffReporter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractDiffReporter.java 10 Jul 2004 13:37:26 -0000 1.1
+++ AbstractDiffReporter.java 16 Jul 2004 09:44:09 -0000 1.2
@@ -22,11 +22,15 @@
import net.sf.clirr.core.ApiDifference;
import net.sf.clirr.core.Severity;
import net.sf.clirr.core.Message;
+import net.sf.clirr.core.ScopeSelector;
+import net.sf.clirr.core.CheckerException;
import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.JavaClass;
public abstract class AbstractDiffReporter
{
+ private static final Message MSG_UNABLE_TO_DETERMINE_CLASS_SCOPE = new Message(9000);
private ApiDiffDispatcher dispatcher;
@@ -40,9 +44,135 @@
return dispatcher;
}
- protected final void log(Message msg, Severity severity, String clazz, Method method, Field field, String[] args)
+ protected final void log(
+ Message msg,
+ Severity severity,
+ String clazz, Method method, Field field,
+ String[] args)
{
- final ApiDifference diff = new ApiDifference(msg, severity, clazz, null, null, args);
+ final ApiDifference diff = new ApiDifference(
+ msg, severity, clazz, null, null, args);
getApiDiffDispatcher().fireDiff(diff);
}
+
+ /**
+ * Determine whether the severity of the problem should be reduced
+ * to INFO because the specified class is package or private accessibility.
+ * Clirr reports changes at level INFO for all private and package
+ * scoped objects.
+ * <p
+ * Note that the class passed here should always be from the <iold</i
+ * class version, because we're checking whether <iexisting</i code
+ * would have been able to access it (potential compatibility problems)
+ * or not.
+ *
+ * @param clazz is the class the change is being reported about.
+ * @param sev is the severity that should be reported for public/protected
+ * scoped classes.
+ *
+ * @return param sev if the class is public/protected, and Severity.INFO
+ * if the class is package or private scope.
+ */
+ protected final Severity getSeverity(JavaClass clazz, Severity sev)
+ {
+ // use ScopeSelector, not isPublic/isProtected, because the latter
+ // methods don't correctly handle scopes of nested classes.
+ ScopeSelector.Scope scope;
+
+ try
+ {
+ scope = ScopeSelector.getClassScope(clazz);
+ }
+ catch (CheckerException ex)
+ {
+ // Note: this should never happen. If it does, it probably
+ // means clirr has been passed a severely-stuffed-up jar
+ // for analysis.
+ log(MSG_UNABLE_TO_DETERMINE_CLASS_SCOPE,
+ Severity.ERROR, clazz.getClassName(), null, null, null);
+ return sev;
+ }
+
+ if ((scope == ScopeSelector.SCOPE_PUBLIC)
+ || (scope == ScopeSelector.SCOPE_PROTECTED))
+ {
+ return sev;
+ }
+ else
+ {
+ return Severity.INFO;
+ }
+ }
+
+ /**
+ * Determine whether the severity of the problem should be reduced
+ * to INFO because:
+ * <ul
+ * <lithe specified method is package or private accessibility, or</li
+ * <lithe specified method is in a package or private class. </li
+ * </ul
+ * <p
+ * Clirr reports changes at level INFO for all private and package
+ * scoped objects.
+ * <p
+ * Note that the method passed here should always be from the <iold</i
+ * class version, because we're checking whether <iexisting</i code
+ * would have been able to access it (potential compatibility problems)
+ * or not.
+ *
+ * @param clazz is the class containing the method of interest
+ * @param method is the method the change is being reported about.
+ * @param sev is the severity that should be reported for public/protected
+ * scoped methods.
+ *
+ * @return param sev if the method is public/protected, and Severity.INFO
+ * if the method is package or private scope.
+ */
+ protected final Severity getSeverity(JavaClass clazz, Method method, Severity sev)
+ {
+ if (method.isPublic() || method.isProtected())
+ {
+ return getSeverity(clazz, sev);
+ }
+ else
+ {
+ return Severity.INFO;
+ }
+ }
+
+ /**
+ * Determine whether the severity of the problem should be reduced
+ * to INFO because:
+ * <ul
+ * <lithe specified field is package or private accessibility, or</li
+ * <lithe specified field is in a package or private class. </li
+ * </ul
+ * <p
+ * Clirr reports changes at level INFO for all private and package
+ * scoped objects.
+ * <p
+ * Note that the field passed here should always be from the <iold</i
+ * class version, because we're checking whether <iexisting</i code
+ * would have been able to access it (potential compatibility problems)
+ * or not.
+ *
+ * @param clazz is the class containing the method of interest
+ * @param field is the field the change is being reported about.
+ * @param sev is the severity that should be reported for public/protected
+ * scoped field.
+ *
+ * @return param sev if the field is public/protected, and Severity.INFO
+ * if the field is package or private scope.
+ */
+ protected final Severity getSeverity(JavaClass clazz, Field field, Severity sev)
+ {
+ if (field.isPublic() || field.isProtected())
+ {
+ return getSeverity(clazz, sev);
+ }
+ else
+ {
+ return Severity.INFO;
+ }
+ }
}
|