PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/java_enums.i

#
Swig | 66 lines | 51 code | 15 blank | 0 comment | 0 complexity | a2df7e471027586b852432dacf213583 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This testcase uses the %javaconst directive to control how enums are initialised
  2. %module java_enums
  3. %include "enumtypeunsafe.swg"
  4. // Some pragmas to add in an interface to the module class
  5. %pragma(java) moduleinterfaces="Serializable"
  6. %pragma(java) moduleimports=%{
  7. import java.io.*; // For Serializable
  8. %}
  9. %pragma(java) modulecode=%{
  10. public static final long serialVersionUID = 0x52151001; // Suppress ecj warning
  11. %}
  12. // Set default Java const code generation
  13. %javaconst(1);
  14. // Change the default generation so that these enums are generated into an interface instead of a class
  15. %typemap(javaclassmodifiers) enum stuff "public interface"
  16. %inline %{
  17. enum stuff { FIDDLE = 2*100, STICKS = 5+8, BONGO, DRUMS };
  18. %}
  19. // Check that the enum typemaps are working by using a short for the enums instead of int
  20. %javaconst(0); // will create compile errors in runme file if short typemaps not used
  21. namespace Space {
  22. %typemap(jtype) enum nonsense "short"
  23. %typemap(jstype) enum nonsense "short"
  24. %typemap(javain) enum nonsense "$javainput"
  25. %typemap(in) enum nonsense %{ $1 = (enum Space::nonsense)$input; %}
  26. %typemap(out) enum nonsense %{ $result = (jshort)$1; %}
  27. %typemap(jni) enum nonsense "jshort"
  28. %typemap(javaout) enum nonsense {
  29. return $jnicall;
  30. }
  31. }
  32. %inline %{
  33. namespace Space {
  34. enum nonsense { POPPYCOCK, JUNK };
  35. nonsense test1(nonsense n) { return n; }
  36. enum nonsense test2(enum nonsense n) { return n; }
  37. }
  38. %}
  39. // Test the %javaconstvalue directive for enums
  40. %{
  41. static const int FOUR = 4;
  42. %}
  43. %javaconst(1);
  44. %javaconstvalue(4) Quattro;
  45. %inline %{
  46. enum Numero { Quattro = FOUR };
  47. %}
  48. // Test boolean enums
  49. %inline %{
  50. typedef enum { PLAY = true, STOP = false } play_state;
  51. %}