开发者

java packages prefix with swig

开发者 https://www.devze.com 2023-03-31 23:09 出处:网络
I\'m generating code in java using SWIG. One of the generated class belongs to a package (my.block.myint). And one of the generated method looks like this:

I'm generating code in java using SWIG. One of the generated class belongs to a package (my.block.myint). And one of the generated method looks like this:

public static boolean intersect(Box2D box1, Box2D box2) { ... }

This method needs a class named Box2D which is in another package (my.core)

I would like th开发者_运维百科at the generated function looks like this instead:

public static boolean intersect(my.core.Box2D box1, my.core.Box2D box2) { ... }

For the moment I'm using this pragma in my .i file:

%typemap(javaimports) Box2D "my.core.Box2D";

which copy the Box2D.java file in the package my.block.myint, but this is not a satisfactory method. Thanks for the ideas!


If the classes are coming from a %import directive for another SWIG module you can use %typemap("javapackage"), e.g.

%typemap("javapackage") Box2D, Box2D *, Box2D & "my.core.Box2D";

If the classes are part of the current module and you want to put the current module in a specific package you can do this with -package when you call SWIG, e.g.:

swig -c++ -Wall -java -package my.core.Box2D -outdir my/core/Box2D box2d.i

Finally, if you want to make the methods on the Java proxy class take a Java type, rather than a type SWIG knows about already you can do:

%typemap(jstype) Box2D "my.core.Box2D"

but note that you will need to supply an additional typemap to explain to SWIG how to convert from the my.core.Box2D type to the type that the JNI interface it generates expects. That could be with a javain typemap, or it could be with a jtype typemap and a corresponding jni typemap too.

0

精彩评论

暂无评论...
验证码 换一张
取 消