diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index 4997e03..d12a536 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -1363,7 +1363,6 @@ private: struct ConstText { bool needsSchema; kj::StringTree decl; - kj::StringTree def; }; ConstText makeConstText(kj::StringPtr scope, kj::StringPtr name, ConstSchema schema) { @@ -1393,19 +1392,16 @@ private: return ConstText { false, kj::strTree("public static final ", typeName_, ' ', upperCase, " = ", - literalValue(constProto.getType(), constProto.getValue()), ";\n"), - scope.size() == 0 ? kj::strTree() : kj::strTree( - "final ", typeName_, ' ', scope, upperCase, ";\n") + literalValue(constProto.getType(), constProto.getValue()), ";\n") }; case schema::Value::TEXT: { - kj::String constType = kj::strTree( - "::capnp::_::ConstText<", schema.as().size(), ">").flatten(); return ConstText { true, - kj::strTree(linkage, "const ", constType, ' ', upperCase, ";\n"), - kj::strTree("const ", constType, ' ', scope, upperCase, "(::capnp::schemas::b_", - kj::hex(proto.getId()), ".words + ", schema.getValueSchemaOffset(), ");\n") + kj::strTree("public static final org.capnproto.Text.Reader ", upperCase, + " = new org.capnproto.Text.Reader(Schemas.b_", + kj::hex(proto.getId()), ", ", schema.getValueSchemaOffset(), + ", ", constProto.getValue().getText().size(), ");\n") }; } @@ -1414,7 +1410,6 @@ private: "::capnp::_::ConstData<", schema.as().size(), ">").flatten(); return ConstText { true, - kj::strTree(linkage, "const ", constType, ' ', upperCase, ";\n"), kj::strTree("const ", constType, ' ', scope, upperCase, "(::capnp::schemas::b_", kj::hex(proto.getId()), ".words + ", schema.getValueSchemaOffset(), ");\n") }; @@ -1425,7 +1420,6 @@ private: "::capnp::_::ConstStruct<", typeName_, ">").flatten(); return ConstText { true, - kj::strTree(linkage, "const ", constType, ' ', upperCase, ";\n"), kj::strTree("const ", constType, ' ', scope, upperCase, "(::capnp::schemas::b_", kj::hex(proto.getId()), ".words + ", schema.getValueSchemaOffset(), ");\n") }; @@ -1436,7 +1430,6 @@ private: "::capnp::_::ConstList<", typeName(type.getList().getElementType()), ">").flatten(); return ConstText { true, - kj::strTree(linkage, "const ", constType, ' ', upperCase, ";\n"), kj::strTree("const ", constType, ' ', scope, upperCase, "(::capnp::schemas::b_", kj::hex(proto.getId()), ".words + ", schema.getValueSchemaOffset(), ");\n") }; @@ -1444,7 +1437,7 @@ private: case schema::Value::ANY_POINTER: case schema::Value::INTERFACE: - return ConstText { false, kj::strTree(), kj::strTree() }; + return ConstText { false, kj::strTree() }; } KJ_UNREACHABLE; @@ -1683,8 +1676,7 @@ private: kj::strTree(), kj::strTree(), - - kj::mv(constText.def), + kj::strTree(), }; } diff --git a/compiler/src/test/scala/org/capnproto/EncodingTest.scala b/compiler/src/test/scala/org/capnproto/EncodingTest.scala index 7e55d97..9b80ae1 100644 --- a/compiler/src/test/scala/org/capnproto/EncodingTest.scala +++ b/compiler/src/test/scala/org/capnproto/EncodingTest.scala @@ -84,6 +84,8 @@ class EncodingSuite extends FunSuite { assert(1234.5f == TestConstants.FLOAT32_CONST); (-123e45) should equal (TestConstants.FLOAT64_CONST); + (TestConstants.TEXT_CONST.toString()) should equal ("foo"); + (TestConstants.ENUM_CONST) should equal (TestEnum.CORGE); } diff --git a/compiler/src/test/schema/test.capnp b/compiler/src/test/schema/test.capnp index 9bf8dfd..91085dc 100644 --- a/compiler/src/test/schema/test.capnp +++ b/compiler/src/test/schema/test.capnp @@ -196,6 +196,7 @@ struct TestConstants { const uint64Const :UInt64 = 12345678901234567890; const float32Const :Float32 = 1234.5; const float64Const :Float64 = -123e45; + const textConst :Text = "foo"; # ... const enumConst :TestEnum = corge; }