Skip to content

Commit

Permalink
simplify implementation of enumerate
Browse files Browse the repository at this point in the history
  • Loading branch information
forax committed Dec 18, 2022
1 parent 855ddb1 commit d4d97b6
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions main/main/ConverterResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,12 @@ final class Default {
});
}

@SuppressWarnings({"rawtypes", "unchecked"})
static Optional<Function<Object, ?>> enumerated(Lookup lookup, Type valueType) {
requireNonNull(lookup, "lookup is null");
requireNonNull(valueType, "valueType is null");
if (valueType instanceof Class<?> clazz && clazz.isEnum()) {
MethodHandle mh;
try {
mh = lookup.findStatic(clazz, "valueOf", methodType(clazz, String.class));
} catch (NoSuchMethodException e) {
throw (NoSuchMethodError) new NoSuchMethodError().initCause(e);
} catch (IllegalAccessException e) {
throw (IllegalAccessError) new IllegalAccessError().initCause(e);
}
return Optional.of(ConverterResolver.converter(mh));
return Optional.of(arg -> Enum.valueOf((Class) clazz, (String) arg));
}
return Optional.empty();
}
Expand Down

0 comments on commit d4d97b6

Please sign in to comment.