Add access modifier support for interface feature
Add ability to change the modifiers for the C# and Java interface generated when using the %interface macros. For C# use the 'csinterfacemodifiers' typemap. For Java use the 'javainterfacemodifiers' typemap. For example: %typemap(csinterfacemodifiers) X "internal interface" Closes #1874
This commit is contained in:
parent
c8ac73513b
commit
c1b004f4fa
9 changed files with 59 additions and 3 deletions
|
|
@ -7,6 +7,18 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
||||||
Version 4.1.0 (in progress)
|
Version 4.1.0 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2020-09-25: wsfulton
|
||||||
|
[C#, Java] #1874 Add ability to change the modifiers for the interface
|
||||||
|
generated when using the %interface macros.
|
||||||
|
|
||||||
|
For C# use the 'csinterfacemodifiers' typemap.
|
||||||
|
For Java use the 'javainterfacemodifiers' typemap.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
%typemap(csinterfacemodifiers) X "internal interface"
|
||||||
|
|
||||||
|
|
||||||
2020-09-24: geefr
|
2020-09-24: geefr
|
||||||
[C#] #1868 Fix wchar_t* csvarout typemap for member variable wrappers.
|
[C#] #1868 Fix wchar_t* csvarout typemap for member variable wrappers.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ javabody -> csbody
|
||||||
javafinalize -> csfinalize
|
javafinalize -> csfinalize
|
||||||
javadestruct -> csdisposing and csdispose
|
javadestruct -> csdisposing and csdispose
|
||||||
javadestruct_derived -> csdisposing_derived and csdispose_derived
|
javadestruct_derived -> csdisposing_derived and csdispose_derived
|
||||||
|
javainterfacemodifiers -> csinterfacemodifiers
|
||||||
javainterfacecode -> csinterfacecode
|
javainterfacecode -> csinterfacecode
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6610,6 +6610,15 @@ Below shows an example modifying the finalizer, assuming the <tt>delete</tt> met
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p><tt>%typemap(javainterfacemodifiers)</tt></p>
|
||||||
|
<div class="indent">
|
||||||
|
Interface modifiers for the Java interface generated when using the <tt>interface</tt> feature, see <a href="Java.html#Java_interfaces">Java interfaces</a> section. The default is "public interface".
|
||||||
|
<p>
|
||||||
|
<b>Compatibility note:</b> This typemap was added in SWIG-4.1.0.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<p><tt>%typemap(javainterfacecode, declaration="...", cptrmethod="...")</tt></p>
|
<p><tt>%typemap(javainterfacecode, declaration="...", cptrmethod="...")</tt></p>
|
||||||
<div class="indent">
|
<div class="indent">
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -6709,7 +6718,7 @@ The "javaimports" typemap is ignored if the enum class is wrapped by an inner Ja
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
[ javaimports typemap ]
|
[ javaimports typemap ]
|
||||||
public interface [ javainterfacename ] {
|
[ javainterfacemodifiers typemap ] [ javainterfacename ] {
|
||||||
[ javainterfacecode:cptrmethod typemap attribute ]
|
[ javainterfacecode:cptrmethod typemap attribute ]
|
||||||
... interface declarations ...
|
... interface declarations ...
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,3 +64,31 @@ struct DerivedOverloaded : public BaseOverloaded {
|
||||||
virtual void identical_overload(int i, const PTypedef &p = PTypedef()) {}
|
virtual void identical_overload(int i, const PTypedef &p = PTypedef()) {}
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||||
|
%interface(Space::X)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Test the csinterfacemodifiers and javainterfacemodifiers typemaps.
|
||||||
|
#if defined(SWIGCSHARP)
|
||||||
|
/* change access from default "public class" to "internal class" */
|
||||||
|
%typemap(csclassmodifiers) InternalAccess "internal class"
|
||||||
|
/* The following modifiers are also needed with the above access modifier change */
|
||||||
|
%typemap(csclassmodifiers) Space::X "internal class"
|
||||||
|
%typemap(csinterfacemodifiers) Space::X "internal interface"
|
||||||
|
#elif defined(SWIGJAVA)
|
||||||
|
%typemap(javaclassmodifiers) InternalAccess "final /*notpublic*/ class"
|
||||||
|
%typemap(javaclassmodifiers) Space::X "final class"
|
||||||
|
%typemap(javainterfacemodifiers) Space::X "/*notpublic*/ interface"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
struct InternalAccess {};
|
||||||
|
namespace Space {
|
||||||
|
class X {
|
||||||
|
public:
|
||||||
|
virtual void x(const InternalAccess& date) const = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
|
||||||
|
|
@ -894,6 +894,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
|
||||||
%typemap(csinterfaces) SWIGTYPE "global::System.IDisposable"
|
%typemap(csinterfaces) SWIGTYPE "global::System.IDisposable"
|
||||||
%typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
%typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||||
%typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
%typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||||
|
%typemap(csinterfacemodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public interface"
|
||||||
|
|
||||||
|
|
||||||
// csbody typemaps... these are in macros so that the visibility of the methods can be easily changed by users.
|
// csbody typemaps... these are in macros so that the visibility of the methods can be easily changed by users.
|
||||||
|
|
|
||||||
|
|
@ -1196,6 +1196,7 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
|
||||||
%typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
%typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||||
%typemap(javaimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
%typemap(javaimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||||
%typemap(javainterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
%typemap(javainterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||||
|
%typemap(javainterfacemodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public interface"
|
||||||
|
|
||||||
/* javabody typemaps */
|
/* javabody typemaps */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,7 @@
|
||||||
#define WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC 824
|
#define WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC 824
|
||||||
#define WARN_JAVA_NO_DIRECTORCONNECT_ATTR 825
|
#define WARN_JAVA_NO_DIRECTORCONNECT_ATTR 825
|
||||||
#define WARN_JAVA_NSPACE_WITHOUT_PACKAGE 826
|
#define WARN_JAVA_NSPACE_WITHOUT_PACKAGE 826
|
||||||
|
#define WARN_JAVA_TYPEMAP_INTERFACEMODIFIERS_UNDEF 847
|
||||||
|
|
||||||
/* please leave 810-829 free for Java */
|
/* please leave 810-829 free for Java */
|
||||||
|
|
||||||
|
|
@ -297,6 +298,7 @@
|
||||||
#define WARN_CSHARP_EXCODE 844
|
#define WARN_CSHARP_EXCODE 844
|
||||||
#define WARN_CSHARP_CANTHROW 845
|
#define WARN_CSHARP_CANTHROW 845
|
||||||
#define WARN_CSHARP_NO_DIRECTORCONNECT_ATTR 846
|
#define WARN_CSHARP_NO_DIRECTORCONNECT_ATTR 846
|
||||||
|
#define WARN_CSHARP_TYPEMAP_INTERFACEMODIFIERS_UNDEF 847
|
||||||
|
|
||||||
/* please leave 830-849 free for C# */
|
/* please leave 830-849 free for C# */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2050,7 +2050,8 @@ public:
|
||||||
|
|
||||||
void emitInterfaceDeclaration(Node *n, String *interface_name, File *f_interface) {
|
void emitInterfaceDeclaration(Node *n, String *interface_name, File *f_interface) {
|
||||||
Printv(f_interface, typemapLookup(n, "csimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
|
Printv(f_interface, typemapLookup(n, "csimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
|
||||||
Printf(f_interface, "public interface %s", interface_name);
|
Printv(f_interface, typemapLookup(n, "csinterfacemodifiers", Getattr(n, "classtypeobj"), WARN_CSHARP_TYPEMAP_INTERFACEMODIFIERS_UNDEF), NIL);
|
||||||
|
Printf(f_interface, " %s", interface_name);
|
||||||
if (List *baselist = Getattr(n, "bases")) {
|
if (List *baselist = Getattr(n, "bases")) {
|
||||||
String *bases = 0;
|
String *bases = 0;
|
||||||
for (Iterator base = First(baselist); base.item; base = Next(base)) {
|
for (Iterator base = First(baselist); base.item; base = Next(base)) {
|
||||||
|
|
|
||||||
|
|
@ -2145,7 +2145,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Printv(f_interface, typemapLookup(n, "javaimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
|
Printv(f_interface, typemapLookup(n, "javaimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
|
||||||
Printf(f_interface, "public interface %s", interface_name);
|
Printv(f_interface, typemapLookup(n, "javainterfacemodifiers", Getattr(n, "classtypeobj"), WARN_JAVA_TYPEMAP_INTERFACEMODIFIERS_UNDEF), NIL);
|
||||||
|
Printf(f_interface, " %s", interface_name);
|
||||||
if (List *baselist = Getattr(n, "bases")) {
|
if (List *baselist = Getattr(n, "bases")) {
|
||||||
String *bases = 0;
|
String *bases = 0;
|
||||||
for (Iterator base = First(baselist); base.item; base = Next(base)) {
|
for (Iterator base = First(baselist); base.item; base = Next(base)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue