1 package test.net.sourceforge.pmd;
2
3 import net.sourceforge.pmd.Report;
4 import net.sourceforge.pmd.Rule;
5 import net.sourceforge.pmd.RuleContext;
6 import net.sourceforge.pmd.RuleProperties;
7 import net.sourceforge.pmd.RuleViolation;
8
9 import java.util.HashSet;
10 import java.util.Iterator;
11 import java.util.List;
12 import java.util.Set;
13
14 public class MockRule implements Rule {
15
16 private String name;
17 private String description;
18 private String message;
19 private Set violations = new HashSet();
20 private RuleProperties properties = new RuleProperties();
21 private String example;
22 private boolean m_include;
23 private int priority;
24
25 public String getExample() {
26 return example;
27 }
28
29 public void setExample(String example) {
30 this.example = example;
31 }
32
33 public int getPriority() {
34 return this.priority;
35 }
36
37 public String getPriorityName() {
38 return null;
39 }
40
41 public void setPriority(int priority) {
42 this.priority = priority;
43 }
44
45 public String getDescription() {
46 return description;
47 }
48
49 public void setDescription(String description) {
50 this.description = description;
51 }
52
53 public String getName() {
54 return name;
55 }
56
57 public void setName(String name) {
58 this.name = name;
59 }
60
61 public String getMessage() {
62 return message;
63 }
64
65 public void setMessage(String message) {
66 this.message = message;
67 }
68
69 public boolean hasProperty(String name) {
70 return properties.containsKey(name);
71 }
72
73 public void addProperty(String name, String value) {
74 properties.setValue(name, value);
75 }
76
77 public int getIntProperty(String name) {
78 return Integer.parseInt(properties.getProperty(name));
79 }
80
81 public double getDoubleProperty(String name) {
82 return Double.parseDouble(properties.getProperty(name));
83 }
84
85 public boolean getBooleanProperty(String name) {
86 return Boolean.valueOf(properties.getProperty(name)).booleanValue();
87 }
88
89 public String getStringProperty(String name) {
90 return properties.getProperty(name);
91 }
92
93 public RuleProperties getProperties() {
94 return properties;
95 }
96
97 public boolean include() {
98 return true;
99 }
100
101 public void setInclude(boolean include) {
102 m_include = include;
103 }
104
105 /***
106 * For use by RuleSetFactory only!
107 */
108 public MockRule() {
109 }
110
111 public MockRule(String name, String description, String message) {
112 this.name = name;
113 this.description = description;
114 this.message = message;
115 }
116
117
118 public void addViolation(RuleViolation violation) {
119 violations.add(violation);
120 }
121
122 public void apply(List astCompilationUnits, RuleContext ctx) {
123 Report report = ctx.getReport();
124
125 Iterator vs = violations.iterator();
126 while (vs.hasNext()) {
127 report.addRuleViolation((RuleViolation) vs.next());
128 }
129 }
130
131 }
This page was automatically generated by Maven