[ObjC] ClangTidy fixes, no functional changes.

PiperOrigin-RevId: 565779732
pull/14110/head
Thomas Van Lenten 1 year ago committed by Copybara-Service
parent 6fc84676c1
commit a1e8ff0b16
  1. 2
      src/google/protobuf/compiler/objectivec/enum.cc
  2. 2
      src/google/protobuf/compiler/objectivec/generator.cc
  3. 7
      src/google/protobuf/compiler/objectivec/helpers.cc
  4. 3
      src/google/protobuf/compiler/objectivec/import_writer.cc
  5. 1
      src/google/protobuf/compiler/objectivec/import_writer.h
  6. 16
      src/google/protobuf/compiler/objectivec/line_consumer.cc
  7. 2
      src/google/protobuf/compiler/objectivec/line_consumer.h
  8. 4
      src/google/protobuf/compiler/objectivec/line_consumer_unittest.cc
  9. 23
      src/google/protobuf/compiler/objectivec/names.cc
  10. 1
      src/google/protobuf/compiler/objectivec/names.h
  11. 2
      src/google/protobuf/compiler/objectivec/names_unittest.cc
  12. 1
      src/google/protobuf/compiler/objectivec/oneof.cc
  13. 2
      src/google/protobuf/compiler/objectivec/oneof.h
  14. 5
      src/google/protobuf/compiler/objectivec/primitive_field.cc
  15. 1
      src/google/protobuf/compiler/objectivec/primitive_field.h
  16. 4
      src/google/protobuf/compiler/objectivec/text_format_decode_data.cc
  17. 1
      src/google/protobuf/compiler/objectivec/text_format_decode_data.h
  18. 21
      src/google/protobuf/compiler/objectivec/text_format_decode_data_unittest.cc

