Comments (6)
Thank you for this question!
This decision was made long time ago, when Android was avoiding Java enums.
It looks like Android's reasons are now obsolete so I'm going to change cito
to emit Java enums.
from fut.
How to transpile flags? I'm aware of EnumSet, but how would you transpile:
public enum* Inventory
{
None = 0,
Gun = 1,
Knife = 2,
Weapons = Gun | Knife,
Key = 4
}
?
from fut.
import java.util.EnumSet;
public enum Inventory
{
_GUN,
_KNIFE,
_KEY;
public static final EnumSet<Inventory> NONE = EnumSet.noneOf(Inventory.class);
public static final EnumSet<Inventory> GUN = EnumSet.of(_GUN);
public static final EnumSet<Inventory> KNIFE = EnumSet.of(_KNIFE);
public static final EnumSet<Inventory> WEAPONS = EnumSet.of(_GUN, _KNIFE);
public static final EnumSet<Inventory> KEY = EnumSet.of(_KEY);
/// The `&` operator.
public static EnumSet<Inventory> retaining(EnumSet<Inventory> a, EnumSet<Inventory> b)
{
EnumSet<Inventory> result = EnumSet.copyOf(a);
result.retainAll(b);
return result;
}
/// The `|` operator.
public static EnumSet<Inventory> adding(EnumSet<Inventory> a, EnumSet<Inventory> b)
{
EnumSet<Inventory> result = EnumSet.copyOf(a);
result.addAll(b);
return result;
}
}
?
from fut.
Ć | Java |
---|---|
f1 == f2 |
f1.equals(f2) |
~f |
EnumSet.complementOf(f) |
f1 &= f2; |
f1 = EnumSet.copyOf(f1); f1.retainAll(f2); |
f1 |= f2; |
f1 = EnumSet.copyOf(f1); f1.addAll(f2); |
f1.HasFlag(f2) |
f1.containsAll(f2) |
f1 ^ f2 (symmetric difference) |
??? |
from fut.
Ah nice, thanks for taking a look into this. The EnumSet solution looks good to me, though I don't write Java often so I'm not an authority on the matter. I think for symmetric difference most people generally rely on a library as there is no built in. There is two different implementations here to get an idea: https://rosettacode.org/wiki/Symmetric_difference#Java
from fut.
EnumSet
is problematic. Assigning (integer or other enum) values to Java enum is problematic.
For now, I'm going to emit Java enums only for non-flags enums with no assigned values. Other enums will remain interface
s with int
constants.
from fut.
Related Issues (20)
- `#include <stdio.h>` in `native` blocks doesn't work HOT 1
- Correctly generate the main function for C/C++ HOT 3
- Reference example of Dictionary is not working HOT 1
- Transpile to Golang HOT 2
- Regex C++ issue smatch vs cmatch HOT 1
- Thoughts on expanding the standard lib HOT 3
- JSON parsing support HOT 14
- WIP: Support for starting child processes and reading output
- Emit compiler directives based on language being compiled HOT 6
- Allow delegates / anonymous functions HOT 6
- Promise / Callback Types (Instead of async/await?) HOT 3
- String Comparisons HOT 1
- Revisiting ICU dependency HOT 4
- What is the ref-code in the Playground examples, if C/C++ were supposed to not have GC? HOT 23
- Is there some mailing list, forum, Element/Matrix chat or something for communication? HOT 6
- What exactly guarantees that all of the produced codes have exactly the same behavior? HOT 7
- syntactic sugar for getters/setters HOT 1
- Duplicated symbol error reported on wrong line HOT 1
- false positive error inside #if condition? HOT 1
- Transpiling to Dart
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fut.