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 net.sf.clirr.event.Severity; 23 import net.sf.clirr.framework.AbstractDiffReporter; 24 import net.sf.clirr.framework.ApiDiffDispatcher; 25 import net.sf.clirr.framework.ClassChangeCheck; 26 import org.apache.bcel.classfile.JavaClass; 27 28 /*** 29 * Detects changes in class modifiers (abstract, final). 30 * 31 * @author lkuehne 32 */ 33 public final class ClassModifierCheck 34 extends AbstractDiffReporter 35 implements ClassChangeCheck 36 { 37 /*** 38 * Create a new instance of this check. 39 * @param dispatcher the diff dispatcher that distributes the detected changes to the listeners. 40 */ 41 public ClassModifierCheck(ApiDiffDispatcher dispatcher) 42 { 43 super(dispatcher); 44 } 45 46 /*** {@inheritDoc} */ 47 public void check(JavaClass compatBaseLine, JavaClass currentVersion) 48 { 49 final boolean currentIsFinal = currentVersion.isFinal(); 50 final boolean compatIsFinal = compatBaseLine.isFinal(); 51 final boolean currentIsAbstract = currentVersion.isAbstract(); 52 final boolean compatIsAbstract = compatBaseLine.isAbstract(); 53 final boolean currentIsInterface = currentVersion.isInterface(); 54 final boolean compatIsInterface = compatBaseLine.isInterface(); 55 56 final String className = compatBaseLine.getClassName(); 57 58 // TODO: There are cases when nonfinal classes are effectively final 59 // because they do not have public or protected ctors. For such 60 // classes we should not emit errors when a final modifier is 61 // introduced. 62 63 if (compatIsFinal && !currentIsFinal) 64 { 65 log("Removed final modifier in class " + className, 66 Severity.INFO, className, null, null); 67 } 68 else if (!compatIsFinal && currentIsFinal) 69 { 70 log("Added final modifier in class " + className, 71 Severity.ERROR, className, null, null); 72 } 73 74 // interfaces are always abstract, don't report gender change here 75 if (compatIsAbstract && !currentIsAbstract && !compatIsInterface) 76 { 77 log("Removed abstract modifier in class " + className, 78 Severity.INFO, className, null, null); 79 } 80 else if (!compatIsAbstract && currentIsAbstract && !currentIsInterface) 81 { 82 log("Added abstract modifier in class " + className, 83 Severity.ERROR, className, null, null); 84 } 85 } 86 87 }

This page was automatically generated by Maven