bind,bind/testdata: skip conflicting Java constructors
Our Java proxy class defines a constructor which takes a single int that is the reference number of the Go peer. However, in Go, constructors of the form NewT(i int32) *T generate the same signature as the internal constructor. The longer fix is to avoid using a constructor for initializing proxies. This CL simply skips clashing Go constructors. Reported in https://groups.google.com/forum/#!topic/golang-nuts/EKC_gEjaQH4 Change-Id: I1153f71d8b5a757c499b3ce6e18e2ea5d22dc9e5 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/167660 Run-TryBot: Elias Naur <mail@eliasnaur.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Родитель
cde3d952bc
Коммит
6bd122906c
|
@ -294,7 +294,7 @@ func (g *JavaGen) genStruct(s structInfo) {
|
|||
g.genProxyImpl(n)
|
||||
cons := g.constructors[s.obj]
|
||||
for _, f := range cons {
|
||||
if !g.isSigSupported(f.Type()) {
|
||||
if !g.isConsSigSupported(f.Type()) {
|
||||
g.Printf("// skipped constructor %s.%s with unsupported parameter or return types\n\n", n, f.Name())
|
||||
continue
|
||||
}
|
||||
|
@ -354,6 +354,28 @@ func (g *JavaGen) genStruct(s structInfo) {
|
|||
g.Printf("}\n\n")
|
||||
}
|
||||
|
||||
// isConsSigSupported reports whether the generators can handle a given
|
||||
// constructor signature.
|
||||
func (g *JavaGen) isConsSigSupported(t types.Type) bool {
|
||||
if !g.isSigSupported(t) {
|
||||
return false
|
||||
}
|
||||
// Skip constructors taking a single int32 argument
|
||||
// since they clash with the proxy constructors that
|
||||
// take a refnum.
|
||||
params := t.(*types.Signature).Params()
|
||||
if params.Len() != 1 {
|
||||
return true
|
||||
}
|
||||
if t, ok := params.At(0).Type().(*types.Basic); ok {
|
||||
switch t.Kind() {
|
||||
case types.Int32, types.Uint32:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// javaTypeName returns the class name of a given Go type name. If
|
||||
// the type name clashes with the package class name, an underscore is
|
||||
// appended.
|
||||
|
@ -1112,7 +1134,7 @@ func (g *JavaGen) genJNIVar(o *types.Var) {
|
|||
}
|
||||
|
||||
func (g *JavaGen) genJNIConstructor(f *types.Func, sName string) {
|
||||
if !g.isSigSupported(f.Type()) {
|
||||
if !g.isConsSigSupported(f.Type()) {
|
||||
return
|
||||
}
|
||||
sig := f.Type().(*types.Signature)
|
||||
|
|
|
@ -618,3 +618,11 @@ type MyStruct struct {
|
|||
func NewMyStruct(ctx context.Context) *MyStruct {
|
||||
return nil
|
||||
}
|
||||
|
||||
type Int32Constructed struct{}
|
||||
|
||||
// Test that constuctors that clash with the internal proxy constructor
|
||||
// are skipped.
|
||||
func NewInt32Constructed(i int32) *Int32Constructed {
|
||||
return nil
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче