|
|
@ -2848,44 +2848,50 @@ void Generator::GenerateClassField(const GeneratorOptions& options, |
|
|
|
// fields with presence.
|
|
|
|
// fields with presence.
|
|
|
|
if (field->is_map()) { |
|
|
|
if (field->is_map()) { |
|
|
|
printer->Print( |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
"/** Clears values from the map. The map will be non-null. */\n" |
|
|
|
"$class$.prototype.$clearername$ = function() {\n" |
|
|
|
"$class$.prototype.$clearername$ = function() {\n" |
|
|
|
" this.$gettername$().clear();$returnvalue$\n" |
|
|
|
" this.$gettername$().clear();$returnvalue$\n" |
|
|
|
"};\n" |
|
|
|
"};\n" |
|
|
|
"\n" |
|
|
|
"\n" |
|
|
|
"\n", |
|
|
|
"\n", |
|
|
|
"class", GetMessagePath(options, field->containing_type()), |
|
|
|
"class", GetMessagePath(options, field->containing_type()), |
|
|
|
"clearername", "clear" + JSGetterName(options, field), |
|
|
|
"clearername", "clear" + JSGetterName(options, field), "gettername", |
|
|
|
"gettername", "get" + JSGetterName(options, field), |
|
|
|
"get" + JSGetterName(options, field), "returnvalue", |
|
|
|
"returnvalue", JSReturnClause(field)); |
|
|
|
JSReturnClause(field)); |
|
|
|
printer->Annotate("clearername", field); |
|
|
|
printer->Annotate("clearername", field); |
|
|
|
} else if (field->is_repeated() || |
|
|
|
} else if (field->is_repeated() || |
|
|
|
(field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
(field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
!field->is_required())) { |
|
|
|
!field->is_required())) { |
|
|
|
// Fields where we can delegate to the regular setter.
|
|
|
|
// Fields where we can delegate to the regular setter.
|
|
|
|
printer->Print( |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
"/** $jsdoc$ */\n" |
|
|
|
"$class$.prototype.$clearername$ = function() {\n" |
|
|
|
"$class$.prototype.$clearername$ = function() {\n" |
|
|
|
" this.$settername$($clearedvalue$);$returnvalue$\n" |
|
|
|
" this.$settername$($clearedvalue$);$returnvalue$\n" |
|
|
|
"};\n" |
|
|
|
"};\n" |
|
|
|
"\n" |
|
|
|
"\n" |
|
|
|
"\n", |
|
|
|
"\n", |
|
|
|
|
|
|
|
"jsdoc", |
|
|
|
|
|
|
|
field->is_repeated() ? "Clears the list making it empty but non-null." |
|
|
|
|
|
|
|
: "Clears the message field making it undefined.", |
|
|
|
"class", GetMessagePath(options, field->containing_type()), |
|
|
|
"class", GetMessagePath(options, field->containing_type()), |
|
|
|
"clearername", "clear" + JSGetterName(options, field), |
|
|
|
"clearername", "clear" + JSGetterName(options, field), "settername", |
|
|
|
"settername", "set" + JSGetterName(options, field), |
|
|
|
"set" + JSGetterName(options, field), "clearedvalue", |
|
|
|
"clearedvalue", (field->is_repeated() ? "[]" : "undefined"), |
|
|
|
(field->is_repeated() ? "[]" : "undefined"), "returnvalue", |
|
|
|
"returnvalue", JSReturnClause(field)); |
|
|
|
JSReturnClause(field)); |
|
|
|
printer->Annotate("clearername", field); |
|
|
|
printer->Annotate("clearername", field); |
|
|
|
} else if (HasFieldPresence(options, field)) { |
|
|
|
} else if (HasFieldPresence(options, field)) { |
|
|
|
// Fields where we can't delegate to the regular setter because it doesn't
|
|
|
|
// Fields where we can't delegate to the regular setter because it doesn't
|
|
|
|
// accept "undefined" as an argument.
|
|
|
|
// accept "undefined" as an argument.
|
|
|
|
printer->Print( |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
"/** Clears the field making it undefined. */\n" |
|
|
|
"$class$.prototype.$clearername$ = function() {\n" |
|
|
|
"$class$.prototype.$clearername$ = function() {\n" |
|
|
|
" jspb.Message.set$maybeoneof$Field(this, " |
|
|
|
" jspb.Message.set$maybeoneof$Field(this, " |
|
|
|
"$index$$maybeoneofgroup$, ", |
|
|
|
"$index$$maybeoneofgroup$, ", |
|
|
|
"class", GetMessagePath(options, field->containing_type()), |
|
|
|
"class", GetMessagePath(options, field->containing_type()), |
|
|
|
"clearername", "clear" + JSGetterName(options, field), |
|
|
|
"clearername", "clear" + JSGetterName(options, field), "maybeoneof", |
|
|
|
"maybeoneof", (field->containing_oneof() ? "Oneof" : ""), |
|
|
|
(field->containing_oneof() ? "Oneof" : ""), "maybeoneofgroup", |
|
|
|
"maybeoneofgroup", (field->containing_oneof() ? |
|
|
|
(field->containing_oneof() ? (", " + JSOneofArray(options, field)) |
|
|
|
(", " + JSOneofArray(options, field)) : ""), |
|
|
|
: ""), |
|
|
|
"index", JSFieldIndex(field)); |
|
|
|
"index", JSFieldIndex(field)); |
|
|
|
printer->Annotate("clearername", field); |
|
|
|
printer->Annotate("clearername", field); |
|
|
|
printer->Print( |
|
|
|
printer->Print( |
|
|
@ -2963,14 +2969,15 @@ void Generator::GenerateRepeatedMessageHelperMethods( |
|
|
|
" * @param {number=} opt_index\n" |
|
|
|
" * @param {number=} opt_index\n" |
|
|
|
" * @return {!$optionaltype$}\n" |
|
|
|
" * @return {!$optionaltype$}\n" |
|
|
|
" */\n" |
|
|
|
" */\n" |
|
|
|
"$class$.prototype.add$name$ = function(opt_value, opt_index) {\n" |
|
|
|
"$class$.prototype.$addername$ = function(opt_value, opt_index) {\n" |
|
|
|
" return jspb.Message.addTo$repeatedtag$WrapperField(", |
|
|
|
" return jspb.Message.addTo$repeatedtag$WrapperField(", |
|
|
|
"optionaltype", JSTypeName(options, field, BYTES_DEFAULT), |
|
|
|
"optionaltype", JSTypeName(options, field, BYTES_DEFAULT), "class", |
|
|
|
"class", GetMessagePath(options, field->containing_type()), |
|
|
|
GetMessagePath(options, field->containing_type()), "addername", |
|
|
|
"name", JSGetterName(options, field, BYTES_DEFAULT, |
|
|
|
"add" + JSGetterName(options, field, BYTES_DEFAULT, |
|
|
|
/* drop_list = */ true), |
|
|
|
/* drop_list = */ true), |
|
|
|
"repeatedtag", (field->is_repeated() ? "Repeated" : "")); |
|
|
|
"repeatedtag", (field->is_repeated() ? "Repeated" : "")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printer->Annotate("addername", field); |
|
|
|
printer->Print( |
|
|
|
printer->Print( |
|
|
|
"this, $index$$oneofgroup$, opt_value, $ctor$, opt_index);\n" |
|
|
|
"this, $index$$oneofgroup$, opt_value, $ctor$, opt_index);\n" |
|
|
|
"};\n" |
|
|
|
"};\n" |
|
|
|