Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 105   Methods: 4
NCLOC: 56   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractSunSecureRule.java 77.8% 96.3% 100% 89.8%
coverage coverage
 1    /*
 2    * Created on Jan 17, 2005
 3    *
 4    * $Id: AbstractSunSecureRule.java,v 1.5 2005/05/05 15:08:30 tomcopeland Exp $
 5    */
 6    package net.sourceforge.pmd.rules.sunsecure;
 7   
 8    import net.sourceforge.pmd.AbstractRule;
 9    import net.sourceforge.pmd.ast.ASTFieldDeclaration;
 10    import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration;
 11    import net.sourceforge.pmd.ast.ASTMethodDeclaration;
 12    import net.sourceforge.pmd.ast.ASTName;
 13    import net.sourceforge.pmd.ast.ASTPrimarySuffix;
 14    import net.sourceforge.pmd.ast.ASTReturnStatement;
 15    import net.sourceforge.pmd.ast.ASTTypeDeclaration;
 16    import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
 17    import net.sourceforge.pmd.ast.SimpleNode;
 18   
 19    import java.util.Iterator;
 20    import java.util.List;
 21   
 22    /**
 23    * Utility methods for the package
 24    *
 25    * @author mgriffa
 26    */
 27    public abstract class AbstractSunSecureRule extends AbstractRule {
 28   
 29    /**
 30    * Tells if the type declaration has a field with varName.
 31    *
 32    * @param varName the name of the field to search
 33    * @param typeDeclaration the type declaration
 34    * @return <code>true</code> if there is a field in the type declaration named varName, <code>false</code> in other case
 35    */
 36  8 protected final boolean isField(String varName, ASTTypeDeclaration typeDeclaration) {
 37  8 final List fds = typeDeclaration.findChildrenOfType(ASTFieldDeclaration.class);
 38  8 if (fds!=null) {
 39  8 for (Iterator it=fds.iterator() ; it.hasNext(); ) {
 40  6 final ASTFieldDeclaration fd = (ASTFieldDeclaration) it.next();
 41  6 final ASTVariableDeclaratorId vid = (ASTVariableDeclaratorId) fd.getFirstChildOfType(ASTVariableDeclaratorId.class);
 42  6 if (vid!=null && vid.getImage().equals(varName)) {
 43  5 return true;
 44    }
 45    }
 46    }
 47  3 return false;
 48    }
 49   
 50   
 51    /**
 52    * Gets the name of the variable returned.
 53    * Some examples: <br>
 54    * for this.foo returns foo <br>
 55    * for foo returns foo <br>
 56    * for foo.bar returns foo.bar
 57    *
 58    * @param ret a return statement to evaluate
 59    * @return the name of the variable associated or <code>null</code> if it cannot be detected
 60    */
 61  8 protected final String getReturnedVariableName(ASTReturnStatement ret) {
 62  8 final ASTName n = (ASTName) ret.getFirstChildOfType(ASTName.class);
 63  8 if (n!=null)
 64  5 return n.getImage();
 65  3 final ASTPrimarySuffix ps = (ASTPrimarySuffix) ret.getFirstChildOfType(ASTPrimarySuffix.class);
 66  3 if (ps!=null)
 67  3 return ps.getImage();
 68  0 return null;
 69    }
 70   
 71    /**
 72    * TODO modify usages to use symbol table
 73    * Tells if the variable name is a local variable declared in the method.
 74    * @param vn the variable name
 75    * @param node the ASTMethodDeclaration where the local variable name will be searched
 76    * @return <code>true</code> if the method declaration contains any local variable named vn and <code>false</code> in other case
 77    */
 78  12 protected boolean isLocalVariable(String vn, ASTMethodDeclaration node) {
 79  12 final List lvars = node.findChildrenOfType(ASTLocalVariableDeclaration.class);
 80  12 if (lvars!=null) {
 81  12 for (Iterator it = lvars.iterator() ; it.hasNext() ; ) {
 82  3 final ASTLocalVariableDeclaration lvd = (ASTLocalVariableDeclaration) it.next();
 83  3 final ASTVariableDeclaratorId vid = (ASTVariableDeclaratorId) lvd.getFirstChildOfType(ASTVariableDeclaratorId.class);
 84  3 if (vid!=null && vid.getImage().equals(vn)) {
 85  3 return true;
 86    }
 87    }
 88    }
 89  9 return false;
 90    }
 91   
 92    /**
 93    * Gets the image of the first ASTName node found by {@link SimpleNode#getFirstChildOfType(Class)}
 94    *
 95    * @param n the node to search
 96    * @return the image of the first ASTName or <code>null</code>
 97    */
 98  8 protected String getFirstNameImage(SimpleNode n) {
 99  8 ASTName name = (ASTName) n.getFirstChildOfType(ASTName.class);
 100  8 if (name!=null)
 101  6 return name.getImage();
 102  2 return null;
 103    }
 104   
 105    }