1 |
| package net.sourceforge.pmd; |
2 |
| |
3 |
| import net.sourceforge.pmd.ast.Node; |
4 |
| import net.sourceforge.pmd.ast.SimpleNode; |
5 |
| |
6 |
| import java.text.MessageFormat; |
7 |
| import java.util.Properties; |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
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 int priority = LOWEST_PRIORITY; |
26 |
| protected String externalInfoUrl; |
27 |
| |
28 |
0
| public String getRuleSetName() {
|
29 |
0
| return ruleSetName;
|
30 |
| } |
31 |
| |
32 |
2623
| public void setRuleSetName(String ruleSetName) {
|
33 |
2623
| this.ruleSetName = ruleSetName;
|
34 |
| } |
35 |
| |
36 |
0
| public String getDescription() {
|
37 |
0
| return description;
|
38 |
| } |
39 |
| |
40 |
2623
| public void setDescription(String description) {
|
41 |
2623
| this.description = description;
|
42 |
| } |
43 |
| |
44 |
0
| public String getExample() {
|
45 |
0
| return example;
|
46 |
| } |
47 |
| |
48 |
2607
| public void setExample(String example) {
|
49 |
2607
| this.example = example;
|
50 |
| } |
51 |
| |
52 |
0
| public boolean hasProperty(String name) {
|
53 |
0
| return properties.containsKey(name);
|
54 |
| } |
55 |
| |
56 |
2932
| public void addProperty(String name, String value) {
|
57 |
2932
| properties.setProperty(name, value);
|
58 |
| } |
59 |
| |
60 |
0
| public void addProperties(Properties properties) {
|
61 |
0
| this.properties.putAll(properties);
|
62 |
| } |
63 |
| |
64 |
0
| public double getDoubleProperty(String name) {
|
65 |
0
| return Double.parseDouble(properties.getProperty(name));
|
66 |
| } |
67 |
| |
68 |
0
| public int getIntProperty(String name) {
|
69 |
0
| return Integer.parseInt(properties.getProperty(name));
|
70 |
| } |
71 |
| |
72 |
18
| public boolean getBooleanProperty(String name) {
|
73 |
18
| return Boolean.valueOf(properties.getProperty(name)).booleanValue();
|
74 |
| } |
75 |
| |
76 |
126
| public String getStringProperty(String name) {
|
77 |
126
| return properties.getProperty(name);
|
78 |
| } |
79 |
| |
80 |
1256
| public String getName() {
|
81 |
1256
| return name;
|
82 |
| } |
83 |
| |
84 |
2623
| public void setName(String name) {
|
85 |
2623
| this.name = name;
|
86 |
| } |
87 |
| |
88 |
474
| public String getMessage() {
|
89 |
474
| return message;
|
90 |
| } |
91 |
| |
92 |
2630
| public void setMessage(String message) {
|
93 |
2630
| this.message = message;
|
94 |
| } |
95 |
| |
96 |
0
| public String getExternalInfoUrl() {
|
97 |
0
| return externalInfoUrl;
|
98 |
| } |
99 |
| |
100 |
2623
| public void setExternalInfoUrl(String url) {
|
101 |
2623
| this.externalInfoUrl = url;
|
102 |
| } |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
0
| public boolean equals(Object o) {
|
112 |
0
| if (o == null) {
|
113 |
0
| return false;
|
114 |
| } |
115 |
| |
116 |
0
| if (this == o) {
|
117 |
0
| return true;
|
118 |
| } |
119 |
| |
120 |
0
| Rule rule = null;
|
121 |
0
| boolean equality = this.getClass().getName().equals(o.getClass().getName());
|
122 |
| |
123 |
0
| if (equality) {
|
124 |
0
| rule = (Rule) o;
|
125 |
0
| equality = this.getName().equals(rule.getName())
|
126 |
| && this.getPriority() == rule.getPriority() |
127 |
| && this.getProperties().equals(rule.getProperties()); |
128 |
| } |
129 |
| |
130 |
0
| return equality;
|
131 |
| } |
132 |
| |
133 |
| |
134 |
| |
135 |
| |
136 |
0
| public int hashCode() {
|
137 |
0
| String s = this.getClass().getName() + this.getName() + String.valueOf(this.getPriority()) + this.getProperties().toString();
|
138 |
0
| return s.hashCode();
|
139 |
| } |
140 |
| |
141 |
| |
142 |
0
| public Properties getProperties() {
|
143 |
0
| return properties;
|
144 |
| } |
145 |
| |
146 |
0
| public boolean include() {
|
147 |
0
| return include;
|
148 |
| } |
149 |
| |
150 |
0
| public void setInclude(boolean include) {
|
151 |
0
| this.include = include;
|
152 |
| } |
153 |
| |
154 |
2652
| public int getPriority() {
|
155 |
2652
| return priority;
|
156 |
| } |
157 |
| |
158 |
0
| public String getPriorityName() {
|
159 |
0
| return PRIORITIES[getPriority() - 1];
|
160 |
| } |
161 |
| |
162 |
2624
| public void setPriority(int priority) {
|
163 |
2624
| this.priority = priority;
|
164 |
| } |
165 |
| |
166 |
0
| public void setUsesDFA() {
|
167 |
0
| this.usesDFA = true;
|
168 |
| } |
169 |
| |
170 |
440
| public boolean usesDFA() {
|
171 |
440
| return this.usesDFA;
|
172 |
| } |
173 |
| |
174 |
| |
175 |
| |
176 |
| |
177 |
| |
178 |
| |
179 |
| |
180 |
| |
181 |
0
| protected final void addViolation(Object data, SimpleNode node) {
|
182 |
0
| RuleContext ctx = (RuleContext) data;
|
183 |
0
| ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node));
|
184 |
| } |
185 |
| |
186 |
| |
187 |
| |
188 |
| |
189 |
| |
190 |
| |
191 |
| |
192 |
| |
193 |
0
| protected final void addViolationWithMessage(Object data, SimpleNode node, String msg) {
|
194 |
0
| RuleContext ctx = (RuleContext) data;
|
195 |
0
| ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, msg));
|
196 |
| } |
197 |
| |
198 |
| |
199 |
| |
200 |
| |
201 |
| |
202 |
| |
203 |
| |
204 |
| |
205 |
243
| protected final void addViolation(Object data, SimpleNode node, String embed) {
|
206 |
243
| RuleContext ctx = (RuleContext) data;
|
207 |
243
| ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), new Object[]{embed})));
|
208 |
| } |
209 |
| |
210 |
| |
211 |
| |
212 |
| |
213 |
| |
214 |
| |
215 |
| |
216 |
| |
217 |
0
| protected final void addViolation(Object data, Node node, Object[] args) {
|
218 |
0
| RuleContext ctx = (RuleContext) data;
|
219 |
0
| ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, (SimpleNode) node, MessageFormat.format(getMessage(), args)));
|
220 |
| } |
221 |
| |
222 |
| } |