mirror of https://github.com/grpc/grpc-java.git
compiler: add std:: qualifications to all references to std::string
This commit is contained in:
parent
a98db126e2
commit
3b1af27073
|
|
@ -52,7 +52,7 @@ using google::protobuf::SourceLocation;
|
|||
using std::to_string;
|
||||
|
||||
// java keywords from: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.9
|
||||
static std::set<string> java_keywords = {
|
||||
static std::set<std::string> java_keywords = {
|
||||
"abstract",
|
||||
"assert",
|
||||
"boolean",
|
||||
|
|
@ -112,8 +112,8 @@ static std::set<string> java_keywords = {
|
|||
// - decapitalize the first letter
|
||||
// - remove embedded underscores & capitalize the following letter
|
||||
// Finally, if the result is a reserved java keyword, append an underscore.
|
||||
static string MixedLower(const string& word) {
|
||||
string w;
|
||||
static std::string MixedLower(const std::string& word) {
|
||||
std::string w;
|
||||
w += tolower(word[0]);
|
||||
bool after_underscore = false;
|
||||
for (size_t i = 1; i < word.length(); ++i) {
|
||||
|
|
@ -134,8 +134,8 @@ static string MixedLower(const string& word) {
|
|||
// - An underscore is inserted where a lower case letter is followed by an
|
||||
// upper case letter.
|
||||
// - All letters are converted to upper case
|
||||
static string ToAllUpperCase(const string& word) {
|
||||
string w;
|
||||
static std::string ToAllUpperCase(const std::string& word) {
|
||||
std::string w;
|
||||
for (size_t i = 0; i < word.length(); ++i) {
|
||||
w += toupper(word[i]);
|
||||
if ((i < word.length() - 1) && islower(word[i]) && isupper(word[i + 1])) {
|
||||
|
|
@ -145,19 +145,19 @@ static string ToAllUpperCase(const string& word) {
|
|||
return w;
|
||||
}
|
||||
|
||||
static inline string LowerMethodName(const MethodDescriptor* method) {
|
||||
static inline std::string LowerMethodName(const MethodDescriptor* method) {
|
||||
return MixedLower(method->name());
|
||||
}
|
||||
|
||||
static inline string MethodPropertiesFieldName(const MethodDescriptor* method) {
|
||||
static inline std::string MethodPropertiesFieldName(const MethodDescriptor* method) {
|
||||
return "METHOD_" + ToAllUpperCase(method->name());
|
||||
}
|
||||
|
||||
static inline string MethodPropertiesGetterName(const MethodDescriptor* method) {
|
||||
static inline std::string MethodPropertiesGetterName(const MethodDescriptor* method) {
|
||||
return MixedLower("get_" + method->name() + "_method");
|
||||
}
|
||||
|
||||
static inline string MethodIdFieldName(const MethodDescriptor* method) {
|
||||
static inline std::string MethodIdFieldName(const MethodDescriptor* method) {
|
||||
return "METHODID_" + ToAllUpperCase(method->name());
|
||||
}
|
||||
|
||||
|
|
@ -165,13 +165,13 @@ static inline bool ShouldGenerateAsLite(const Descriptor* desc) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline string MessageFullJavaName(const Descriptor* desc) {
|
||||
static inline std::string MessageFullJavaName(const Descriptor* desc) {
|
||||
return google::protobuf::compiler::java::ClassName(desc);
|
||||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
template <typename ITR>
|
||||
static void GrpcSplitStringToIteratorUsing(const string& full,
|
||||
static void GrpcSplitStringToIteratorUsing(const std::string& full,
|
||||
const char* delim,
|
||||
ITR& result) {
|
||||
// Optimize the common case where delim is a single character.
|
||||
|
|
@ -185,17 +185,17 @@ static void GrpcSplitStringToIteratorUsing(const string& full,
|
|||
} else {
|
||||
const char* start = p;
|
||||
while (++p != end && *p != c);
|
||||
*result++ = string(start, p - start);
|
||||
*result++ = std::string(start, p - start);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
string::size_type begin_index, end_index;
|
||||
std::string::size_type begin_index, end_index;
|
||||
begin_index = full.find_first_not_of(delim);
|
||||
while (begin_index != string::npos) {
|
||||
while (begin_index != std::string::npos) {
|
||||
end_index = full.find_first_of(delim, begin_index);
|
||||
if (end_index == string::npos) {
|
||||
if (end_index == std::string::npos) {
|
||||
*result++ = full.substr(begin_index);
|
||||
return;
|
||||
}
|
||||
|
|
@ -205,28 +205,28 @@ static void GrpcSplitStringToIteratorUsing(const string& full,
|
|||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
static void GrpcSplitStringUsing(const string& full,
|
||||
static void GrpcSplitStringUsing(const std::string& full,
|
||||
const char* delim,
|
||||
std::vector<string>* result) {
|
||||
std::back_insert_iterator< std::vector<string> > it(*result);
|
||||
std::vector<std::string>* result) {
|
||||
std::back_insert_iterator< std::vector<std::string> > it(*result);
|
||||
GrpcSplitStringToIteratorUsing(full, delim, it);
|
||||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
static std::vector<string> GrpcSplit(const string& full, const char* delim) {
|
||||
std::vector<string> result;
|
||||
static std::vector<std::string> GrpcSplit(const std::string& full, const char* delim) {
|
||||
std::vector<std::string> result;
|
||||
GrpcSplitStringUsing(full, delim, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
static string GrpcEscapeJavadoc(const string& input) {
|
||||
string result;
|
||||
static std::string GrpcEscapeJavadoc(const std::string& input) {
|
||||
std::string result;
|
||||
result.reserve(input.size() * 2);
|
||||
|
||||
char prev = '*';
|
||||
|
||||
for (string::size_type i = 0; i < input.size(); i++) {
|
||||
for (std::string::size_type i = 0; i < input.size(); i++) {
|
||||
char c = input[i];
|
||||
switch (c) {
|
||||
case '*':
|
||||
|
|
@ -280,17 +280,17 @@ static string GrpcEscapeJavadoc(const string& input) {
|
|||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
template <typename DescriptorType>
|
||||
static string GrpcGetCommentsForDescriptor(const DescriptorType* descriptor) {
|
||||
static std::string GrpcGetCommentsForDescriptor(const DescriptorType* descriptor) {
|
||||
SourceLocation location;
|
||||
if (descriptor->GetSourceLocation(&location)) {
|
||||
return location.leading_comments.empty() ?
|
||||
location.trailing_comments : location.leading_comments;
|
||||
}
|
||||
return string();
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
static std::vector<string> GrpcGetDocLines(const string& comments) {
|
||||
static std::vector<std::string> GrpcGetDocLines(const std::string& comments) {
|
||||
if (!comments.empty()) {
|
||||
// TODO(kenton): Ideally we should parse the comment text as Markdown and
|
||||
// write it back as HTML, but this requires a Markdown parser. For now
|
||||
|
|
@ -298,26 +298,26 @@ static std::vector<string> GrpcGetDocLines(const string& comments) {
|
|||
|
||||
// If the comment itself contains block comment start or end markers,
|
||||
// HTML-escape them so that they don't accidentally close the doc comment.
|
||||
string escapedComments = GrpcEscapeJavadoc(comments);
|
||||
std::string escapedComments = GrpcEscapeJavadoc(comments);
|
||||
|
||||
std::vector<string> lines = GrpcSplit(escapedComments, "\n");
|
||||
std::vector<std::string> lines = GrpcSplit(escapedComments, "\n");
|
||||
while (!lines.empty() && lines.back().empty()) {
|
||||
lines.pop_back();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
return std::vector<string>();
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
template <typename DescriptorType>
|
||||
static std::vector<string> GrpcGetDocLinesForDescriptor(const DescriptorType* descriptor) {
|
||||
static std::vector<std::string> GrpcGetDocLinesForDescriptor(const DescriptorType* descriptor) {
|
||||
return GrpcGetDocLines(GrpcGetCommentsForDescriptor(descriptor));
|
||||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
static void GrpcWriteDocCommentBody(Printer* printer,
|
||||
const std::vector<string>& lines,
|
||||
const std::vector<std::string>& lines,
|
||||
bool surroundWithPreTag) {
|
||||
if (!lines.empty()) {
|
||||
if (surroundWithPreTag) {
|
||||
|
|
@ -342,9 +342,9 @@ static void GrpcWriteDocCommentBody(Printer* printer,
|
|||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in distribution.
|
||||
static void GrpcWriteDocComment(Printer* printer, const string& comments) {
|
||||
static void GrpcWriteDocComment(Printer* printer, const std::string& comments) {
|
||||
printer->Print("/**\n");
|
||||
std::vector<string> lines = GrpcGetDocLines(comments);
|
||||
std::vector<std::string> lines = GrpcGetDocLines(comments);
|
||||
GrpcWriteDocCommentBody(printer, lines, false);
|
||||
printer->Print(" */\n");
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ static void GrpcWriteServiceDocComment(Printer* printer,
|
|||
// Deviating from protobuf to avoid extraneous docs
|
||||
// (see https://github.com/google/protobuf/issues/1406);
|
||||
printer->Print("/**\n");
|
||||
std::vector<string> lines = GrpcGetDocLinesForDescriptor(service);
|
||||
std::vector<std::string> lines = GrpcGetDocLinesForDescriptor(service);
|
||||
GrpcWriteDocCommentBody(printer, lines, true);
|
||||
printer->Print(" */\n");
|
||||
}
|
||||
|
|
@ -366,13 +366,13 @@ void GrpcWriteMethodDocComment(Printer* printer,
|
|||
// Deviating from protobuf to avoid extraneous docs
|
||||
// (see https://github.com/google/protobuf/issues/1406);
|
||||
printer->Print("/**\n");
|
||||
std::vector<string> lines = GrpcGetDocLinesForDescriptor(method);
|
||||
std::vector<std::string> lines = GrpcGetDocLinesForDescriptor(method);
|
||||
GrpcWriteDocCommentBody(printer, lines, true);
|
||||
printer->Print(" */\n");
|
||||
}
|
||||
|
||||
static void PrintMethodFields(
|
||||
const ServiceDescriptor* service, std::map<string, string>* vars,
|
||||
const ServiceDescriptor* service, std::map<std::string, std::string>* vars,
|
||||
Printer* p, ProtoFlavor flavor) {
|
||||
p->Print("// Static method descriptors that strictly reflect the proto.\n");
|
||||
(*vars)["service_name"] = service->name();
|
||||
|
|
@ -486,15 +486,15 @@ enum CallType {
|
|||
};
|
||||
|
||||
static void PrintBindServiceMethodBody(const ServiceDescriptor* service,
|
||||
std::map<string, string>* vars,
|
||||
std::map<std::string, std::string>* vars,
|
||||
Printer* p);
|
||||
|
||||
// Prints a StubFactory for given service / stub type.
|
||||
static void PrintStubFactory(
|
||||
const ServiceDescriptor* service,
|
||||
std::map<string, string>* vars,
|
||||
std::map<std::string, std::string>* vars,
|
||||
Printer* p, StubType type) {
|
||||
string stub_type_name;
|
||||
std::string stub_type_name;
|
||||
switch (type) {
|
||||
case ASYNC_CLIENT_IMPL:
|
||||
stub_type_name = "";
|
||||
|
|
@ -523,14 +523,14 @@ static void PrintStubFactory(
|
|||
// Prints a client interface or implementation class, or a server interface.
|
||||
static void PrintStub(
|
||||
const ServiceDescriptor* service,
|
||||
std::map<string, string>* vars,
|
||||
std::map<std::string, std::string>* vars,
|
||||
Printer* p, StubType type) {
|
||||
const string service_name = service->name();
|
||||
const std::string service_name = service->name();
|
||||
(*vars)["service_name"] = service_name;
|
||||
(*vars)["abstract_name"] = service_name + "ImplBase";
|
||||
string stub_name = service_name;
|
||||
string client_name = service_name;
|
||||
string stub_base_class_name = "AbstractStub";
|
||||
std::string stub_name = service_name;
|
||||
std::string client_name = service_name;
|
||||
std::string stub_base_class_name = "AbstractStub";
|
||||
CallType call_type;
|
||||
bool impl_base = false;
|
||||
bool interface = false;
|
||||
|
|
@ -804,7 +804,7 @@ static bool CompareMethodClientStreaming(const MethodDescriptor* method1,
|
|||
// Place all method invocations into a single class to reduce memory footprint
|
||||
// on Android.
|
||||
static void PrintMethodHandlerClass(const ServiceDescriptor* service,
|
||||
std::map<string, string>* vars,
|
||||
std::map<std::string, std::string>* vars,
|
||||
Printer* p) {
|
||||
// Sort method ids based on client_streaming() so switch tables are compact.
|
||||
std::vector<const MethodDescriptor*> sorted_methods(service->method_count());
|
||||
|
|
@ -910,7 +910,7 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service,
|
|||
}
|
||||
|
||||
static void PrintGetServiceDescriptorMethod(const ServiceDescriptor* service,
|
||||
std::map<string, string>* vars,
|
||||
std::map<std::string, std::string>* vars,
|
||||
Printer* p,
|
||||
ProtoFlavor flavor) {
|
||||
(*vars)["service_name"] = service->name();
|
||||
|
|
@ -1011,7 +1011,7 @@ static void PrintGetServiceDescriptorMethod(const ServiceDescriptor* service,
|
|||
}
|
||||
|
||||
static void PrintBindServiceMethodBody(const ServiceDescriptor* service,
|
||||
std::map<string, string>* vars,
|
||||
std::map<std::string, std::string>* vars,
|
||||
Printer* p) {
|
||||
(*vars)["service_name"] = service->name();
|
||||
p->Indent();
|
||||
|
|
@ -1065,7 +1065,7 @@ static void PrintBindServiceMethodBody(const ServiceDescriptor* service,
|
|||
}
|
||||
|
||||
static void PrintService(const ServiceDescriptor* service,
|
||||
std::map<string, string>* vars,
|
||||
std::map<std::string, std::string>* vars,
|
||||
Printer* p,
|
||||
ProtoFlavor flavor,
|
||||
bool disable_version) {
|
||||
|
|
@ -1195,7 +1195,7 @@ void GenerateService(const ServiceDescriptor* service,
|
|||
bool disable_version) {
|
||||
// All non-generated classes must be referred by fully qualified names to
|
||||
// avoid collision with generated classes.
|
||||
std::map<string, string> vars;
|
||||
std::map<std::string, std::string> vars;
|
||||
vars["String"] = "java.lang.String";
|
||||
vars["Deprecated"] = "java.lang.Deprecated";
|
||||
vars["Override"] = "java.lang.Override";
|
||||
|
|
@ -1229,7 +1229,7 @@ void GenerateService(const ServiceDescriptor* service,
|
|||
"com.google.common.util.concurrent.ListenableFuture";
|
||||
|
||||
Printer printer(out, '$');
|
||||
string package_name = ServiceJavaPackage(service->file());
|
||||
std::string package_name = ServiceJavaPackage(service->file());
|
||||
if (!package_name.empty()) {
|
||||
printer.Print(
|
||||
"package $package_name$;\n\n",
|
||||
|
|
@ -1237,7 +1237,7 @@ void GenerateService(const ServiceDescriptor* service,
|
|||
}
|
||||
PrintImports(&printer);
|
||||
|
||||
// Package string is used to fully qualify method names.
|
||||
// Package std::string is used to fully qualify method names.
|
||||
vars["Package"] = service->file()->package();
|
||||
if (!vars["Package"].empty()) {
|
||||
vars["Package"].append(".");
|
||||
|
|
@ -1245,10 +1245,10 @@ void GenerateService(const ServiceDescriptor* service,
|
|||
PrintService(service, &vars, &printer, flavor, disable_version);
|
||||
}
|
||||
|
||||
string ServiceJavaPackage(const FileDescriptor* file) {
|
||||
string result = google::protobuf::compiler::java::ClassName(file);
|
||||
std::string ServiceJavaPackage(const FileDescriptor* file) {
|
||||
std::string result = google::protobuf::compiler::java::ClassName(file);
|
||||
size_t last_dot_pos = result.find_last_of('.');
|
||||
if (last_dot_pos != string::npos) {
|
||||
if (last_dot_pos != std::string::npos) {
|
||||
result.resize(last_dot_pos);
|
||||
} else {
|
||||
result = "";
|
||||
|
|
@ -1256,7 +1256,7 @@ string ServiceJavaPackage(const FileDescriptor* file) {
|
|||
return result;
|
||||
}
|
||||
|
||||
string ServiceClassName(const google::protobuf::ServiceDescriptor* service) {
|
||||
std::string ServiceClassName(const google::protobuf::ServiceDescriptor* service) {
|
||||
return service->name() + "Grpc";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ enum ProtoFlavor {
|
|||
};
|
||||
|
||||
// Returns the package name of the gRPC services defined in the given file.
|
||||
string ServiceJavaPackage(const google::protobuf::FileDescriptor* file);
|
||||
std::string ServiceJavaPackage(const google::protobuf::FileDescriptor* file);
|
||||
|
||||
// Returns the name of the outer class that wraps in all the generated code for
|
||||
// the given service.
|
||||
string ServiceClassName(const google::protobuf::ServiceDescriptor* service);
|
||||
std::string ServiceClassName(const google::protobuf::ServiceDescriptor* service);
|
||||
|
||||
// Writes the generated service interface into the given ZeroCopyOutputStream
|
||||
void GenerateService(const google::protobuf::ServiceDescriptor* service,
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@
|
|||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
|
||||
static string JavaPackageToDir(const string& package_name) {
|
||||
string package_dir = package_name;
|
||||
static std::string JavaPackageToDir(const std::string& package_name) {
|
||||
std::string package_dir = package_name;
|
||||
for (size_t i = 0; i < package_dir.size(); ++i) {
|
||||
if (package_dir[i] == '.') {
|
||||
package_dir[i] = '/';
|
||||
|
|
@ -44,10 +44,10 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
|
|||
virtual ~JavaGrpcGenerator() {}
|
||||
|
||||
virtual bool Generate(const google::protobuf::FileDescriptor* file,
|
||||
const string& parameter,
|
||||
const std::string& parameter,
|
||||
google::protobuf::compiler::GeneratorContext* context,
|
||||
string* error) const {
|
||||
std::vector<std::pair<string, string> > options;
|
||||
std::string* error) const {
|
||||
std::vector<std::pair<std::string, std::string> > options;
|
||||
google::protobuf::compiler::ParseGeneratorParameter(parameter, &options);
|
||||
|
||||
java_grpc_generator::ProtoFlavor flavor =
|
||||
|
|
@ -62,11 +62,11 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
string package_name = java_grpc_generator::ServiceJavaPackage(file);
|
||||
string package_filename = JavaPackageToDir(package_name);
|
||||
std::string package_name = java_grpc_generator::ServiceJavaPackage(file);
|
||||
std::string package_filename = JavaPackageToDir(package_name);
|
||||
for (int i = 0; i < file->service_count(); ++i) {
|
||||
const google::protobuf::ServiceDescriptor* service = file->service(i);
|
||||
string filename = package_filename
|
||||
std::string filename = package_filename
|
||||
+ java_grpc_generator::ServiceClassName(service) + ".java";
|
||||
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
|
||||
context->Open(filename));
|
||||
|
|
|
|||
Loading…
Reference in New Issue