1 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 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 29 public int size() { 30 return rules.size(); 31 } 32 33 38 public void addRule(Rule rule) { 39 if (rule == null) { 40 throw new RuntimeException ("Null Rule reference added to a RuleSet; that's a bug somewhere in PMD"); 41 } 42 rules.add(rule); 43 } 44 45 50 public Collection getRules() { 51 return rules; 52 } 53 54 57 public boolean usesDFA() { 58 for (Iterator i = rules.iterator(); i.hasNext();) { 59 Rule r = (Rule) i.next(); 60 if (r.usesDFA()) { 61 return true; 62 } 63 } 64 return false; 65 } 66 67 73 public Rule getRuleByName(String ruleName) { 74 Rule rule = null; 75 for (Iterator i = rules.iterator(); i.hasNext() && (rule == null);) { 76 Rule r = (Rule) i.next(); 77 if (r.getName().equals(ruleName)) { 78 rule = r; 79 } 80 } 81 return rule; 82 } 83 84 89 public void addRuleSet(RuleSet ruleSet) { 90 rules.addAll(rules.size(), ruleSet.getRules()); 91 } 92 93 public void apply(List acuList, RuleContext ctx) { 94 Iterator rs = rules.iterator(); 95 while (rs.hasNext()) { 96 Rule rule = (Rule) rs.next(); 97 rule.apply(acuList, ctx); 98 } 99 } 100 101 104 public boolean equals(Object o) { 105 if ((o == null) || !(o instanceof RuleSet)) { 106 return false; } 108 109 if (this == o) { 110 return true; } 112 113 RuleSet ruleSet = (RuleSet) o; 114 return this.getName().equals(ruleSet.getName()) && this.getRules().equals(ruleSet.getRules()); 115 } 116 117 120 public int hashCode() { 121 return this.getName().hashCode() + 13 * this.getRules().hashCode(); 122 } 123 124 public Language getLanguage() { 125 return language; 126 } 127 128 public void setLanguage(Language language) { 129 this.language = language; 130 } 131 132 public String getName() { 133 return name; 134 } 135 136 public void setName(String name) { 137 this.name = name; 138 } 139 140 public String getDescription() { 141 return description; 142 } 143 144 public void setDescription(String description) { 145 this.description = description; 146 } 147 148 public boolean usesTypeResolution() { 149 for (Iterator i = rules.iterator(); i.hasNext();) { 150 Rule r = (Rule) i.next(); 151 if (r.usesTypeResolution()) { 152 return true; 153 } 154 } 155 return false; 156 } 157 158 } 159 | Popular Tags |