Add support for %nspace when using directors - Java
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12891 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
cd51908860
commit
debd5e9246
6 changed files with 137 additions and 7 deletions
|
|
@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
|
|||
Version 2.0.5 (in progress)
|
||||
===========================
|
||||
|
||||
2012-01-06: wsfulton
|
||||
[Java] Patch #3452560 from Brant Kyser - add support for %nspace when using directors.
|
||||
|
||||
2011-12-21: wsfulton
|
||||
The 'directorin' typemap now accepts $1, $2 etc expansions instead of having to use workarounds -
|
||||
$1_name, $2_name etc.
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@ CPP_TEST_CASES += \
|
|||
director_ignore \
|
||||
director_keywords \
|
||||
director_namespace_clash \
|
||||
director_nspace \
|
||||
director_nested \
|
||||
director_overload \
|
||||
director_primitives \
|
||||
|
|
|
|||
68
Examples/test-suite/director_nspace.i
Normal file
68
Examples/test-suite/director_nspace.i
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
%module(directors="1") director_nspace
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
||||
SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
|
||||
#endif
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
||||
namespace Bar
|
||||
{
|
||||
class FooBar {
|
||||
public:
|
||||
FooBar() {}
|
||||
FooBar(const FooBar&) {}
|
||||
virtual ~FooBar() {}
|
||||
|
||||
std::string FooBarDo() { return "Bar::Foo2::Foo2Bar()"; }
|
||||
};
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() { return "Bar::Foo::ping()"; }
|
||||
virtual std::string pong() { return "Bar::Foo::pong();" + ping(); }
|
||||
virtual std::string fooBar(FooBar* fooBar) { return fooBar->FooBarDo(); }
|
||||
virtual Foo makeFoo() { return Foo(); }
|
||||
virtual FooBar makeFooBar() { return FooBar(); }
|
||||
|
||||
static Foo* get_self(Foo *self) {return self;}
|
||||
};
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
%nspace Bar::Foo;
|
||||
%nspace Bar::FooBar;
|
||||
|
||||
%feature("director") Bar::Foo;
|
||||
|
||||
namespace Bar
|
||||
{
|
||||
class FooBar {
|
||||
public:
|
||||
FooBar();
|
||||
FooBar(const FooBar&);
|
||||
virtual ~FooBar();
|
||||
|
||||
std::string FooBarDo();
|
||||
|
||||
};
|
||||
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
virtual ~Foo();
|
||||
virtual std::string ping();
|
||||
virtual std::string pong();
|
||||
virtual std::string fooBar(FooBar* fooBar);
|
||||
virtual Foo makeFoo();
|
||||
virtual FooBar makeFooBar();
|
||||
|
||||
static Foo* get_self(Foo *self);
|
||||
};
|
||||
}
|
||||
|
|
@ -43,6 +43,7 @@ SWIGOPT += -package $(JAVA_PACKAGE)
|
|||
# Custom tests - tests with additional commandline options
|
||||
nspace.%: JAVA_PACKAGE = $*Package
|
||||
nspace_extend.%: JAVA_PACKAGE = $*Package
|
||||
director_nspace.%: JAVA_PACKAGE = $*Package
|
||||
|
||||
# Rules for the different types of tests
|
||||
%.cpptest:
|
||||
|
|
|
|||
48
Examples/test-suite/java/director_nspace_runme.java
Normal file
48
Examples/test-suite/java/director_nspace_runme.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// Make sure that directors are connected and disconnected when used inconjunction with
|
||||
// the %nspace feature
|
||||
|
||||
public class director_nspace_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("director_nspace");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
director_nspace_MyBarFoo myBarFoo =
|
||||
new director_nspace_MyBarFoo();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class director_nspace_MyBarFoo extends director_nspacePackage.Bar.Foo {
|
||||
|
||||
@Override
|
||||
public String ping() {
|
||||
return "director_nspace_MyBarFoo.ping();";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pong() {
|
||||
return "director_nspace_MyBarFoo.pong();" + ping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fooBar(director_nspacePackage.Bar.FooBar fooBar) {
|
||||
return fooBar.FooBarDo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public director_nspacePackage.Bar.Foo makeFoo() {
|
||||
return new director_nspacePackage.Bar.Foo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public director_nspacePackage.Bar.FooBar makeFooBar() {
|
||||
return new director_nspacePackage.Bar.FooBar();
|
||||
}
|
||||
}
|
||||
|
|
@ -3483,21 +3483,21 @@ public:
|
|||
String *pkg_path = Swig_typemap_lookup("javapackage", p, "", 0);
|
||||
SwigType *type = Getattr(p, "type");
|
||||
|
||||
if (pkg_path && Len(pkg_path) != 0) {
|
||||
Replaceall(pkg_path, ".", "/");
|
||||
} else
|
||||
if (pkg_path || Len(pkg_path) == 0)
|
||||
pkg_path = package_path;
|
||||
|
||||
String *descriptor_out = Copy(descriptor_in);
|
||||
|
||||
if (Len(pkg_path) > 0) {
|
||||
substituteClassname(type, descriptor_out, true);
|
||||
|
||||
if (Len(pkg_path) > 0 && Strchr(descriptor_out, '.') == NULL) {
|
||||
Replaceall(descriptor_out, "$packagepath", pkg_path);
|
||||
} else {
|
||||
Replaceall(descriptor_out, "$packagepath/", empty_string);
|
||||
Replaceall(descriptor_out, "$packagepath", empty_string);
|
||||
}
|
||||
|
||||
substituteClassname(type, descriptor_out, true);
|
||||
Replaceall(descriptor_out, ".", "/");
|
||||
|
||||
if (pkg_path != package_path)
|
||||
Delete(pkg_path);
|
||||
|
|
@ -3550,6 +3550,11 @@ public:
|
|||
String *imcall_args = NewString("");
|
||||
int classmeth_off = curr_class_dmethod - first_class_dmethod;
|
||||
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
|
||||
String *qualified_classname = Copy(classname);
|
||||
String *nspace = getNSpace();
|
||||
|
||||
if (nspace)
|
||||
Insert(qualified_classname, 0, NewStringf("%s.%s.", package, nspace));
|
||||
|
||||
// Kludge Alert: functionWrapper sets sym:overload properly, but it
|
||||
// isn't at this point, so we have to manufacture it ourselves. At least
|
||||
|
|
@ -3614,7 +3619,7 @@ public:
|
|||
|
||||
tm = Swig_typemap_lookup("jtype", tp, "", 0);
|
||||
if (tm) {
|
||||
Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, classname);
|
||||
Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, qualified_classname);
|
||||
} else {
|
||||
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0));
|
||||
}
|
||||
|
|
@ -3680,6 +3685,7 @@ public:
|
|||
|
||||
Delete(adjustedreturntypeparm);
|
||||
Delete(retpm);
|
||||
Delete(qualified_classname);
|
||||
}
|
||||
|
||||
Swig_director_parms_fixup(l);
|
||||
|
|
@ -4259,7 +4265,10 @@ public:
|
|||
Wrapper *w = NewWrapper();
|
||||
|
||||
if (Len(package_path) > 0)
|
||||
internal_classname = NewStringf("%s/%s", package_path, classname);
|
||||
if (Len(getNSpace()) > 0)
|
||||
internal_classname = NewStringf("%s/%s/%s", package_path, getNSpace(), classname);
|
||||
else
|
||||
internal_classname = NewStringf("%s/%s", package_path, classname);
|
||||
else
|
||||
internal_classname = NewStringf("%s", classname);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue