Add missing Java throws clause for interfaces when using the %interface family of macros.
Fixes #1156.
This commit is contained in:
parent
c44adff7b9
commit
49af1907b8
4 changed files with 48 additions and 2 deletions
|
|
@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
||||||
Version 4.0.0 (in progress)
|
Version 4.0.0 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2018-01-12: wsfulton
|
||||||
|
[Java] Fix issue #1156. Add missing throws clause for interfaces when using the
|
||||||
|
%interface family of macros.
|
||||||
|
|
||||||
2018-01-05: wsfulton
|
2018-01-05: wsfulton
|
||||||
Fix default arguments using expressions containing -> syntax error. Problem reported on
|
Fix default arguments using expressions containing -> syntax error. Problem reported on
|
||||||
swig-user mailing list.
|
swig-user mailing list.
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,28 @@ public class java_throws_runme {
|
||||||
if (!pass)
|
if (!pass)
|
||||||
throw new RuntimeException("Test 6 failed");
|
throw new RuntimeException("Test 6 failed");
|
||||||
|
|
||||||
|
// Interface function
|
||||||
|
pass = false;
|
||||||
|
try {
|
||||||
|
InterfaceTestImpl iti = new InterfaceTestImpl();
|
||||||
|
iti.imethod(true);
|
||||||
|
}
|
||||||
|
catch (MyException e) { pass = true; }
|
||||||
|
|
||||||
|
if (!pass)
|
||||||
|
throw new RuntimeException("Test interface 1 failed");
|
||||||
|
|
||||||
|
pass = false;
|
||||||
|
try {
|
||||||
|
InterfaceTestImpl iti = new InterfaceTestImpl();
|
||||||
|
iti.imethod(false);
|
||||||
|
pass = true;
|
||||||
|
}
|
||||||
|
catch (MyException e) { pass = false; }
|
||||||
|
|
||||||
|
if (!pass)
|
||||||
|
throw new RuntimeException("Test interface 2 failed");
|
||||||
|
|
||||||
// Global function
|
// Global function
|
||||||
pass = false;
|
pass = false;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,23 @@ JAVAEXCEPTION(FeatureTest::staticMethod)
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%include <swiginterface.i>
|
||||||
|
%interface_impl(InterfaceTest);
|
||||||
|
JAVAEXCEPTION(imethod)
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
struct InterfaceTest {
|
||||||
|
virtual void imethod(bool raise) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct InterfaceTestImpl : InterfaceTest {
|
||||||
|
void imethod(bool raise) {
|
||||||
|
if (raise)
|
||||||
|
throw MyException("raise message");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
// Mixing except feature and typemaps when both generate a class for the throws clause
|
// Mixing except feature and typemaps when both generate a class for the throws clause
|
||||||
%typemap(in, throws="ClassNotFoundException") int both {
|
%typemap(in, throws="ClassNotFoundException") int both {
|
||||||
$1 = (int)$input;
|
$1 = (int)$input;
|
||||||
|
|
|
||||||
|
|
@ -2544,8 +2544,6 @@ public:
|
||||||
|
|
||||||
Printf(imcall, ")");
|
Printf(imcall, ")");
|
||||||
Printf(function_code, ")");
|
Printf(function_code, ")");
|
||||||
if (is_interface)
|
|
||||||
Printf(interface_class_code, ");\n");
|
|
||||||
|
|
||||||
// Transform return type used in JNI function (in intermediary class) to type used in Java wrapper function (in proxy class)
|
// Transform return type used in JNI function (in intermediary class) to type used in Java wrapper function (in proxy class)
|
||||||
if ((tm = Swig_typemap_lookup("javaout", n, "", 0))) {
|
if ((tm = Swig_typemap_lookup("javaout", n, "", 0))) {
|
||||||
|
|
@ -2603,6 +2601,11 @@ public:
|
||||||
Swig_warning(WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF, input_file, line_number, "No javaout typemap defined for %s\n", SwigType_str(t, 0));
|
Swig_warning(WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF, input_file, line_number, "No javaout typemap defined for %s\n", SwigType_str(t, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_interface) {
|
||||||
|
Printf(interface_class_code, ")");
|
||||||
|
generateThrowsClause(n, interface_class_code);
|
||||||
|
Printf(interface_class_code, ";\n");
|
||||||
|
}
|
||||||
generateThrowsClause(n, function_code);
|
generateThrowsClause(n, function_code);
|
||||||
Printf(function_code, " %s\n\n", tm ? (const String *) tm : empty_string);
|
Printf(function_code, " %s\n\n", tm ? (const String *) tm : empty_string);
|
||||||
Printv(proxy_class_code, function_code, NIL);
|
Printv(proxy_class_code, function_code, NIL);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue