KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > Plugin


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2004, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import edu.umd.cs.findbugs.plan.DetectorOrderingConstraint;
26
27 /**
28  * A FindBugs plugin.
29  * A plugin contains executable Detector classes, as well as meta
30  * information decribing those detectors (such as human-readable
31  * detector and bug descriptions).
32  *
33  * @see PluginLoader
34  * @author David Hovemeyer
35  */

36 public class Plugin {
37     private String JavaDoc pluginId;
38     private String JavaDoc provider;
39     private String JavaDoc website;
40     private String JavaDoc shortDescription;
41     private ArrayList JavaDoc<DetectorFactory> detectorFactoryList;
42     private ArrayList JavaDoc<BugPattern> bugPatternList;
43     private ArrayList JavaDoc<BugCode> bugCodeList;
44     private boolean enabled;
45
46     // Ordering constraints
47
private ArrayList JavaDoc<DetectorOrderingConstraint> interPassConstraintList;
48     private ArrayList JavaDoc<DetectorOrderingConstraint> intraPassConstraintList;
49
50     /**
51      * Constructor.
52      * Creates an empty plugin object.
53      *
54      * @param pluginId the plugin's unique identifier
55      */

56     public Plugin(String JavaDoc pluginId) {
57         this.pluginId = pluginId;
58         this.detectorFactoryList = new ArrayList JavaDoc<DetectorFactory>();
59         this.bugPatternList = new ArrayList JavaDoc<BugPattern>();
60         this.bugCodeList = new ArrayList JavaDoc<BugCode>();
61         this.interPassConstraintList = new ArrayList JavaDoc<DetectorOrderingConstraint>();
62         this.intraPassConstraintList = new ArrayList JavaDoc<DetectorOrderingConstraint>();
63     }
64
65     /**
66      * Set whether or not this Plugin is enabled.
67      *
68      * @param enabled true if the Plugin is enabled, false if not
69      */

70     public void setEnabled(boolean enabled) {
71         this.enabled = enabled;
72     }
73
74     /**
75      * Return whether or not the Plugin is enabled.
76      *
77      * @return true if the Plugin is enabled, false if not
78      */

79     public boolean isEnabled() {
80         return enabled;
81     }
82
83     /**
84      * Set plugin provider.
85      *
86      * @param provider the plugin provider
87      */

88     public void setProvider(String JavaDoc provider) {
89         this.provider = provider;
90     }
91
92     /**
93      * Get the plugin provider.
94      *
95      * @return the provider, or null if the provider was not specified
96      */

97     public String JavaDoc getProvider() {
98         return provider;
99     }
100
101     /**
102      * Set plugin website.
103      *
104      * @param website the plugin website
105      */

106     public void setWebsite(String JavaDoc website) {
107         this.website = website;
108     }
109
110     /**
111      * Get the plugin website.
112      *
113      * @return the website, or null if the was not specified
114      */

115     public String JavaDoc getWebsite() {
116         return website;
117     }
118
119     /**
120      * Set plugin short (one-line) text description.
121      *
122      * @param shortDescription the plugin short text description
123      */

124     public void setShortDescription(String JavaDoc shortDescription) {
125         this.shortDescription = shortDescription;
126     }
127
128     /**
129      * Get the plugin short (one-line) description.
130      *
131      * @return the short description, or null if the
132      * short description was not specified
133      */

134     public String JavaDoc getShortDescription() {
135         return shortDescription;
136     }
137
138     /**
139      * Add a DetectorFactory for a Detector implemented by the Plugin.
140      *
141      * @param factory the DetectorFactory
142      */

143     public void addDetectorFactory(DetectorFactory factory) {
144         detectorFactoryList.add(factory);
145     }
146     
147     /**
148      * Add a BugPattern reported by the Plugin.
149      *
150      * @param bugPattern
151      */

152     public void addBugPattern(BugPattern bugPattern) {
153         bugPatternList.add(bugPattern);
154     }
155     
156     /**
157      * Add a BugCode reported by the Plugin.
158      *
159      * @param bugCode
160      */

161     public void addBugCode(BugCode bugCode) {
162         bugCodeList.add(bugCode);
163     }
164
165     /**
166      * Add an inter-pass Detector ordering constraint.
167      *
168      * @param constraint the inter-pass Detector ordering constraint
169      */

170     public void addInterPassOrderingConstraint(DetectorOrderingConstraint constraint) {
171         interPassConstraintList.add(constraint);
172     }
173
174     /**
175      * Add an intra-pass Detector ordering constraint.
176      *
177      * @param constraint the intra-pass Detector ordering constraint
178      */

179     public void addIntraPassOrderingConstraint(DetectorOrderingConstraint constraint) {
180         intraPassConstraintList.add(constraint);
181     }
182
183     /**
184      * Look up a DetectorFactory by short name.
185      *
186      * @param shortName the short name
187      * @return the DetectorFactory
188      */

189     public DetectorFactory getFactoryByShortName(final String JavaDoc shortName) {
190         return chooseFactory(new FactoryChooser() {
191             public boolean choose(DetectorFactory factory) {
192                 return factory.getShortName().equals(shortName);
193             }
194         });
195     }
196
197     /**
198      * Look up a DetectorFactory by full name.
199      *
200      * @param fullName the full name
201      * @return the DetectorFactory
202      */

203     public DetectorFactory getFactoryByFullName(final String JavaDoc fullName) {
204         return chooseFactory(new FactoryChooser() {
205             public boolean choose(DetectorFactory factory) {
206                 return factory.getFullName().equals(fullName);
207             }
208         });
209     }
210     
211     /**
212      * Get Iterator over DetectorFactory objects in the Plugin.
213      *
214      * @return Iterator over DetectorFactory objects
215      */

216     public Iterator JavaDoc<DetectorFactory> detectorFactoryIterator() {
217         return detectorFactoryList.iterator();
218     }
219     
220     /**
221      * Get Iterator over BugPattern objects in the Plugin.
222      *
223      * @return Iterator over BugPattern objects
224      */

225     public Iterator JavaDoc<BugPattern> bugPatternIterator() {
226         return bugPatternList.iterator();
227     }
228     
229     /**
230      * Get Iterator over BugCode objects in the Plugin.
231      *
232      * @return Iterator over BugCode objects
233      */

234     public Iterator JavaDoc<BugCode> bugCodeIterator() {
235         return bugCodeList.iterator();
236     }
237
238     /**
239      * Return an Iterator over the inter-pass Detector ordering constraints.
240      */

241     public Iterator JavaDoc<DetectorOrderingConstraint> interPassConstraintIterator() {
242         return interPassConstraintList.iterator();
243     }
244
245     /**
246      * Return an Iterator over the intra-pass Detector ordering constraints.
247      */

248     public Iterator JavaDoc<DetectorOrderingConstraint> intraPassConstraintIterator() {
249         return intraPassConstraintList.iterator();
250     }
251
252     /**
253      * @return Returns the pluginId.
254      */

255     public String JavaDoc getPluginId() {
256         return pluginId;
257     }
258
259     private interface FactoryChooser {
260         public boolean choose(DetectorFactory factory);
261     }
262
263     private DetectorFactory chooseFactory(FactoryChooser chooser) {
264         for (Iterator JavaDoc<DetectorFactory> i = detectorFactoryIterator(); i.hasNext(); ) {
265             DetectorFactory factory = i.next();
266             if (chooser.choose(factory))
267                 return factory;
268         }
269         return null;
270     }
271 }
272
273 // vim:ts=4
274
Popular Tags