APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.tools.javac.util

public Class Options

extends Object
Class Inheritance
Imports
java.util.*, java.util.function.Consumer, .Supplier, com.sun.tools.javac.code.Lint.LintCategory, com.sun.tools.javac.main.Option

A table of all command-line options. If an option has an argument, the option name is mapped to the argument. If a set option has no argument, it is mapped to itself.

Instances start in an uninitialized/empty state. They transition to the initialized state once they start being populated from the flags and arguments provided to the compiler, or manually via initialize.

Because Options singletons are used to configure many other compiler singletons, depending on how the compiler is invoked, it's possible for some of these singletons to query options before they have been populated. If this happens, null/false is returned, and then if/when listeners are notified (indicating that the population process is complete), if it turns out that the actual option value is different from what was previously returned, then an assertion error is generated (as this would indicate a startup ordering bug). To fix, change the initialization order or have the singleton initialize itself using whenReady.

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Field Summary

Modifier and TypeField and Description
private boolean
private List<Runnable>
public static final Context.Key<Options>
optionsKey

The context key for the options.

private static final long
private final LinkedHashMap<String, String>

Constructor Summary

AccessConstructor and Description
protected
Options(Context context)

Method Summary

Modifier and TypeMethod and Description
public void
public void
private <T> T
computeIfReady(Supplier<T> ifReady, T ifNotReady, String flag)

Return the computed value if initialized, otherwise return the given default value and add a notify listener that asserts that our assumption was correct.

public String
get(String
option name
name
)

Get the value for an undocumented option.

public String
get(Option
option to get
option
)

Get the value for an option.

public boolean
getBoolean(String
option name
name
)

Get the boolean value for an undocumented option, patterned after Boolean.getBoolean, essentially will return true, iff the value exists and is set to "true".

public boolean
getBoolean(String
option name
name
,
boolean
return value if option is not set
defaultValue
)

Get the undocumented boolean with a default value if the option is not set.

public EnumSet<Lint.LintCategory>

Returns:

