View Javadoc
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.HashSet; 23 import java.util.Iterator; 24 import java.util.Set; 25 26 import net.sf.clirr.event.Severity; 27 import net.sf.clirr.framework.AbstractDiffReporter; 28 import net.sf.clirr.framework.ApiDiffDispatcher; 29 import net.sf.clirr.framework.ClassChangeCheck; 30 import org.apache.bcel.classfile.JavaClass; 31 32 /*** 33 * Detects changes in the set of interfaces implemented by a class. 34 * 35 * @author lkuehne 36 */ 37 public final class InterfaceSetCheck 38 extends AbstractDiffReporter 39 implements ClassChangeCheck 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 InterfaceSetCheck(ApiDiffDispatcher dispatcher) 46 { 47 super(dispatcher); 48 } 49 50 /*** {@inheritDoc} */ 51 public void check(JavaClass compatBaseline, JavaClass currentVersion) 52 { 53 JavaClass[] compatInterfaces = compatBaseline.getAllInterfaces(); 54 JavaClass[] currentInterfaces = currentVersion.getAllInterfaces(); 55 56 // Note: an interface has itself in the set of all interfaces 57 // we have to consider that below to avoid funny messages for gender changes 58 59 // Note: getAllInterfaces might return multiple array entries with the same 60 // interface, so we need to use sets to remove duplicates... 61 Set compat = createClassSet(compatInterfaces); 62 Set current = createClassSet(currentInterfaces); 63 64 final String className = compatBaseline.getClassName(); 65 66 for (Iterator it = compat.iterator(); it.hasNext();) 67 { 68 String compatInterface = (String) it.next(); 69 70 if (!current.contains(compatInterface) 71 && !compatInterface.equals(className)) 72 { 73 log("Removed " + compatInterface 74 + " from the set of interfaces implemented by " 75 + className, 76 Severity.ERROR, className, null, null); 77 } 78 else 79 { 80 current.remove(compatInterface); 81 } 82 } 83 84 for (Iterator it = current.iterator(); it.hasNext();) 85 { 86 String name = (String) it.next(); 87 if (!name.equals(className)) 88 { 89 log("Added " + name 90 + " to the set of implemented interfaces implemented by " 91 + className, 92 Severity.INFO, className, null, null); 93 } 94 } 95 } 96 97 private Set createClassSet(JavaClass[] classes) 98 { 99 Set current = new HashSet(); 100 for (int i = 0; i < classes.length; i++) 101 { 102 String currentInterface = classes[i].getClassName(); 103 current.add(currentInterface); 104 } 105 return current; 106 } 107 }

This page was automatically generated by Maven