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 15 public class RuleSets { 16 19 private Collection ruleSets = new ArrayList (); 20 21 24 public RuleSets() { 25 } 26 27 32 public RuleSets(RuleSet ruleSet) { 33 this(); 34 addRuleSet(ruleSet); 35 } 36 37 44 public void addRuleSet(RuleSet ruleSet) { 45 ruleSets.add(ruleSet); 46 } 47 48 53 public RuleSet[] getAllRuleSets() { 54 return (RuleSet[]) ruleSets.toArray(new RuleSet[ruleSets.size()]); 55 } 56 57 public Iterator getRuleSetsIterator() { 58 return ruleSets.iterator(); 59 } 60 61 66 public Set getAllRules() { 67 HashSet result = new HashSet (); 68 for (Iterator i = ruleSets.iterator(); i.hasNext();) { 69 result.addAll(((RuleSet) i.next()).getRules()); 70 } 71 return result; 72 } 73 74 84 public boolean applies(Language languageOfSource, Language languageOfRule) { 85 return (languageOfSource.equals(languageOfRule) || (languageOfSource 86 .equals(Language.JAVA) && (null == languageOfRule))); 87 } 88 89 99 public void apply(List acuList, RuleContext ctx, Language language) { 100 for (Iterator i = ruleSets.iterator(); i.hasNext();) { 101 RuleSet ruleSet = (RuleSet) i.next(); 102 if (applies(language, ruleSet.getLanguage())) { 103 ruleSet.apply(acuList, ctx); 104 } 105 } 106 } 107 108 115 public boolean usesDFA(Language language) { 116 for (Iterator i = ruleSets.iterator(); i.hasNext();) { 117 RuleSet ruleSet = (RuleSet) i.next(); 118 if (applies(language, ruleSet.getLanguage()) && ruleSet.usesDFA()) { 119 return true; 120 } 121 } 122 return false; 123 } 124 125 131 public Rule getRuleByName(String ruleName) { 132 Rule rule = null; 133 for (Iterator i = ruleSets.iterator(); i.hasNext() && (rule == null);) { 134 RuleSet ruleSet = (RuleSet) i.next(); 135 rule = ruleSet.getRuleByName(ruleName); 136 } 137 return rule; 138 } 139 140 public boolean usesTypeResolution(Language language) { 141 for (Iterator i = ruleSets.iterator(); i.hasNext();) { 142 RuleSet ruleSet = (RuleSet) i.next(); 143 if (applies(language, ruleSet.getLanguage()) && ruleSet.usesTypeResolution()) { 144 return true; 145 } 146 } 147 return false; 148 } 149 } 150 | Popular Tags |