2016-09-16 19:19:01 +02:00
|
|
|
// 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 java
|
|
|
|
|
|
|
|
import (
|
2017-01-01 22:43:46 +01:00
|
|
|
gopkg "Java/java"
|
2016-09-16 19:19:01 +02:00
|
|
|
"Java/java/io"
|
|
|
|
"Java/java/lang"
|
2017-01-01 19:55:42 +01:00
|
|
|
"Java/java/lang/System"
|
2016-12-26 20:47:09 +01:00
|
|
|
"Java/java/util/Spliterators"
|
2016-09-16 19:19:01 +02:00
|
|
|
"Java/java/util/concurrent"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Runnable struct {
|
|
|
|
lang.Runnable
|
|
|
|
}
|
|
|
|
|
bind,cmd,internal: generate reverse bindings for exported Go structs
Before this CL, the type of the implicit "this" parameter to Java methods
implemented in Go could only be a super class of the generated Java
class. For example, the following GoRunnable type is an implementation of
the Java interface java.lang.Runnable with a toString method:
package somepkg
import "Java/java/lang"
type GoRunnable struct {
lang.Runnable
}
func (r *GoRunnable) ToString(this lang.Runnable) string {
...
}
The "this" parameter is implicit in the sense that the reverse generator
automatically fills it with a reference to the Java instance of
GoRunnable.
Note that "this" has the type Java/java/lang.Runnable, not
Java/go/somepkg.GoRunnable, which renders it impossible to call Java
methods and functions that expect GoRunnable. The most practical example
of this is the Android databinding libraries.
This CL changes the implicit this parameter to always match the exact
type. In the example, the toString implementation becomes:
import gopkg "Java/go/somepkg"
func (r *GoRunnable) ToString(this gopkg.GoRunnable) string {
...
}
One strategy would be to simply treat the generated Java classes
(GoRunnable in our example) as any other Java class and import it
through javap. However, since the Java classes are generated after
importing, this present a chicken-and-egg problem.
Instead, use the newly added support for structs with embedded prefixed types
and synthesize class descriptors for every exported Go struct type.
Change-Id: Ic5ce4a151312bd89f91798ed4088c9959225b448
Reviewed-on: https://go-review.googlesource.com/34776
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-12-31 16:41:36 +01:00
|
|
|
func (r *Runnable) Run(this gopkg.Runnable) {
|
2016-09-16 19:19:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type InputStream struct {
|
|
|
|
io.InputStream
|
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *InputStream) Read() (int32, error) {
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewInputStream() *InputStream {
|
|
|
|
return new(InputStream)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Future struct {
|
|
|
|
concurrent.Future
|
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *Future) Get() lang.Object {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *Future) Get2(_ int64, _ concurrent.TimeUnit) lang.Object {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Object struct {
|
|
|
|
lang.Object
|
|
|
|
}
|
2016-12-26 20:47:09 +01:00
|
|
|
|
|
|
|
func innerClassTypes() {
|
|
|
|
// java.util.Spliterators.iterator use inner class types
|
|
|
|
// for the return value as well as parameters.
|
|
|
|
Spliterators.Iterator_Ljava_util_Spliterator_00024OfInt_2(nil)
|
|
|
|
}
|
2017-01-01 19:55:42 +01:00
|
|
|
|
|
|
|
func returnType() {
|
|
|
|
// Implicit types (java.io.Console) should be wrapped.
|
|
|
|
cons := System.Console()
|
|
|
|
cons.Flush()
|
|
|
|
}
|