| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Go Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style | |
| 3 // license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Package bind implements a code generator for gobind. | |
| 6 // | |
| 7 // See the documentation on the gobind command for usage details. | |
| 8 package bind // import "golang.org/x/mobile/bind" | |
| 9 | |
| 10 // TODO(crawshaw): slice support | |
| 11 // TODO(crawshaw): channel support | |
| 12 | |
| 13 import ( | |
| 14 "bytes" | |
| 15 "go/format" | |
| 16 "go/token" | |
| 17 "io" | |
| 18 | |
| 19 "golang.org/x/tools/go/types" | |
| 20 ) | |
| 21 | |
| 22 // GenJava generates a Java API from a Go package. | |
| 23 func GenJava(w io.Writer, fset *token.FileSet, pkg *types.Package) error { | |
| 24 buf := new(bytes.Buffer) | |
| 25 g := &javaGen{ | |
| 26 printer: &printer{buf: buf, indentEach: []byte(" ")}, | |
| 27 fset: fset, | |
| 28 pkg: pkg, | |
| 29 } | |
| 30 if err := g.gen(); err != nil { | |
| 31 return err | |
| 32 } | |
| 33 _, err := io.Copy(w, buf) | |
| 34 return err | |
| 35 } | |
| 36 | |
| 37 // GenGo generates a Go stub to support foreign language APIs. | |
| 38 func GenGo(w io.Writer, fset *token.FileSet, pkg *types.Package) error { | |
| 39 buf := new(bytes.Buffer) | |
| 40 g := &goGen{ | |
| 41 printer: &printer{buf: buf, indentEach: []byte("\t")}, | |
| 42 fset: fset, | |
| 43 pkg: pkg, | |
| 44 } | |
| 45 if err := g.gen(); err != nil { | |
| 46 return err | |
| 47 } | |
| 48 src := buf.Bytes() | |
| 49 srcf, err := format.Source(src) | |
| 50 if err != nil { | |
| 51 w.Write(src) // for debugging | |
| 52 return err | |
| 53 } | |
| 54 _, err = w.Write(srcf) | |
| 55 return err | |
| 56 } | |
| OLD | NEW |