|
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 |
1478
| public RuleSets() {
|
|
25 |
| } |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
1260
| public RuleSets(RuleSet ruleSet) {
|
|
33 |
1260
| this();
|
|
34 |
1260
| addRuleSet(ruleSet);
|
|
35 |
| } |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
1478
| public void addRuleSet(RuleSet ruleSet) {
|
|
45 |
1478
| ruleSets.add(ruleSet);
|
|
46 |
| } |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
0
| public RuleSet[] getAllRuleSets() {
|
|
54 |
0
| return (RuleSet[]) ruleSets.toArray(new RuleSet[ruleSets.size()]);
|
|
55 |
| } |
|
56 |
| |
|
57 |
0
| public Iterator getRuleSetsIterator() {
|
|
58 |
0
| return ruleSets.iterator();
|
|
59 |
| } |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
0
| public Set getAllRules() {
|
|
67 |
0
| HashSet result = new HashSet();
|
|
68 |
0
| for (Iterator i = ruleSets.iterator(); i.hasNext();) {
|
|
69 |
0
| result.addAll(((RuleSet) i.next()).getRules());
|
|
70 |
| } |
|
71 |
0
| return result;
|
|
72 |
| } |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
3780
| public boolean applies(Language languageOfSource, Language languageOfRule) {
|
|
85 |
3780
| return (languageOfSource.equals(languageOfRule) || (languageOfSource
|
|
86 |
| .equals(Language.JAVA) && (null == languageOfRule))); |
|
87 |
| } |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
1260
| public void apply(List acuList, RuleContext ctx, Language language) {
|
|
100 |
1260
| for (Iterator i = ruleSets.iterator(); i.hasNext();) {
|
|
101 |
1260
| RuleSet ruleSet = (RuleSet) i.next();
|
|
102 |
1260
| if (applies(language, ruleSet.getLanguage())) {
|
|
103 |
1260
| ruleSet.apply(acuList, ctx);
|
|
104 |
| } |
|
105 |
| } |
|
106 |
| } |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
1260
| public boolean usesDFA(Language language) {
|
|
116 |
1260
| for (Iterator i = ruleSets.iterator(); i.hasNext();) {
|
|
117 |
1260
| RuleSet ruleSet = (RuleSet) i.next();
|
|
118 |
1260
| if (applies(language, ruleSet.getLanguage()) && ruleSet.usesDFA()) {
|
|
119 |
5
| return true;
|
|
120 |
| } |
|
121 |
| } |
|
122 |
1255
| return false;
|
|
123 |
| } |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
218
| public Rule getRuleByName(String ruleName) {
|
|
132 |
218
| Rule rule = null;
|
|
133 |
218
| for (Iterator i = ruleSets.iterator(); i.hasNext() && (rule == null);) {
|
|
134 |
218
| RuleSet ruleSet = (RuleSet) i.next();
|
|
135 |
218
| rule = ruleSet.getRuleByName(ruleName);
|
|
136 |
| } |
|
137 |
218
| return rule;
|
|
138 |
| } |
|
139 |
| |
|
140 |
1260
| public boolean usesTypeResolution(Language language) {
|
|
141 |
1260
| for (Iterator i = ruleSets.iterator(); i.hasNext();) {
|
|
142 |
1260
| RuleSet ruleSet = (RuleSet) i.next();
|
|
143 |
1260
| if (applies(language, ruleSet.getLanguage()) && ruleSet.usesTypeResolution()) {
|
|
144 |
18
| return true;
|
|
145 |
| } |
|
146 |
| } |
|
147 |
1242
| return false;
|
|
148 |
| } |
|
149 |
| } |