Class ErrorProneFlags

java.lang.Object
com.google.errorprone.ErrorProneFlags
All Implemented Interfaces:
Serializable

public final class ErrorProneFlags extends Object implements Serializable
Represents an immutable map of Error Prone flags to their set values.

All get* methods return an Optional<*> containing the value for the given key, or empty if the flag is unset.

To access ErrorProneFlags from a BugChecker class, add a constructor to the class that takes one parameter of type ErrorProneFlags.

See documentation for full syntax description.

See Also:
  • Field Details

  • Method Details

    • empty

      public static ErrorProneFlags empty()
    • fromMap

      public static ErrorProneFlags fromMap(Map<String,String> flagsMap)
    • getFlagsMap

      public com.google.common.collect.ImmutableMap<String,String> getFlagsMap()
    • get

      public Optional<String> get(String key)
      Gets flag value for the given key as a String, wrapped in an Optional, which is empty if the flag is unset.
    • getBoolean

      public Optional<Boolean> getBoolean(String key)
      Gets the flag value for the given key as a Boolean, wrapped in an Optional, which is empty if the flag is unset.

      The value within the Optional will be true if the flag's value is "true", false for "false", both case insensitive. If the value is neither "true" nor "false", throws an IllegalArgumentException.

      Note that any flag set without a value, e.g. -XepOpt:FlagValue, will be "true".

    • getEnum

      public <T extends Enum<T>> Optional<T> getEnum(String key, Class<T> clazz)
      Gets the flag value for an enum of the given type, wrapped in an Optional, which is empty if the flag is unset.
    • getEnumSet

      public <T extends Enum<T>> Optional<com.google.common.collect.ImmutableSet<T>> getEnumSet(String key, Class<T> clazz)
      Gets the flag value for a comma-separated set of enums of the given type, wrapped in an Optional, which is empty if the flag is unset. If the flag is explicitly set to empty, an empty set will be returned.
    • getInteger

      public Optional<Integer> getInteger(String key)
      Gets the flag value for the given key as an Integer, wrapped in an Optional, which is empty if the flag is unset.

      If the flag's value cannot be interpreted as an Integer, throws a NumberFormatException (note: float values will *not* be interpreted as integers and will throw an exception!)

    • getListOrEmpty

      public com.google.common.collect.ImmutableList<String> getListOrEmpty(String key)
      Gets the flag value for the given key as a comma-separated ImmutableList of Strings, or an empty list if the flag is unset.

      (note: empty strings included, e.g. "-XepOpt:List=,1,,2," => ["","1","","2",""])

    • getSetOrEmpty

      public com.google.common.collect.ImmutableSet<String> getSetOrEmpty(String key)
      Gets the flag value for the given key as a comma-separated Set of Strings, or an empty set if unset.

      (note: empty strings included, e.g. "-XepOpt:Set=,1,,1,2," => ["","1","2"])

    • isEmpty

      public boolean isEmpty()
      Whether this Flags object is empty, i.e. no flags have been set.
    • plus

      Returns a new ErrorProneFlags object with the values of two ErrorProneFlags objects added together. For flags that appear in both instances, the values in other override this.
    • builder

      public static ErrorProneFlags.Builder builder()