View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd;
5   
6   import java.util.List;
7   import java.util.Properties;
8   
9   /**
10   * This is the basic Rule interface for PMD rules.
11   */
12  //FUTURE Implement Cloneable and clone()
13  public interface Rule {
14  	// FUTURE Use enum
15  	public static final int LOWEST_PRIORITY = 5;
16  
17  	// FUTURE Use enum
18  	public static final String[] PRIORITIES = { "High", "Medium High",
19  			"Medium", "Medium Low", "Low" };
20  
21  	/**
22  	 * Get the name of this Rule.
23  	 */
24  	String getName();
25  
26  	/**
27  	 * Set the name of this Rule.
28  	 */
29  	void setName(String name);
30  	
31  	/**
32  	 * Get the version of PMD in which this Rule was added.
33  	 * Return <code>null</code> if not applicable.
34  	 */
35  	String getSince();
36  	
37  	/**
38  	 * Set the version of PMD in which this Rule was added.
39  	 */
40  	void setSince(String since);
41  	
42  	/**
43  	 * Get the class of this Rule.
44  	 */
45  	String getRuleClass();
46  
47  	/**
48  	 * Set the class of this Rule.
49  	 */
50  	void setRuleClass(String ruleClass);
51  
52  	/**
53  	 * Get the name of the RuleSet containing this Rule.
54  	 * 
55  	 * @see RuleSet
56  	 */
57  	String getRuleSetName();
58  
59  	/**
60  	 * Set the name of the RuleSet containing this Rule.
61  	 * 
62  	 * @see RuleSet
63  	 */
64  	void setRuleSetName(String name);
65  
66  	/**
67  	 * Get the message to show when this Rule identifies a violation.
68  	 */
69  	String getMessage();
70  
71  	/**
72  	 * Set the message to show when this Rule identifies a violation.
73  	 */
74  	void setMessage(String message);
75  
76  	/**
77  	 * Get the description of this Rule.
78  	 */
79  	String getDescription();
80  
81  	/**
82  	 * Set the description of this Rule.
83  	 */
84  	void setDescription(String description);
85  
86  	/**
87  	 * Get the list of examples for this Rule.
88  	 */
89  	List<String> getExamples();
90  
91  	/**
92  	 * Still used by the JDeveloper plugin
93  	 * 
94  	 * @deprecated use getExamples(), since we now support multiple examples
95  	 */
96  	String getExample();
97  
98  	/**
99  	 * Add a single example for this Rule.
100 	 */
101 	void addExample(String example);
102 
103 	/**
104 	 * Get a URL for external information about this Rule.
105 	 */
106 	String getExternalInfoUrl();
107 
108 	/**
109 	 * Set a URL for external information about this Rule.
110 	 */
111 	void setExternalInfoUrl(String externalInfoUrl);
112 
113 	/**
114 	 * Get the priority of this Rule.
115 	 */
116 	int getPriority();
117 
118 	/**
119 	 * Set the priority of this Rule.
120 	 */
121 	void setPriority(int priority);
122 
123 	/**
124 	 * Get a name for the priority of this Rule.
125 	 */
126 	String getPriorityName();
127 
128 	/**
129 	 * TODO What is this?
130 	 * 
131 	 * @deprecated Don't know what this is for, so deprecating it.
132 	 */
133 	boolean include();
134 
135 	/**
136 	 * TODO What is this?
137 	 * 
138 	 * @deprecated Don't know what this is for, so deprecating it.
139 	 */
140 	void setInclude(boolean include);
141 
142 	/**
143 	 * Get all properties for this Rule.
144 	 * 
145 	 * @return the properties for the rule
146 	 */
147 	Properties getProperties();
148 
149 	/**
150 	 * Add a specific property to this Rule.
151 	 */
152 	void addProperty(String name, String property);
153 
154 	/**
155 	 * Add a set of properties to this Rule.
156 	 */
157 	void addProperties(Properties properties);
158 
159 	/**
160 	 * Get whether this Rule has a property of the given name.
161 	 */
162 	boolean hasProperty(String name);
163 
164 	/**
165 	 * Get the <code>boolean</code> value for the given property.
166 	 */
167 	boolean getBooleanProperty(String name);
168 
169 	/**
170 	 * Get the <code>int</code> value for the given property.
171 	 */
172 	int getIntProperty(String name);
173 
174 	/**
175 	 * Get the <code>double</code> value for the given property.
176 	 */
177 	double getDoubleProperty(String name);
178 
179 	/**
180 	 * Get the <code>java.util.String</code> value for the given property.
181 	 */
182 	String getStringProperty(String name);
183 
184 	/**
185 	 * Get the PropertyDescriptor for the given property.
186 	 */
187 	// FUTURE Rename to getPropertyDescriptor(String)
188 	PropertyDescriptor propertyDescriptorFor(String name);
189 
190 	/**
191 	 * Sets whether this Rule uses Data Flow Analysis.
192 	 */
193 	// FUTURE Use JavaBean conventions for boolean attributes
194 	void setUsesDFA();
195 
196 	/**
197 	 * Gets whether this Rule uses Data Flow Analysis.
198 	 */
199 	// FUTURE Use JavaBean conventions for boolean attributes
200 	boolean usesDFA();
201 
202 	/**
203 	 * Sets whether this Rule uses Type Resolution.
204 	 */
205 	// FUTURE Use JavaBean conventions for boolean attributes
206 	void setUsesTypeResolution();
207 
208 	/**
209 	 * Gets whether this Rule uses Type Resolution.
210 	 */
211 	// FUTURE Use JavaBean conventions for boolean attributes
212 	boolean usesTypeResolution();
213 
214 	/**
215 	 * Gets whether this Rule uses the RuleChain.
216 	 */
217 	// FUTURE Use JavaBean conventions for boolean attributes
218 	boolean usesRuleChain();
219 
220 	/**
221 	 * Gets the collection of AST node names visited by the Rule on the
222 	 * RuleChain.
223 	 */
224 	List<String> getRuleChainVisits();
225 
226 	/**
227 	 * Adds an AST node name to be visited by the Rule on the RuleChain.
228 	 */
229 	void addRuleChainVisit(String astNodeName);
230 	
231 	/**
232 	 * Start processing. Called once, before apply() is first called. 
233 	 */
234 	void start(RuleContext ctx);
235 
236 	/**
237 	 * Apply this rule to the given collection of compilation units, using the
238 	 * given context.
239 	 */
240 	void apply(List<?> astCompilationUnits, RuleContext ctx);
241 	
242 	/**
243 	 * End processing. Called once, after apply() is last called. 
244 	 */
245 	void end(RuleContext ctx);
246 }