Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 38   Methods: 2
NCLOC: 18   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
UseCollectionIsEmpty.java 75% 100% 100% 90.9%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd.rules.design;
 5   
 6    import net.sourceforge.pmd.ast.SimpleNode;
 7    import net.sourceforge.pmd.rules.AbstractInefficientZeroCheck;
 8    import net.sourceforge.pmd.symboltable.NameOccurrence;
 9    import net.sourceforge.pmd.util.CollectionUtil;
 10   
 11    /**
 12    * Detect structures like "foo.size() == 0" and suggest replacing them with
 13    * foo.isEmpty(). Will also find != 0 (replacable with !isEmpty()).
 14    *
 15    * @author Jason Bennett
 16    */
 17    public class UseCollectionIsEmpty extends AbstractInefficientZeroCheck {
 18   
 19  11 public boolean appliesToClassName(String name){
 20  11 return CollectionUtil.isCollectionType(name, true);
 21    }
 22   
 23    /**
 24    * Determine if we're dealing with .size method
 25    *
 26    * @param occ
 27    * The name occurance
 28    * @return true if it's .length, else false
 29    */
 30  11 public boolean isTargetMethod(NameOccurrence occ) {
 31  11 if (occ.getNameForWhichThisIsAQualifier() != null) {
 32  11 if (((SimpleNode) occ.getLocation()).getImage().endsWith(".size")) {
 33  7 return true;
 34    }
 35    }
 36  4 return false;
 37    }
 38    }