001: /**
002: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
003: */package net.sourceforge.pmd;
004:
005: import java.util.List;
006: import java.util.Properties;
007:
008: /**
009: * This is the basic Rule interface for PMD rules.
010: */
011: //FUTURE Implement Cloneable and clone()
012: public interface Rule {
013: // FUTURE Use enum
014: public static final int LOWEST_PRIORITY = 5;
015:
016: // FUTURE Use enum
017: public static final String[] PRIORITIES = { "High", "Medium High",
018: "Medium", "Medium Low", "Low" };
019:
020: /**
021: * Get the name of this Rule.
022: */
023: String getName();
024:
025: /**
026: * Set the name of this Rule.
027: */
028: void setName(String name);
029:
030: /**
031: * Get the version of PMD in which this Rule was added.
032: * Return <code>null</code> if not applicable.
033: */
034: String getSince();
035:
036: /**
037: * Set the version of PMD in which this Rule was added.
038: */
039: void setSince(String since);
040:
041: /**
042: * Get the class of this Rule.
043: */
044: String getRuleClass();
045:
046: /**
047: * Set the class of this Rule.
048: */
049: void setRuleClass(String ruleClass);
050:
051: /**
052: * Get the name of the RuleSet containing this Rule.
053: *
054: * @see RuleSet
055: */
056: String getRuleSetName();
057:
058: /**
059: * Set the name of the RuleSet containing this Rule.
060: *
061: * @see RuleSet
062: */
063: void setRuleSetName(String name);
064:
065: /**
066: * Get the message to show when this Rule identifies a violation.
067: */
068: String getMessage();
069:
070: /**
071: * Set the message to show when this Rule identifies a violation.
072: */
073: void setMessage(String message);
074:
075: /**
076: * Get the description of this Rule.
077: */
078: String getDescription();
079:
080: /**
081: * Set the description of this Rule.
082: */
083: void setDescription(String description);
084:
085: /**
086: * Get the list of examples for this Rule.
087: */
088: List<String> getExamples();
089:
090: /**
091: * Still used by the JDeveloper plugin
092: *
093: * @deprecated use getExamples(), since we now support multiple examples
094: */
095: String getExample();
096:
097: /**
098: * Add a single example for this Rule.
099: */
100: void addExample(String example);
101:
102: /**
103: * Get a URL for external information about this Rule.
104: */
105: String getExternalInfoUrl();
106:
107: /**
108: * Set a URL for external information about this Rule.
109: */
110: void setExternalInfoUrl(String externalInfoUrl);
111:
112: /**
113: * Get the priority of this Rule.
114: */
115: int getPriority();
116:
117: /**
118: * Set the priority of this Rule.
119: */
120: void setPriority(int priority);
121:
122: /**
123: * Get a name for the priority of this Rule.
124: */
125: String getPriorityName();
126:
127: /**
128: * TODO What is this?
129: *
130: * @deprecated Don't know what this is for, so deprecating it.
131: */
132: boolean include();
133:
134: /**
135: * TODO What is this?
136: *
137: * @deprecated Don't know what this is for, so deprecating it.
138: */
139: void setInclude(boolean include);
140:
141: /**
142: * Get all properties for this Rule.
143: *
144: * @return the properties for the rule
145: */
146: Properties getProperties();
147:
148: /**
149: * Add a specific property to this Rule.
150: */
151: void addProperty(String name, String property);
152:
153: /**
154: * Add a set of properties to this Rule.
155: */
156: void addProperties(Properties properties);
157:
158: /**
159: * Get whether this Rule has a property of the given name.
160: */
161: boolean hasProperty(String name);
162:
163: /**
164: * Get the <code>boolean</code> value for the given property.
165: */
166: boolean getBooleanProperty(String name);
167:
168: /**
169: * Get the <code>int</code> value for the given property.
170: */
171: int getIntProperty(String name);
172:
173: /**
174: * Get the <code>double</code> value for the given property.
175: */
176: double getDoubleProperty(String name);
177:
178: /**
179: * Get the <code>java.util.String</code> value for the given property.
180: */
181: String getStringProperty(String name);
182:
183: /**
184: * Get the PropertyDescriptor for the given property.
185: */
186: // FUTURE Rename to getPropertyDescriptor(String)
187: PropertyDescriptor propertyDescriptorFor(String name);
188:
189: /**
190: * Sets whether this Rule uses Data Flow Analysis.
191: */
192: // FUTURE Use JavaBean conventions for boolean attributes
193: void setUsesDFA();
194:
195: /**
196: * Gets whether this Rule uses Data Flow Analysis.
197: */
198: // FUTURE Use JavaBean conventions for boolean attributes
199: boolean usesDFA();
200:
201: /**
202: * Sets whether this Rule uses Type Resolution.
203: */
204: // FUTURE Use JavaBean conventions for boolean attributes
205: void setUsesTypeResolution();
206:
207: /**
208: * Gets whether this Rule uses Type Resolution.
209: */
210: // FUTURE Use JavaBean conventions for boolean attributes
211: boolean usesTypeResolution();
212:
213: /**
214: * Gets whether this Rule uses the RuleChain.
215: */
216: // FUTURE Use JavaBean conventions for boolean attributes
217: boolean usesRuleChain();
218:
219: /**
220: * Gets the collection of AST node names visited by the Rule on the
221: * RuleChain.
222: */
223: List<String> getRuleChainVisits();
224:
225: /**
226: * Adds an AST node name to be visited by the Rule on the RuleChain.
227: */
228: void addRuleChainVisit(String astNodeName);
229:
230: /**
231: * Start processing. Called once, before apply() is first called.
232: */
233: void start(RuleContext ctx);
234:
235: /**
236: * Apply this rule to the given collection of compilation units, using the
237: * given context.
238: */
239: void apply(List<?> astCompilationUnits, RuleContext ctx);
240:
241: /**
242: * End processing. Called once, after apply() is last called.
243: */
244: void end(RuleContext ctx);
245: }
|