google / google/j2cl

Enum.valueOf() support?

Open
#90 10 comments 2 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.4k
Forks
161
PR merge metrics
No merged PRs in 30d

Description

`Enum.valueOf()` (and the corresponding `Class.getEnumConstants()`) isn't supported in j2cl, but there are TODOs in the code suggesting that this might be feasible, and perhaps would be accepted as an external contribution?

https://github.com/google/j2cl/blob/d555a3350bd9e374686138b0c484207a363aefa0/jre/java/java/lang/Enum.java#L56
https://github.com/google/j2cl/blob/d555a3350bd9e374686138b0c484207a363aefa0/jre/java/java/lang/Class.java#L100-L103

Having not yet tried, my hunch was that this might have been left out due to its interaction with @JsEnum https://github.com/google/j2cl/blob/d555a3350bd9e374686138b0c484207a363aefa0/transpiler/java/com/google/j2cl/generator/JavaScriptImplGenerator.java#L597-L601? Otherwise, it _looks_ like the array literal returned by `SomeEnum.values()` (via `com.google.j2cl.frontend.common.EnumMethodsCreator#createValuesMethod`) could possibly be passed made into an additional argument for `Util.$setClassMetadataForEnum` so it is available on the Class itself?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.