Fully qualify class names so that cross-package references work.

This commit is contained in:
David Renshaw 2015-12-07 15:34:21 -05:00
parent d3fdf4d17d
commit 037bebfb9c
3 changed files with 17 additions and 3 deletions

View file

@ -202,12 +202,17 @@ private:
auto node = schema.getProto(); auto node = schema.getProto();
if (node.getScopeId() == 0) { if (node.getScopeId() == 0) {
usedImports.insert(node.getId()); usedImports.insert(node.getId());
kj::String className;
kj::String package;
for (auto annotation: node.getAnnotations()) { for (auto annotation: node.getAnnotations()) {
if (annotation.getId() == OUTER_CLASSNAME_ANNOTATION_ID) { if (annotation.getId() == OUTER_CLASSNAME_ANNOTATION_ID) {
return kj::strTree("", toTitleCase(annotation.getValue().getText())); className = toTitleCase(annotation.getValue().getText());
}
if (annotation.getId() == PACKAGE_ANNOTATION_ID) {
package = kj::str(annotation.getValue().getText());
} }
} }
return kj::strTree(" ");//kj::strTree(outerClassName); return kj::strTree(kj::mv(package), ".", kj::mv(className));
} else { } else {
Schema parent = schemaLoader.get(node.getScopeId()); Schema parent = schemaLoader.get(node.getScopeId());
for (auto nested: parent.getProto().getNestedNodes()) { for (auto nested: parent.getProto().getNestedNodes()) {

View file

@ -600,6 +600,15 @@ class EncodingSuite extends FunSuite {
Serialize.computeSerializedSizeInWords(builder) should equal (4) Serialize.computeSerializedSizeInWords(builder) should equal (4)
} }
test("Import") {
val builder = new MessageBuilder()
val root = builder.initRoot(org.capnproto.testimport.TestImport.Foo.factory)
val field = root.initImportedStruct()
TestUtil.initTestMessage(field)
TestUtil.checkTestMessage(field)
TestUtil.checkTestMessage(field.asReader())
}
// to debug, do this: // to debug, do this:
//Serialize.write((new java.io.FileOutputStream("/Users/dwrensha/Desktop/test.dat")).getChannel(), //Serialize.write((new java.io.FileOutputStream("/Users/dwrensha/Desktop/test.dat")).getChannel(),
// message) // message)

View file

@ -65,7 +65,7 @@ object Build extends sbt.Build {
val compileTestSchema = taskKey[Unit]("Run capnpc-java on test schema") val compileTestSchema = taskKey[Unit]("Run capnpc-java on test schema")
val compileTestSchemaTask = compileTestSchema := { val compileTestSchemaTask = compileTestSchema := {
val result0 = "mkdir -p compiler/src/test/generated".!! val result0 = "mkdir -p compiler/src/test/generated".!!
val result = "capnp compile -I compiler/src/main/schema/ --src-prefix=compiler/src/test/schema/ -o./capnpc-java:compiler/src/test/generated compiler/src/test/schema/test.capnp".!! val result = "capnp compile -I compiler/src/main/schema/ --src-prefix=compiler/src/test/schema/ -o./capnpc-java:compiler/src/test/generated compiler/src/test/schema/test.capnp compiler/src/test/schema/test-import.capnp".!!
println(s"**** CodeGen for test.capnp started\n$result\n**** CodeGen complete."); println(s"**** CodeGen for test.capnp started\n$result\n**** CodeGen complete.");
} }