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.checks;
21
22 import net.sf.clirr.core.Severity;
23 import net.sf.clirr.core.Message;
24 import net.sf.clirr.core.internal.AbstractDiffReporter;
25 import net.sf.clirr.core.internal.ApiDiffDispatcher;
26 import net.sf.clirr.core.internal.ClassChangeCheck;
27 import net.sf.clirr.core.spi.JavaType;
28
29 /***
30 * Detects gender changes (a class became an interface or vice versa).
31 *
32 * @author lkuehne
33 */
34 public final class GenderChangeCheck
35 extends AbstractDiffReporter
36 implements ClassChangeCheck
37 {
38 private static final Message MSG_GENDER_CLASS_TO_INTERFACE = new Message(2000);
39 private static final Message MSG_GENDER_INTERFACE_TO_CLASS = new Message(2001);
40
41 /***
42 * Create a new instance of this check.
43 * @param dispatcher the diff dispatcher that distributes the detected changes to the listeners.
44 */
45 public GenderChangeCheck(ApiDiffDispatcher dispatcher)
46 {
47 super(dispatcher);
48 }
49
50
51 /*** {@inheritDoc} */
52 public boolean check(JavaType baseLine, JavaType current)
53 {
54 if (!baseLine.isInterface() && current.isInterface())
55 {
56 log(MSG_GENDER_CLASS_TO_INTERFACE,
57 getSeverity(baseLine, Severity.ERROR),
58 baseLine.getName(), null, null, null);
59 }
60 else if (baseLine.isInterface() && !current.isInterface())
61 {
62 log(MSG_GENDER_INTERFACE_TO_CLASS,
63 getSeverity(baseLine, Severity.ERROR),
64 baseLine.getName(), null, null, null);
65 }
66
67 return true;
68 }
69 }