1 //////////////////////////////////////////////////////////////////////////////
2 // Clirr: compares two versions of a java library for binary compatibility
3 // Copyright (C) 2003 - 2004 Lars Kühne
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 //////////////////////////////////////////////////////////////////////////////
19
20 package net.sf.clirr.checks;
21
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25
26 import net.sf.clirr.event.ApiDifference;
27 import net.sf.clirr.event.Severity;
28 import net.sf.clirr.framework.AbstractDiffReporter;
29 import net.sf.clirr.framework.ApiDiffDispatcher;
30 import net.sf.clirr.framework.ClassChangeCheck;
31 import org.apache.bcel.classfile.JavaClass;
32 import org.apache.bcel.util.ClassSet;
33
34 /***
35 * Detects gender changes (a class became an interface or vice versa).
36 *
37 * @author lkuehne
38 */
39 public final class GenderChangeCheck
40 extends AbstractDiffReporter
41 implements ClassChangeCheck
42 {
43
44 /***
45 * Create a new instance of this check.
46 * @param dispatcher the diff dispatcher that distributes the detected changes to the listeners.
47 */
48 public GenderChangeCheck(ApiDiffDispatcher dispatcher)
49 {
50 super(dispatcher);
51 }
52
53
54 /*** {@inheritDoc} */
55 public void check(JavaClass baseLine, JavaClass current)
56 {
57 if (baseLine.isClass() != current.isClass())
58 {
59 getApiDiffDispatcher().fireDiff(new ApiDifference(
60 "Changed Gender of " + baseLine.getClassName(), Severity.ERROR,
61 baseLine.getClassName(), null, null)
62 );
63 }
64 }
65
66 // TODO: This should be a method in BCEL's ClassSet !!!
67 private JavaClass findClass(String className, ClassSet classSet)
68 {
69 JavaClass[] classes = classSet.toArray();
70 for (int i = 0; i < classes.length; i++)
71 {
72 JavaClass clazz = classes[i];
73 if (clazz.getClassName().equals(className))
74 {
75 return clazz;
76 }
77 }
78 throw new IllegalStateException();
79 }
80
81 private String[] intersectionClassNames(ClassSet setA, ClassSet setB)
82 {
83 String[] aNames = setA.getClassNames();
84 String[] bNames = setB.getClassNames();
85 Arrays.sort(aNames);
86 Arrays.sort(bNames);
87
88 List helper = new ArrayList();
89
90 for (int i = 0; i < aNames.length; i++)
91 {
92 String aName = aNames[i];
93 if (Arrays.binarySearch(bNames, aName) >= 0)
94 {
95 helper.add(aName);
96 }
97 }
98
99 String[] retVal = new String[helper.size()];
100 helper.toArray(retVal);
101 return retVal;
102 }
103 }
This page was automatically generated by Maven