1 |
| |
2 |
| |
3 |
| |
4 |
| package net.sourceforge.pmd; |
5 |
| |
6 |
| import java.util.HashSet; |
7 |
| import java.util.Iterator; |
8 |
| import java.util.List; |
9 |
| import java.util.Set; |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| public class RuleSet { |
16 |
| |
17 |
| private Set rules = new HashSet(); |
18 |
| private String name = ""; |
19 |
| private String description = ""; |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
6
| public int size() {
|
26 |
6
| return rules.size();
|
27 |
| } |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
3412
| public void addRule(Rule rule) {
|
34 |
3412
| if (rule == null) {
|
35 |
0
| throw new RuntimeException("Null Rule reference added to a RuleSet; that's a bug somewhere in PMD");
|
36 |
| } |
37 |
3412
| rules.add(rule);
|
38 |
| } |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
25
| public Set getRules() {
|
45 |
25
| return rules;
|
46 |
| } |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
755
| public boolean usesDFA() {
|
52 |
755
| for (Iterator i = rules.iterator(); i.hasNext();) {
|
53 |
755
| Rule r = (Rule) i.next();
|
54 |
755
| if (r.usesDFA()) {
|
55 |
1
| return true;
|
56 |
| } |
57 |
| } |
58 |
754
| return false;
|
59 |
| } |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
180
| public Rule getRuleByName(String ruleName) {
|
68 |
180
| Rule rule = null;
|
69 |
180
| for (Iterator i = rules.iterator(); i.hasNext() && (rule == null);) {
|
70 |
1382
| Rule r = (Rule) i.next();
|
71 |
1382
| if (r.getName().equals(ruleName)) {
|
72 |
178
| rule = r;
|
73 |
| } |
74 |
| } |
75 |
180
| return rule;
|
76 |
| } |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
1
| public void addRuleSet(RuleSet ruleSet) {
|
84 |
1
| rules.addAll(ruleSet.getRules());
|
85 |
| } |
86 |
| |
87 |
754
| public void apply(List acuList, RuleContext ctx) {
|
88 |
754
| Iterator rs = rules.iterator();
|
89 |
754
| while (rs.hasNext()) {
|
90 |
753
| Rule rule = (Rule) rs.next();
|
91 |
753
| rule.apply(acuList, ctx);
|
92 |
| } |
93 |
| } |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
2621
| public String getName() {
|
101 |
2621
| return name;
|
102 |
| } |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
201
| public void setName(String name) {
|
110 |
201
| this.name = name;
|
111 |
| } |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
1
| public String getDescription() {
|
119 |
1
| return description;
|
120 |
| } |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
194
| public void setDescription(String description) {
|
128 |
194
| this.description = description;
|
129 |
| } |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
6
| public boolean equals(Object o) {
|
135 |
6
| if ((o == null) || !(o instanceof RuleSet)) {
|
136 |
2
| return false;
|
137 |
| } |
138 |
| |
139 |
4
| if (this == o) {
|
140 |
1
| return true;
|
141 |
| } |
142 |
| |
143 |
3
| RuleSet ruleSet = (RuleSet) o;
|
144 |
3
| return this.getName().equals(ruleSet.getName()) && this.getRules().equals(ruleSet.getRules());
|
145 |
| } |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
6
| public int hashCode() {
|
151 |
6
| return this.getName().hashCode() + 13*this.getRules().hashCode();
|
152 |
| } |
153 |
| } |