1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/* Tests the Java specific directives */
%module java_typemaps_proxy
%typemap(javaimports) SWIGTYPE "import java.math.*;"
%typemap(javacode) NS::Farewell %{
public void saybye(BigDecimal num_times) {
// BigDecimal requires the java.math library
}
%}
%typemap(javaclassmodifiers) NS::Farewell "public final class"
%typemap(javaimports) NS::Greeting %{
import java.util.*; // for EventListener
import java.lang.*; // for Exception
%};
%typemap(javabase) NS::Greeting "Exception"
%typemap(javainterfaces) NS::Greeting "EventListener"
%typemap(javacode) NS::Greeting %{
public static final long serialVersionUID = 0x52151000; // Suppress ecj warning
// Pure Java code generated using %typemap(javacode)
public void sayhello() {
hello();
}
public static void cheerio(EventListener e) {
}
%}
// Create a new getCPtr() function which takes Java null and is public
%typemap(javabody) NS::Greeting %{
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
// Make the pointer constructor public
%typemap(javabody) NS::Farewell %{
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
public $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
// get rid of the finalize method for NS::Farewell
%typemap(javafinalize) NS::Farewell ""
// Test typemaps are being found for templated classes
%typemap(javacode) NS::Adieu<int**> %{
public static void adieu() {
}
%}
// Check the %javamethodmodifiers feature
%javamethodmodifiers NS::Farewell::methodmodifiertest() "private";
%inline %{
namespace NS {
class Greeting {
public:
void hello() {}
static void ciao(Greeting* g) {}
};
class Farewell {
public:
void methodmodifiertest() {}
};
template<class T> class Adieu {};
}
%}
%template(AdieuIntPtrPtr) NS::Adieu<int**>;
// Check the premature garbage collection prevention parameter can be turned off
%typemap(jtype, nopgcpp="1") Without * "long"
%pragma(java) jniclassclassmodifiers="public class"
%inline %{
struct Without {
Without(Without *p) : var(0) {}
static void static_method(Without *p) {}
void member_method(Without *p) {}
Without *var;
};
Without *global_without = 0;
void global_method_without(Without *p) {}
struct With {
With(With *p) {}
static void static_method(With *p) {}
void member_method(With *p) {}
};
void global_method_with(With *p) {}
%}
%typemap(jtype, nopgcpp="1") const ConstWithout * "long"
%inline %{
class ConstWithout {
public:
ConstWithout(const ConstWithout *p) : const_var(0), var_const(0) {}
static void static_method(const ConstWithout *p) {}
void member_method(const ConstWithout *p) {}
void const_member_method(const ConstWithout *p) const {}
const ConstWithout * const_var;
const ConstWithout * const var_const;
};
const ConstWithout * global_constwithout = 0;
void global_method_constwithout(const ConstWithout *p) {}
%}
// $imfuncname substitution
%typemap(javaout) int imfuncname_test {
return $moduleJNI.$imfuncname(swigCPtr, this) + 123;
}
%typemap(javaout) int imfuncname_static_test {
return $moduleJNI.$imfuncname() + 234;
}
%typemap(javaout) int imfuncname_global_test {
return $moduleJNI.$imfuncname() + 345;
}
%inline %{
struct ProxyA {
int imfuncname_test() { return 0; }
static int imfuncname_static_test() { return 0; }
};
int imfuncname_global_test() { return 0; }
%}
|