1 |
| package net.sourceforge.pmd; |
2 |
| |
3 |
| import java.util.ArrayList; |
4 |
| import java.util.Collection; |
5 |
| import java.util.HashSet; |
6 |
| import java.util.Iterator; |
7 |
| import java.util.List; |
8 |
| import java.util.Set; |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| public class RuleSets { |
16 |
| |
17 |
| |
18 |
| |
19 |
| private Collection ruleSets = new ArrayList(); |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
1270
| public RuleSets() {
|
25 |
| } |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
1055
| public RuleSets(RuleSet ruleSet) {
|
33 |
1055
| this();
|
34 |
1055
| addRuleSet(ruleSet);
|
35 |
| } |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
1269
| public void addRuleSet(RuleSet ruleSet) {
|
45 |
1269
| ruleSets.add(ruleSet);
|
46 |
| } |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
1
| public RuleSet[] getAllRuleSets() {
|
54 |
1
| return (RuleSet[]) ruleSets.toArray(new RuleSet[0]);
|
55 |
| } |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
0
| public Set getAllRules() {
|
63 |
0
| HashSet result = new HashSet();
|
64 |
0
| for (Iterator i = ruleSets.iterator(); i.hasNext();) {
|
65 |
0
| result.addAll(((RuleSet) i.next()).getRules());
|
66 |
| } |
67 |
0
| return result;
|
68 |
| } |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
2110
| public boolean applies(Language languageOfSource, Language languageOfRule) {
|
81 |
2110
| return (languageOfSource.equals(languageOfRule) || (languageOfSource
|
82 |
| .equals(Language.JAVA) && (null == languageOfRule))); |
83 |
| } |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
1055
| public void apply(List acuList, RuleContext ctx, Language language) {
|
96 |
1055
| for (Iterator i = ruleSets.iterator(); i.hasNext();) {
|
97 |
1055
| RuleSet ruleSet = (RuleSet) i.next();
|
98 |
1055
| if (applies(language, ruleSet.getLanguage())) {
|
99 |
1055
| ruleSet.apply(acuList, ctx);
|
100 |
| } |
101 |
| } |
102 |
| } |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
1055
| public boolean usesDFA(Language language) {
|
112 |
1055
| for (Iterator i = ruleSets.iterator(); i.hasNext();) {
|
113 |
1055
| RuleSet ruleSet = (RuleSet) i.next();
|
114 |
1055
| if (applies(language, ruleSet.getLanguage()) && ruleSet.usesDFA()) {
|
115 |
0
| return true;
|
116 |
| } |
117 |
| } |
118 |
1055
| return false;
|
119 |
| } |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
213
| public Rule getRuleByName(String ruleName) {
|
128 |
213
| Rule rule = null;
|
129 |
213
| for (Iterator i = ruleSets.iterator(); i.hasNext() && (rule == null);) {
|
130 |
213
| RuleSet ruleSet = (RuleSet) i.next();
|
131 |
213
| rule = ruleSet.getRuleByName(ruleName);
|
132 |
| } |
133 |
213
| return rule;
|
134 |
| } |
135 |
| } |