KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > apt > util > 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.apt.util;
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

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