diff --git a/bind/genjava.go b/bind/genjava.go index 87ab0a5..db64c64 100644 --- a/bind/genjava.go +++ b/bind/genjava.go @@ -964,10 +964,17 @@ func (g *javaGen) genJava() error { g.Printf("static {\n") g.Indent() g.Printf("Seq.touch(); // for loading the native library\n") + for _, p := range g.pkg.Imports() { + if g.validPkg(p) { + g.Printf("%s.%s.touch();\n", g.javaPkgName(p), className(p)) + } + } g.Printf("init();\n") g.Outdent() g.Printf("}\n\n") g.Printf("private %s() {} // uninstantiable\n\n", g.className()) + g.Printf("// touch is called from other bound packages to initialize this package\n") + g.Printf("public static void touch() {}\n\n") g.Printf("private static native void init();\n\n") for _, s := range g.structs { diff --git a/bind/java/SeqTest.java b/bind/java/SeqTest.java index 1647508..824b2ab 100644 --- a/bind/java/SeqTest.java +++ b/bind/java/SeqTest.java @@ -475,6 +475,11 @@ public class SeqTest extends InstrumentationTestCase { } public void testImportedPkg() { + Testpkg.CallImportedI(new Secondpkg.I.Stub() { + @Override public long F(long i) { + return i; + } + }); assertEquals("imported string should match", Secondpkg.HelloString, Secondpkg.Hello()); Secondpkg.I i = Testpkg.NewImportedI(); Secondpkg.S s = Testpkg.NewImportedS(); diff --git a/bind/testdata/basictypes.java.golden b/bind/testdata/basictypes.java.golden index 489d5fe..887acca 100644 --- a/bind/testdata/basictypes.java.golden +++ b/bind/testdata/basictypes.java.golden @@ -14,6 +14,9 @@ public abstract class Basictypes { private Basictypes() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); public static final boolean ABool = true; diff --git a/bind/testdata/customprefix.java.golden b/bind/testdata/customprefix.java.golden index 7a770b3..04693ed 100644 --- a/bind/testdata/customprefix.java.golden +++ b/bind/testdata/customprefix.java.golden @@ -14,6 +14,9 @@ public abstract class Customprefix { private Customprefix() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); diff --git a/bind/testdata/interfaces.java.golden b/bind/testdata/interfaces.java.golden index 982ebaf..9e9b338 100644 --- a/bind/testdata/interfaces.java.golden +++ b/bind/testdata/interfaces.java.golden @@ -14,6 +14,9 @@ public abstract class Interfaces { private Interfaces() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); public interface Error extends go.Seq.Object { diff --git a/bind/testdata/issue10788.java.golden b/bind/testdata/issue10788.java.golden index 0111b4c..cf73bd5 100644 --- a/bind/testdata/issue10788.java.golden +++ b/bind/testdata/issue10788.java.golden @@ -14,6 +14,9 @@ public abstract class Issue10788 { private Issue10788() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); public static final class TestStruct implements go.Seq.Object { diff --git a/bind/testdata/issue12328.java.golden b/bind/testdata/issue12328.java.golden index a2492aa..7af1892 100644 --- a/bind/testdata/issue12328.java.golden +++ b/bind/testdata/issue12328.java.golden @@ -14,6 +14,9 @@ public abstract class Issue12328 { private Issue12328() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); public static final class T implements go.Seq.Object { diff --git a/bind/testdata/issue12403.java.golden b/bind/testdata/issue12403.java.golden index 8359c4c..90c074b 100644 --- a/bind/testdata/issue12403.java.golden +++ b/bind/testdata/issue12403.java.golden @@ -14,6 +14,9 @@ public abstract class Issue12403 { private Issue12403() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); public interface Parsable extends go.Seq.Object { diff --git a/bind/testdata/structs.java.golden b/bind/testdata/structs.java.golden index 377437e..17ade9a 100644 --- a/bind/testdata/structs.java.golden +++ b/bind/testdata/structs.java.golden @@ -14,6 +14,9 @@ public abstract class Structs { private Structs() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); public static final class S implements go.Seq.Object { diff --git a/bind/testdata/try.java.golden b/bind/testdata/try.java.golden index 0aa6946..2b0514f 100644 --- a/bind/testdata/try.java.golden +++ b/bind/testdata/try.java.golden @@ -14,6 +14,9 @@ public abstract class Try { private Try() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); diff --git a/bind/testdata/vars.java.golden b/bind/testdata/vars.java.golden index 8a6b8fe..f232b6e 100644 --- a/bind/testdata/vars.java.golden +++ b/bind/testdata/vars.java.golden @@ -14,6 +14,9 @@ public abstract class Vars { private Vars() {} // uninstantiable + // touch is called from other bound packages to initialize this package + public static void touch() {} + private static native void init(); public static final class S implements go.Seq.Object, I { diff --git a/bind/testpkg/testpkg.go b/bind/testpkg/testpkg.go index 0c6c4d4..17f09cf 100644 --- a/bind/testpkg/testpkg.go +++ b/bind/testpkg/testpkg.go @@ -454,6 +454,10 @@ func WithImportedS(s *secondpkg.S) *secondpkg.S { return s } +func CallImportedI(i secondpkg.I) { + i.F(0) +} + func NewSimpleS() *simplepkg.S { return nil }