From db1b2a06e3999ffd6e52719ec0216849aa515ba1 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Sat, 16 Jul 2016 21:34:25 +0300 Subject: nits --- src/google/protobuf/compiler/js/js_generator.cc | 53 ++++++++++--------------- 1 file changed, 21 insertions(+), 32 deletions(-) (limited to 'src/google/protobuf/compiler/js/js_generator.cc') diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 7829ccbf..53067739 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -1257,11 +1257,14 @@ string GetPivot(const Descriptor* desc) { // Returns true for fields that represent "null" as distinct from the default // value. See http://go/proto3#heading=h.kozewqqcqhuz for more information. bool HasFieldPresence(const FieldDescriptor* field) { + if (field->is_repeated()) { + return false; + } + return - !field->is_repeated() && - ((field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) || + (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) || (field->containing_oneof() != NULL) || - (field->file()->syntax() != FileDescriptor::SYNTAX_PROTO3)); + (field->file()->syntax() != FileDescriptor::SYNTAX_PROTO3); } // For proto3 fields without presence, returns a string representing the default @@ -2322,20 +2325,6 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), "returnvalue", JSReturnClause(field)); - printer->Print( - "/**\n" - " * Returns whether this field is set.\n" - " * @return{!boolean}\n" - " */\n" - "$class$.prototype.has$name$ = function() {\n" - " return jspb.Message.getField(this, $index$) != null;\n" - "};\n" - "\n" - "\n", - "class", GetPath(options, field->containing_type()), - "name", JSGetterName(options, field), - "index", JSFieldIndex(field)); - } else { bool untyped = false; @@ -2497,22 +2486,22 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), "returnvalue", JSReturnClause(field)); } + } - if (HasFieldPresence(field)) { - printer->Print( - "/**\n" - " * Returns whether this field is set.\n" - " * @return{!boolean}\n" - " */\n" - "$class$.prototype.has$name$ = function() {\n" - " return jspb.Message.getField(this, $index$) != null;\n" - "};\n" - "\n" - "\n", - "class", GetPath(options, field->containing_type()), - "name", JSGetterName(options, field), - "index", JSFieldIndex(field)); - } + if (HasFieldPresence(field)) { + printer->Print( + "/**\n" + " * Returns whether this field is set.\n" + " * @return{!boolean}\n" + " */\n" + "$class$.prototype.has$name$ = function() {\n" + " return jspb.Message.getField(this, $index$) != null;\n" + "};\n" + "\n" + "\n", + "class", GetPath(options, field->containing_type()), + "name", JSGetterName(options, field), + "index", JSFieldIndex(field)); } } -- cgit v1.2.3