Clover Coverage Report - PMD-3.8
Coverage timestamp: Wed Oct 14 2009 06:14:43 CDT
../../../img/srcFileCovDistChart10.png 0% of files have more coverage
55   245   41   1.53
10   155   0.75   36
36     1.14  
1    
 
  AbstractRule       Line # 17 55 41 92.1% 0.9207921
 
  (230)
 
1    /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4    package net.sourceforge.pmd;
5   
6    import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
7    import net.sourceforge.pmd.ast.ASTCompilationUnit;
8    import net.sourceforge.pmd.ast.JavaParserVisitorAdapter;
9    import net.sourceforge.pmd.ast.Node;
10    import net.sourceforge.pmd.ast.SimpleNode;
11   
12    import java.text.MessageFormat;
13    import java.util.Iterator;
14    import java.util.List;
15    import java.util.Properties;
16   
 
17    public abstract class AbstractRule extends JavaParserVisitorAdapter implements Rule {
18   
19    protected String name = getClass().getName();
20    protected Properties properties = new Properties();
21    protected String message;
22    protected String description;
23    protected String example;
24    protected String ruleSetName;
25    protected boolean include;
26    protected boolean usesDFA;
27    protected int priority = LOWEST_PRIORITY;
28    protected String externalInfoUrl;
29   
 
30  1 toggle public String getRuleSetName() {
31  1 return ruleSetName;
32    }
33   
 
34  1711 toggle public void setRuleSetName(String ruleSetName) {
35  1711 this.ruleSetName = ruleSetName;
36    }
37   
 
38  2 toggle public String getDescription() {
39  2 return description;
40    }
41   
 
42  1704 toggle public void setDescription(String description) {
43  1704 this.description = description;
44    }
45   
 
46  1 toggle public String getExample() {
47  1 return example;
48    }
49   
 
50  1737 toggle public void setExample(String example) {
51  1737 this.example = example;
52    }
53   
 
54  555 toggle public boolean hasProperty(String name) {
55  555 return properties.containsKey(name);
56    }
57   
 
58  847 toggle public void addProperty(String name, String value) {
59  847 properties.setProperty(name, value);
60    }
61   
 
62  2 toggle public void addProperties(Properties properties) {
63  2 this.properties.putAll(properties);
64    }
65   
 
66  235 toggle public double getDoubleProperty(String name) {
67  235 return Double.parseDouble(properties.getProperty(name));
68    }
69   
 
70  182 toggle public int getIntProperty(String name) {
71  182 return Integer.parseInt(properties.getProperty(name));
72    }
73   
 
74  89 toggle public boolean getBooleanProperty(String name) {
75  89 return Boolean.valueOf(properties.getProperty(name)).booleanValue();
76    }
77   
 
78  70 toggle public String getStringProperty(String name) {
79  70 return properties.getProperty(name);
80    }
81   
 
82  1130 toggle public String getName() {
83  1130 return name;
84    }
85   
 
86  1732 toggle public void setName(String name) {
87  1732 this.name = name;
88    }
89   
 
90  335 toggle public String getMessage() {
91  335 return message;
92    }
93   
 
94  1735 toggle public void setMessage(String message) {
95  1735 this.message = message;
96    }
97   
 
98  5 toggle public String getExternalInfoUrl() {
99  5 return externalInfoUrl;
100    }
101   
 
102  1710 toggle public void setExternalInfoUrl(String url) {
103  1710 this.externalInfoUrl = url;
104    }
105   
106    /**
107    * Test if rules are equals. Rules are equals if
108    * 1. they have the same implementation class
109    * 2. they have the same name
110    * 3. they have the same priority
111    * 4. they share the same properties/values
112    */
 
113  16 toggle public boolean equals(Object o) {
114  16 if (o == null) {
115  1 return false; // trivial
116    }
117   
118  15 if (this == o) {
119  5 return true; // trivial
120    }
121   
122  10 Rule rule = null;
123  10 boolean equality = this.getClass().getName().equals(o.getClass().getName());
124   
125  10 if (equality) {
126  8 rule = (Rule) o;
127  8 equality = this.getName().equals(rule.getName())
128    && this.getPriority() == rule.getPriority()
129    && this.getProperties().equals(rule.getProperties());
130    }
131   
132  10 return equality;
133    }
134   
135    /**
136    * Return a hash code to conform to equality. Try with a string.
137    */
 
138  20 toggle public int hashCode() {
139  20 String s = this.getClass().getName() + this.getName() + String.valueOf(this.getPriority()) + this.getProperties().toString();
140  20 return s.hashCode();
141    }
142