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,36 +1041,48 @@ 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), spaces(indent), "public static final class Reader {\n",
" public static class Factory implements org.capnproto.FromStructReader<Reader> {\n", spaces(indent),
spaces(indent), " public static class Factory implements org.capnproto.FromStructReader<Reader> {\n",
" public Reader fromStructReader(org.capnproto.StructReader reader) {\n", spaces(indent),
spaces(indent), " return new Reader(reader);\n", " public final Reader fromStructReader(org.capnproto.StructReader reader) {\n",
spaces(indent), " }\n", spaces(indent), " return new Reader(reader);\n",
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " public static final Factory factory = new Factory();\n", spaces(indent), " }\n",
spaces(indent), " public Reader(org.capnproto.StructReader base){ this._reader = base; }\n", spaces(indent), " public static final Factory factory = new Factory();\n",
"\n", spaces(indent), " public Reader(org.capnproto.StructReader base){ this._reader = base; }\n",
(isUnion ? "\n",
kj::strTree(spaces(indent), " public Which which() {\n", (isUnion ?
spaces(indent), " return Which.values()[_reader.getShortField(", kj::strTree(spaces(indent), " public Which which() {\n",
discriminantOffset, ")];\n", spaces(indent), " return Which.values()[_reader.getShortField(",
spaces(indent), " }\n") discriminantOffset, ")];\n",
: kj::strTree()), spaces(indent), " }\n")
kj::mv(methodDecls), : kj::strTree()),
spaces(indent), " public org.capnproto.StructReader _reader;\n", kj::mv(methodDecls),
spaces(indent), "}\n" spaces(indent), " public org.capnproto.StructReader _reader;\n",
"\n"); spaces(indent), "}\n"
"\n");
} }
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 org.capnproto.StructBuilder _builder;\n", spaces(indent), "public static final class Builder {\n",
spaces(indent), "}\n", spaces(indent), " public static class Factory implements org.capnproto.FromStructBuilder<Builder> {\n",
"\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), "}\n",
"\n");
} }
StructText makeStructText(kj::StringPtr scope, kj::StringPtr name, StructSchema schema, StructText makeStructText(kj::StringPtr scope, kj::StringPtr name, StructSchema schema,