@ -7,6 +7,7 @@
#include "google/protobuf/compiler/objectivec/enum.h"
#include <cstddef>
#include <limits>
#include <string>
@ -16,6 +17,7 @@
#include "google/protobuf/compiler/objectivec/helpers.h"
#include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/compiler/objectivec/text_format_decode_data.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h"
namespace google {

@ -22,9 +22,11 @@
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/objectivec/file.h"
#include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/compiler/objectivec/options.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"

@ -7,6 +7,9 @@
#include "google/protobuf/compiler/objectivec/helpers.h"
#include <climits>
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
@ -14,11 +17,13 @@
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/strtod.h"
#include "google/protobuf/stubs/common.h"
@ -261,7 +266,7 @@ std::string DefaultValue(const FieldDescriptor* field) {
case FieldDescriptor::CPPTYPE_STRING: {
const bool has_default_value = field->has_default_value();
absl::string_view default_string = field->default_value_string();
if (!has_default_value || default_string.length() == 0) {
if (!has_default_value || default_string.empty()) {
// If the field is defined as being the empty string,
// then we will just assign to nil, as the empty string is the
// default for both strings and data.

@ -16,8 +16,11 @@
#include "absl/log/absl_check.h"
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/objectivec/line_consumer.h"
#include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h"
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some

@ -13,7 +13,6 @@
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h"
namespace google {
namespace protobuf {

@ -5,32 +5,26 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#include <errno.h>
#include <fcntl.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <climits>
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/objectivec/line_consumer.h"
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#ifdef _WIN32
#include "google/protobuf/io/io_win32.h"
#endif
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.
namespace google {
namespace protobuf {
namespace compiler {

@ -9,8 +9,8 @@
#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_LINE_CONSUMER_H__
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "google/protobuf/io/zero_copy_stream.h"
// Must be included last

@ -13,13 +13,16 @@
#include <vector>
#include <gtest/gtest.h>
#include "google/protobuf/stubs/common.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
namespace google {
namespace protobuf {
namespace compiler {
namespace objectivec {
namespace {
class TestLineCollector : public LineConsumer {
@ -154,6 +157,7 @@ TEST(ObjCHelper, ParseSimple_RejectLinesNoMessage) {
}
} // namespace
} // namespace objectivec
} // namespace compiler
} // namespace protobuf

@ -8,23 +8,25 @@
#include "google/protobuf/compiler/objectivec/names.h"
#include <algorithm>
#include <climits>
#include <fstream>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/objectivec/line_consumer.h"
#include "google/protobuf/compiler/objectivec/nsobject_methods.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor.h"
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.
@ -300,7 +302,7 @@ std::string UnderscoresToCamelCase(absl::string_view input,
bool first_segment_forces_upper = false;
for (auto& value : values) {
bool all_upper = UpperSegments().contains(value);
if (all_upper && (result.length() == 0)) {
if (all_upper && (result.empty())) {
first_segment_forces_upper = true;
}
if (all_upper) {
@ -310,8 +312,7 @@ std::string UnderscoresToCamelCase(absl::string_view input,
}
result += value;
}
if ((result.length() != 0) && !first_capitalized &&
!first_segment_forces_upper) {
if ((!result.empty()) && !first_capitalized && !first_segment_forces_upper) {
result[0] = absl::ascii_tolower(result[0]);
}
return result;
@ -729,7 +730,7 @@ std::string FilePath(const FileDescriptor* file) {
std::string basename;
std::string directory;
PathSplit(file->name(), &directory, &basename);
if (directory.length() > 0) {
if (!directory.empty()) {
output = absl::StrCat(directory, "/");
}
basename = StripProto(basename);
@ -879,7 +880,7 @@ std::string FieldNameCapitalized(const FieldDescriptor* field) {
// Want the same suffix handling, so upcase the first letter of the other
// name.
std::string result = FieldName(field);
if (result.length() > 0) {
if (!result.empty()) {
result[0] = absl::ascii_toupper(result[0]);
}
return result;
@ -904,7 +905,7 @@ std::string OneofName(const OneofDescriptor* descriptor) {
std::string OneofNameCapitalized(const OneofDescriptor* descriptor) {
// Use the common handling and then up-case the first letter.
std::string result = OneofName(descriptor);
if (result.length() > 0) {
if (!result.empty()) {
result[0] = absl::ascii_toupper(result[0]);
}
return result;
@ -920,7 +921,7 @@ std::string UnCamelCaseFieldName(absl::string_view name,
worker = absl::StripSuffix(worker, "Array");
}
if (field->type() == FieldDescriptor::TYPE_GROUP) {
if (worker.length() > 0) {
if (!worker.empty()) {
if (absl::ascii_islower(worker[0])) {
std::string copy(worker);
copy[0] = absl::ascii_toupper(worker[0]);

@ -13,6 +13,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "google/protobuf/descriptor.h"
// Must be included last

@ -13,6 +13,7 @@ namespace google {
namespace protobuf {
namespace compiler {
namespace objectivec {
namespace {
TEST(ObjCHelper, IsRetainedName) {
@ -108,6 +109,7 @@ TEST(ObjCHelper, IsCreateName) {
// right things are happening.
} // namespace
} // namespace objectivec
} // namespace compiler
} // namespace protobuf

@ -12,6 +12,7 @@
#include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/objectivec/helpers.h"
#include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h"
namespace google {

@ -9,9 +9,9 @@
#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__
#include <string>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h"

@ -12,7 +12,10 @@
#include "absl/container/flat_hash_map.h"
#include "absl/log/absl_log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/objectivec/field.h"
#include "google/protobuf/compiler/objectivec/helpers.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h"
namespace google {
@ -144,7 +147,7 @@ RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
SetPrimitiveVariables(descriptor, &variables_);
std::string base_name = PrimitiveArrayTypeName(descriptor);
if (base_name.length()) {
if (!base_name.empty()) {
variables_["array_storage_type"] = absl::StrCat("GPB", base_name, "Array");
} else {
std::string storage_type = variables_["storage_type"];

@ -9,6 +9,7 @@
#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_PRIMITIVE_FIELD_H__
#include "google/protobuf/compiler/objectivec/field.h"
#include "google/protobuf/descriptor.h"
namespace google {
namespace protobuf {

@ -7,12 +7,12 @@
#include "google/protobuf/compiler/objectivec/text_format_decode_data.h"
#include <iostream>
#include <ostream>
#include <cstdint>
#include <sstream>
#include <string>
#include <vector>
#include "absl/log/absl_check.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/match.h"

@ -8,6 +8,7 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_TEXT_FORMAT_DECODE_DATA_H__
#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_TEXT_FORMAT_DECODE_DATA_H__
#include <cstddef>
#include <cstdint>
#include <string>
#include <utility>

@ -7,6 +7,7 @@
#include "google/protobuf/compiler/objectivec/text_format_decode_data.h"
#include <cstdint>
#include <string>
#include <gtest/gtest.h>
@ -18,6 +19,7 @@ namespace google {
namespace protobuf {
namespace compiler {
namespace objectivec {
namespace {
TEST(ObjCHelper, TextFormatDecodeData_DecodeDataForString_RawStrings) {
@ -83,12 +85,13 @@ TEST(ObjCHelper, TextFormatDecodeData_DecodeDataForString_ByteCodes) {
// Long name so multiple decode ops are needed.
// clang-format off
input_for_decode =
"longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000";
"longFieldNameIsLoooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
"ooooooooooooooooong1000";
desired_output_for_decode =
"long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000";
// clang-format on
"long_field_name_is_"
"looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
"oong_1000";
expected = std::string("\x04\xA5\xA4\xA2\xBF\x1F\x0E\x84\x0", 9);
result = TextFormatDecodeData::DecodeDataForString(input_for_decode,
desired_output_for_decode);
@ -153,11 +156,12 @@ TEST(ObjCHelper, TextFormatDecodeData_ByteCodes) {
decode_data.AddString(3, "abcdefghIJ", "_AbcdefghIJ");
decode_data.AddString(2, "abcdefghIJ", "Abcd_EfghIJ");
decode_data.AddString(4, "abcdefghIJ", "ABCD__EfghI_j");
// clang-format off
decode_data.AddString(1000,
"longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000",
"long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000");
// clang-format on
"longFieldNameIsLoooooooooooooooooooooooooooooooooooooo"
"ooooooooooooooooooooooooooooooooooong1000",
"long_field_name_is_"
"looooooooooooooooooooooooooooooooooooooooooooooooooooo"
"oooooooooooooooooooong_1000");
EXPECT_EQ(5, decode_data.num_entries());
@ -220,6 +224,7 @@ TEST(ObjCHelperDeathTest, TextFormatDecodeData_Failures) {
#endif // PROTOBUF_HAS_DEATH_TEST
} // namespace
} // namespace objectivec
} // namespace compiler
} // namespace protobuf

Loading…
Cancel
Save