📄 main.java
字号:
/** * @(#)Main.java 1.55 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.tools.javac.v8;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.text.MessageFormat;import java.util.ResourceBundle;import java.util.MissingResourceException;import java.util.StringTokenizer;import com.sun.tools.javac.v8.util.*;import com.sun.tools.javac.v8.code.*;import com.sun.tools.javac.v8.tree.*;import com.sun.tools.javac.v8.comp.*;import com.sun.tools.javac.v8.parser.*;/** * This class provides a commandline interface to the GJC compiler. */public class Main { /** * For testing: enter any options you want to be set implicitly * here. */ static String[] forcedOpts = {}; /** * The name of the compiler, for use in diagnostics. */ String ownName; /** * The writer to use for diagnostic output. */ PrintWriter out; /** * Result codes. */ static final int EXIT_OK = 0; /** * Result codes. */ static final int EXIT_ERROR = 1; /** * Result codes. */ static final int EXIT_CMDERR = 2; /** * Result codes. */ static final int EXIT_SYSERR = 3; /** * Result codes. */ static final int EXIT_ABNORMAL = 4; /** * This class represents an option recognized by the main program */ private class Option { /** * Option string. */ String name; /** * Documentation key for arguments. */ String argsNameKey; /** * Documentation key for description. */ String descrKey; Option(String name, String argsNameKey, String descrKey) { super(); this.name = name; this.argsNameKey = argsNameKey; this.descrKey = descrKey; } Option(String name, String descrKey) { this(name, null, descrKey); } /** * Does this option take an operand? */ boolean hasArg() { return argsNameKey != null; } /** * Does argument string match option pattern? * @param arg The command line argument string. */ boolean matches(String arg) { return name.equals(arg); } /** * Print a line of documentation describing this standard option. */ void help() { String s = " " + helpSynopsis(); out.print(s); for (int j = s.length(); j < 28; j++) out.print(" "); Log.printLines(out, getLocalizedString(descrKey)); } String helpSynopsis() { String s = name + " "; if (argsNameKey != null) s += getLocalizedString(argsNameKey); return s; } /** * Print a line of documentation describing this standard or extended options. */ void xhelp() { help(); } /** * Process the option (with arg). Return true if error detected. */ boolean process(String option, String arg) { options.put(option, arg); return false; } /** * Process the option (without arg). Return true if error detected. */ boolean process(String option) { return process(option, option); } } { } /** * A nonstandard or extended (-X) option */ private class XOption extends Option { XOption(String name, String argsNameKey, String descrKey) { super(name, argsNameKey, descrKey); } XOption(String name, String descrKey) { this(name, null, descrKey); } void help() { } void xhelp() { super.help(); } } { } /** * A hidden (implementor) option */ private class HiddenOption extends Option { HiddenOption(String name) { super(name, null, null); } void help() { } void xhelp() { } } { } private Option[] recognizedOptions = {new Option("-g", "opt.g"), new Option("-g:none", "opt.g.none") { boolean process(String option) { options.put("-g:", "none"); return false; } } , new Option("-g:{lines,vars,source}", "opt.g.lines.vars.source") { boolean matches(String s) { return s.startsWith("-g:"); } boolean process(String option) { String suboptions = option.substring(3); options.put("-g:", suboptions); for (StringTokenizer t = new StringTokenizer( suboptions, ","); t.hasMoreTokens();) { String tok = t.nextToken(); String opt = "-g:" + tok; options.put(opt, opt); } return false; } } , new Option("-nowarn", "opt.nowarn"), new Option("-verbose", "opt.verbose"), new Option("-deprecation", "opt.deprecation"), new Option("-classpath", "opt.arg.path", "opt.classpath"), new Option("-sourcepath", "opt.arg.path", "opt.sourcepath"), new Option("-bootclasspath", "opt.arg.path", "opt.bootclasspath"), new Option("-extdirs", "opt.arg.dirs", "opt.extdirs"), new Option("-d", "opt.arg.directory", "opt.d"), new Option("-encoding", "opt.arg.encoding", "opt.encoding"), new Option("-source", "opt.arg.release", "opt.source") { boolean process(String option, String operand) { Source source = Source.lookup(operand); if (source == null) { error("err.invalid.source", operand); return true; } boolean err = super.process(option, operand); String targetString = (String) options.get("-target"); Target target = (targetString != null) ? Target.lookup( targetString) : null; if (source.ordinal >= Source.JDK1_4.ordinal) { if (target != null) { if (target.ordinal < Target.JDK1_4.ordinal) { error("err.source.target.conflict"); return true; } } else { options.put("-target", Target.JDK1_4.name); } } return err; } } , new Option("-target", "opt.arg.release", "opt.target") { boolean process(String option, String operand) { Target target = Target.lookup(operand); if (target == null) { error("err.invalid.target", operand); return true; } boolean err = super.process(option, operand); String sourceString = (String) options.get("-source"); Source source = (sourceString != null) ? Source.lookup( sourceString) : null; if (source != null && target != null && source.ordinal >= Source.JDK1_4.ordinal && target.ordinal < Target.JDK1_4.ordinal) { error("err.source.target.conflict"); return true; } return err; } } , new Option("-help", "opt.help") { boolean process(String option) { Main.this.help(); return super.process(option); } } , new XOption("-Xbootclasspath/p:", "opt.arg.path", "opt.Xbootclasspath.p") { boolean matches(String arg) { return arg.startsWith(name); } String helpSynopsis() { return name + getLocalizedString(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -