1 
2 // This testcase uses the %javaconst directive to control how enums are initialised
3 
4 %module java_enums
5 
6 %include "enumtypeunsafe.swg"
7 
8 // Some pragmas to add in an interface to the module class
9 %pragma(java) moduleinterfaces="Serializable"
10 %pragma(java) moduleimports=%{
11 import java.io.*; // For Serializable
12 %}
13 %pragma(java) modulecode=%{
14   public static final long serialVersionUID = 0x52151001; // Suppress ecj warning
15 %}
16 
17 
18 // Set default Java const code generation
19 %javaconst(1);
20 
21 // Test enums with trailing comma after the last item.
22 enum WithTrailingComma
23 {
24     First,
25     Second,
26 };
27 
28 %ignore ReallyFirstOneIsIgnored;
29 enum WithTrailingCommaAndIgnoredFirstItem
30 {
31     ReallyFirstOneIsIgnored,
32     FirstNonIgnoredOne,
33     SecondNonIgnoredOne,
34 };
35 
36 // Change the default generation so that these enums are generated into an interface instead of a class
37 %typemap(javaclassmodifiers) enum stuff "public interface"
38 
39 %inline %{
40 enum stuff { FIDDLE = 2*100,  STICKS = 5+8, BONGO, DRUMS };
41 %}
42 
43 // Check that the enum typemaps are working by using a short for the enums instead of int
44 %javaconst(0); // will create compile errors in runme file if short typemaps not used
45 
46 namespace Space {
47 %typemap(jtype) enum nonsense "short"
48 %typemap(jstype) enum nonsense "short"
49 %typemap(javain) enum nonsense "$javainput"
50 %typemap(in) enum nonsense %{ $1 = (enum Space::nonsense)$input; %}
51 %typemap(out) enum nonsense %{ $result = (jshort)$1; %}
52 %typemap(jni) enum nonsense "jshort"
53 %typemap(javaout) enum nonsense {
54     return $jnicall;
55   }
56 }
57 
58 %inline %{
59 namespace Space {
60 enum nonsense { POPPYCOCK, JUNK };
61 nonsense test1(nonsense n) { return n; }
62 enum nonsense test2(enum nonsense n) { return n; }
63 }
64 %}
65 
66 // Test the %javaconstvalue directive for enums
67 %{
68 static const int FOUR = 4;
69 %}
70 
71 %javaconst(1);
72 %javaconstvalue(4) Quattro;
73 %inline %{
74 enum Numero { Quattro = FOUR };
75 %}
76 
77 // Test boolean enums
78 %inline %{
79 typedef enum { PLAY = true, STOP = false } play_state;
80 %}
81 
82