1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.clirr.core.internal;
21
22 import net.sf.clirr.core.ApiDifference;
23 import net.sf.clirr.core.Severity;
24 import net.sf.clirr.core.Message;
25 import net.sf.clirr.core.spi.JavaType;
26 import net.sf.clirr.core.spi.Field;
27 import net.sf.clirr.core.spi.Method;
28 import net.sf.clirr.core.spi.Scope;
29
30 public abstract class AbstractDiffReporter
31 {
32 private static final Message MSG_UNABLE_TO_DETERMINE_CLASS_SCOPE = new Message(9000);
33
34 private ApiDiffDispatcher dispatcher;
35
36 public AbstractDiffReporter(ApiDiffDispatcher dispatcher)
37 {
38 this.dispatcher = dispatcher;
39 }
40
41 protected final ApiDiffDispatcher getApiDiffDispatcher()
42 {
43 return dispatcher;
44 }
45
46 protected final void log(
47 Message msg,
48 Severity severity,
49 String clazz, Method method, Field field,
50 String[] args)
51 {
52 final ApiDifference diff = new ApiDifference(
53 msg, severity, clazz, null, null, args);
54 getApiDiffDispatcher().fireDiff(diff);
55 }
56
57 /***
58 * Determine whether the severity of the problem should be reduced
59 * to INFO because the specified class is package or private accessibility.
60 * Clirr reports changes at level INFO for all private and package
61 * scoped objects.
62 * <p>
63 * Note that the class passed here should always be from the <i>old</i>
64 * class version, because we're checking whether <i>existing</i> code
65 * would have been able to access it (potential compatibility problems)
66 * or not.
67 *
68 * @param clazz is the class the change is being reported about.
69 * @param sev is the severity that should be reported for public/protected
70 * scoped classes.
71 *
72 * @return param sev if the class is public/protected, and Severity.INFO
73 * if the class is package or private scope.
74 */
75 protected final Severity getSeverity(JavaType clazz, Severity sev)
76 {
77 Scope scope = clazz.getEffectiveScope();
78
79 if (scope.isLessVisibleThan(Scope.PROTECTED))
80 {
81 return Severity.INFO;
82 }
83 else
84 {
85 return sev;
86 }
87 }
88
89 /***
90 * Determine whether the severity of the problem should be reduced
91 * to INFO because:
92 * <ul>
93 * <li>the specified method is package or private accessibility, or</li>
94 * <li>the specified method is in a package or private class. </li
95 * </ul>
96 * <p>
97 * Clirr reports changes at level INFO for all private and package
98 * scoped objects.
99 * <p>
100 * Note that the method passed here should always be from the <i>old</i>
101 * class version, because we're checking whether <i>existing</i> code
102 * would have been able to access it (potential compatibility problems)
103 * or not.
104 *
105 * @param clazz is the class containing the method of interest
106 * @param method is the method the change is being reported about.
107 * @param sev is the severity that should be reported for public/protected
108 * scoped methods.
109 *
110 * @return param sev if the method is public/protected, and Severity.INFO
111 * if the method is package or private scope.
112 */
113 protected final Severity getSeverity(JavaType clazz, Method method, Severity sev)
114 {
115
116 if (!method.getDeclaredScope().isLessVisibleThan(Scope.PROTECTED))
117 {
118 return getSeverity(clazz, sev);
119 }
120 else
121 {
122 return Severity.INFO;
123 }
124 }
125
126 /***
127 * Determine whether the severity of the problem should be reduced
128 * to INFO because:
129 * <ul>
130 * <li>the specified field is package or private accessibility, or</li>
131 * <li>the specified field is in a package or private class. </li>
132 * </ul>
133 * <p>
134 * Clirr reports changes at level INFO for all private and package
135 * scoped objects.
136 * <p>
137 * Note that the field passed here should always be from the <i>old</i>
138 * class version, because we're checking whether <i>existing</i> code
139 * would have been able to access it (potential compatibility problems)
140 * or not.
141 *
142 * @param clazz is the class containing the method of interest
143 * @param field is the field the change is being reported about.
144 * @param sev is the severity that should be reported for public/protected
145 * scoped field.
146 *
147 * @return param sev if the field is public/protected, and Severity.INFO
148 * if the field is package or private scope.
149 */
150 protected final Severity getSeverity(JavaType clazz, Field field, Severity sev)
151 {
152 if (!field.getDeclaredScope().isLessVisibleThan(Scope.PROTECTED))
153 {
154 return getSeverity(clazz, sev);
155 }
156 else
157 {
158 return Severity.INFO;
159 }
160 }
161 }