From ea641a673675b469e8d2dc4aef4e0a05c26ef4f4 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Wed, 28 May 2014 19:17:27 -0400 Subject: [PATCH] Void is an actual value --- compiler/src/main/cpp/capnpc-java.c++ | 31 +++++++------------ .../capnproto/examples/AddressbookMain.java | 2 +- runtime/src/main/java/org/capnproto/Void.java | 5 +++ 3 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 runtime/src/main/java/org/capnproto/Void.java diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index 281ffe0..a109e58 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -245,7 +245,7 @@ private: kj::StringTree typeName(schema::Type::Reader type) { switch (type.which()) { - case schema::Type::VOID: return kj::strTree("void"); + case schema::Type::VOID: return kj::strTree("org.capnproto.Void"); case schema::Type::BOOL: return kj::strTree("boolean"); case schema::Type::INT8: return kj::strTree("byte"); @@ -802,7 +802,7 @@ private: (typeBody.which() == schema::Type::ENUM ? kj::strTree(" return ", type, ".values()[_reader.getShortField(", offset, ")];\n") : (typeBody.which() == schema::Type::VOID ? - kj::strTree(" // nothing to return\n") : + kj::strTree(" return org.capnproto.Void.VOID;\n") : kj::strTree(" return _reader.get",toTitleCase(type),"Field(", offset, ");\n"))), spaces(indent), " }\n", "\n"), @@ -814,26 +814,19 @@ private: (typeBody.which() == schema::Type::ENUM ? kj::strTree(" return ", type, ".values()[_builder.getShortField(", offset, ")];\n") : (typeBody.which() == schema::Type::VOID ? - kj::strTree(" // nothing to return\n") : + kj::strTree(" return org.capnproto.Void.VOID;\n") : kj::strTree(" return _builder.get",toTitleCase(type),"Field(", offset, ");\n"))), spaces(indent), " }\n", - (typeBody.which() == schema::Type::VOID ? - kj::strTree(spaces(indent), " public final void set", titleCase, "() {\n", - unionDiscrim.set, - spaces(indent), " }\n") : - (typeBody.which() == schema::Type::ENUM ? - kj::strTree( - spaces(indent), " public final void set", titleCase, "(", type, " value) {\n", - unionDiscrim.set, - spaces(indent), " _builder.setShortField(", offset, ", (short)value.ordinal());\n", - spaces(indent), " }\n") : - kj::strTree( - spaces(indent), " public final void set", titleCase, "(", type, " value) {\n", - unionDiscrim.set, - spaces(indent), " _builder.set", toTitleCase(type), - "Field(", offset, ", value);\n", - spaces(indent), " }\n"))), + spaces(indent), " public final void set", titleCase, "(", type, " value) {\n", + unionDiscrim.set, + (typeBody.which() == schema::Type::ENUM ? + kj::strTree(spaces(indent), " _builder.setShortField(", offset, ", (short)value.ordinal());\n") : + (typeBody.which() == schema::Type::VOID ? + kj::strTree() : + kj::strTree(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 408d021..225e596 100644 --- a/examples/src/main/java/org/capnproto/examples/AddressbookMain.java +++ b/examples/src/main/java/org/capnproto/examples/AddressbookMain.java @@ -40,7 +40,7 @@ public class AddressbookMain { 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(); + bob.getEmployment().setUnemployed(org.capnproto.Void.VOID); Serialize.writeMessage((new FileOutputStream(FileDescriptor.out)).getChannel(), message); diff --git a/runtime/src/main/java/org/capnproto/Void.java b/runtime/src/main/java/org/capnproto/Void.java new file mode 100644 index 0000000..54fc269 --- /dev/null +++ b/runtime/src/main/java/org/capnproto/Void.java @@ -0,0 +1,5 @@ +package org.capnproto; + +public enum Void { + VOID +}