Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 61   Methods: 3
NCLOC: 47   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
UnnecessaryCaseChange.java 50% 68% 100% 63.6%
coverage coverage
 1    package net.sourceforge.pmd.rules;
 2   
 3    import net.sourceforge.pmd.AbstractRule;
 4    import net.sourceforge.pmd.ast.ASTName;
 5    import net.sourceforge.pmd.ast.ASTPrimaryExpression;
 6    import net.sourceforge.pmd.ast.ASTPrimaryPrefix;
 7    import net.sourceforge.pmd.ast.ASTPrimarySuffix;
 8   
 9    public class UnnecessaryCaseChange extends AbstractRule {
 10   
 11  3 public Object visit(ASTPrimaryExpression exp, Object data) {
 12  3 if (exp.jjtGetNumChildren() < 4) {
 13  0 return data;
 14    }
 15   
 16  3 String first = getBadPrefixOrNull(exp);
 17  3 if (first == null) {
 18  0 return data;
 19    }
 20   
 21  3 String second = getBadSuffixOrNull(exp);
 22  3 if (second == null) {
 23  0 return data;
 24    }
 25   
 26  3 addViolation(data, exp);
 27  3 return data;
 28    }
 29   
 30  3 private String getBadPrefixOrNull(ASTPrimaryExpression exp) {
 31    // verify PrimaryPrefix/Name[ends-with(@Image, 'toUpperCase']
 32  3 if (!(exp.jjtGetChild(0) instanceof ASTPrimaryPrefix)) {
 33  0 return null;
 34    }
 35   
 36  3 ASTPrimaryPrefix prefix = (ASTPrimaryPrefix)exp.jjtGetChild(0);
 37  3 if (prefix.jjtGetNumChildren() != 1 || !(prefix.jjtGetChild(0) instanceof ASTName)) {
 38  0 return null;
 39    }
 40   
 41  3 ASTName name = (ASTName)prefix.jjtGetChild(0);
 42  3 if (name.getImage() == null || !(name.getImage().endsWith("toUpperCase") || name.getImage().endsWith("toLowerCase"))){
 43  0 return null;
 44    }
 45  3 return name.getImage();
 46    }
 47   
 48  3 private String getBadSuffixOrNull(ASTPrimaryExpression exp) {
 49    // verify PrimarySuffix[@Image='equals']
 50  3 if (!(exp.jjtGetChild(2) instanceof ASTPrimarySuffix)) {
 51  0 return null;
 52    }
 53   
 54  3 ASTPrimarySuffix suffix = (ASTPrimarySuffix)exp.jjtGetChild(2);
 55  3 if (suffix.getImage() == null || !(suffix.getImage().equals("equals") || suffix.getImage().equals("equalsIgnoreCase") )) {
 56  0 return null;
 57    }
 58  3 return suffix.getImage();
 59    }
 60   
 61    }