Skip to content

Commit

Permalink
Remove the deprecated ErrorProneFlags methods.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 572515443
  • Loading branch information
graememorgan authored and Error Prone Team committed Oct 11, 2023
1 parent 90baca0 commit 3cdff25
Showing 1 changed file with 11 additions and 31 deletions.
42 changes: 11 additions & 31 deletions check_api/src/main/java/com/google/errorprone/ErrorProneFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CheckReturnValue;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -107,7 +105,9 @@ public <T extends Enum<T>> Optional<ImmutableSet<T>> getEnumSet(String key, Clas
return this.get(key)
.map(
value ->
Streams.stream(Splitter.on(',').omitEmptyStrings().split(value))
COMMA_SPLITTER
.omitEmptyStrings()
.splitToStream(value)
.map(v -> asEnumValue(key, v, clazz))
.collect(toImmutableSet()));
}
Expand Down Expand Up @@ -147,40 +147,16 @@ 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 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",""]})
*
* @deprecated prefer {@link #getListOrEmpty(String)}
*/
@Deprecated
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 ImmutableList} of Strings, or
* an empty list if the flag is unset.
*
* <p>(note: empty strings included, e.g. {@code "-XepOpt:List=,1,,2," => ["","1","","2",""]})
*/
public ImmutableList<String> getListOrEmpty(String key) {
return getList(key).map(ImmutableList::copyOf).orElse(ImmutableList.of());
}

/**
* 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"]})
*
* @deprecated prefer {@link #getSetOrEmpty(String)}
*/
@Deprecated
public Optional<Set<String>> getSet(String key) {
return this.get(key).map(v -> ImmutableSet.copyOf(Splitter.on(',').split(v)));
return get(key)
.map(v -> ImmutableList.copyOf(COMMA_SPLITTER.split(v)))
.orElse(ImmutableList.of());
}

/**
Expand All @@ -190,9 +166,13 @@ public Optional<Set<String>> getSet(String key) {
* <p>(note: empty strings included, e.g. {@code "-XepOpt:Set=,1,,1,2," => ["","1","2"]})
*/
public ImmutableSet<String> getSetOrEmpty(String key) {
return getSet(key).map(ImmutableSet::copyOf).orElse(ImmutableSet.of());
return get(key)
.map(v -> ImmutableSet.copyOf(COMMA_SPLITTER.split(v)))
.orElse(ImmutableSet.of());
}

private static final Splitter COMMA_SPLITTER = Splitter.on(',');

/** Whether this Flags object is empty, i.e. no flags have been set. */
public boolean isEmpty() {
return this.flagsMap.isEmpty();
Expand Down

0 comments on commit 3cdff25

Please sign in to comment.