Breaking change: Remove deprecated std::string error collector overrides

PiperOrigin-RevId: 590740727
pull/15060/head
Mike Kruskal 12 months ago committed by Copybara-Service
parent 4b2a30c22c
commit 543fbcdbd9
  1. 22
      src/google/protobuf/compiler/importer.h
  2. 27
      src/google/protobuf/descriptor.h
  3. 21
      src/google/protobuf/io/tokenizer.h
  4. 17
      src/google/protobuf/retention_test.cc
  5. 6
      upb/util/def_to_proto_test.h

@ -181,30 +181,12 @@ class PROTOBUF_EXPORT MultiFileErrorCollector {
// Line and column numbers are zero-based. A line number of -1 indicates
// an error with the entire file (e.g. "not found").
virtual void RecordError(absl::string_view filename, int line, int column,
absl::string_view message) {
PROTOBUF_IGNORE_DEPRECATION_START
AddError(std::string(filename), line, column, std::string(message));
PROTOBUF_IGNORE_DEPRECATION_STOP
}
absl::string_view message)
= 0;
virtual void RecordWarning(absl::string_view filename, int line, int column,
absl::string_view message) {
PROTOBUF_IGNORE_DEPRECATION_START
AddWarning(std::string(filename), line, column, std::string(message));
PROTOBUF_IGNORE_DEPRECATION_STOP
}
private:
// These should never be called directly, but if a legacy class overrides
// them they'll get routed to by the Record* methods.
ABSL_DEPRECATED("Use RecordError")
virtual void AddError(const std::string& filename, int line, int column,
const std::string& message) {
ABSL_LOG(FATAL) << "AddError or RecordError must be implemented.";
}
ABSL_DEPRECATED("Use RecordWarning")
virtual void AddWarning(const std::string& filename, int line, int column,
const std::string& message) {}
};
// Abstract interface which represents a directory tree containing proto files.

@ -2156,12 +2156,8 @@ class PROTOBUF_EXPORT DescriptorPool {
virtual void RecordError(absl::string_view filename,
absl::string_view element_name,
const Message* descriptor, ErrorLocation location,
absl::string_view message) {
PROTOBUF_IGNORE_DEPRECATION_START
AddError(std::string(filename), std::string(element_name), descriptor,
location, std::string(message));
PROTOBUF_IGNORE_DEPRECATION_STOP
}
absl::string_view message)
= 0;
// Reports a warning in the FileDescriptorProto. Use this function if the
// problem occurred should NOT interrupt building the FileDescriptorProto.
@ -2176,27 +2172,8 @@ class PROTOBUF_EXPORT DescriptorPool {
const Message* descriptor,
ErrorLocation location,
absl::string_view message) {
PROTOBUF_IGNORE_DEPRECATION_START
AddWarning(std::string(filename), std::string(element_name), descriptor,
location, std::string(message));
PROTOBUF_IGNORE_DEPRECATION_STOP
}
private:
// These should never be called directly, but if a legacy class overrides
// them they'll get routed to by the Record* methods.
ABSL_DEPRECATED("Use RecordError")
virtual void AddError(const std::string& filename,
const std::string& element_name,
const Message* descriptor, ErrorLocation location,
const std::string& message) {
ABSL_LOG(FATAL) << "AddError or RecordError must be implemented.";
}
ABSL_DEPRECATED("Use RecordWarning")
virtual void AddWarning(const std::string& filename,
const std::string& element_name,
const Message* descriptor, ErrorLocation location,
const std::string& message) {}
};
// Convert the FileDescriptorProto to real descriptors and place them in

@ -55,33 +55,16 @@ class PROTOBUF_EXPORT ErrorCollector {
// column numbers. The numbers are zero-based, so you may want to add
// 1 to each before printing them.
virtual void RecordError(int line, ColumnNumber column,
absl::string_view message) {
PROTOBUF_IGNORE_DEPRECATION_START
AddError(line, column, std::string(message));
PROTOBUF_IGNORE_DEPRECATION_STOP
}
absl::string_view message)
= 0;
// Indicates that there was a warning in the input at the given line and
// column numbers. The numbers are zero-based, so you may want to add
// 1 to each before printing them.
virtual void RecordWarning(int line, ColumnNumber column,
absl::string_view message) {
PROTOBUF_IGNORE_DEPRECATION_START
AddWarning(line, column, std::string(message));
PROTOBUF_IGNORE_DEPRECATION_STOP
}
private:
// These should never be called directly, but if a legacy class overrides
// them they'll get routed to by the Record* methods.
ABSL_DEPRECATED("Use RecordError")
virtual void AddError(int line, ColumnNumber column,
const std::string& message) {
ABSL_LOG(FATAL) << "AddError or RecordError must be implemented.";
}
ABSL_DEPRECATED("Use RecordWarning")
virtual void AddWarning(int line, ColumnNumber column,
const std::string& message) {}
};
// This class converts a stream of raw text into a stream of tokens for

