KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > tool > Options


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.tool;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16
17 /**
18  * Class used to handle options in the EclipseFileManager and the EclipseCompiler
19  */

20 public final class Options {
21     private static final Set JavaDoc<String JavaDoc> ZERO_ARGUMENT_OPTIONS;
22     private static final Set JavaDoc<String JavaDoc> ONE_ARGUMENT_OPTIONS;
23     private static final Set JavaDoc<String JavaDoc> FILE_MANAGER_OPTIONS;
24     static {
25         ZERO_ARGUMENT_OPTIONS = new HashSet JavaDoc<String JavaDoc>();
26         ZERO_ARGUMENT_OPTIONS.add("-progress");//$NON-NLS-1$
27
ZERO_ARGUMENT_OPTIONS.add("-proceedOnError");//$NON-NLS-1$
28
ZERO_ARGUMENT_OPTIONS.add("-time");//$NON-NLS-1$
29
ZERO_ARGUMENT_OPTIONS.add("-v");//$NON-NLS-1$
30
ZERO_ARGUMENT_OPTIONS.add("-version");//$NON-NLS-1$
31
ZERO_ARGUMENT_OPTIONS.add("-showversion");//$NON-NLS-1$
32
ZERO_ARGUMENT_OPTIONS.add("-deprecation");//$NON-NLS-1$
33
ZERO_ARGUMENT_OPTIONS.add("-help");//$NON-NLS-1$
34
ZERO_ARGUMENT_OPTIONS.add("-?");//$NON-NLS-1$
35
ZERO_ARGUMENT_OPTIONS.add("-help:warn");//$NON-NLS-1$
36
ZERO_ARGUMENT_OPTIONS.add("-?:warn");//$NON-NLS-1$
37
ZERO_ARGUMENT_OPTIONS.add("-noExit");//$NON-NLS-1$
38
ZERO_ARGUMENT_OPTIONS.add("-verbose");//$NON-NLS-1$
39
ZERO_ARGUMENT_OPTIONS.add("-referenceInfo");//$NON-NLS-1$
40
ZERO_ARGUMENT_OPTIONS.add("-inlineJSR");//$NON-NLS-1$
41
ZERO_ARGUMENT_OPTIONS.add("-g");//$NON-NLS-1$
42
ZERO_ARGUMENT_OPTIONS.add("-g:none");//$NON-NLS-1$
43
ZERO_ARGUMENT_OPTIONS.add("-nowarn");//$NON-NLS-1$
44
ZERO_ARGUMENT_OPTIONS.add("-warn:none");//$NON-NLS-1$
45
ZERO_ARGUMENT_OPTIONS.add("-preserveAllLocals");//$NON-NLS-1$
46
ZERO_ARGUMENT_OPTIONS.add("-enableJavadoc");//$NON-NLS-1$
47
ZERO_ARGUMENT_OPTIONS.add("-Xemacs");//$NON-NLS-1$
48
ZERO_ARGUMENT_OPTIONS.add("-X");//$NON-NLS-1$
49
ZERO_ARGUMENT_OPTIONS.add("-O");//$NON-NLS-1$
50
ZERO_ARGUMENT_OPTIONS.add("-1.3");//$NON-NLS-1$
51
ZERO_ARGUMENT_OPTIONS.add("-1.4");//$NON-NLS-1$
52
ZERO_ARGUMENT_OPTIONS.add("-1.5");//$NON-NLS-1$
53
ZERO_ARGUMENT_OPTIONS.add("-5");//$NON-NLS-1$
54
ZERO_ARGUMENT_OPTIONS.add("-5.0");//$NON-NLS-1$
55
ZERO_ARGUMENT_OPTIONS.add("-1.6");//$NON-NLS-1$
56
ZERO_ARGUMENT_OPTIONS.add("-6");//$NON-NLS-1$
57
ZERO_ARGUMENT_OPTIONS.add("-6.0");//$NON-NLS-1$
58
ZERO_ARGUMENT_OPTIONS.add("-proc:only");//$NON-NLS-1$
59
ZERO_ARGUMENT_OPTIONS.add("-proc:none");//$NON-NLS-1$
60
ZERO_ARGUMENT_OPTIONS.add("-XprintProcessorInfo");//$NON-NLS-1$
61
ZERO_ARGUMENT_OPTIONS.add("-XprintRounds");//$NON-NLS-1$
62

63         FILE_MANAGER_OPTIONS = new HashSet JavaDoc<String JavaDoc>();
64         FILE_MANAGER_OPTIONS.add("-bootclasspath");//$NON-NLS-1$
65
FILE_MANAGER_OPTIONS.add("-encoding");//$NON-NLS-1$
66
FILE_MANAGER_OPTIONS.add("-d");//$NON-NLS-1$
67
FILE_MANAGER_OPTIONS.add("-classpath");//$NON-NLS-1$
68
FILE_MANAGER_OPTIONS.add("-cp");//$NON-NLS-1$
69
FILE_MANAGER_OPTIONS.add("-sourcepath");//$NON-NLS-1$
70
FILE_MANAGER_OPTIONS.add("-extdirs");//$NON-NLS-1$
71
FILE_MANAGER_OPTIONS.add("-endorseddirs");//$NON-NLS-1$
72
FILE_MANAGER_OPTIONS.add("-s");//$NON-NLS-1$
73
FILE_MANAGER_OPTIONS.add("-processorpath");//$NON-NLS-1$
74

75         ONE_ARGUMENT_OPTIONS = new HashSet JavaDoc<String JavaDoc>();
76         ONE_ARGUMENT_OPTIONS.addAll(FILE_MANAGER_OPTIONS);
77         ONE_ARGUMENT_OPTIONS.add("-log");//$NON-NLS-1$
78
ONE_ARGUMENT_OPTIONS.add("-repeat");//$NON-NLS-1$
79
ONE_ARGUMENT_OPTIONS.add("-maxProblems");//$NON-NLS-1$
80
ONE_ARGUMENT_OPTIONS.add("-source");//$NON-NLS-1$
81
ONE_ARGUMENT_OPTIONS.add("-target");//$NON-NLS-1$
82
ONE_ARGUMENT_OPTIONS.add("-processor");//$NON-NLS-1$
83
ONE_ARGUMENT_OPTIONS.add("-classNames");//$NON-NLS-1$
84

85     }
86     public static int processOptionsFileManager(String JavaDoc option) {
87         if (option == null) return -1;
88         if (FILE_MANAGER_OPTIONS.contains(option)) {
89             return 1;
90         }
91         return -1;
92     }
93
94     public static int processOptions(String JavaDoc option) {
95         if (option == null) return -1;
96         if (ZERO_ARGUMENT_OPTIONS.contains(option)) {
97             return 0;
98         }
99         if (ONE_ARGUMENT_OPTIONS.contains(option)) {
100             return 1;
101         }
102         if (option.startsWith("-g")) { //$NON-NLS-1$
103
int length = option.length();
104             if (length > 3) {
105                 StringTokenizer JavaDoc tokenizer =
106                     new StringTokenizer JavaDoc(option.substring(3, option.length()), ",");//$NON-NLS-1$
107
while (tokenizer.hasMoreTokens()) {
108                     String JavaDoc token = tokenizer.nextToken();
109                     if ("vars".equals(token) || "lines".equals(token) || "source".equals(token)) {//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
110
continue;
111                     }
112                     return -1;
113                 }
114                 return 0;
115             }
116             return -1;
117         }
118         if (option.startsWith("-warn")) {//$NON-NLS-1$
119
int length = option.length();
120             if (length <= 6) {
121                 return -1;
122             }
123             int warnTokenStart;
124             switch (option.charAt(6)) {
125                 case '+' :
126                     warnTokenStart = 7;
127                     break;
128                 case '-' :
129                     warnTokenStart = 7;
130                     break;
131                 default:
132                     warnTokenStart = 6;
133             }
134         
135             StringTokenizer JavaDoc tokenizer =
136                 new StringTokenizer JavaDoc(option.substring(warnTokenStart, option.length()), ","); //$NON-NLS-1$
137
int tokenCounter = 0;
138
139             while (tokenizer.hasMoreTokens()) {
140                 String JavaDoc token = tokenizer.nextToken();
141                 tokenCounter++;
142                 if ("constructorName".equals(token)//$NON-NLS-1$
143
|| token.equals("pkgDefaultMethod")//$NON-NLS-1$
144
|| token.equals("packageDefaultMethod")//$NON-NLS-1$
145
|| token.equals("maskedCatchBlock")//$NON-NLS-1$
146
|| token.equals("maskedCatchBlocks")//$NON-NLS-1$
147
|| token.equals("deprecation")//$NON-NLS-1$
148
|| token.equals("allDeprecation")//$NON-NLS-1$
149
|| token.equals("unusedLocal")//$NON-NLS-1$
150
|| token.equals("unusedLocals")//$NON-NLS-1$
151
|| token.equals("unusedArgument")//$NON-NLS-1$
152
|| token.equals("unusedArguments")//$NON-NLS-1$
153
|| token.equals("unusedImport")//$NON-NLS-1$
154
|| token.equals("unusedImports")//$NON-NLS-1$
155
|| token.equals("unusedPrivate")//$NON-NLS-1$
156
|| token.equals("unusedLabel")//$NON-NLS-1$
157
|| token.equals("localHiding")//$NON-NLS-1$
158
|| token.equals("fieldHiding")//$NON-NLS-1$
159
|| token.equals("specialParamHiding")//$NON-NLS-1$
160
|| token.equals("conditionAssign")//$NON-NLS-1$
161
|| token.equals("syntheticAccess")//$NON-NLS-1$
162
|| token.equals("synthetic-access")//$NON-NLS-1$
163
|| token.equals("nls")//$NON-NLS-1$
164
|| token.equals("staticReceiver")//$NON-NLS-1$
165
|| token.equals("indirectStatic")//$NON-NLS-1$
166
|| token.equals("noEffectAssign")//$NON-NLS-1$
167
|| token.equals("intfNonInherited")//$NON-NLS-1$
168
|| token.equals("interfaceNonInherited")//$NON-NLS-1$
169
|| token.equals("charConcat")//$NON-NLS-1$
170
|| token.equals("noImplicitStringConversion")//$NON-NLS-1$
171
|| token.equals("semicolon")//$NON-NLS-1$
172
|| token.equals("serial")//$NON-NLS-1$
173
|| token.equals("emptyBlock")//$NON-NLS-1$
174
|| token.equals("uselessTypeCheck")//$NON-NLS-1$
175
|| token.equals("unchecked")//$NON-NLS-1$
176
|| token.equals("unsafe")//$NON-NLS-1$
177
|| token.equals("raw")//$NON-NLS-1$
178
|| token.equals("finalBound")//$NON-NLS-1$
179
|| token.equals("suppress")//$NON-NLS-1$
180
|| token.equals("warningToken")//$NON-NLS-1$
181
|| token.equals("unnecessaryElse")//$NON-NLS-1$
182
|| token.equals("javadoc")//$NON-NLS-1$
183
|| token.equals("allJavadoc")//$NON-NLS-1$
184
|| token.equals("assertIdentifier")//$NON-NLS-1$
185
|| token.equals("enumIdentifier")//$NON-NLS-1$
186
|| token.equals("finally")//$NON-NLS-1$
187
|| token.equals("unusedThrown")//$NON-NLS-1$
188
|| token.equals("unqualifiedField")//$NON-NLS-1$
189
|| token.equals("unqualified-field-access")//$NON-NLS-1$
190
|| token.equals("typeHiding")//$NON-NLS-1$
191
|| token.equals("varargsCast")//$NON-NLS-1$
192
|| token.equals("null")//$NON-NLS-1$
193
|| token.equals("boxing")//$NON-NLS-1$
194
|| token.equals("over-ann")//$NON-NLS-1$
195
|| token.equals("dep-ann")//$NON-NLS-1$
196
|| token.equals("intfAnnotation")//$NON-NLS-1$
197
|| token.equals("enumSwitch")//$NON-NLS-1$
198
|| token.equals("incomplete-switch")//$NON-NLS-1$
199
|| token.equals("hiding")//$NON-NLS-1$
200
|| token.equals("static-access")//$NON-NLS-1$
201
|| token.equals("unused")//$NON-NLS-1$
202
|| token.equals("paramAssign")//$NON-NLS-1$
203
|| token.equals("discouraged")//$NON-NLS-1$
204
|| token.equals("forbidden")//$NON-NLS-1$
205
|| token.equals("fallthrough")) {//$NON-NLS-1$
206
continue;
207                 } else if (token.equals("tasks")) {//$NON-NLS-1$
208
String JavaDoc taskTags = "";//$NON-NLS-1$
209
int start = token.indexOf('(');
210                     int end = token.indexOf(')');
211                     if (start >= 0 && end >= 0 && start < end){
212                         taskTags = token.substring(start+1, end).trim();
213                         taskTags = taskTags.replace('|',',');
214                     }
215                     if (taskTags.length() == 0){
216                         return -1;
217                     }
218                     continue;
219                 } else {
220                     return -1;
221                 }
222             }
223             if (tokenCounter == 0) {
224                 return -1;
225             } else {
226                 return 0;
227             }
228         }
229         if (option.startsWith("-J")//$NON-NLS-1$
230
|| option.startsWith("-X")//$NON-NLS-1$
231
|| option.startsWith("-A")) {//$NON-NLS-1$
232
return 0;
233         }
234         return -1;
235     }
236 }
237
Popular Tags