the specified set of categories
getLintCategoriesOf
(Option
the plain (non-custom) version of the option (e.g., Option#XLINT)
option
,
Supplier<? extends EnumSet<Lint.LintCategory>>
populates the default set, or null for an empty default set
defaults
)

Collect the set of LintCategorys specified by option flag(s) of the form -Flag and/or -Flag:[-]key,[-]key,...

public void
initialize()

Mark this instance as ready to accept queries.

public static Options
instance(Context context)

Get the Options instance for this context.

public boolean

Returns:

true if lc is disabled via option's lint custom variant (e.g., Option#XLINT_CUSTOM)
isDisabled
(Option
the plain (non-custom) version of the option (e.g., Option#XLINT)
option
,
Lint.LintCategory
the LintCategory in question
lc
)

Determine if a specific LintCategory is disabled via a custom option flag of the form -Flag:none or -Flag:-key.

public boolean

Returns:

true if lc is enabled via option's lint custom variant (e.g., Option#XLINT_CUSTOM)
isEnabled
(Option
the plain (non-custom) version of the option (e.g., Option#XLINT)
option
,
Lint.LintCategory
the LintCategory in question
lc
)

Determine if a specific LintCategory is enabled via a custom option flag of the form -Flag, -Flag:all, or -Flag:key.

public boolean

Returns:

true if lc is explicitly disabled via option's lint custom variant (e.g., Option#XLINT_CUSTOM)
isExplicitlyDisabled
(Option
the plain (non-custom) version of the option (e.g., Option#XLINT)
option
,
Lint.LintCategory
the LintCategory in question
lc
)

Determine if a specific LintCategory is explicitly disabled via a custom option flag of the form -Flag:-key.

public boolean

Returns:

true if lc is explicitly enabled via option's lint custom variant (e.g., Option#XLINT_CUSTOM)
isExplicitlyEnabled
(Option
the plain (non-custom) version of the option (e.g., Option#XLINT)
option
,
Lint.LintCategory
the LintCategory in question
lc
)

Determine if a specific LintCategory is explicitly enabled via a custom option flag of the form -Flag:key.

public boolean
isSet(String name)

Check if the value for an undocumented option has been set.

public boolean
isSet(Option option)

Check if the value for an option has been set.

public boolean
isSet(Option option, String value)

Check if the value for a choice option has been set to a specific value.

public boolean
isUnset(String name)

Check if the value for an undocumented option has not been set.

public boolean
isUnset(Option option)

Check if the value for an option has not been set.

public boolean
isUnset(Option option, String value)

Check if the value for a choice option has not been set to a specific value.

public Set<String>
public void
public void
put(String name, String value)

public void
put(Option option, String value)

public void
putAll(Options options)

public void
remove(String name)

public int
size()

public void
whenReady(Consumer<? super Options>
action to take; will be given this instance
action
)

Perform the given action once this instance is ready for queries, or immediately if it is ready now.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

initializedback to summary
private boolean initialized
listenersback to summary
private List<Runnable> listeners
optionsKeyback to summary
public static final Context.Key<Options> optionsKey

The context key for the options.

serialVersionUIDback to summary
private static final long serialVersionUID
valuesback to summary
private final LinkedHashMap<String, String> values

Constructor Detail

Optionsback to summary
protected Options(Context context)
Annotations
@SuppressWarnings:this-escape

Method Detail

addListenerback to summary
public void addListener(Runnable listener)
clearback to summary
public void clear()
computeIfReadyback to summary
private <T> T computeIfReady(Supplier<T> ifReady, T ifNotReady, String flag)

Return the computed value if initialized, otherwise return the given default value and add a notify listener that asserts that our assumption was correct.

getback to summary
public String get(String name)

Get the value for an undocumented option.

Parameters
name:String

option name

getback to summary
public String get(Option option)

Get the value for an option.

Parameters
option:Option

option to get

getBooleanback to summary
public boolean getBoolean(String name)

Get the boolean value for an undocumented option, patterned after Boolean.getBoolean, essentially will return true, iff the value exists and is set to "true".

Parameters
name:String

option name

getBooleanback to summary
public boolean getBoolean(String name, boolean defaultValue)

Get the undocumented boolean with a default value if the option is not set.

Parameters
name:String

option name

defaultValue:boolean

return value if option is not set

getLintCategoriesOfback to summary
public EnumSet<Lint.LintCategory> getLintCategoriesOf(Option option, Supplier<? extends EnumSet<Lint.LintCategory>> defaults)

Collect the set of LintCategorys specified by option flag(s) of the form -Flag and/or -Flag:[-]key,[-]key,....

The given option must have a custom lint variant (available via Option#getLintCustom).

The set of categories is calculated as follows. First, an initial set is created:

  • If -Flag or -Flag:all appears, the initial set contains all categories; otherwise,
  • If -Flag:none appears, the initial set is empty; otherwise,
  • The defaults parameter is invoked to construct an initial set.
Next, for each lint category key key:
  • If -Flag:key flag appears, the corresponding category is added to the set; otherwise
  • If -Flag:-key flag appears, the corresponding category is removed to the set
Unrecognized keys are ignored.
Parameters
option:Option

the plain (non-custom) version of the option (e.g., Option#XLINT)

defaults:Supplier<? extends EnumSet<Lint.LintCategory>>

populates the default set, or null for an empty default set

Returns:EnumSet<Lint.LintCategory>

the specified set of categories

Exceptions
IllegalArgumentException:
if there is no lint custom variant of option
initializeback to summary
public void initialize()

Mark this instance as ready to accept queries.

instanceback to summary
public static Options instance(Context context)

Get the Options instance for this context.

isDisabledback to summary
public boolean isDisabled(Option option, Lint.LintCategory lc)

Determine if a specific LintCategory is disabled via a custom option flag of the form -Flag:none or -Flag:-key.

The given option must have a custom lint variant (available via Option#getLintCustom).

Note

It's possible the category was also enabled; this method does not check that.

Parameters
option:Option

the plain (non-custom) version of the option (e.g., Option#XLINT)

lc:Lint.LintCategory

the LintCategory in question

Returns:boolean

true if lc is disabled via option's lint custom variant (e.g., Option#XLINT_CUSTOM)

Exceptions
IllegalArgumentException:
if there is no lint custom variant of option
isEnabledback to summary
public boolean isEnabled(Option option, Lint.LintCategory lc)

Determine if a specific LintCategory is enabled via a custom option flag of the form -Flag, -Flag:all, or -Flag:key.

The given option must have a custom lint variant (available via Option#getLintCustom).

Note

It's possible the category was also disabled; this method does not check that.

Parameters
option:Option

the plain (non-custom) version of the option (e.g., Option#XLINT)

lc:Lint.LintCategory

the LintCategory in question

Returns:boolean

true if lc is enabled via option's lint custom variant (e.g., Option#XLINT_CUSTOM)

Exceptions
IllegalArgumentException:
if there is no lint custom variant of option
isExplicitlyDisabledback to summary
public boolean isExplicitlyDisabled(Option option, Lint.LintCategory lc)

Determine if a specific LintCategory is explicitly disabled via a custom option flag of the form -Flag:-key.

The given option must have a custom lint variant (available via Option#getLintCustom).

Note

This does not check for an option flag of the form -Flag:none.

Note

It's possible the category was also enabled; this method does not check that.

Parameters
option:Option

the plain (non-custom) version of the option (e.g., Option#XLINT)

lc:Lint.LintCategory

the LintCategory in question

Returns:boolean

true if lc is explicitly disabled via option's lint custom variant (e.g., Option#XLINT_CUSTOM)

Exceptions
IllegalArgumentException:
if there is no lint custom variant of option
isExplicitlyEnabledback to summary
public boolean isExplicitlyEnabled(Option option, Lint.LintCategory lc)

Determine if a specific LintCategory is explicitly enabled via a custom option flag of the form -Flag:key.

The given option must have a custom lint variant (available via Option#getLintCustom).

Note

This does not check for option flags of the form -Flag or -Flag:all.

Note

It's possible the category was also disabled; this method does not check that.

Parameters
option:Option

the plain (non-custom) version of the option (e.g., Option#XLINT)

lc:Lint.LintCategory

the LintCategory in question

Returns:boolean

true if lc is explicitly enabled via option's lint custom variant (e.g., Option#XLINT_CUSTOM)

Exceptions
IllegalArgumentException:
if there is no lint custom variant of option
isSetback to summary
public boolean isSet(String name)

Check if the value for an undocumented option has been set.

isSetback to summary
public boolean isSet(Option option)

Check if the value for an option has been set.

isSetback to summary
public boolean isSet(Option option, String value)

Check if the value for a choice option has been set to a specific value.

isUnsetback to summary
public boolean isUnset(String name)

Check if the value for an undocumented option has not been set.

isUnsetback to summary
public boolean isUnset(Option option)

Check if the value for an option has not been set.

isUnsetback to summary
public boolean isUnset(Option option, String value)

Check if the value for a choice option has not been set to a specific value.

keySetback to summary
public Set<String> keySet()
notifyListenersback to summary
public void notifyListeners()
putback to summary
public void put(String name, String value)
putback to summary
public void put(Option option, String value)
putAllback to summary
public void putAll(Options options)
removeback to summary
public void remove(String name)
sizeback to summary
public int size()
whenReadyback to summary
public void whenReady(Consumer<? super Options> action)

Perform the given action once this instance is ready for queries, or immediately if it is ready now.

Parameters
action:Consumer<? super Options>

action to take; will be given this instance