Before this CL, generated Java classes or interfaces were inner classes to the top package class. That is both unnecessary and creates ugly class names. Instead, move every generated class and interface to its own package level class. NOTE: This is a backwards incompatible change and requires every client of gomobile APIs to be updated to leave out the package class in the type names. For example, the Go type package pkg type S struct { } now generates (with the default java package name go) a Java class named go.pkg.S. The name before this CL was go.pkg.Pkg.S. Also, change the custom java package to specify the package prefix and not the full package as before. This is an unfortunate change needed to avoid name clashes between two bound packages. On the plus side, the change brings the custom package case closer to the default behaviour, which is a commen prefix, "go.", and a distinct java package for every Go package bound. Change-Id: Iadfaad56e101d1caf7e2a05006f4d384859a20fe Reviewed-on: https://go-review.googlesource.com/27436 Reviewed-by: David Crawshaw <crawshaw@golang.org>
68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
// Copyright 2014 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package bind
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
)
|
|
|
|
type Printer struct {
|
|
Buf *bytes.Buffer
|
|
IndentEach []byte
|
|
indentText []byte
|
|
needIndent bool
|
|
}
|
|
|
|
func (p *Printer) writeIndent() error {
|
|
if !p.needIndent {
|
|
return nil
|
|
}
|
|
p.needIndent = false
|
|
_, err := p.Buf.Write(p.indentText)
|
|
return err
|
|
}
|
|
|
|
func (p *Printer) Write(b []byte) (n int, err error) {
|
|
wrote := 0
|
|
for len(b) > 0 {
|
|
if err := p.writeIndent(); err != nil {
|
|
return wrote, err
|
|
}
|
|
i := bytes.IndexByte(b, '\n')
|
|
if i < 0 {
|
|
break
|
|
}
|
|
n, err = p.Buf.Write(b[0 : i+1])
|
|
wrote += n
|
|
if err != nil {
|
|
return wrote, err
|
|
}
|
|
b = b[i+1:]
|
|
p.needIndent = true
|
|
}
|
|
if len(b) > 0 {
|
|
n, err = p.Buf.Write(b)
|
|
wrote += n
|
|
}
|
|
return wrote, err
|
|
}
|
|
|
|
func (p *Printer) Printf(format string, args ...interface{}) {
|
|
if _, err := fmt.Fprintf(p, format, args...); err != nil {
|
|
panic(fmt.Sprintf("printer: %v", err))
|
|
}
|
|
}
|
|
|
|
func (p *Printer) Indent() {
|
|
p.indentText = append(p.indentText, p.IndentEach...)
|
|
}
|
|
|
|
func (p *Printer) Outdent() {
|
|
if len(p.indentText) > len(p.IndentEach)-1 {
|
|
p.indentText = p.indentText[len(p.IndentEach):]
|
|
}
|
|
}
|