@ -13,6 +13,7 @@
#include "google/protobuf/descriptor.pb.h"
#include <gtest/gtest.h>
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/compiler/parser.h"
#include "google/protobuf/dynamic_message.h"
@ -160,6 +161,12 @@ TEST(RetentionTest, Method) {
.GetExtension(protobuf_unittest::method_option));
}
class SimpleErrorCollector : public io::ErrorCollector {
public:
SimpleErrorCollector() = default;
void RecordError(int line, io::ColumnNumber column,
absl::string_view message) override{};
};
TEST(RetentionTest, StripSourceRetentionOptionsWithSourceCodeInfo) {
// The tests above make assertions against the generated code, but this test
@ -202,7 +209,7 @@ TEST(RetentionTest, StripSourceRetentionOptionsWithSourceCodeInfo) {
FileDescriptorSet::descriptor()->file()->name());
io::ArrayInputStream input_stream(proto_file.data(),
static_cast<int>(proto_file.size()));
io::ErrorCollector error_collector;
SimpleErrorCollector error_collector;
io::Tokenizer tokenizer(&input_stream, &error_collector);
compiler::Parser parser;
FileDescriptorProto file_descriptor;
@ -242,7 +249,7 @@ TEST(RetentionTest, RemoveEmptyOptions) {
FileDescriptorSet::descriptor()->file()->name());
io::ArrayInputStream input_stream(proto_file.data(),
static_cast<int>(proto_file.size()));
io::ErrorCollector error_collector;
SimpleErrorCollector error_collector;
io::Tokenizer tokenizer(&input_stream, &error_collector);
compiler::Parser parser;
FileDescriptorProto file_descriptor;
@ -282,7 +289,7 @@ TEST(RetentionTest, InvalidDescriptor) {
FileDescriptorSet::descriptor()->file()->name());
io::ArrayInputStream input_stream(proto_file.data(),
static_cast<int>(proto_file.size()));
io::ErrorCollector error_collector;
SimpleErrorCollector error_collector;
io::Tokenizer tokenizer(&input_stream, &error_collector);
compiler::Parser parser;
FileDescriptorProto file_descriptor_proto;
@ -331,7 +338,7 @@ TEST(RetentionTest, MissingRequiredField) {
FileDescriptorSet::descriptor()->file()->name());
io::ArrayInputStream input_stream(proto_file.data(),
static_cast<int>(proto_file.size()));
io::ErrorCollector error_collector;
SimpleErrorCollector error_collector;
io::Tokenizer tokenizer(&input_stream, &error_collector);
compiler::Parser parser;
FileDescriptorProto file_descriptor_proto;
@ -387,7 +394,7 @@ TEST(RetentionTest, InvalidRecursionDepth) {
FileDescriptorSet::descriptor()->file()->name());
io::ArrayInputStream input_stream(proto_file.data(),
static_cast<int>(proto_file.size()));
io::ErrorCollector error_collector;
SimpleErrorCollector error_collector;
io::Tokenizer tokenizer(&input_stream, &error_collector);
compiler::Parser parser;
FileDescriptorProto file_descriptor_proto;

@ -46,9 +46,9 @@ MATCHER_P(EqualsProtoTreatNansAsEqual, proto,
}
class NullErrorCollector : public google::protobuf::DescriptorPool::ErrorCollector {
void AddError(const std::string& filename, const std::string& element_name,
const google::protobuf::Message* descriptor, ErrorLocation location,
const std::string& message) override {}
void RecordError(absl::string_view filename, absl::string_view element_name,
const google::protobuf::Message* descriptor, ErrorLocation location,
absl::string_view message) override {}
void RecordWarning(absl::string_view filename, absl::string_view element_name,
const google::protobuf::Message* descriptor, ErrorLocation location,
absl::string_view message) override {}

Loading…
Cancel
Save