bind, bind/java: support generating exceptional constructors

In Go type constructors can often return an error type too
beside an instance of the type being created. This is useful
in cases where the parameters might be wrong and instantiaion
cannot succeed. This CL extends the Java generator so that
these methods are also converted into class constructors that
also can throw.

Change-Id: I5e531eec126904a026767a8503968255b9fd833b
Reviewed-on: https://go-review.googlesource.com/31184
Reviewed-by: Elias Naur <elias.naur@gmail.com>
This commit is contained in:
Péter Szilágyi
2016-10-17 14:21:52 +00:00
committed by Elias Naur
parent 4cb3e7f634
commit 2ea7e2cc92
4 changed files with 46 additions and 8 deletions
+18 -3
View File
@@ -530,12 +530,27 @@ public class SeqTest extends InstrumentationTestCase {
public void testConstructor() {
Interface i = new Concrete();
i.f();
S2 s = new S2(1, 2);
assertEquals("new S2().sum", 3.0, s.sum());
assertEquals("new S2().tryTwoStrings", "gostring", s.tryTwoStrings("go", "string"));
new S3();
S4 s4 = new S4(123);
assertEquals("Constructor argument", 123, s4.getI());
new S3();
S4 s4 = new S4(123);
assertEquals("Constructor argument", 123, s4.getI());
s4 = new S4(123.456);
assertEquals("Overloaded constructor argument", 123, s4.getI());
s4 = new S4(false);
assertEquals("Exceptional constructor", 0, s4.getI());
try {
s4 = new S4(true);
fail("Constructor error wasn't caught");
} catch (Exception e) {
}
}
public void testEmptyError() {