PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

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

#
Swig | 66 lines | 51 code | 15 blank | 0 comment | 0 complexity | a2df7e471027586b852432dacf213583 MD5 | raw file
 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=%{
11import 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// Change the default generation so that these enums are generated into an interface instead of a class
22%typemap(javaclassmodifiers) enum stuff "public interface"
23
24%inline %{
25enum stuff { FIDDLE = 2*100,  STICKS = 5+8, BONGO, DRUMS };
26%}
27
28// Check that the enum typemaps are working by using a short for the enums instead of int
29%javaconst(0); // will create compile errors in runme file if short typemaps not used 
30
31namespace Space {
32%typemap(jtype) enum nonsense "short"
33%typemap(jstype) enum nonsense "short"
34%typemap(javain) enum nonsense "$javainput"
35%typemap(in) enum nonsense %{ $1 = (enum Space::nonsense)$input; %}
36%typemap(out) enum nonsense %{ $result = (jshort)$1; %}
37%typemap(jni) enum nonsense "jshort"
38%typemap(javaout) enum nonsense {
39    return $jnicall;
40  }
41}
42
43%inline %{
44namespace Space {
45enum nonsense { POPPYCOCK, JUNK };
46nonsense test1(nonsense n) { return n; }
47enum nonsense test2(enum nonsense n) { return n; }
48}
49%}
50
51// Test the %javaconstvalue directive for enums
52%{
53static const int FOUR = 4;
54%}
55
56%javaconst(1);
57%javaconstvalue(4) Quattro;
58%inline %{
59enum Numero { Quattro = FOUR };
60%}
61
62// Test boolean enums
63%inline %{
64typedef enum { PLAY = true, STOP = false } play_state;
65%}
66