diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index 31f7b99..67e20d1 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -796,7 +796,18 @@ private: kj::strTree(" return _builder.get",toTitleCase(type),"Field(", offset, ");\n"))), spaces(indent), " }\n", - //spaces(indent), " public final void set", titleCase, "(", type, " value", setterDefault, ");\n", + (typeBody.which() == schema::Type::VOID ? + kj::strTree(spaces(indent), " public final void set", titleCase, "() {}\n") : + (typeBody.which() == schema::Type::ENUM ? + kj::strTree( + spaces(indent), " public final void set", titleCase, "(", type, " value) {\n", + spaces(indent), " _builder.setShortField(", offset, ", (short)value.ordinal());\n", + spaces(indent), " }\n") : + kj::strTree( + spaces(indent), " public final void set", titleCase, "(", type, " value) {\n", + spaces(indent), " _builder.set", toTitleCase(type), + "Field(", offset, ", value);\n", + spaces(indent), " }\n"))), "\n"), kj::strTree(), diff --git a/examples/src/main/java/org/capnproto/examples/AddressbookMain.java b/examples/src/main/java/org/capnproto/examples/AddressbookMain.java index 6ac37c3..13bb43f 100644 --- a/examples/src/main/java/org/capnproto/examples/AddressbookMain.java +++ b/examples/src/main/java/org/capnproto/examples/AddressbookMain.java @@ -4,6 +4,7 @@ import org.capnproto.MessageBuilder; import org.capnproto.MessageReader; import org.capnproto.StructList; import org.capnproto.InputStreamMessageReader; +import org.capnproto.Text; import org.capnproto.examples.Addressbook.*; @@ -16,7 +17,25 @@ public class AddressbookMain { StructList.Builder people = addressbook.initPeople(2); Person.Builder alice = people.get(0); - //alice.setId(123); + alice.setId(123); + alice.setName(new Text.Reader("Alice")); + alice.setEmail(new Text.Reader("alice@example.com")); + + StructList.Builder alicePhones = alice.initPhones(1); + alicePhones.get(0).setNumber(new Text.Reader("555-1212")); + alicePhones.get(0).setType(Person.PhoneNumber.Type.MOBILE); + alice.getEmployment().setSchool(new Text.Reader("MIT")); + + Person.Builder bob = people.get(0); + bob.setId(456); + bob.setName(new Text.Reader("Bob")); + bob.setEmail(new Text.Reader("bob@example.com")); + StructList.Builder bobPhones = bob.initPhones(2); + bobPhones.get(0).setNumber(new Text.Reader("555-4567")); + bobPhones.get(0).setType(Person.PhoneNumber.Type.HOME); + bobPhones.get(1).setNumber(new Text.Reader("555-7654")); + bobPhones.get(1).setType(Person.PhoneNumber.Type.WORK); + bob.getEmployment().setUnemployed(); } public static void printAddressBook() throws java.io.IOException {