Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I declare Java enums in Frege native declarations?

Tags:

java

enums

frege

When using the Frege native-gen tool on the JavaFX Animation class it generates Frege code that includes the following:

data Animation = mutable native javafx.animation.Animation where
  native getRate   :: Animation -> IO Double
  native getStatus :: Animation -> IO Animation_Status

but the code does not compile since the Animation_Status type is missing. On the Java side, this is an enum. http://docs.oracle.com/javafx/2/api/javafx/animation/Animation.Status.html

What is the advised way of handling this in the native declaration?

like image 297
Dierk Avatar asked Dec 14 '25 17:12

Dierk


1 Answers

We can generate Frege code for inner classes. The class name that is input to the native-gen tool is the name returned by Class.getName. For the Animation.Status enum, it is javafx.animation.Animation$Status.

$ java -jar native-gen-1.0-SNAPSHOT.jar 

Enter class name: javafx.animation.Animation$Status

data Animation_Status = pure native javafx.animation.Animation.Status where

  pure native paused "javafx.animation.Animation.Status.PAUSED" :: Animation_Status
  pure native running "javafx.animation.Animation.Status.RUNNING" :: Animation_Status
  pure native stopped "javafx.animation.Animation.Status.STOPPED" :: Animation_Status

  pure native valueOf "javafx.animation.Animation.Status.valueOf" :: String -> Animation_Status

  native values "javafx.animation.Animation.Status.values" :: () -> STMutable s (JArray Animation_Status)

derive Serializable Animation_Status

By the way, the native-gen version I am working on currently can generate Frege code for an entire Java package and its subpackages recursively. We could just give the root package javafx and it would create Frege modules for all the classes in all its subpackages. I will release this hopefully by the end of this week.

like image 113
Marimuthu Madasamy Avatar answered Dec 16 '25 10:12

Marimuthu Madasamy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!