diff --git a/CHANGES.current b/CHANGES.current index 336b0152c..350a3b433 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,15 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-03-12: wsfulton + #1524 %interface family of macros no longer contain the getter/setter + methods for wrapping variables. The interface only contains + virtual and non-virtual instance methods, that is, no static methods. + Enums are also no longer added to the interface (affects Java only where + they were missing from the proxy class, C# never had them in the interface). + + *** POTENTIAL INCOMPATIBILITY *** + 2022-03-12: wsfulton #1277 Fixes for the family of %interface macros, %interface, %interface_impl and %interface_custom fixes for overloaded methods diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 469463831..5a631956f 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -3546,6 +3546,12 @@ will be excluded from the interface and there will not be an additional method added to the proxy class implementing that interface.
++The Java interface only ever contains virtual and non-virtual instance methods from the wrapped C++ class. +Any static methods, enums or variables in the wrapped C++ class are not supported and are not added to the interface. +They are of course still available in the Java proxy class. +
+Wherever a class marked as an interface is used, such as the UseBases method in the example, the interface name is used as the type in the Java layer: diff --git a/Examples/test-suite/csharp/multiple_inheritance_interfaces_runme.cs b/Examples/test-suite/csharp/multiple_inheritance_interfaces_runme.cs index c786ff9b3..96b74bc5c 100644 --- a/Examples/test-suite/csharp/multiple_inheritance_interfaces_runme.cs +++ b/Examples/test-suite/csharp/multiple_inheritance_interfaces_runme.cs @@ -83,5 +83,7 @@ public class multiple_inheritance_interfaces_runme { d.ia(10); d.ia("bye"); d.ia("bye", false); + + UndesirablesSwigImpl.UndesiredStaticMethod(UndesirablesSwigImpl.UndesiredEnum.UndesiredEnum1); } } diff --git a/Examples/test-suite/java/multiple_inheritance_interfaces_runme.java b/Examples/test-suite/java/multiple_inheritance_interfaces_runme.java index 3f2b00000..35a872c1c 100644 --- a/Examples/test-suite/java/multiple_inheritance_interfaces_runme.java +++ b/Examples/test-suite/java/multiple_inheritance_interfaces_runme.java @@ -74,5 +74,7 @@ public class multiple_inheritance_interfaces_runme { d.ia(10); d.ia("bye"); d.ia("bye", false); + + UndesirablesSwigImpl.UndesiredStaticMethod(UndesirablesSwigImpl.UndesiredEnum.UndesiredEnum1); } } diff --git a/Examples/test-suite/multiple_inheritance_interfaces.i b/Examples/test-suite/multiple_inheritance_interfaces.i index 48e24344a..891e20f72 100644 --- a/Examples/test-suite/multiple_inheritance_interfaces.i +++ b/Examples/test-suite/multiple_inheritance_interfaces.i @@ -49,6 +49,33 @@ struct V : S {}; struct W : T {}; %} +#if defined(SWIGJAVA) || defined(SWIGCSHARP) +%interface_impl(Undesirables); +#endif + +%inline %{ +// Don't put variables and enums into interface +class Undesirables +{ +public: + Undesirables() : UndesiredVariable() {} + virtual ~Undesirables() {} + virtual void Method(int i) = 0; + + enum UndesiredEnum { UndesiredEnum1, UndesiredEnum2 }; + static void UndesiredStaticMethod(UndesiredEnum e) {} + int UndesiredVariable; + static int UndesiredStaticVariable; + static const int UndesiredStaticConstVariable = 0; +}; + +int Undesirables::UndesiredStaticVariable = 0; + +struct UndesirablesDerived : Undesirables { + virtual void Method(int i) {} +}; +%} + #if defined(SWIGJAVA) || defined(SWIGCSHARP) %interface_impl(BaseOverloaded); #endif diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index da09b3b82..7f19070ee 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -2323,7 +2323,7 @@ public: String *pre_code = NewString(""); String *post_code = NewString(""); String *terminator_code = NewString(""); - bool is_interface = GetFlag(parentNode(n), "feature:interface") + bool is_interface = GetFlag(parentNode(n), "feature:interface") && !checkAttribute(n, "kind", "variable") && !static_flag && Getattr(n, "interface:owner") == 0; if (!proxy_flag) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 7819e0468..ae1e0fc2c 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -2459,7 +2459,7 @@ public: bool setter_flag = false; String *pre_code = NewString(""); String *post_code = NewString(""); - bool is_interface = GetFlag(parentNode(n), "feature:interface") + bool is_interface = GetFlag(parentNode(n), "feature:interface") && !checkAttribute(n, "kind", "variable") && !static_flag && Getattr(n, "interface:owner") == 0; if (!proxy_flag)