View Javadoc
1 package net.sourceforge.pmd; 2 3 import net.sourceforge.pmd.ast.ASTCompilationUnit; 4 import net.sourceforge.pmd.ast.JavaParserVisitorAdapter; 5 6 import java.util.Iterator; 7 import java.util.List; 8 9 public abstract class AbstractRule extends JavaParserVisitorAdapter implements Rule { 10 11 private String name = getClass().getName(); 12 private RuleProperties properties = new RuleProperties(); 13 private String message; 14 private String description; 15 private String example; 16 private boolean m_include; 17 private int m_priority = LOWEST_PRIORITY; 18 19 public String getDescription() { 20 return description; 21 } 22 23 public void setDescription(String description) { 24 this.description = description; 25 } 26 27 public String getExample() { 28 return example; 29 } 30 31 public void setExample(String example) { 32 this.example = example; 33 } 34 35 public boolean hasProperty(String name) { 36 return properties.containsKey(name); 37 } 38 39 public void addProperty(String name, String property) { 40 properties.setProperty(name, property); 41 } 42 43 public double getDoubleProperty(String name) { 44 return properties.getDoubleValue(name); 45 } 46 47 public int getIntProperty(String name) { 48 return properties.getIntegerValue(name); 49 } 50 51 public boolean getBooleanProperty(String name) { 52 return properties.getBooleanValue(name); 53 } 54 55 public String getStringProperty(String name) { 56 return properties.getValue(name); 57 } 58 59 public String getName() { 60 return name; 61 } 62 63 public void setName(String name) { 64 this.name = name; 65 } 66 67 public String getMessage() { 68 return message; 69 } 70 71 public void setMessage(String message) { 72 this.message = message; 73 } 74 75 public boolean equals(Object o) { 76 if (!(o instanceof Rule)) { 77 return false; 78 } 79 return ((Rule)o).getName().equals(getName()); 80 } 81 82 public int hashCode() { 83 return getName().hashCode(); 84 } 85 86 protected void visitAll(List acus, RuleContext ctx) { 87 for (Iterator i = acus.iterator(); i.hasNext();) { 88 ASTCompilationUnit node = (ASTCompilationUnit) i.next(); 89 visit(node, ctx); 90 } 91 } 92 93 public void apply(List acus, RuleContext ctx) { 94 visitAll(acus, ctx); 95 } 96 97 public RuleViolation createRuleViolation(RuleContext ctx, int lineNumber) { 98 return new RuleViolation(this, lineNumber, ctx); 99 } 100 101 public RuleViolation createRuleViolation(RuleContext ctx, int lineNumber, String specificDescription) { 102 return new RuleViolation(this, lineNumber, specificDescription, ctx); 103 } 104 105 /*** 106 ******************************************************************************** 107 * 108 * Gets an enumeration to enumerate through this rule's property names. 109 * 110 * @return An enumeration of property names 111 */ 112 public RuleProperties getProperties() { 113 return properties; 114 } 115 116 /*** 117 ********************************************************************************* 118 * 119 * When the rule is to be included in the analysis, returns true; otherwise, returns false. 120 * 121 * @return True when the rule is included in analysis. 122 */ 123 public boolean include() { 124 return m_include; 125 } 126 127 /*** 128 ********************************************************************************* 129 * 130 * When the rule is to be included in the analysis, set to true; otherwise, set to false. 131 * 132 * @param include True when the rule is included in analysis. 133 */ 134 public void setInclude(boolean include) { 135 m_include = include; 136 } 137 138 /*** 139 ********************************************************************************* 140 * 141 * Returns the rule's priority that is used for including the rule in reports and analysis. 142 * 143 * @return A number between 1 and LOWEST_PRIORITY. 144 */ 145 public int getPriority() { 146 if ((m_priority < 0) || (m_priority > LOWEST_PRIORITY)) { 147 m_priority = LOWEST_PRIORITY; 148 } 149 150 return m_priority; 151 } 152 153 /*** 154 ********************************************************************************* 155 * 156 * Returns the rule's priority name that is used for including the rule in reports and analysis. 157 * 158 * @return A member of PRIORITIES. 159 */ 160 public String getPriorityName() { 161 return PRIORITIES[getPriority() - 1]; 162 } 163 164 /*** 165 ********************************************************************************* 166 * 167 * A rule will specify a priority for inclusion in reports and analysis. The default 168 * priority is "Low". 169 * 170 * @param The rule's priority of 1..LOWEST_PRIORITY. 171 */ 172 public void setPriority(int priority) { 173 if ((priority < 1) || (priority > LOWEST_PRIORITY)) { 174 m_priority = LOWEST_PRIORITY; 175 } else { 176 m_priority = priority; 177 } 178 } 179 }

This page was automatically generated by Maven