Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 117   Methods: 12
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
IncompatibleDifferenceStrategy.java - 100% 100% 100%
coverage
 1    /*
 2    * Copyright (c) 2001-2009, Jean Tessier
 3    * All rights reserved.
 4    *
 5    * Redistribution and use in source and binary forms, with or without
 6    * modification, are permitted provided that the following conditions
 7    * are met:
 8    *
 9    * * Redistributions of source code must retain the above copyright
 10    * notice, this list of conditions and the following disclaimer.
 11    *
 12    * * Redistributions in binary form must reproduce the above copyright
 13    * notice, this list of conditions and the following disclaimer in the
 14    * documentation and/or other materials provided with the distribution.
 15    *
 16    * * Neither the name of Jean Tessier nor the names of his contributors
 17    * may be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 24    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31    */
 32   
 33    package com.jeantessier.diff;
 34   
 35    import java.util.*;
 36   
 37    import com.jeantessier.classreader.*;
 38   
 39    /**
 40    * TODO class comments
 41    */
 42    public class IncompatibleDifferenceStrategy extends APIDifferenceStrategy {
 43  139 public IncompatibleDifferenceStrategy(DifferenceStrategy strategy) {
 44  139 super(strategy);
 45    }
 46   
 47  32 public boolean isClassDifferent(Classfile oldClass, Classfile newClass) {
 48  32 return isRemoved(oldClass, newClass) ||
 49    (!isNew(oldClass, newClass) &&
 50    isClassModified(oldClass, newClass));
 51    }
 52   
 53  163 public boolean isFieldDifferent(Field_info oldField, Field_info newField) {
 54  163 return isRemoved(oldField, newField) ||
 55    isDeprecationModified(oldField, newField) ||
 56    isDeclarationModified(oldField, newField);
 57    }
 58   
 59  166 public boolean isMethodDifferent(Method_info oldMethod, Method_info newMethod) {
 60  166 return isRemoved(oldMethod, newMethod) ||
 61    isDeprecationModified(oldMethod, newMethod) ||
 62    isDeclarationModified(oldMethod, newMethod);
 63    }
 64   
 65  6 public boolean isPackageDifferent(Map<String, Classfile> oldPackage, Map<String, Classfile> newPackage) {
 66  6 return isPackageRemoved(oldPackage, newPackage) ||
 67    (!isPackageNew(oldPackage, newPackage) &&
 68    isPackageModified(oldPackage, newPackage));
 69    }
 70   
 71  36 public boolean isDeclarationModified(Classfile oldClass, Classfile newClass) {
 72  36 return oldClass != null && newClass != null &&
 73    ((oldClass.isPublic() && !newClass.isPublic()) ||
 74    (oldClass.isInterface() != newClass.isInterface()) ||
 75    (!oldClass.isAbstract() && newClass.isAbstract()) ||
 76    (!oldClass.isFinal() && newClass.isFinal()) ||
 77    isExtendsClauseModified(oldClass, newClass) ||
 78    isImplementsClauseModified(oldClass, newClass));
 79    }
 80   
 81  31 private boolean isExtendsClauseModified(Classfile oldClass, Classfile newClass) {
 82  31 return !oldClass.getSuperclassName().equals(newClass.getSuperclassName());
 83    }
 84   
 85  31 private boolean isImplementsClauseModified(Classfile oldClass, Classfile newClass) {
 86  31 return !oldClass.getAllInterfaces().containsAll(newClass.getAllInterfaces()) ||
 87    !newClass.getAllInterfaces().containsAll(oldClass.getAllInterfaces());
 88    }
 89   
 90  125 private boolean isDeclarationModified(Field_info oldField, Field_info newField) {
 91  125 return oldField != null && newField != null &&
 92    ((oldField.isPublic() && !newField.isPublic()) ||
 93    (oldField.isProtected() && (newField.isPackage() || newField.isPrivate())) ||
 94    (!oldField.isFinal() && newField.isFinal()) ||
 95    !oldField.getType().equals(newField.getType()));
 96    }
 97   
 98  142 private boolean isDeclarationModified(Method_info oldMethod, Method_info newMethod) {
 99  142 return oldMethod != null && newMethod != null &&
 100    ((oldMethod.isPublic() && !newMethod.isPublic()) ||
 101    (oldMethod.isProtected() && (newMethod.isPackage() || newMethod.isPrivate())) ||
 102    (!oldMethod.isAbstract() && newMethod.isAbstract()) ||
 103    (!oldMethod.isStatic() && newMethod.isStatic()) ||
 104    (!oldMethod.isFinal() && newMethod.isFinal()) ||
 105    !oldMethod.getReturnType().equals(newMethod.getReturnType()) ||
 106    isThrowsClauseModified(oldMethod, newMethod));
 107    }
 108   
 109  95 private boolean isThrowsClauseModified(Method_info oldMethod, Method_info newMethod) {
 110  95 return !oldMethod.getExceptions().containsAll(newMethod.getExceptions()) ||
 111    !newMethod.getExceptions().containsAll(oldMethod.getExceptions());
 112    }
 113   
 114  307 protected boolean isDeprecationModified(Deprecatable oldItem, Deprecatable newItem) {
 115  307 return oldItem != null && newItem != null && !oldItem.isDeprecated() && newItem.isDeprecated();
 116    }
 117    }