Skip to content

Commit

Permalink
Support proto enum aliases: Update CHANGELOG and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nymanjens committed Apr 25, 2024
1 parent 9539541 commit 03a97fa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Added support for repeated annotations to [`TestParameterValuesProvider.Context`](
https://google.github.io/TestParameterInjector/docs/latest/com/google/testing/junit/testparameterinjector/TestParameterValuesProvider.Context.html)
- Converting incorrectly YAML-parsed booleans back to their enum values when possible
- Support enum aliases (defined as static fields on the enum), and in particular
Protocol Buffer enum aliases

## 1.15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ static <E extends Enum<E>> Enum<?> parseEnum(String str, Class<?> enumType) {
try {
return Enum.valueOf((Class<E>) enumType, str);
} catch (IllegalArgumentException e) {
// The given name was not a valid enum value. However, the enum might have an alias to one of
// its values defined as static field. This happens for example (via code generation) in the
// case of Protocol Buffer aliases (see the allow_alias option).
Optional<Enum<?>> enumValue = maybeGetStaticConstant(enumType, str);
if (enumValue.isPresent()) {
return enumValue.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ static <E extends Enum<E>> Enum<?> parseEnum(String str, Class<?> enumType) {
try {
return Enum.valueOf((Class<E>) enumType, str);
} catch (IllegalArgumentException e) {
// The given name was not a valid enum value. However, the enum might have an alias to one of
// its values defined as static field. This happens for example (via code generation) in the
// case of Protocol Buffer aliases (see the allow_alias option).
Optional<Enum<?>> enumValue = maybeGetStaticConstant(enumType, str);
if (enumValue.isPresent()) {
return enumValue.get();
Expand Down

0 comments on commit 03a97fa

Please sign in to comment.