KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > doctorj > Options


1 package org.incava.doctorj;
2
3 import java.io.*;
4 import java.util.*;
5 import org.incava.analysis.ContextReport;
6 import org.incava.jagol.*;
7 import org.incava.lang.StringExt;
8
9
10 /**
11  * Options for Javadoc processing, supporting:
12  *
13  * doctorj (just errors)
14  * doctorj --public (warning level of 0; public methods)
15  * doctorj --protected (warning level of 1)
16  * doctorj --package (warning level of 2)
17  * doctorj --private (warning level of 3)
18  * doctorj --pedantic (warning level at max)
19  */

20 public class Options extends OptionSet
21 {
22     public static int MAXIMUM_WARNING_LEVEL = 100;
23
24     public static int MINIMUM_WARNING_LEVEL = -1;
25
26     public static int DEFAULT_WARNING_LEVEL = 4;
27
28     /**
29      * The strictness level, for warnings.
30      */

31     public static int warningLevel = DEFAULT_WARNING_LEVEL;
32
33     /**
34      * Whether to use single-line (emacs) or multi-line (non-emacs) output
35      * format. The emacs form is most suitable for IDEs, which expect
36      * single-line output.
37      */

38     public static boolean emacsOutput = false;
39
40     /**
41      * The version.
42      */

43     public static String JavaDoc VERSION = "5.1.2";
44
45     /**
46      * The Java source version.
47      */

48     public static String JavaDoc source = "1.4";
49
50     /**
51      * The warning level option.
52      */

53     private IntegerOption _levelOpt;
54
55     /**
56      * The warning level option.
57      */

58     private IntegerOption _warningOpt;
59
60     /**
61      * Option to set warning level to the equivalent of --level=0.
62      */

63     private BooleanOption _errorsOpt;
64
65 // /**
66
// * Option to set warning level to the equivalent of --level=1.
67
// */
68
// private BooleanOption _publicOpt;
69

70 // /**
71
// * Option to set warning level to the equivalent of --level=2.
72
// */
73
// private BooleanOption _protectedOpt;
74

75 // /**
76
// * Option to set warning level to the equivalent of --level=3.
77
// */
78
// private BooleanOption _packageOpt;
79

80 // /**
81
// * Option to set warning level to the equivalent of --level=4.
82
// */
83
// private BooleanOption _privateOpt;
84

85 // /**
86
// * Option to set warning level to the equivalent of --level=max.
87
// */
88
// private BooleanOption _pedanticOpt;
89

90     /**
91      * The emacs option.
92      */

93     private BooleanOption _emacsOpt;
94
95     /**
96      * The tab width option.
97      */

98     private IntegerOption _tabWidthOpt;
99
100     /**
101      * The verbose option.
102      */

103     private BooleanOption _verboseOpt;
104
105     /**
106      * The list of word-list (dictionary) files.
107      */

108     private ListOption _dictOpt;
109
110     /**
111      * The version option.
112      */

113     private BooleanOption _versionOpt;
114
115     /**
116      * The source option.
117      */

118     private StringOption _sourceOpt;
119
120     private static Options instance = null;
121
122     public static Options get()
123     {
124         if (instance == null) {
125             instance = new Options();
126         }
127         return instance;
128     }
129
130     protected Options()
131     {
132         super("doctorj", "Analyzes and validates Java and Javadoc");
133
134         // use the doctorj.* equivalent property for each option.
135

136         Boolean JavaDoc emacs = new Boolean JavaDoc(emacsOutput);
137         String JavaDoc emacsProperty = System.getProperty("doctorj.emacs");
138         tr.Ace.log("emacs property: " + emacsProperty);
139         if (emacsProperty != null) {
140             emacs = new Boolean JavaDoc(emacsProperty);
141             tr.Ace.log("emacs: " + emacs);
142         }
143
144         Integer JavaDoc lvl = new Integer JavaDoc(warningLevel);
145         String JavaDoc warningLvlProperty = System.getProperty("doctorj.level");
146         if (warningLvlProperty == null) {
147             warningLvlProperty = System.getProperty("doctorj.warning");
148         }
149         
150         if (warningLvlProperty != null) {
151             lvl = new Integer JavaDoc(warningLvlProperty);
152         }
153         
154         Integer JavaDoc tabWidth = new Integer JavaDoc(ContextReport.tabWidth);
155         String JavaDoc tabWidthProperty = System.getProperty("doctorj.tabwidth");
156         if (tabWidthProperty != null) {
157             tabWidth = new Integer JavaDoc(tabWidthProperty);
158         }
159
160         Boolean JavaDoc verbose = new Boolean JavaDoc(false);
161         String JavaDoc verboseProperty = System.getProperty("doctorj.verbose");
162         if (verboseProperty != null) {
163             verbose = new Boolean JavaDoc(verboseProperty);
164         }
165
166         List wordLists = new ArrayList();
167         String JavaDoc dirProperty = System.getProperty("doctorj.dir");
168         tr.Ace.log("dirProperty: " + dirProperty);
169         
170         if (dirProperty != null) {
171             Locale locale = Locale.getDefault();
172             tr.Ace.log("locale: " + locale);
173             
174             String JavaDoc wordListFile = dirProperty + "/words." + locale;
175             tr.Ace.log("wordListFile: " + wordListFile);
176             
177             wordLists.add(wordListFile);
178         }
179         
180         String JavaDoc dictProperty = System.getProperty("doctorj.dictionaries");
181         tr.Ace.log("dictProperty", dictProperty);
182         
183         if (dictProperty != null) {
184             List list = StringExt.listify(dictProperty);
185             Iterator it = list.iterator();
186             while (it.hasNext()) {
187                 String JavaDoc s = (String JavaDoc)it.next();
188                 wordLists.add(s);
189             }
190         }
191         
192         add(_emacsOpt = new BooleanOption("emacs", "whether to list violations in Emacs form (single line)", emacs));
193         add(_levelOpt = new IntegerOption("level", "the level of warnings to be output, with 0 being to check only errors", lvl));
194         add(_warningOpt = new IntegerOption("warning", "same as --level", lvl));
195
196 // add(_errorsOpt = new BooleanOption("errors", "report only errors; equivalent to warning level of 0"));
197
// add(_publicOpt = new BooleanOption("public", "public methods; equivalent to warning level of 1"));
198
// add(_protectedOpt = new BooleanOption("protected", "protected methods; equivalent to warning level of 2"));
199
// add(_packageOpt = new BooleanOption("package", "package methods; equivalent to warning level of 3"));
200
// add(_privateOpt = new BooleanOption("private", "private methods; warning level of 4"));
201
// add(_pedanticOpt = new BooleanOption("pedantic", "warning level at max"));
202

203         add(_tabWidthOpt = new IntegerOption("tabwidth", "the number of spaces to treat tabs equal to", tabWidth));
204         add(_dictOpt = new ListOption("dictionaries", "the list of dictionary (word list) files", wordLists));
205         add(_verboseOpt = new BooleanOption("verbose", "whether to run in verbose mode (for debugging)", verbose));
206         add(_versionOpt = new BooleanOption("version", "Displays the version"));
207         add(_sourceOpt = new StringOption("source", "the Java source version; either 1.3, 1.4 (the default), or 1.5", source));
208         _versionOpt.setShortName('v');
209         
210         addRunControlFile("/etc/doctorj.conf");
211         addRunControlFile("~/.doctorjrc");
212     }
213
214     /**
215      * Processes the run control files and command line arguments, and sets the
216      * static variables. Returns the arguments that were not consumed by option
217      * processing.
218      */

219     public String JavaDoc[] process(String JavaDoc[] args)
220     {
221         tr.Ace.log("args: " + args);
222         String JavaDoc[] unprocessed = super.process(args);
223
224         Integer JavaDoc tabWidthInt = _tabWidthOpt.getValue();
225         if (tabWidthInt != null) {
226             tr.Ace.log("setting tab width: " + tabWidthInt);
227             ContextReport.tabWidth = tabWidthInt.intValue();
228         }
229     
230         Integer JavaDoc levelInt = _levelOpt.getValue();
231         if (levelInt != null) {
232             tr.Ace.log("setting warning level: " + levelInt);
233             warningLevel = levelInt.intValue();
234         }
235
236 // if (_errorsOpt.getValue() != null) {
237
// warningLevel = 0;
238
// }
239
// else if (_publicOpt.getValue() != null) {
240
// warningLevel = 1;
241
// }
242
// else if (_protectedOpt.getValue() != null) {
243
// warningLevel = 2;
244
// }
245
// else if (_packageOpt.getValue() != null) {
246
// warningLevel = 3;
247
// }
248
// else if (_privateOpt.getValue() != null) {
249
// warningLevel = 4;
250
// }
251
// else if (_pedanticOpt.getValue() != null) {
252
// warningLevel = MAXIMUM_WARNING_LEVEL;
253
// }
254

255         Boolean JavaDoc emacsBool = _emacsOpt.getValue();
256         if (emacsBool != null) {
257             tr.Ace.log("setting output format: " + emacsBool);
258             emacsOutput = emacsBool.booleanValue();
259         }
260         
261         Boolean JavaDoc verboseBool = _verboseOpt.getValue();
262         if (verboseBool != null) {
263             tr.Ace.setVerbose(verboseBool.booleanValue());
264         }
265
266         Boolean JavaDoc versionBool = _versionOpt.getValue();
267         if (versionBool != null) {
268             System.out.println("doctorj, version " + VERSION);
269             System.out.println("Written by Jeff Pace (jpace [at] incava [dot] org)");
270             System.out.println("Released under the Lesser GNU Public License");
271             System.exit(0);
272         }
273
274         List dictList = _dictOpt.getValue();
275         if (dictList != null) {
276             Iterator it = dictList.iterator();
277             while (it.hasNext()) {
278                 String JavaDoc dict = (String JavaDoc)it.next();
279                 ItemDocAnalyzer.spellChecker.addDictionary(dict);
280             }
281         }
282
283         String JavaDoc sourceStr = _sourceOpt.getValue();
284         if (sourceStr != null) {
285             tr.Ace.log("sourceStr", sourceStr);
286             source = sourceStr;
287         }
288
289         tr.Ace.blue("unprocessed", unprocessed);
290         
291         return unprocessed;
292     }
293
294 }
295
Popular Tags