Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 149   Methods: 11
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RuleSets.java 81.2% 79.3% 72.7% 78.6%
coverage coverage
 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    * Grouping of Rules per Language in a RuleSet.
 12    *
 13    * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
 14    */
 15    public class RuleSets {
 16    /**
 17    * Map of RuleLanguage on RuleSet.
 18    */
 19    private Collection ruleSets = new ArrayList();
 20   
 21    /**
 22    * Public constructor.
 23    */
 24  1478 public RuleSets() {
 25    }
 26   
 27    /**
 28    * Public constructor. Add the given rule set.
 29    *
 30    * @param ruleSet the RuleSet
 31    */
 32  1260 public RuleSets(RuleSet ruleSet) {
 33  1260 this();
 34  1260 addRuleSet(ruleSet);
 35    }
 36   
 37    /**
 38    * Add a ruleset for a language. Only one ruleset can be added for a specific
 39    * language. If ruleSet.getLanguage() is null, it is assumed to be a RuleSet of java
 40    * rules.
 41    *
 42    * @param ruleSet the RuleSet
 43    */
 44  1478 public void addRuleSet(RuleSet ruleSet) {
 45  1478 ruleSets.add(ruleSet);
 46    }
 47   
 48    /**
 49    * Get all the RuleSets.
 50    *
 51    * @return RuleSet[]
 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    * Return all rules from all rulesets.
 63    *
 64    * @return Set
 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    * Check if a source with given language should be checked by rules for a given
 76    * language. This is the case if both languages are equal, or if the source is in
 77    * java, and the language of the rules is unknown (for backward-compatibility
 78    * reasons).
 79    *
 80    * @param languageOfSource language of a source; can not be null
 81    * @param languageOfRule language of a ruleset; can be null
 82    * @return boolean true if the rule applies, else false
 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    * Apply all applicable rules to the compilation units.
 91    * Applicable means the language of the rules must match the language
 92    * of the source (@see applies).
 93    *
 94    * @param acuList the List of compilation units; the type these must have,
 95    * depends on the source language
 96    * @param ctx the RuleContext
 97    * @param language the Language of the source
 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    * Check if the rules that apply to a source of the given language
 110    * use DFA.
 111    *
 112    * @param language the language of a source
 113    * @return true if any rule in the RuleSet needs the DFA layer
 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    * Returns the Rule with the given name
 127    *
 128    * @param ruleName the name of the rule to find
 129    * @return the rule or null if not found
 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    }