From 9d5f7955ffc8a54b340e8116cac6d87c3eec0940 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 27 Sep 2016 21:26:28 +0200 Subject: [PATCH] bind: correctly generate methods with implicit this and parameters Change-Id: I885a21876d9f639bc0996c9279fd0afefa93cef6 Reviewed-on: https://go-review.googlesource.com/29877 Reviewed-by: Hyang-Ah Hana Kim --- bind/genjava.go | 8 ++++---- bind/testpkg/javapkg/classes.go | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bind/genjava.go b/bind/genjava.go index c0b1569..589af2f 100644 --- a/bind/genjava.go +++ b/bind/genjava.go @@ -298,13 +298,13 @@ func (g *JavaGen) genConstructor(f *types.Func, n string) { func (g *JavaGen) genFuncArgs(f *types.Func, jm *java.Func) { sig := f.Type().(*types.Signature) params := sig.Params() - i := 0 + first := 0 if jm != nil { // Skip the implicit this argument to the Go method - i = params.Len() - len(jm.Params) + first = params.Len() - len(jm.Params) } - for ; i < params.Len(); i++ { - if i > 0 { + for i := first; i < params.Len(); i++ { + if i > first { g.Printf(", ") } v := params.At(i) diff --git a/bind/testpkg/javapkg/classes.go b/bind/testpkg/javapkg/classes.go index da18266..9915391 100644 --- a/bind/testpkg/javapkg/classes.go +++ b/bind/testpkg/javapkg/classes.go @@ -149,3 +149,11 @@ func NewJavaInteger() lang.Integer { type NoargConstructor struct { util.BitSet // An otherwise unused class with a no-arg constructor } + +type GoRand struct { + util.Random +} + +func (_ *GoRand) Next(this util.Random, i int32) int32 { + return this.Super().Next(i) +}