| 1566 | } |
| 1567 | |
| 1568 | func (g *JavaGen) GenJava() error { |
| 1569 | pkgPath := "" |
| 1570 | if g.Pkg != nil { |
| 1571 | pkgPath = g.Pkg.Path() |
| 1572 | } |
| 1573 | g.Printf(javaPreamble, g.javaPkgName(g.Pkg), g.className(), g.gobindOpts(), pkgPath) |
| 1574 | |
| 1575 | g.Printf("public abstract class %s {\n", g.className()) |
| 1576 | g.Indent() |
| 1577 | g.Printf("static {\n") |
| 1578 | g.Indent() |
| 1579 | g.Printf("Seq.touch(); // for loading the native library\n") |
| 1580 | if g.Pkg != nil { |
| 1581 | for _, p := range g.Pkg.Imports() { |
| 1582 | if g.validPkg(p) { |
| 1583 | g.Printf("%s.%s.touch();\n", g.javaPkgName(p), JavaClassName(p)) |
| 1584 | } |
| 1585 | } |
| 1586 | } |
| 1587 | g.Printf("_init();\n") |
| 1588 | g.Outdent() |
| 1589 | g.Printf("}\n\n") |
| 1590 | g.Printf("private %s() {} // uninstantiable\n\n", g.className()) |
| 1591 | g.Printf("// touch is called from other bound packages to initialize this package\n") |
| 1592 | g.Printf("public static void touch() {}\n\n") |
| 1593 | g.Printf("private static native void _init();\n\n") |
| 1594 | |
| 1595 | for _, iface := range g.interfaces { |
| 1596 | n := iface.obj.Name() |
| 1597 | g.Printf("private static final class proxy%s", n) |
| 1598 | if isErrorType(iface.obj.Type()) { |
| 1599 | g.Printf(" extends Exception") |
| 1600 | } |
| 1601 | g.Printf(" implements Seq.Proxy, %s {\n", g.javaTypeName(n)) |
| 1602 | g.Indent() |
| 1603 | g.genProxyImpl("proxy" + n) |
| 1604 | g.Printf("proxy%s(int refnum) { this.refnum = refnum; Seq.trackGoRef(refnum, this); }\n\n", n) |
| 1605 | |
| 1606 | if isErrorType(iface.obj.Type()) { |
| 1607 | g.Printf("@Override public String getMessage() { return error(); }\n\n") |
| 1608 | } |
| 1609 | for _, m := range iface.summary.callable { |
| 1610 | if !g.isSigSupported(m.Type()) { |
| 1611 | g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", n, m.Name()) |
| 1612 | continue |
| 1613 | } |
| 1614 | g.Printf("public native ") |
| 1615 | g.genFuncSignature(m, nil, false) |
| 1616 | } |
| 1617 | |
| 1618 | g.Outdent() |
| 1619 | g.Printf("}\n") |
| 1620 | } |
| 1621 | |
| 1622 | g.Printf("\n") |
| 1623 | |
| 1624 | for _, c := range g.constants { |
| 1625 | g.genConst(c) |