/** * Gets the flag value for the given key as an Integer, wrapped in an {@link Optional}, which is * empty if the flag is unset. * * <p>If the flag's value cannot be interpreted as an Integer, throws a {@link * NumberFormatException} (note: float values will *not* be interpreted as integers and will throw * an exception!) */ public Optional<Integer> getInteger(String key) { return this.get(key).map(Integer::valueOf); }
ErrorProneCLIFlagsConfig(ErrorProneFlags flags) { if (!flags.get(FL_ANNOTATED_PACKAGES).isPresent()) { throw new IllegalStateException( "DO NOT report an issue to Error Prone for this crash! NullAway configuration is " getPackagePattern( getFlagStringSet(flags, FL_EXCLUDED_FIELD_ANNOT, DEFAULT_EXCLUDED_FIELD_ANNOT)); castToNonNullMethod = flags.get(FL_CTNN_METHOD).orElse(null); autofixSuppressionComment = flags.get(FL_SUPPRESS_COMMENT).orElse(""); if (autofixSuppressionComment.contains("\n")) { throw new IllegalStateException( jarInferRegexStripModelJarName = flags.get(FL_JI_REGEX_MODEL_PATH).orElse(BASENAME_REGEX); jarInferRegexStripCodeJarName = flags.get(FL_JI_REGEX_CODE_PATH).orElse(BASENAME_REGEX); errorURL = flags.get(FL_ERROR_URL).orElse(DEFAULT_URL);
/** * Gets the flag value for the given key as a Boolean, wrapped in an {@link Optional}, which is * empty if the flag is unset. * * <p>The value within the {@link Optional} will be {@code true} if the flag's value is "true", * {@code false} for "false", both case insensitive. If the value is neither "true" nor "false", * throws an {@link IllegalArgumentException}. * * <p>Note that any flag set without a value, e.g. {@code -XepOpt:FlagValue}, will be "true". */ public Optional<Boolean> getBoolean(String key) { return this.get(key).map(ErrorProneFlags::parseBoolean); }
/** * Gets the flag value for the given key as a comma-separated {@link List} of Strings, wrapped in * an {@link Optional}, which is empty if the flag is unset. * * <p>(note: empty strings included, e.g. {@code "-XepOpt:List=,1,,2," => ["","1","","2",""]}) */ public Optional<List<String>> getList(String key) { return this.get(key).map(v -> ImmutableList.copyOf(Splitter.on(',').split(v))); }
/** * Gets the flag value for the given key as a comma-separated {@link Set} of Strings, wrapped in * an {@link Optional}, which is empty if the flag is unset. * * <p>(note: empty strings included, e.g. {@code "-XepOpt:Set=,1,,1,2," => ["","1","2"]}) */ public Optional<Set<String>> getSet(String key) { return this.get(key).map(v -> ImmutableSet.copyOf(Splitter.on(',').split(v))); }
/** * Gets the flag value for an enum of the given type, wrapped in an {@link Optional}, which is * empty if the flag is unset. */ public <T extends Enum<T>> Optional<T> getEnum(String key, Class<T> clazz) { return this.get(key).map(value -> asEnumValue(key, value, clazz)); }
private static ImmutableSet<String> getFlagStringSet(ErrorProneFlags flags, String flagName) { Optional<String> flagValue = flags.get(flagName); if (flagValue.isPresent()) { return ImmutableSet.copyOf(flagValue.get().split(DELIMITER)); } return ImmutableSet.of(); }
private static ImmutableSet<String> getFlagStringSet( ErrorProneFlags flags, String flagName, ImmutableSet<String> defaults) { Set<String> combined = new LinkedHashSet<>(defaults); Optional<String> flagValue = flags.get(flagName); if (flagValue.isPresent()) { Collections.addAll(combined, flagValue.get().split(DELIMITER)); } return ImmutableSet.copyOf(combined); } }
/** * Gets the flag value for a comma-separated set of enums of the given type, wrapped in an {@link * Optional}, which is empty if the flag is unset. If the flag is explicitly set to empty, an * empty set will be returned. */ public <T extends Enum<T>> Optional<ImmutableSet<T>> getEnumSet(String key, Class<T> clazz) { return this.get(key) .map( value -> Streams.stream(Splitter.on(',').omitEmptyStrings().split(value)) .map(v -> asEnumValue(key, v, clazz)) .collect(toImmutableSet())); }
/** * Gets the flag value for the given key as a Boolean, wrapped in an {@link Optional}, which is * empty if the flag is unset. * * <p>The value within the {@link Optional} will be {@code true} if the flag's value is "true", * {@code false} for "false", both case insensitive. If the value is neither "true" nor "false", * throws an {@link IllegalArgumentException}. * * <p>Note that any flag set without a value, e.g. {@code -XepOpt:FlagValue}, will be "true". */ public Optional<Boolean> getBoolean(String key) { return this.get(key).map(ErrorProneFlags::parseBoolean); }
/** * Gets the flag value for the given key as an Integer, wrapped in an {@link Optional}, which is * empty if the flag is unset. * * <p>If the flag's value cannot be interpreted as an Integer, throws a {@link * NumberFormatException} (note: float values will *not* be interpreted as integers and will throw * an exception!) */ public Optional<Integer> getInteger(String key) { return this.get(key).map(Integer::valueOf); }
/** * Gets the flag value for the given key as a comma-separated {@link ImmutableList} of Strings, * wrapped in an {@link Optional}, which is empty if the flag is unset. * * <p>(note: empty strings included, e.g. {@code "-XepOpt:List=,1,,2," => ["","1","","2",""]}) */ public Optional<ImmutableList<String>> getList(String key) { return this.get(key).map(v -> ImmutableList.copyOf(Splitter.on(',').split(v))); }