提交 308c50f9 编写于 作者: J jjg

6988436: Cleanup javac option handling

Reviewed-by: darcy
上级 2e08419d
...@@ -25,11 +25,14 @@ ...@@ -25,11 +25,14 @@
package com.sun.tools.javac.code; package com.sun.tools.javac.code;
import com.sun.tools.javac.util.*; import java.util.*;
import com.sun.tools.javac.jvm.Target;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*; import static javax.lang.model.SourceVersion.*;
import java.util.*;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.jvm.Target;
import static com.sun.tools.javac.main.OptionName.*;
/** The source language version accepted. /** The source language version accepted.
* *
...@@ -71,7 +74,7 @@ public enum Source { ...@@ -71,7 +74,7 @@ public enum Source {
Source instance = context.get(sourceKey); Source instance = context.get(sourceKey);
if (instance == null) { if (instance == null) {
Options options = Options.instance(context); Options options = Options.instance(context);
String sourceString = options.get("-source"); String sourceString = options.get(SOURCE);
if (sourceString != null) instance = lookup(sourceString); if (sourceString != null) instance = lookup(sourceString);
if (instance == null) instance = DEFAULT; if (instance == null) instance = DEFAULT;
context.put(sourceKey, instance); context.put(sourceKey, instance);
......
...@@ -119,10 +119,10 @@ public class Attr extends JCTree.Visitor { ...@@ -119,10 +119,10 @@ public class Attr extends JCTree.Visitor {
allowAnonOuterThis = source.allowAnonOuterThis(); allowAnonOuterThis = source.allowAnonOuterThis();
allowStringsInSwitch = source.allowStringsInSwitch(); allowStringsInSwitch = source.allowStringsInSwitch();
sourceName = source.name; sourceName = source.name;
relax = (options.get("-retrofit") != null || relax = (options.isSet("-retrofit") ||
options.get("-relax") != null); options.isSet("-relax"));
useBeforeDeclarationWarning = options.get("useBeforeDeclarationWarning") != null; useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
enableSunApiLintControl = options.get("enableSunApiLintControl") != null; enableSunApiLintControl = options.isSet("enableSunApiLintControl");
} }
/** Switch: relax some constraints for retrofit mode. /** Switch: relax some constraints for retrofit mode.
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package com.sun.tools.javac.comp; package com.sun.tools.javac.comp;
import com.sun.source.tree.AssignmentTree;
import java.util.*; import java.util.*;
import java.util.Set; import java.util.Set;
...@@ -46,6 +45,8 @@ import static com.sun.tools.javac.code.Flags.*; ...@@ -46,6 +45,8 @@ import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.main.OptionName.*;
/** Type checking helper class for the attribution phase. /** Type checking helper class for the attribution phase.
* *
* <p><b>This is NOT part of any supported API. * <p><b>This is NOT part of any supported API.
...@@ -99,10 +100,10 @@ public class Check { ...@@ -99,10 +100,10 @@ public class Check {
allowGenerics = source.allowGenerics(); allowGenerics = source.allowGenerics();
allowAnnotations = source.allowAnnotations(); allowAnnotations = source.allowAnnotations();
allowCovariantReturns = source.allowCovariantReturns(); allowCovariantReturns = source.allowCovariantReturns();
complexInference = options.get("-complexinference") != null; complexInference = options.isSet(COMPLEXINFERENCE);
skipAnnotations = options.get("skipAnnotations") != null; skipAnnotations = options.isSet("skipAnnotations");
warnOnSyntheticConflicts = options.get("warnOnSyntheticConflicts") != null; warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts");
suppressAbortOnBadClassFile = options.get("suppressAbortOnBadClassFile") != null; suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile");
Target target = Target.instance(context); Target target = Target.instance(context);
syntheticNameChar = target.syntheticNameChar(); syntheticNameChar = target.syntheticNameChar();
......
...@@ -109,7 +109,7 @@ public class Lower extends TreeTranslator { ...@@ -109,7 +109,7 @@ public class Lower extends TreeTranslator {
types = Types.instance(context); types = Types.instance(context);
Options options = Options.instance(context); Options options = Options.instance(context);
debugLower = options.get("debuglower") != null; debugLower = options.isSet("debuglower");
pkginfoOpt = PkgInfo.get(options); pkginfoOpt = PkgInfo.get(options);
} }
......
...@@ -102,7 +102,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { ...@@ -102,7 +102,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
diags = JCDiagnostic.Factory.instance(context); diags = JCDiagnostic.Factory.instance(context);
target = Target.instance(context); target = Target.instance(context);
Options options = Options.instance(context); Options options = Options.instance(context);
skipAnnotations = options.get("skipAnnotations") != null; skipAnnotations = options.isSet("skipAnnotations");
} }
/** A queue for classes whose members still need to be entered into the /** A queue for classes whose members still need to be entered into the
......
...@@ -110,14 +110,14 @@ public class Resolve { ...@@ -110,14 +110,14 @@ public class Resolve {
boxingEnabled = source.allowBoxing(); boxingEnabled = source.allowBoxing();
varargsEnabled = source.allowVarargs(); varargsEnabled = source.allowVarargs();
Options options = Options.instance(context); Options options = Options.instance(context);
debugResolve = options.get("debugresolve") != null; debugResolve = options.isSet("debugresolve");
allowTransitionalJSR292 = options.get("allowTransitionalJSR292") != null; allowTransitionalJSR292 = options.isSet("allowTransitionalJSR292");
Target target = Target.instance(context); Target target = Target.instance(context);
allowMethodHandles = allowTransitionalJSR292 || allowMethodHandles = allowTransitionalJSR292 ||
target.hasMethodHandles(); target.hasMethodHandles();
allowInvokeDynamic = (allowTransitionalJSR292 || allowInvokeDynamic = (allowTransitionalJSR292 ||
target.hasInvokedynamic()) && target.hasInvokedynamic()) &&
options.get("invokedynamic") != null; options.isSet("invokedynamic");
polymorphicSignatureScope = new Scope(syms.noSymbol); polymorphicSignatureScope = new Scope(syms.noSymbol);
inapplicableMethodException = new InapplicableMethodException(diags); inapplicableMethodException = new InapplicableMethodException(diags);
......
...@@ -150,8 +150,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil ...@@ -150,8 +150,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
useZipFileIndex = System.getProperty("useJavaUtilZip") == null;// TODO: options.get("useJavaUtilZip") == null; useZipFileIndex = System.getProperty("useJavaUtilZip") == null;// TODO: options.get("useJavaUtilZip") == null;
mmappedIO = options.get("mmappedIO") != null; mmappedIO = options.isSet("mmappedIO");
ignoreSymbolFile = options.get("ignore.symbol.file") != null; ignoreSymbolFile = options.isSet("ignore.symbol.file");
} }
public JavaFileObject getFileForInput(String name) { public JavaFileObject getFileForInput(String name) {
...@@ -435,7 +435,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil ...@@ -435,7 +435,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
zdir = new ZipFile(zipFileName); zdir = new ZipFile(zipFileName);
} }
else { else {
usePreindexedCache = options.get("usezipindex") != null; usePreindexedCache = options.isSet("usezipindex");
preindexCacheLocation = options.get("java.io.tmpdir"); preindexCacheLocation = options.get("java.io.tmpdir");
String optCacheLoc = options.get("cachezipindexdir"); String optCacheLoc = options.get("cachezipindexdir");
...@@ -469,7 +469,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil ...@@ -469,7 +469,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
null, null,
usePreindexedCache, usePreindexedCache,
preindexCacheLocation, preindexCacheLocation,
options.get("writezipindexfiles") != null)); options.isSet("writezipindexfiles")));
} }
} }
else { else {
...@@ -482,7 +482,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil ...@@ -482,7 +482,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
symbolFilePrefix, symbolFilePrefix,
usePreindexedCache, usePreindexedCache,
preindexCacheLocation, preindexCacheLocation,
options.get("writezipindexfiles") != null)); options.isSet("writezipindexfiles")));
} }
} }
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
......
...@@ -56,6 +56,8 @@ import static com.sun.tools.javac.code.TypeTags.*; ...@@ -56,6 +56,8 @@ import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.ClassFile.*; import static com.sun.tools.javac.jvm.ClassFile.*;
import static com.sun.tools.javac.jvm.ClassFile.Version.*; import static com.sun.tools.javac.jvm.ClassFile.Version.*;
import static com.sun.tools.javac.main.OptionName.*;
/** This class provides operations to read a classfile into an internal /** This class provides operations to read a classfile into an internal
* representation. The internal representation is anchored in a * representation. The internal representation is anchored in a
* ClassSymbol which contains in its scope symbol representations * ClassSymbol which contains in its scope symbol representations
...@@ -259,23 +261,23 @@ public class ClassReader implements Completer { ...@@ -259,23 +261,23 @@ public class ClassReader implements Completer {
Options options = Options.instance(context); Options options = Options.instance(context);
annotate = Annotate.instance(context); annotate = Annotate.instance(context);
verbose = options.get("-verbose") != null; verbose = options.isSet(VERBOSE);
checkClassFile = options.get("-checkclassfile") != null; checkClassFile = options.isSet("-checkclassfile");
Source source = Source.instance(context); Source source = Source.instance(context);
allowGenerics = source.allowGenerics(); allowGenerics = source.allowGenerics();
allowVarargs = source.allowVarargs(); allowVarargs = source.allowVarargs();
allowAnnotations = source.allowAnnotations(); allowAnnotations = source.allowAnnotations();
saveParameterNames = options.get("save-parameter-names") != null; saveParameterNames = options.isSet("save-parameter-names");
cacheCompletionFailure = options.get("dev") == null; cacheCompletionFailure = options.isUnset("dev");
preferSource = "source".equals(options.get("-Xprefer")); preferSource = "source".equals(options.get("-Xprefer"));
completionFailureName = completionFailureName =
(options.get("failcomplete") != null) options.isSet("failcomplete")
? names.fromString(options.get("failcomplete")) ? names.fromString(options.get("failcomplete"))
: null; : null;
typevars = new Scope(syms.noSymbol); typevars = new Scope(syms.noSymbol);
debugJSR308 = options.get("TA:reader") != null; debugJSR308 = options.isSet("TA:reader");
initAttributeReaders(); initAttributeReaders();
} }
......
...@@ -45,8 +45,10 @@ import static com.sun.tools.javac.code.Flags.*; ...@@ -45,8 +45,10 @@ import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.UninitializedType.*; import static com.sun.tools.javac.jvm.UninitializedType.*;
import static com.sun.tools.javac.main.OptionName.*;
import static javax.tools.StandardLocation.CLASS_OUTPUT; import static javax.tools.StandardLocation.CLASS_OUTPUT;
/** This class provides operations to map an internal symbol table graph /** This class provides operations to map an internal symbol table graph
* rooted in a ClassSymbol into a classfile. * rooted in a ClassSymbol into a classfile.
* *
...@@ -178,15 +180,16 @@ public class ClassWriter extends ClassFile { ...@@ -178,15 +180,16 @@ public class ClassWriter extends ClassFile {
types = Types.instance(context); types = Types.instance(context);
fileManager = context.get(JavaFileManager.class); fileManager = context.get(JavaFileManager.class);
debugJSR308 = options.get("TA:writer") != null; debugJSR308 = options.isSet("TA:writer");
verbose = options.get("-verbose") != null; verbose = options.isSet(VERBOSE);
scramble = options.get("-scramble") != null; scramble = options.isSet("-scramble");
scrambleAll = options.get("-scrambleAll") != null; scrambleAll = options.isSet("-scrambleAll");
retrofit = options.get("-retrofit") != null; retrofit = options.isSet("-retrofit");
genCrt = options.get("-Xjcov") != null; genCrt = options.isSet(XJCOV);
debugstackmap = options.get("debugstackmap") != null; debugstackmap = options.isSet("debugstackmap");
emitSourceFile = options.get("-g:")==null || options.get("-g:source")!=null; emitSourceFile = options.isUnset(G_CUSTOM) ||
options.isSet(G_CUSTOM, "source");
String dumpModFlags = options.get("dumpmodifiers"); String dumpModFlags = options.get("dumpmodifiers");
dumpClassModifiers = dumpClassModifiers =
......
...@@ -46,6 +46,7 @@ import static com.sun.tools.javac.code.Kinds.*; ...@@ -46,6 +46,7 @@ import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.ByteCodes.*; import static com.sun.tools.javac.jvm.ByteCodes.*;
import static com.sun.tools.javac.jvm.CRTFlags.*; import static com.sun.tools.javac.jvm.CRTFlags.*;
import static com.sun.tools.javac.main.OptionName.*;
/** This pass maps flat Java (i.e. without inner classes) to bytecodes. /** This pass maps flat Java (i.e. without inner classes) to bytecodes.
* *
...@@ -113,19 +114,19 @@ public class Gen extends JCTree.Visitor { ...@@ -113,19 +114,19 @@ public class Gen extends JCTree.Visitor {
Options options = Options.instance(context); Options options = Options.instance(context);
lineDebugInfo = lineDebugInfo =
options.get("-g:") == null || options.isUnset(G_CUSTOM) ||
options.get("-g:lines") != null; options.isSet(G_CUSTOM, "lines");
varDebugInfo = varDebugInfo =
options.get("-g:") == null options.isUnset(G_CUSTOM)
? options.get("-g") != null ? options.isSet(G)
: options.get("-g:vars") != null; : options.isSet(G_CUSTOM, "vars");
genCrt = options.get("-Xjcov") != null; genCrt = options.isSet(XJCOV);
debugCode = options.get("debugcode") != null; debugCode = options.isSet("debugcode");
allowInvokedynamic = target.hasInvokedynamic() || options.get("invokedynamic") != null; allowInvokedynamic = target.hasInvokedynamic() || options.isSet("invokedynamic");
generateIproxies = generateIproxies =
target.requiresIproxy() || target.requiresIproxy() ||
options.get("miranda") != null; options.isSet("miranda");
if (target.generateStackMapTable()) { if (target.generateStackMapTable()) {
// ignore cldc because we cannot have both stackmap formats // ignore cldc because we cannot have both stackmap formats
......
...@@ -31,6 +31,8 @@ import com.sun.tools.javac.code.Flags; ...@@ -31,6 +31,8 @@ import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import static com.sun.tools.javac.main.OptionName.*;
/** The classfile version target. /** The classfile version target.
* *
* <p><b>This is NOT part of any supported API. * <p><b>This is NOT part of any supported API.
...@@ -73,7 +75,7 @@ public enum Target { ...@@ -73,7 +75,7 @@ public enum Target {
Target instance = context.get(targetKey); Target instance = context.get(targetKey);
if (instance == null) { if (instance == null) {
Options options = Options.instance(context); Options options = Options.instance(context);
String targetString = options.get("-target"); String targetString = options.get(TARGET);
if (targetString != null) instance = lookup(targetString); if (targetString != null) instance = lookup(targetString);
if (instance == null) instance = DEFAULT; if (instance == null) instance = DEFAULT;
context.put(targetKey, instance); context.put(targetKey, instance);
......
...@@ -26,45 +26,44 @@ ...@@ -26,45 +26,44 @@
package com.sun.tools.javac.main; package com.sun.tools.javac.main;
import java.io.*; import java.io.*;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.Queue;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.processing.Processor;
import javax.lang.model.SourceVersion;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.DiagnosticListener; import javax.tools.DiagnosticListener;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener; import com.sun.source.util.TaskListener;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.parser.*; import com.sun.tools.javac.parser.*;
import com.sun.tools.javac.comp.*; import com.sun.tools.javac.comp.*;
import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.jvm.*;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.processing.*; import com.sun.tools.javac.processing.*;
import javax.annotation.processing.Processor;
import static javax.tools.StandardLocation.CLASS_OUTPUT; import static javax.tools.StandardLocation.CLASS_OUTPUT;
import static com.sun.tools.javac.main.OptionName.*;
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
import static com.sun.tools.javac.util.ListBuffer.lb; import static com.sun.tools.javac.util.ListBuffer.lb;
import java.util.HashMap;
import java.util.Queue;
import javax.lang.model.SourceVersion;
/** This class could be the main entry point for GJC when GJC is used as a /** This class could be the main entry point for GJC when GJC is used as a
* component in a larger software system. It provides operations to * component in a larger software system. It provides operations to
...@@ -356,22 +355,22 @@ public class JavaCompiler implements ClassReader.SourceCompleter { ...@@ -356,22 +355,22 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
Options options = Options.instance(context); Options options = Options.instance(context);
verbose = options.get("-verbose") != null; verbose = options.isSet(VERBOSE);
sourceOutput = options.get("-printsource") != null; // used to be -s sourceOutput = options.isSet(PRINTSOURCE); // used to be -s
stubOutput = options.get("-stubs") != null; stubOutput = options.isSet("-stubs");
relax = options.get("-relax") != null; relax = options.isSet("-relax");
printFlat = options.get("-printflat") != null; printFlat = options.isSet("-printflat");
attrParseOnly = options.get("-attrparseonly") != null; attrParseOnly = options.isSet("-attrparseonly");
encoding = options.get("-encoding"); encoding = options.get(ENCODING);
lineDebugInfo = options.get("-g:") == null || lineDebugInfo = options.isUnset(G_CUSTOM) ||
options.get("-g:lines") != null; options.isSet(G_CUSTOM, "lines");
genEndPos = options.get("-Xjcov") != null || genEndPos = options.isSet(XJCOV) ||
context.get(DiagnosticListener.class) != null; context.get(DiagnosticListener.class) != null;
devVerbose = options.get("dev") != null; devVerbose = options.isSet("dev");
processPcks = options.get("process.packages") != null; processPcks = options.isSet("process.packages");
werror = options.get("-Werror") != null; werror = options.isSet(WERROR);
verboseCompilePolicy = options.get("verboseCompilePolicy") != null; verboseCompilePolicy = options.isSet("verboseCompilePolicy");
if (attrParseOnly) if (attrParseOnly)
compilePolicy = CompilePolicy.ATTR_ONLY; compilePolicy = CompilePolicy.ATTR_ONLY;
...@@ -381,15 +380,15 @@ public class JavaCompiler implements ClassReader.SourceCompleter { ...@@ -381,15 +380,15 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
implicitSourcePolicy = ImplicitSourcePolicy.decode(options.get("-implicit")); implicitSourcePolicy = ImplicitSourcePolicy.decode(options.get("-implicit"));
completionFailureName = completionFailureName =
(options.get("failcomplete") != null) options.isSet("failcomplete")
? names.fromString(options.get("failcomplete")) ? names.fromString(options.get("failcomplete"))
: null; : null;
shouldStopPolicy = shouldStopPolicy =
(options.get("shouldStopPolicy") != null) options.isSet("shouldStopPolicy")
? CompileState.valueOf(options.get("shouldStopPolicy")) ? CompileState.valueOf(options.get("shouldStopPolicy"))
: null; : null;
if (options.get("oldDiags") == null) if (options.isUnset("oldDiags"))
log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context)); log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
} }
...@@ -954,7 +953,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter { ...@@ -954,7 +953,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
// Process annotations if processing is not disabled and there // Process annotations if processing is not disabled and there
// is at least one Processor available. // is at least one Processor available.
Options options = Options.instance(context); Options options = Options.instance(context);
if (options.get("-proc:none") != null) { if (options.isSet(PROC, "none")) {
processAnnotations = false; processAnnotations = false;
} else if (procEnvImpl == null) { } else if (procEnvImpl == null) {
procEnvImpl = new JavacProcessingEnvironment(context, processors); procEnvImpl = new JavacProcessingEnvironment(context, processors);
...@@ -1013,7 +1012,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter { ...@@ -1013,7 +1012,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
// annotation processing is to occur with compilation, // annotation processing is to occur with compilation,
// emit a warning. // emit a warning.
Options options = Options.instance(context); Options options = Options.instance(context);
if (options.get("-proc:only") != null) { if (options.isSet(PROC, "only")) {
log.warning("proc.proc-only.requested.no.procs"); log.warning("proc.proc-only.requested.no.procs");
todo.clear(); todo.clear();
} }
...@@ -1101,10 +1100,10 @@ public class JavaCompiler implements ClassReader.SourceCompleter { ...@@ -1101,10 +1100,10 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
Options options = Options.instance(context); Options options = Options.instance(context);
return return
explicitAnnotationProcessingRequested || explicitAnnotationProcessingRequested ||
options.get("-processor") != null || options.isSet(PROCESSOR) ||
options.get("-processorpath") != null || options.isSet(PROCESSORPATH) ||
options.get("-proc:only") != null || options.isSet(PROC, "only") ||
options.get("-Xprint") != null; options.isSet(XPRINT);
} }
/** /**
......
...@@ -32,6 +32,9 @@ import java.net.URL; ...@@ -32,6 +32,9 @@ import java.net.URL;
import java.security.DigestInputStream; import java.security.DigestInputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.annotation.processing.Processor;
import com.sun.tools.javac.code.Source; import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.file.CacheFSInfo; import com.sun.tools.javac.file.CacheFSInfo;
...@@ -41,9 +44,8 @@ import com.sun.tools.javac.main.JavacOption.Option; ...@@ -41,9 +44,8 @@ import com.sun.tools.javac.main.JavacOption.Option;
import com.sun.tools.javac.main.RecognizedOptions.OptionHelper; import com.sun.tools.javac.main.RecognizedOptions.OptionHelper;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import com.sun.tools.javac.processing.AnnotationProcessingError; import com.sun.tools.javac.processing.AnnotationProcessingError;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import static com.sun.tools.javac.main.OptionName.*;
import javax.annotation.processing.Processor;
/** This class provides a commandline interface to the GJC compiler. /** This class provides a commandline interface to the GJC compiler.
* *
...@@ -239,16 +241,16 @@ public class Main { ...@@ -239,16 +241,16 @@ public class Main {
} }
} }
if (!checkDirectory("-d")) if (!checkDirectory(D))
return null; return null;
if (!checkDirectory("-s")) if (!checkDirectory(S))
return null; return null;
String sourceString = options.get("-source"); String sourceString = options.get(SOURCE);
Source source = (sourceString != null) Source source = (sourceString != null)
? Source.lookup(sourceString) ? Source.lookup(sourceString)
: Source.DEFAULT; : Source.DEFAULT;
String targetString = options.get("-target"); String targetString = options.get(TARGET);
Target target = (targetString != null) Target target = (targetString != null)
? Target.lookup(targetString) ? Target.lookup(targetString)
: Target.DEFAULT; : Target.DEFAULT;
...@@ -285,7 +287,7 @@ public class Main { ...@@ -285,7 +287,7 @@ public class Main {
// phase this out with JSR 292 PFD // phase this out with JSR 292 PFD
if ("no".equals(options.get("allowTransitionalJSR292"))) { if ("no".equals(options.get("allowTransitionalJSR292"))) {
options.put("allowTransitionalJSR292", null); options.put("allowTransitionalJSR292", null);
} else if (target.hasInvokedynamic() && options.get("allowTransitionalJSR292") == null) { } else if (target.hasInvokedynamic() && options.isUnset("allowTransitionalJSR292")) {
options.put("allowTransitionalJSR292", "allowTransitionalJSR292"); options.put("allowTransitionalJSR292", "allowTransitionalJSR292");
} }
...@@ -300,7 +302,7 @@ public class Main { ...@@ -300,7 +302,7 @@ public class Main {
return filenames.toList(); return filenames.toList();
} }
// where // where
private boolean checkDirectory(String optName) { private boolean checkDirectory(OptionName optName) {
String value = options.get(optName); String value = options.get(optName);
if (value == null) if (value == null)
return true; return true;
...@@ -367,10 +369,10 @@ public class Main { ...@@ -367,10 +369,10 @@ public class Main {
return EXIT_CMDERR; return EXIT_CMDERR;
} else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) { } else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
// it is allowed to compile nothing if just asking for help or version info // it is allowed to compile nothing if just asking for help or version info
if (options.get("-help") != null if (options.isSet(HELP)
|| options.get("-X") != null || options.isSet(X)
|| options.get("-version") != null || options.isSet(VERSION)
|| options.get("-fullversion") != null) || options.isSet(FULLVERSION))
return EXIT_OK; return EXIT_OK;
error("err.no.source.files"); error("err.no.source.files");
return EXIT_CMDERR; return EXIT_CMDERR;
...@@ -382,7 +384,7 @@ public class Main { ...@@ -382,7 +384,7 @@ public class Main {
return EXIT_SYSERR; return EXIT_SYSERR;
} }
boolean forceStdOut = options.get("stdout") != null; boolean forceStdOut = options.isSet("stdout");
if (forceStdOut) { if (forceStdOut) {
out.flush(); out.flush();
out = new PrintWriter(System.out, true); out = new PrintWriter(System.out, true);
...@@ -391,7 +393,7 @@ public class Main { ...@@ -391,7 +393,7 @@ public class Main {
context.put(Log.outKey, out); context.put(Log.outKey, out);
// allow System property in following line as a Mustang legacy // allow System property in following line as a Mustang legacy
boolean batchMode = (options.get("nonBatchMode") == null boolean batchMode = (options.isUnset("nonBatchMode")
&& System.getProperty("nonBatchMode") == null); && System.getProperty("nonBatchMode") == null);
if (batchMode) if (batchMode)
CacheFSInfo.preRegister(context); CacheFSInfo.preRegister(context);
...@@ -455,7 +457,7 @@ public class Main { ...@@ -455,7 +457,7 @@ public class Main {
// for buggy compiler error recovery by swallowing thrown // for buggy compiler error recovery by swallowing thrown
// exceptions. // exceptions.
if (comp == null || comp.errorCount() == 0 || if (comp == null || comp.errorCount() == 0 ||
options == null || options.get("dev") != null) options == null || options.isSet("dev"))
bugMessage(ex); bugMessage(ex);
return EXIT_ABNORMAL; return EXIT_ABNORMAL;
} finally { } finally {
...@@ -478,7 +480,7 @@ public class Main { ...@@ -478,7 +480,7 @@ public class Main {
*/ */
void feMessage(Throwable ex) { void feMessage(Throwable ex) {
Log.printLines(out, ex.getMessage()); Log.printLines(out, ex.getMessage());
if (ex.getCause() != null && options.get("dev") != null) { if (ex.getCause() != null && options.isSet("dev")) {
ex.getCause().printStackTrace(out); ex.getCause().printStackTrace(out);
} }
} }
......
...@@ -25,14 +25,6 @@ ...@@ -25,14 +25,6 @@
package com.sun.tools.javac.processing; package com.sun.tools.javac.processing;
import com.sun.tools.javac.util.*;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.Element;
import java.util.*;
import java.io.Closeable; import java.io.Closeable;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
...@@ -43,14 +35,26 @@ import java.io.Writer; ...@@ -43,14 +35,26 @@ import java.io.Writer;
import java.io.FilterWriter; import java.io.FilterWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.IOException; import java.io.IOException;
import java.util.*;
import javax.tools.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.Element;
import javax.tools.*;
import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileManager.Location;
import static javax.tools.StandardLocation.SOURCE_OUTPUT; import static javax.tools.StandardLocation.SOURCE_OUTPUT;
import static javax.tools.StandardLocation.CLASS_OUTPUT; import static javax.tools.StandardLocation.CLASS_OUTPUT;
import com.sun.tools.javac.code.Lint;
import com.sun.tools.javac.util.*;
import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
/** /**
* The FilerImplementation class must maintain a number of * The FilerImplementation class must maintain a number of
* constraints. First, multiple attempts to open the same path within * constraints. First, multiple attempts to open the same path within
...@@ -366,7 +370,7 @@ public class JavacFiler implements Filer, Closeable { ...@@ -366,7 +370,7 @@ public class JavacFiler implements Filer, Closeable {
aggregateGeneratedSourceNames = new LinkedHashSet<String>(); aggregateGeneratedSourceNames = new LinkedHashSet<String>();
aggregateGeneratedClassNames = new LinkedHashSet<String>(); aggregateGeneratedClassNames = new LinkedHashSet<String>();
lint = (Options.instance(context)).lint("processing"); lint = (Lint.instance(context)).isEnabled(PROCESSING);
} }
public JavaFileObject createSourceFile(CharSequence name, public JavaFileObject createSourceFile(CharSequence name,
......
...@@ -79,6 +79,8 @@ import com.sun.tools.javac.util.Options; ...@@ -79,6 +79,8 @@ import com.sun.tools.javac.util.Options;
import static javax.tools.StandardLocation.*; import static javax.tools.StandardLocation.*;
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
import static com.sun.tools.javac.main.OptionName.*;
import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
/** /**
* Objects of this class hold and manage the state needed to support * Objects of this class hold and manage the state needed to support
...@@ -160,15 +162,14 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -160,15 +162,14 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
source = Source.instance(context); source = Source.instance(context);
diags = JCDiagnostic.Factory.instance(context); diags = JCDiagnostic.Factory.instance(context);
options = Options.instance(context); options = Options.instance(context);
printProcessorInfo = options.get("-XprintProcessorInfo") != null; printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
printRounds = options.get("-XprintRounds") != null; printRounds = options.isSet(XPRINTROUNDS);
verbose = options.get("-verbose") != null; verbose = options.isSet(VERBOSE);
lint = options.lint("processing"); lint = Lint.instance(context).isEnabled(PROCESSING);
procOnly = options.get("-proc:only") != null || procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT);
options.get("-Xprint") != null; fatalErrors = options.isSet("fatalEnterError");
fatalErrors = options.get("fatalEnterError") != null; showResolveErrors = options.isSet("showResolveErrors");
showResolveErrors = options.get("showResolveErrors") != null; werror = options.isSet(WERROR);
werror = options.get("-Werror") != null;
platformAnnotations = initPlatformAnnotations(); platformAnnotations = initPlatformAnnotations();
foundTypeProcessors = false; foundTypeProcessors = false;
...@@ -200,7 +201,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -200,7 +201,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
Log log = Log.instance(context); Log log = Log.instance(context);
Iterator<? extends Processor> processorIterator; Iterator<? extends Processor> processorIterator;
if (options.get("-Xprint") != null) { if (options.isSet(XPRINT)) {
try { try {
Processor processor = PrintingProcessor.class.newInstance(); Processor processor = PrintingProcessor.class.newInstance();
processorIterator = List.of(processor).iterator(); processorIterator = List.of(processor).iterator();
...@@ -213,7 +214,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -213,7 +214,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
} else if (processors != null) { } else if (processors != null) {
processorIterator = processors.iterator(); processorIterator = processors.iterator();
} else { } else {
String processorNames = options.get("-processor"); String processorNames = options.get(PROCESSOR);
JavaFileManager fileManager = context.get(JavaFileManager.class); JavaFileManager fileManager = context.get(JavaFileManager.class);
try { try {
// If processorpath is not explicitly set, use the classpath. // If processorpath is not explicitly set, use the classpath.
...@@ -264,7 +265,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -264,7 +265,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH) ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
: standardFileManager.getLocation(CLASS_PATH); : standardFileManager.getLocation(CLASS_PATH);
if (needClassLoader(options.get("-processor"), workingPath) ) if (needClassLoader(options.get(PROCESSOR), workingPath) )
handleException(key, e); handleException(key, e);
} else { } else {
...@@ -745,7 +746,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -745,7 +746,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
psi.runContributingProcs(renv); psi.runContributingProcs(renv);
// Debugging // Debugging
if (options.get("displayFilerState") != null) if (options.isSet("displayFilerState"))
filer.displayState(); filer.displayState();
} }
......
...@@ -35,11 +35,14 @@ import java.util.Set; ...@@ -35,11 +35,14 @@ import java.util.Set;
import javax.tools.DiagnosticListener; import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.api.DiagnosticFormatter; import com.sun.tools.javac.api.DiagnosticFormatter;
import com.sun.tools.javac.main.OptionName;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
import static com.sun.tools.javac.main.OptionName.*;
/** A class for error logs. Reports errors and warnings, and /** A class for error logs. Reports errors and warnings, and
* keeps track of error numbers and positions. * keeps track of error numbers and positions.
* *
...@@ -129,14 +132,14 @@ public class Log extends AbstractLog { ...@@ -129,14 +132,14 @@ public class Log extends AbstractLog {
this.noticeWriter = noticeWriter; this.noticeWriter = noticeWriter;
Options options = Options.instance(context); Options options = Options.instance(context);
this.dumpOnError = options.get("-doe") != null; this.dumpOnError = options.isSet(DOE);
this.promptOnError = options.get("-prompt") != null; this.promptOnError = options.isSet(PROMPT);
this.emitWarnings = options.get("-Xlint:none") == null; this.emitWarnings = options.isUnset(XLINT_CUSTOM, "none");
this.suppressNotes = options.get("suppressNotes") != null; this.suppressNotes = options.isSet("suppressNotes");
this.MaxErrors = getIntOption(options, "-Xmaxerrs", getDefaultMaxErrors()); this.MaxErrors = getIntOption(options, XMAXERRS, getDefaultMaxErrors());
this.MaxWarnings = getIntOption(options, "-Xmaxwarns", getDefaultMaxWarnings()); this.MaxWarnings = getIntOption(options, XMAXWARNS, getDefaultMaxWarnings());
boolean rawDiagnostics = options.get("rawDiagnostics") != null; boolean rawDiagnostics = options.isSet("rawDiagnostics");
messages = JavacMessages.instance(context); messages = JavacMessages.instance(context);
this.diagFormatter = rawDiagnostics ? new RawDiagnosticFormatter(options) : this.diagFormatter = rawDiagnostics ? new RawDiagnosticFormatter(options) :
new BasicDiagnosticFormatter(options, messages); new BasicDiagnosticFormatter(options, messages);
...@@ -150,7 +153,7 @@ public class Log extends AbstractLog { ...@@ -150,7 +153,7 @@ public class Log extends AbstractLog {
expectDiagKeys = new HashSet<String>(Arrays.asList(ek.split(", *"))); expectDiagKeys = new HashSet<String>(Arrays.asList(ek.split(", *")));
} }
// where // where
private int getIntOption(Options options, String optionName, int defaultValue) { private int getIntOption(Options options, OptionName optionName, int defaultValue) {
String s = options.get(optionName); String s = options.get(optionName);
try { try {
if (s != null) { if (s != null) {
......
...@@ -271,7 +271,7 @@ public class Names { ...@@ -271,7 +271,7 @@ public class Names {
} }
protected Name.Table createTable(Options options) { protected Name.Table createTable(Options options) {
boolean useUnsharedTable = options.get("useUnsharedTable") != null; boolean useUnsharedTable = options.isSet("useUnsharedTable");
if (useUnsharedTable) if (useUnsharedTable)
return new UnsharedNameTable(this); return new UnsharedNameTable(this);
else else
......
...@@ -25,8 +25,9 @@ ...@@ -25,8 +25,9 @@
package com.sun.tools.javac.util; package com.sun.tools.javac.util;
import com.sun.tools.javac.main.OptionName;
import java.util.*; import java.util.*;
import com.sun.tools.javac.main.OptionName;
import static com.sun.tools.javac.main.OptionName.*;
/** A table of all command-line options. /** A table of all command-line options.
* If an option has an argument, the option name is mapped to the argument. * If an option has an argument, the option name is mapped to the argument.
...@@ -60,14 +61,62 @@ public class Options { ...@@ -60,14 +61,62 @@ public class Options {
context.put(optionsKey, this); context.put(optionsKey, this);
} }
/**
* Get the value for an undocumented option.
*/
public String get(String name) { public String get(String name) {
return values.get(name); return values.get(name);
} }
/**
* Get the value for an option.
*/
public String get(OptionName name) { public String get(OptionName name) {
return values.get(name.optionName); return values.get(name.optionName);
} }
/**
* Check if the value for an undocumented option has been set.
*/
public boolean isSet(String name) {
return (values.get(name) != null);
}
/**
* Check if the value for an option has been set.
*/
public boolean isSet(OptionName name) {
return (values.get(name.optionName) != null);
}
/**
* Check if the value for a choice option has been set to a specific value.
*/
public boolean isSet(OptionName name, String value) {
return (values.get(name.optionName + value) != null);
}
/**
* Check if the value for an undocumented option has not been set.
*/
public boolean isUnset(String name) {
return (values.get(name) == null);
}
/**
* Check if the value for an option has not been set.
*/
public boolean isUnset(OptionName name) {
return (values.get(name.optionName) == null);
}
/**
* Check if the value for a choice option has not been set to a specific value.
*/
public boolean isUnset(OptionName name, String value) {
return (values.get(name.optionName + value) == null);
}
public void put(String name, String value) { public void put(String name, String value) {
values.put(name, value); values.put(name, value);
} }
...@@ -92,16 +141,14 @@ public class Options { ...@@ -92,16 +141,14 @@ public class Options {
return values.size(); return values.size();
} }
static final String LINT = "-Xlint";
/** Check for a lint suboption. */ /** Check for a lint suboption. */
public boolean lint(String s) { public boolean lint(String s) {
// return true if either the specific option is enabled, or // return true if either the specific option is enabled, or
// they are all enabled without the specific one being // they are all enabled without the specific one being
// disabled // disabled
return return
get(LINT + ":" + s)!=null || isSet(XLINT_CUSTOM, s) ||
(get(LINT)!=null || get(LINT + ":all")!=null) && (isSet(XLINT) || isSet(XLINT_CUSTOM, "all")) &&
get(LINT+":-"+s)==null; isUnset(XLINT_CUSTOM, "-" + s);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册