下面列出了org.eclipse.jdt.core.dom.FileASTRequestor#com.sun.tools.javac.main.Option 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void initHandlers() {
handlersForLocation = new HashMap<Location, LocationHandler>();
handlersForOption = new EnumMap<Option, LocationHandler>(Option.class);
LocationHandler[] handlers = {
new BootClassPathLocationHandler(),
new ClassPathLocationHandler(),
new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH),
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH),
new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D),
new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S),
new OutputLocationHandler((StandardLocation.NATIVE_HEADER_OUTPUT), Option.H)
};
for (LocationHandler h: handlers) {
handlersForLocation.put(h.location, h);
for (Option o: h.options)
handlersForOption.put(o, h);
}
}
@Override
boolean handleOption(Option option, String value) {
if (!options.contains(option)) {
return false;
}
if (value == null) {
systemJavaHome = Locations.javaHome;
} else if (value.equals("none")) {
systemJavaHome = null;
} else {
update(getPath(value));
}
modules = null;
return true;
}
/**
* Returns an empty processor iterator if no processors are on the
* relevant path, otherwise if processors are present, logs an
* error. Called when a service loader is unavailable for some
* reason, either because a service loader class cannot be found
* or because a security policy prevents class loaders from being
* created.
*
* @param key The resource key to use to log an error message
* @param e If non-null, pass this exception to Abort
*/
private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
if (fileManager instanceof JavacFileManager) {
StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
: standardFileManager.getLocation(CLASS_PATH);
if (needClassLoader(options.get(Option.PROCESSOR), workingPath) )
handleException(key, e);
} else {
handleException(key, e);
}
java.util.List<Processor> pl = Collections.emptyList();
return pl.iterator();
}
public int isSupportedOption(String option) {
for (Option o : javacFileManagerOptions) {
if (o.matches(option))
return o.hasArg() ? 1 : 0;
}
return -1;
}
@Override
boolean handleOption(Option option, String value) {
if (!options.contains(option))
return false;
// TODO: could/should validate outputDir exists and is a directory
// need to decide how best to report issue for benefit of
// direct API call on JavaFileManager.handleOption(specifies IAE)
// vs. command line decoding.
outputDir = new File(value);
return true;
}
@Override
boolean handleOption(Option option, String value) {
if (!options.contains(option)) {
return false;
}
moduleTable.clear();
// Allow an extended syntax for --patch-module consisting of a series
// of values separated by NULL characters. This is to facilitate
// supporting deferred file manager options on the command line.
// See Option.PATCH_MODULE for the code that composes these multiple
// values.
for (String v : value.split("\0")) {
int eq = v.indexOf('=');
if (eq > 0) {
String moduleName = v.substring(0, eq);
SearchFile mPatchFile = new SearchFile()
.addFiles(v.substring(eq + 1));
String name = location.getName() + "[" + moduleName + "]";
ModuleLocationHandler h = new ModuleLocationHandler(this, name,
moduleName, mPatchFile, false);
moduleTable.add(h);
} else {
// Should not be able to get here;
// this should be caught and handled in Option.PATCH_MODULE
log.error(Errors.LocnInvalidArgForXpatch(value));
}
}
return true;
}
/** Construct a new class finder. */
protected ClassFinder(Context context) {
context.put(classFinderKey, this);
reader = ClassReader.instance(context);
names = Names.instance(context);
syms = Symtab.instance(context);
fileManager = context.get(JavaFileManager.class);
dependencies = Dependencies.instance(context);
if (fileManager == null)
throw new AssertionError("FileManager initialization error");
diagFactory = JCDiagnostic.Factory.instance(context);
log = Log.instance(context);
annotate = Annotate.instance(context);
Options options = Options.instance(context);
verbose = options.isSet(Option.VERBOSE);
cacheCompletionFailure = options.isUnset("dev");
preferSource = "source".equals(options.get("-Xprefer"));
userPathsFirst = options.isSet(Option.XXUSERPATHSFIRST);
allowSigFiles = context.get(PlatformDescription.class) != null;
completionFailureName =
options.isSet("failcomplete")
? names.fromString(options.get("failcomplete"))
: null;
profile = Profile.instance(context);
}
public String getEncodingName() {
String encName = options.get(Option.ENCODING);
if (encName == null)
return getDefaultEncodingName();
else
return encName;
}
/**
* Create a handler. The location and options provide a way to map
* from a location or an option to the corresponding handler.
* @see #initHandlers
*/
protected LocationHandler(Location location, Option... options) {
this.location = location;
this.options = options.length == 0 ?
EnumSet.noneOf(Option.class):
EnumSet.copyOf(Arrays.asList(options));
}
private Option canonicalize(Option option) {
switch (option) {
case XBOOTCLASSPATH:
return Option.BOOTCLASSPATH;
case DJAVA_ENDORSED_DIRS:
return Option.ENDORSEDDIRS;
case DJAVA_EXT_DIRS:
return Option.EXTDIRS;
default:
return option;
}
}
protected Source getSource() {
String sourceName = options.get(Option.SOURCE);
Source source = null;
if (sourceName != null)
source = Source.lookup(sourceName);
return (source != null ? source : Source.DEFAULT);
}
public String getEncodingName() {
String encName = options.get(Option.ENCODING);
if (encName == null)
return getDefaultEncodingName();
else
return encName;
}
@Override
boolean handleOption(Option option, String value) {
if (!options.contains(option))
return false;
// TODO: could/should validate outputDir exists and is a directory
// need to decide how best to report issue for benefit of
// direct API call on JavaFileManager.handleOption(specifies IAE)
// vs. command line decoding.
outputDir = new File(value);
return true;
}
void update(Options optionTable) {
for (Option o: options) {
String v = optionTable.get(o);
if (v != null) {
handleOption(o, v);
}
}
}
void initHandlers() {
handlersForLocation = new HashMap<>();
handlersForOption = new EnumMap<>(Option.class);
BasicLocationHandler[] handlers = {
new BootClassPathLocationHandler(),
new ClassPathLocationHandler(),
new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH),
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH),
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH),
new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D),
new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S),
new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H),
new ModuleSourcePathLocationHandler(),
new PatchModulesLocationHandler(),
new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH),
new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH),
new SystemModulesLocationHandler(),
};
for (BasicLocationHandler h : handlers) {
handlersForLocation.put(h.location, h);
for (Option o : h.options) {
handlersForOption.put(o, h);
}
}
}
/**
* Create a handler. The location and options provide a way to map
* from a location or an option to the corresponding handler.
* @see #initHandlers
*/
protected LocationHandler(Location location, Option... options) {
this.location = location;
this.options = options.length == 0 ?
EnumSet.noneOf(Option.class):
EnumSet.copyOf(Arrays.asList(options));
}
BootClassPathLocationHandler() {
super(StandardLocation.PLATFORM_CLASS_PATH,
Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH,
Option.XBOOTCLASSPATH_PREPEND,
Option.XBOOTCLASSPATH_APPEND,
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
Option.EXTDIRS, Option.DJAVA_EXT_DIRS);
}
public String getEncodingName() {
String encName = options.get(Option.ENCODING);
if (encName == null)
return getDefaultEncodingName();
else
return encName;
}
private int getIntOption(Options options, Option option, int defaultValue) {
String s = options.get(option);
try {
if (s != null) {
int n = Integer.parseInt(s);
return (n <= 0 ? Integer.MAX_VALUE : n);
}
} catch (NumberFormatException e) {
// silently ignore ill-formed numbers
}
return defaultValue;
}
private Option canonicalize(Option option) {
switch (option) {
case XBOOTCLASSPATH:
return Option.BOOTCLASSPATH;
case DJAVA_ENDORSED_DIRS:
return Option.ENDORSEDDIRS;
case DJAVA_EXT_DIRS:
return Option.EXTDIRS;
default:
return option;
}
}
private int getIntOption(Options options, Option option, int defaultValue) {
String s = options.get(option);
try {
if (s != null) {
int n = Integer.parseInt(s);
return (n <= 0 ? Integer.MAX_VALUE : n);
}
} catch (NumberFormatException e) {
// silently ignore ill-formed numbers
}
return defaultValue;
}
public int isSupportedOption(String option) {
Set<Option> recognizedOptions = Option.getJavacToolOptions();
for (Option o : recognizedOptions) {
if (o.matches(option))
return o.hasArg() ? 1 : 0;
}
return -1;
}
/**
* Create a handler. The location and options provide a way to map
* from a location or an option to the corresponding handler.
* @see #initHandlers
*/
protected LocationHandler(Location location, Option... options) {
this.location = location;
this.options = options.length == 0 ?
EnumSet.noneOf(Option.class):
EnumSet.copyOf(Arrays.asList(options));
}
protected Resolve(Context context) {
context.put(resolveKey, this);
syms = Symtab.instance(context);
varNotFound = new
SymbolNotFoundError(ABSENT_VAR);
methodNotFound = new
SymbolNotFoundError(ABSENT_MTH);
methodWithCorrectStaticnessNotFound = new
SymbolNotFoundError(WRONG_STATICNESS,
"method found has incorrect staticness");
typeNotFound = new
SymbolNotFoundError(ABSENT_TYP);
names = Names.instance(context);
log = Log.instance(context);
attr = Attr.instance(context);
deferredAttr = DeferredAttr.instance(context);
chk = Check.instance(context);
infer = Infer.instance(context);
reader = ClassReader.instance(context);
treeinfo = TreeInfo.instance(context);
types = Types.instance(context);
diags = JCDiagnostic.Factory.instance(context);
Source source = Source.instance(context);
boxingEnabled = source.allowBoxing();
varargsEnabled = source.allowVarargs();
Options options = Options.instance(context);
debugResolve = options.isSet("debugresolve");
compactMethodDiags = options.isSet(Option.XDIAGS, "compact") ||
options.isUnset(Option.XDIAGS) && options.isUnset("rawDiagnostics");
verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
Target target = Target.instance(context);
allowMethodHandles = target.hasMethodHandles();
allowDefaultMethods = source.allowDefaultMethods();
allowStructuralMostSpecific = source.allowStructuralMostSpecific();
polymorphicSignatureScope = new Scope(syms.noSymbol);
inapplicableMethodException = new InapplicableMethodException(diags);
}
@Override
boolean handleOption(Option option, String value) {
if (!options.contains(option))
return false;
// TODO: could/should validate outputDir exists and is a directory
// need to decide how best to report issue for benefit of
// direct API call on JavaFileManager.handleOption(specifies IAE)
// vs. command line decoding.
outputDir = new File(value);
return true;
}
@Override
boolean handleOption(Option option, String value) {
if (!options.contains(option))
return false;
// TODO: could/should validate outputDir exists and is a directory
// need to decide how best to report issue for benefit of
// direct API call on JavaFileManager.handleOption(specifies IAE)
// vs. command line decoding.
outputDir = new File(value);
return true;
}
public int isSupportedOption(String option) {
Set<Option> recognizedOptions = Option.getJavacToolOptions();
for (Option o : recognizedOptions) {
if (o.matches(option))
return o.hasArg() ? 1 : 0;
}
return -1;
}
@Override
boolean handleOption(Option option, String value) {
if (!options.contains(option))
return false;
searchPath = value == null ? null :
Collections.unmodifiableCollection(createPath().addFiles(value));
return true;
}
void update(Options optionTable) {
for (Option o: options) {
String v = optionTable.get(o);
if (v != null) {
handleOption(o, v);
}
}
}
public int isSupportedOption(String option) {
for (Option o : javacFileManagerOptions) {
if (o.matches(option))
return o.hasArg() ? 1 : 0;
}
return -1;
}