15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.javac.main;
27
28 import java.io.File;
29 import java.io.FileWriter;
30 import java.io.PrintWriter;
31 import java.util.Collections;
32 import java.util.EnumSet;
33 import java.util.LinkedHashMap;
34 import java.util.Map;
35 import java.util.Set;
36
37 import javax.lang.model.SourceVersion;
38
39 import com.sun.tools.doclint.DocLint;
40 import com.sun.tools.javac.code.Lint;
41 import com.sun.tools.javac.code.Lint.LintCategory;
42 import com.sun.tools.javac.code.Source;
43 import com.sun.tools.javac.code.Type;
44 import com.sun.tools.javac.jvm.Profile;
45 import com.sun.tools.javac.jvm.Target;
46 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
47 import com.sun.tools.javac.util.Log;
48 import com.sun.tools.javac.util.Log.PrefixKind;
49 import com.sun.tools.javac.util.Log.WriterKind;
50 import com.sun.tools.javac.util.Options;
51 import com.sun.tools.javac.util.StringUtils;
52 import static com.sun.tools.javac.main.Option.ChoiceKind.*;
53 import static com.sun.tools.javac.main.Option.OptionGroup.*;
54 import static com.sun.tools.javac.main.Option.OptionKind.*;
55
56 /**
57 * Options for javac. The specific Option to handle a command-line option
58 * is identified by searching the members of this enum in order, looking for
59 * the first {@link #matches match}. The action for an Option is performed
60 * by calling {@link #process process}, and by providing a suitable
61 * {@link OptionHelper} to provide access the compiler state.
62 *
63 * <p><b>This is NOT part of any supported API.
64 * If you write code that depends on this, you do so at your own
65 * risk. This code and its internal interfaces are subject to change
66 * or deletion without notice.</b></p>
67 */
68 public enum Option {
69 G("-g", "opt.g", STANDARD, BASIC),
70
71 G_NONE("-g:none", "opt.g.none", STANDARD, BASIC) {
247 if (source == null) {
248 helper.error("err.invalid.source", operand);
249 return true;
250 }
251 return super.process(helper, option, operand);
252 }
253 },
254
255 TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
256 @Override
257 public boolean process(OptionHelper helper, String option, String operand) {
258 Target target = Target.lookup(operand);
259 if (target == null) {
260 helper.error("err.invalid.target", operand);
261 return true;
262 }
263 return super.process(helper, option, operand);
264 }
265 },
266
267 PROFILE("-profile", "opt.arg.profile", "opt.profile", STANDARD, BASIC) {
268 @Override
269 public boolean process(OptionHelper helper, String option, String operand) {
270 Profile profile = Profile.lookup(operand);
271 if (profile == null) {
272 helper.error("err.invalid.profile", operand);
273 return true;
274 }
275 return super.process(helper, option, operand);
276 }
277 },
278
279 VERSION("-version", "opt.version", STANDARD, INFO) {
280 @Override
281 public boolean process(OptionHelper helper, String option) {
282 Log log = helper.getLog();
283 String ownName = helper.getOwnName();
284 log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version());
285 return super.process(helper, option);
286 }
|
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.javac.main;
27
28 import java.io.File;
29 import java.io.FileWriter;
30 import java.io.PrintWriter;
31 import java.util.Collections;
32 import java.util.EnumSet;
33 import java.util.LinkedHashMap;
34 import java.util.Map;
35 import java.util.ServiceLoader;
36 import java.util.Set;
37 import java.util.TreeSet;
38
39 import javax.lang.model.SourceVersion;
40
41 import com.sun.tools.doclint.DocLint;
42 import com.sun.tools.javac.code.Lint;
43 import com.sun.tools.javac.code.Lint.LintCategory;
44 import com.sun.tools.javac.code.Source;
45 import com.sun.tools.javac.code.Type;
46 import com.sun.tools.javac.jvm.Profile;
47 import com.sun.tools.javac.jvm.Target;
48 import com.sun.tools.javac.platform.PlatformProvider;
49 import com.sun.tools.javac.platform.PlatformProviderFactory;
50 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
51 import com.sun.tools.javac.util.Log;
52 import com.sun.tools.javac.util.Log.PrefixKind;
53 import com.sun.tools.javac.util.Log.WriterKind;
54 import com.sun.tools.javac.util.Options;
55 import com.sun.tools.javac.util.StringUtils;
56
57 import static com.sun.tools.javac.main.Option.ChoiceKind.*;
58 import static com.sun.tools.javac.main.Option.OptionGroup.*;
59 import static com.sun.tools.javac.main.Option.OptionKind.*;
60
61 /**
62 * Options for javac. The specific Option to handle a command-line option
63 * is identified by searching the members of this enum in order, looking for
64 * the first {@link #matches match}. The action for an Option is performed
65 * by calling {@link #process process}, and by providing a suitable
66 * {@link OptionHelper} to provide access the compiler state.
67 *
68 * <p><b>This is NOT part of any supported API.
69 * If you write code that depends on this, you do so at your own
70 * risk. This code and its internal interfaces are subject to change
71 * or deletion without notice.</b></p>
72 */
73 public enum Option {
74 G("-g", "opt.g", STANDARD, BASIC),
75
76 G_NONE("-g:none", "opt.g.none", STANDARD, BASIC) {
252 if (source == null) {
253 helper.error("err.invalid.source", operand);
254 return true;
255 }
256 return super.process(helper, option, operand);
257 }
258 },
259
260 TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
261 @Override
262 public boolean process(OptionHelper helper, String option, String operand) {
263 Target target = Target.lookup(operand);
264 if (target == null) {
265 helper.error("err.invalid.target", operand);
266 return true;
267 }
268 return super.process(helper, option, operand);
269 }
270 },
271
272 RELEASE("-release", "opt.arg.release", "opt.release", STANDARD, BASIC) {
273 @Override
274 void help(Log log, OptionKind kind) {
275 if (this.kind != kind)
276 return;
277
278 Iterable<PlatformProviderFactory> factories =
279 ServiceLoader.load(PlatformProviderFactory.class, Arguments.class.getClassLoader());
280 Set<String> platforms = new TreeSet<>();
281
282 for (PlatformProviderFactory factory : factories) {
283 for (PlatformProvider platform : factory.createPlatformProviders()) {
284 platforms.add(platform.getName());
285 }
286 }
287
288 StringBuilder targets = new StringBuilder();
289 String delim = "";
290 for (String platform : platforms) {
291 targets.append(delim);
292 targets.append(platform);
293 delim = ", ";
294 }
295
296 log.printRawLines(WriterKind.NOTICE,
297 String.format(HELP_LINE_FORMAT,
298 super.helpSynopsis(log),
299 log.localize(PrefixKind.JAVAC, descrKey, targets.toString())));
300 }
301 },
302
303 PROFILE("-profile", "opt.arg.profile", "opt.profile", STANDARD, BASIC) {
304 @Override
305 public boolean process(OptionHelper helper, String option, String operand) {
306 Profile profile = Profile.lookup(operand);
307 if (profile == null) {
308 helper.error("err.invalid.profile", operand);
309 return true;
310 }
311 return super.process(helper, option, operand);
312 }
313 },
314
315 VERSION("-version", "opt.version", STANDARD, INFO) {
316 @Override
317 public boolean process(OptionHelper helper, String option) {
318 Log log = helper.getLog();
319 String ownName = helper.getOwnName();
320 log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version());
321 return super.process(helper, option);
322 }
|