View Javadoc
1 package net.sourceforge.pmd; 2 3 import java.util.HashSet; 4 import java.util.Iterator; 5 import java.util.List; 6 import java.util.Set; 7 8 public class RuleSet { 9 private Set rules = new HashSet(); 10 private String name; 11 private String description; 12 13 /*** 14 * Indicates whether or not the rule set should be included in PMD's analysis. 15 * True to include the rule set; otherwise, false to exclude the rule set. 16 */ 17 private boolean m_include; 18 19 /*** 20 * The name of the file the rule set is stored in, e.g., "basic_rules.xml". The user may 21 * change the rule set name; therefore, the rule set name cannot be used for a file name. 22 * This variable is set when the rule set is read. 23 */ 24 private String m_fileName; 25 26 public int size() { 27 return rules.size(); 28 } 29 30 public void addRule(Rule rule) { 31 rules.add(rule); 32 } 33 34 public Set getRules() { 35 return rules; 36 } 37 38 public Rule getRuleByName(String ruleName) { 39 for (Iterator i = rules.iterator(); i.hasNext();) { 40 Rule r = (Rule) i.next(); 41 if (r.getName().equals(ruleName)) { 42 return r; 43 } 44 } 45 throw new RuntimeException("Couldn't find rule named " + ruleName + " in the ruleset " + name); 46 } 47 48 public void addRuleSet(RuleSet ruleSet) { 49 rules.addAll(ruleSet.getRules()); 50 } 51 52 public void apply(List acuList, RuleContext ctx) { 53 Iterator rs = rules.iterator(); 54 while (rs.hasNext()) { 55 Rule rule = (Rule) rs.next(); 56 57 rule.apply(acuList, ctx); 58 } 59 } 60 61 public String getName() { 62 return name; 63 } 64 65 public void setName(String name) { 66 this.name = name; 67 } 68 69 public String getDescription() { 70 return description; 71 } 72 73 public void setDescription(String description) { 74 this.description = description; 75 } 76 77 /*** 78 * Returns true when the rule set is included in PMD's analysis; otherwise, false when 79 * it is excluded. 80 * 81 * @return True to include during analysis. 82 */ 83 public boolean include() { 84 return m_include; 85 } 86 87 /*** 88 * Set to true when the rule set is included in PMD's analysis; otherwise, set to false 89 * when it is excluded. 90 * 91 * @param include True to include during analysis. 92 */ 93 public void setInclude(boolean include) { 94 m_include = include; 95 } 96 97 /*** 98 * Get the name of the file the rule set is to be stored in, e.g., "basic_rules.xml". 99 * 100 * @return The name of the rule set file. 101 */ 102 public String getFileName() { 103 if (m_fileName == null) { 104 m_fileName = name.toLowerCase().replace(' ', '_') + ".xml"; 105 } 106 107 return m_fileName; 108 } 109 110 /*** 111 * Set the name of the file the rule set is to be stored in, e.g., "basic_rules.xml". 112 * 113 * @param fileName The name of the rule set file. 114 */ 115 public void setFileName(String fileName) { 116 if (fileName != null) { 117 fileName = fileName.trim(); 118 119 if (fileName.length() == 0) { 120 fileName = null; 121 } 122 } 123 124 m_fileName = fileName; 125 } 126 }

This page was automatically generated by Maven