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.List;
24
25 import net.sf.clirr.event.Severity;
26 import net.sf.clirr.framework.AbstractDiffReporter;
27 import net.sf.clirr.framework.ApiDiffDispatcher;
28 import net.sf.clirr.framework.ClassChangeCheck;
29 import org.apache.bcel.classfile.JavaClass;
30
31 /***
32 * Detects changes in the set of superclasses.
33 *
34 * @author lkuehne
35 */
36 public final class ClassHierarchyCheck
37 extends AbstractDiffReporter
38 implements ClassChangeCheck
39 {
40 /***
41 * Create a new instance of this check.
42 * @param dispatcher the diff dispatcher that distributes the detected changes to the listeners.
43 */
44 public ClassHierarchyCheck(ApiDiffDispatcher dispatcher)
45 {
46 super(dispatcher);
47 }
48
49 private List getSetDifference(JavaClass[] orig, JavaClass[] subtracted)
50 {
51 List list1 = getClassNames(orig);
52 List list2 = getClassNames(subtracted);
53
54 List retval = new ArrayList(list1);
55 retval.removeAll(list2);
56
57 return retval;
58 }
59
60 private List getClassNames(JavaClass[] orig)
61 {
62 List list = new ArrayList(orig.length);
63 for (int i = 0; i < orig.length; i++)
64 {
65 JavaClass javaClass = orig[i];
66 list.add(javaClass.getClassName());
67 }
68 return list;
69 }
70
71 /*** {@inheritDoc} */
72 public void check(JavaClass compatBaseline, JavaClass currentVersion)
73 {
74 JavaClass[] compatSuper = compatBaseline.getSuperClasses();
75 JavaClass[] currentSuper = currentVersion.getSuperClasses();
76
77 boolean isThrowable = false;
78 for (int i = 0; i < compatSuper.length; i++)
79 {
80 JavaClass javaClass = compatSuper[i];
81 if ("java.lang.Throwable".equals(javaClass.getClassName()))
82 {
83 isThrowable = true;
84 }
85 }
86
87 List added = getSetDifference(currentSuper, compatSuper);
88 List removed = getSetDifference(compatSuper, currentSuper);
89
90 final String className = compatBaseline.getClassName();
91 for (int i = 0; i < added.size(); i++)
92 {
93 String s = (String) added.get(i);
94 log("Added " + s + " to the list of superclasses of " + className,
95 isThrowable ? Severity.WARNING : Severity.INFO, className, null, null);
96 }
97
98 for (int i = 0; i < removed.size(); i++)
99 {
100 String s = (String) removed.get(i);
101 log("Removed " + s + " from the list of superclasses of " + className,
102 Severity.ERROR, className, null, null);
103 }
104 }
105 }
This page was automatically generated by Maven