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