generate code for builder factory

This commit is contained in:
David Renshaw 2014-05-12 20:54:46 -04:00
parent ef068e7221
commit d3726d6118

View file

@ -1041,11 +1041,12 @@ private:
kj::StringTree makeReaderDef(kj::StringPtr fullName, kj::StringPtr unqualifiedParentType, kj::StringTree makeReaderDef(kj::StringPtr fullName, kj::StringPtr unqualifiedParentType,
bool isUnion, uint discriminantOffset, kj::Array<kj::StringTree>&& methodDecls, bool isUnion, uint discriminantOffset, kj::Array<kj::StringTree>&& methodDecls,
int indent) { int indent) {
return kj::strTree(spaces(indent), "public static final class Reader {\n", return kj::strTree(
spaces(indent), "public static final class Reader {\n",
spaces(indent), spaces(indent),
" public static class Factory implements org.capnproto.FromStructReader<Reader> {\n", " public static class Factory implements org.capnproto.FromStructReader<Reader> {\n",
spaces(indent), spaces(indent),
" public Reader fromStructReader(org.capnproto.StructReader reader) {\n", " public final Reader fromStructReader(org.capnproto.StructReader reader) {\n",
spaces(indent), " return new Reader(reader);\n", spaces(indent), " return new Reader(reader);\n",
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " }\n", spaces(indent), " }\n",
@ -1067,7 +1068,18 @@ private:
kj::StringTree makeBuilderDef(kj::StringPtr fullName, kj::StringPtr unqualifiedParentType, kj::StringTree makeBuilderDef(kj::StringPtr fullName, kj::StringPtr unqualifiedParentType,
bool isUnion, kj::Array<kj::StringTree>&& methodDecls, bool isUnion, kj::Array<kj::StringTree>&& methodDecls,
int indent) { int indent) {
return kj::strTree(spaces(indent), "public static final class Builder {\n", return kj::strTree(
spaces(indent), "public static final class Builder {\n",
spaces(indent), " public static class Factory implements org.capnproto.FromStructBuilder<Builder> {\n",
spaces(indent), " public final Builder fromStructBuilder(org.capnproto.StructBuilder builder) {\n",
spaces(indent), " return new Builder(builder);\n",
spaces(indent), " }\n",
spaces(indent), " public final org.capnproto.StructSize structSize() {\n",
spaces(indent), " throw new Error();\n",
spaces(indent), " }\n",
spaces(indent), " }\n",
spaces(indent), " public static final Factory factory = new Factory();\n",
spaces(indent), " public Builder(org.capnproto.StructBuilder base){ this._builder = base; }\n",
spaces(indent), " public org.capnproto.StructBuilder _builder;\n", spaces(indent), " public org.capnproto.StructBuilder _builder;\n",
spaces(indent), "}\n", spaces(indent), "}\n",
"\n"); "\n");