You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate enums as interface + enum + class for unknown values
The new generated enum is represented as an interface with two nested classes:
- enum class Known with the list of known enumeration values
- class Unknown which represents any not-known value
The enums `enum` would be generated as:
```java
interface Enum extends IKaitaiEnum {
public static class Unknown extends IKaitaiEnum.Unknown implements Enum {
private Unknown(long id) { super(id); }
}
public enum Known implements Enum {
Variant1(1),
Variant2(2),
Variant(3);
private final long id;
static HashMap<Long, Enum> variants = new HashMap<>(3);
static {
for (final Known e : Known.values()) {
variants.put(e.id, e);
}
}
private Known(long id) { this.id = id; }
@OverRide
public long id() { return this.id; }
}
public static Enum byId(final long id) {
return Known.variants.computeIfAbsent(id, _id -> new Unknown(id));
}
}
```
Unfortunately, it is not possible to generate enum what will implement nested interface
due to cyclic reference. If that would be possible, we would be protected against name clashes.
In the current implementation the names Known and Unknown can clash with enum name itself
0 commit comments