2
0
mirror of synced 2025-02-23 14:58:12 +00:00

mobile/bind: initialize imported bound packages

Make sure that a bound package's imported and also bound packages
are initialized before referencing methods and constructors in the
imported packages.

Change-Id: If158aac83c245a33695d3b1648d0dfc37a7313ac
Reviewed-on: https://go-review.googlesource.com/20652
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Elias Naur 2016-03-13 18:28:54 +01:00
parent 462ddb163e
commit d841a034b5
12 changed files with 43 additions and 0 deletions

View File

@ -964,10 +964,17 @@ func (g *javaGen) genJava() error {
g.Printf("static {\n") g.Printf("static {\n")
g.Indent() g.Indent()
g.Printf("Seq.touch(); // for loading the native library\n") 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.Printf("init();\n")
g.Outdent() g.Outdent()
g.Printf("}\n\n") g.Printf("}\n\n")
g.Printf("private %s() {} // uninstantiable\n\n", g.className()) 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") g.Printf("private static native void init();\n\n")
for _, s := range g.structs { for _, s := range g.structs {

View File

@ -475,6 +475,11 @@ public class SeqTest extends InstrumentationTestCase {
} }
public void testImportedPkg() { 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()); assertEquals("imported string should match", Secondpkg.HelloString, Secondpkg.Hello());
Secondpkg.I i = Testpkg.NewImportedI(); Secondpkg.I i = Testpkg.NewImportedI();
Secondpkg.S s = Testpkg.NewImportedS(); Secondpkg.S s = Testpkg.NewImportedS();

View File

@ -14,6 +14,9 @@ public abstract class Basictypes {
private Basictypes() {} // uninstantiable private Basictypes() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();
public static final boolean ABool = true; public static final boolean ABool = true;

View File

@ -14,6 +14,9 @@ public abstract class Customprefix {
private Customprefix() {} // uninstantiable private Customprefix() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();

View File

@ -14,6 +14,9 @@ public abstract class Interfaces {
private Interfaces() {} // uninstantiable private Interfaces() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();
public interface Error extends go.Seq.Object { public interface Error extends go.Seq.Object {

View File

@ -14,6 +14,9 @@ public abstract class Issue10788 {
private Issue10788() {} // uninstantiable private Issue10788() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();
public static final class TestStruct implements go.Seq.Object { public static final class TestStruct implements go.Seq.Object {

View File

@ -14,6 +14,9 @@ public abstract class Issue12328 {
private Issue12328() {} // uninstantiable private Issue12328() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();
public static final class T implements go.Seq.Object { public static final class T implements go.Seq.Object {

View File

@ -14,6 +14,9 @@ public abstract class Issue12403 {
private Issue12403() {} // uninstantiable private Issue12403() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();
public interface Parsable extends go.Seq.Object { public interface Parsable extends go.Seq.Object {

View File

@ -14,6 +14,9 @@ public abstract class Structs {
private Structs() {} // uninstantiable private Structs() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();
public static final class S implements go.Seq.Object { public static final class S implements go.Seq.Object {

View File

@ -14,6 +14,9 @@ public abstract class Try {
private Try() {} // uninstantiable private Try() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();

View File

@ -14,6 +14,9 @@ public abstract class Vars {
private Vars() {} // uninstantiable private Vars() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init(); private static native void init();
public static final class S implements go.Seq.Object, I { public static final class S implements go.Seq.Object, I {

View File

@ -454,6 +454,10 @@ func WithImportedS(s *secondpkg.S) *secondpkg.S {
return s return s
} }
func CallImportedI(i secondpkg.I) {
i.F(0)
}
func NewSimpleS() *simplepkg.S { func NewSimpleS() *simplepkg.S {
return nil return nil
} }