MCPcopy Create free account
hub / github.com/golang/mobile / lookupMethod

Method lookupMethod

bind/genjava.go:146–198  ·  view source on GitHub ↗

lookupMethod searches the Java class descriptor for a method that matches the Go method.

(m *types.Func, hasThis bool)

Source from the content-addressed store, hash-verified

144// lookupMethod searches the Java class descriptor for a method
145// that matches the Go method.
146func (j *javaClassInfo) lookupMethod(m *types.Func, hasThis bool) *java.Func {
147 jm := j.methods[m.Name()]
148 if jm == nil {
149 // If an exact match is not found, try the method with trailing underscores
150 // stripped. This way, name clashes can be avoided when overriding multiple
151 // overloaded methods from Go.
152 base := strings.TrimRight(m.Name(), "_")
153 jm = j.methods[base]
154 if jm == nil {
155 return nil
156 }
157 }
158 // A name match was found. Now use the parameter and return types to locate
159 // the correct variant.
160 sig := m.Type().(*types.Signature)
161 params := sig.Params()
162 // Convert Go parameter types to their Java counterparts, if possible.
163 var jparams []*java.Type
164 i := 0
165 if hasThis {
166 i = 1
167 }
168 for ; i < params.Len(); i++ {
169 jparams = append(jparams, j.toJavaType(params.At(i).Type()))
170 }
171 var ret *java.Type
172 var throws bool
173 if results := sig.Results(); results.Len() > 0 {
174 ret = j.toJavaType(results.At(0).Type())
175 if results.Len() > 1 {
176 throws = isErrorType(results.At(1).Type())
177 }
178 }
179loop:
180 for _, f := range jm.Funcs {
181 if len(f.Params) != len(jparams) {
182 continue
183 }
184 if throws != (f.Throws != "") {
185 continue
186 }
187 if !reflect.DeepEqual(ret, f.Ret) {
188 continue
189 }
190 for i, p := range f.Params {
191 if !reflect.DeepEqual(p, jparams[i]) {
192 continue loop
193 }
194 }
195 return f
196 }
197 return nil
198}
199
200// ClassNames returns the list of names of the generated Java classes and interfaces.
201func (g *JavaGen) ClassNames() []string {

Callers 2

genStructMethod · 0.80
GenCMethod · 0.80

Calls 4

toJavaTypeMethod · 0.95
isErrorTypeFunction · 0.85
TypeMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected