-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16553b1
commit fb04db6
Showing
6 changed files
with
96 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tech.picnic.errorprone.bugpatterns.util; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.errorprone.ErrorProneFlags; | ||
|
||
/** Helper methods for working with {@link ErrorProneFlags}. */ | ||
public final class Flags { | ||
private Flags() {} | ||
|
||
/** | ||
* Returns the list of (comma-separated) arguments passed using the given Error Prone flag. | ||
* | ||
* @param errorProneFlags The full set of flags provided. | ||
* @param name The name of the flag of interest. | ||
* @return A non-{@code null} list of provided arguments; this list is empty if the flag was not | ||
* provided, or if the flag's value is the empty string. | ||
*/ | ||
public static ImmutableList<String> getList(ErrorProneFlags errorProneFlags, String name) { | ||
return errorProneFlags | ||
.getList(name) | ||
.map(ImmutableList::copyOf) | ||
.filter(flags -> !flags.equals(ImmutableList.of(""))) | ||
.orElseGet(ImmutableList::of); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/FlagsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package tech.picnic.errorprone.bugpatterns.util; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.errorprone.ErrorProneOptions; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
final class FlagsTest { | ||
private static Stream<Arguments> getListTestCases() { | ||
/* { args, flag, expected } */ | ||
return Stream.of( | ||
arguments(ImmutableList.of(), "Foo", ImmutableList.of()), | ||
arguments(ImmutableList.of("-XepOpt:Foo=bar,baz"), "Qux", ImmutableList.of()), | ||
arguments(ImmutableList.of("-XepOpt:Foo="), "Foo", ImmutableList.of()), | ||
arguments(ImmutableList.of("-XepOpt:Foo=bar"), "Foo", ImmutableList.of("bar")), | ||
arguments(ImmutableList.of("-XepOpt:Foo=bar,baz"), "Foo", ImmutableList.of("bar", "baz")), | ||
arguments(ImmutableList.of("-XepOpt:Foo=,"), "Foo", ImmutableList.of("", ""))); | ||
} | ||
|
||
@MethodSource("getListTestCases") | ||
@ParameterizedTest | ||
void getList(ImmutableList<String> args, String flag, ImmutableList<String> expected) { | ||
assertThat(Flags.getList(ErrorProneOptions.processArgs(args).getFlags(), flag)) | ||
.containsExactlyElementsOf(expected); | ||
} | ||
} |