diff --git a/CHANGES.current b/CHANGES.current index 1e9704783..baf364a47 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,16 @@ Version 2.0.0 (in progress) ============================ +2010-03-06: wsfulton + [Java] The intermediary JNI class modifiers are now public by default meaning these + intermediary low level functions are now accessible by default from outside any package + used. The proxy class pointer constructor and getCPtr() methods are also now public. + These are needed in order for the nspace option to work without any other mods. + The previous default of protected access can be restored using: + + SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE) + %pragma(java) jniclassclassmodifiers = "class" + 2010-03-06: wsfulton [C#] Added the nspace feature for C#. Documentation for the nspace feature is now available. diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 4753fbce7..0984b2ecf 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -2253,17 +2253,17 @@ The jniclasscode pragma is quite useful for adding in a static block fo
Pragmas will take either "" or %{ %} as delimiters. -For example, let's change the intermediary JNI class access to public. +For example, let's change the intermediary JNI class access to just the default package-private access.
-%pragma(java) jniclassclassmodifiers="public class" +%pragma(java) jniclassclassmodifiers="class"
-All the methods in the intermediary JNI class will then be callable outside of the package as the method modifiers are public by default. +All the methods in the intermediary JNI class will then not be be callable outside of the package as the method modifiers have been changed from public access to default access. This is useful if you want to prevent users calling these low level functions.
The defaults can be overridden to tailor these classes. -Here is an example which will change the getCPtr method and constructor from the default protected access to public access. -This has a practical application if you are invoking SWIG more than once and generating the wrapped classes into different packages in each invocation. -If the classes in one package are using the classes in another package, then these methods need to be public. +Here is an example which will change the getCPtr method and constructor from the default public access to protected access. +If the classes in one package are not using the classes in another package, then these methods need not be public and removing access to these low level implementation details, is a good thing. +If you are invoking SWIG more than once and generating the wrapped classes into different packages in each invocation, then you cannot do this as you will then have different packages.
-The typemap code is the same that is in "java.swg", barring the two method modifiers. +The typemap code is the same that is in "java.swg", barring the last two method modifiers. Note that SWIGTYPE will target all proxy classes, but not the type wrapper classes. Also the above typemap is only used for proxy classes that are potential base classes. To target proxy classes that are derived from a wrapped class as well, the "javabody_derived" typemap should also be overridden. +There is a macro in java.swg that implements this and the above can instead be implemented using:
++SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE) ++
For the typemap to be used in all type wrapper classes, all the different types that type wrapper classes could be used for should be targeted:
diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index eb63f342d..14be0aa20 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -1,11 +1,6 @@ // Test the nspace feature %module nspace -#if defined(SWIGJAVA) -SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) -%pragma(java) jniclassclassmodifiers = "public class" -#endif - // nspace feature only supported by these languages #if defined(SWIGJAVA) || defined(SWIGCSHARP) diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 6173502ca..f37cba77a 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -1085,7 +1085,7 @@ /* Set the default for SWIGTYPE: pointer constructor is protected, getCPtr is protected. Season to your own taste! */ -SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE) +SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) // Typewrapper classes %typemap(javabody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ @@ -1195,7 +1195,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) #define %nojavaexception %feature("except","0",throws="") #define %clearjavaexception %feature("except","",throws="") -%pragma(java) jniclassclassmodifiers="class" +%pragma(java) jniclassclassmodifiers="public class" %pragma(java) moduleclassmodifiers="public class" /* Some ANSI C typemaps */