Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 234   Methods: 36
NCLOC: 145   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CommonAbstractRule.java 0% 36% 47.2% 38%
coverage coverage
 1    package net.sourceforge.pmd;
 2   
 3    import java.text.MessageFormat;
 4    import java.util.Properties;
 5   
 6    import net.sourceforge.pmd.ast.Node;
 7    import net.sourceforge.pmd.ast.SimpleNode;
 8   
 9    /**
 10    * Basic abstract implementation of all parser-independent methods of the
 11    * Rule interface.
 12    *
 13    * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
 14    */
 15    public abstract class CommonAbstractRule implements Rule {
 16   
 17    protected String name = getClass().getName();
 18    protected Properties properties = new Properties();
 19    protected String message;
 20    protected String description;
 21    protected String example;
 22    protected String ruleSetName;
 23    protected boolean include;
 24    protected boolean usesDFA;
 25    protected boolean usesTypeResolution;
 26    protected int priority = LOWEST_PRIORITY;
 27    protected String externalInfoUrl;
 28   
 29  0 public String getRuleSetName() {
 30  0 return ruleSetName;
 31    }
 32   
 33  128 public void setRuleSetName(String ruleSetName) {
 34  128 this.ruleSetName = ruleSetName;
 35    }
 36   
 37  0 public String getDescription() {
 38  0 return description;
 39    }
 40   
 41  119 public void setDescription(String description) {
 42  119 this.description = description;
 43    }
 44   
 45  0 public String getExample() {
 46  0 return example;
 47    }
 48   
 49  119 public void setExample(String example) {
 50  119 this.example = example;
 51    }
 52   
 53  0 public boolean hasProperty(String name) {
 54  0 return properties.containsKey(name);
 55    }
 56   
 57  125 public void addProperty(String name, String value) {
 58  125 properties.setProperty(name, value);
 59    }
 60   
 61  0 public void addProperties(Properties properties) {
 62  0 this.properties.putAll(properties);
 63    }
 64   
 65  0 public double getDoubleProperty(String name) {
 66  0 return Double.parseDouble(properties.getProperty(name));
 67    }
 68   
 69  0 public int getIntProperty(String name) {
 70  0 return Integer.parseInt(properties.getProperty(name));
 71    }
 72   
 73  2 public boolean getBooleanProperty(String name) {
 74  2 return Boolean.valueOf(properties.getProperty(name)).booleanValue();
 75    }
 76   
 77  13 public String getStringProperty(String name) {
 78  13 return properties.getProperty(name);
 79    }
 80   
 81  67 public String getName() {
 82  67 return name;
 83    }
 84   
 85  119 public void setName(String name) {
 86  119 this.name = name;
 87    }
 88   
 89  35 public String getMessage() {
 90  35 return message;
 91    }
 92   
 93  125 public void setMessage(String message) {
 94  125 this.message = message;
 95    }
 96   
 97  0 public String getExternalInfoUrl() {
 98  0 return externalInfoUrl;
 99    }
 100   
 101  119 public void setExternalInfoUrl(String url) {
 102  119 this.externalInfoUrl = url;
 103    }
 104   
 105    /**
 106    * Test if rules are equals. Rules are equals if
 107    * 1. they have the same implementation class
 108    * 2. they have the same name
 109    * 3. they have the same priority
 110    * 4. they share the same properties/values
 111    */
 112  0 public boolean equals(Object o) {
 113  0 if (o == null) {
 114  0 return false; // trivial
 115    }
 116   
 117  0 if (this == o) {
 118  0 return true; // trivial
 119    }
 120   
 121  0 Rule rule = null;
 122  0 boolean equality = this.getClass().getName().equals(o.getClass().getName());
 123   
 124  0 if (equality) {
 125  0 rule = (Rule) o;
 126  0 equality = this.getName().equals(rule.getName())
 127    && this.getPriority() == rule.getPriority()
 128    && this.getProperties().equals(rule.getProperties());
 129    }
 130   
 131  0 return equality;
 132    }
 133   
 134    /**
 135    * Return a hash code to conform to equality. Try with a string.
 136    */
 137  0 public int hashCode() {
 138  0 String s = this.getClass().getName() + this.getName() + this.getPriority() + this.getProperties().toString();
 139  0 return s.hashCode();
 140    }
 141   
 142   
 143  23 public Properties getProperties() {
 144  23 return properties;
 145    }
 146   
 147  0 public boolean include() {
 148  0 return include;
 149    }
 150   
 151  0 public void setInclude(boolean include) {
 152  0 this.include = include;
 153    }
 154   
 155  121 public int getPriority() {
 156  121 return priority;
 157    }
 158   
 159  0 public String getPriorityName() {
 160  0 return PRIORITIES[getPriority() - 1];
 161    }
 162   
 163  119 public void setPriority(int priority) {
 164  119 this.priority = priority;
 165    }
 166   
 167  0 public void setUsesDFA() {
 168  0 this.usesDFA = true;
 169    }
 170   
 171  26 public boolean usesDFA() {
 172  26 return this.usesDFA;
 173    }
 174   
 175  0 public void setUsesTypeResolution() {
 176  0 this.usesTypeResolution= true;
 177    }
 178   
 179  26 public boolean usesTypeResolution() {
 180  26 return this.usesTypeResolution;
 181    }
 182   
 183   
 184    /**
 185    * Adds a violation to the report.
 186    *
 187    * @param ctx the RuleContext
 188    * @param node the node that produces the violation
 189    */
 190  0 protected final void addViolation(Object data, SimpleNode node) {
 191  0 RuleContext ctx = (RuleContext) data;
 192  0 ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node));
 193    }
 194   
 195    /**
 196    * Adds a violation to the report.
 197    *
 198    * @param ctx the RuleContext
 199    * @param node the node that produces the violation
 200    * @param msg specific message to put in the report
 201    */
 202  0 protected final void addViolationWithMessage(Object data, SimpleNode node, String msg) {
 203  0 RuleContext ctx = (RuleContext) data;
 204  0 ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, msg));
 205    }
 206   
 207    /**
 208    * Adds a violation to the report.
 209    *
 210    * @param ctx the RuleContext
 211    * @param node the node that produces the violation
 212    * @param embed a variable to embed in the rule violation message
 213    */
 214  18 protected final void addViolation(Object data, SimpleNode node, String embed) {
 215  18 RuleContext ctx = (RuleContext) data;
 216  18 ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), new Object[]{embed})));
 217    }
 218   
 219    /**
 220    * Adds a violation to the report.
 221    *
 222    * @param ctx the RuleContext
 223    * @param node the node that produces the violation, may be null, in which case all line and column info will be set to zero
 224    * @param args objects to embed in the rule violation message
 225    */
 226  0 protected final void addViolation(Object data, Node node, Object[] args) {
 227  0 RuleContext ctx = (RuleContext) data;
 228  0 ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, (SimpleNode) node, MessageFormat.format(getMessage(), args)));
 229    }
 230   
 231  0 public PropertyDescriptor propertyDescriptorFor(String name) {
 232  0 return null; // TODO not implemented yet
 233    }
 234    }