mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
bulk code format fix (#8707)
This commit is contained in:
@@ -28,11 +28,11 @@
|
||||
|
||||
// Stringify helpers used solely to cast GRPC_VERSION
|
||||
#ifndef STR
|
||||
# define STR(s) # s
|
||||
#define STR(s) #s
|
||||
#endif
|
||||
|
||||
#ifndef XSTR
|
||||
# define XSTR(s) STR(s)
|
||||
#define XSTR(s) STR(s)
|
||||
#endif
|
||||
|
||||
typedef grpc_generator::Printer Printer;
|
||||
@@ -46,8 +46,8 @@ namespace grpc_java_generator {
|
||||
typedef std::string string;
|
||||
namespace {
|
||||
// Generates imports for the service
|
||||
static void GenerateImports(grpc_generator::File *file,
|
||||
grpc_generator::Printer *printer, VARS &vars) {
|
||||
static void GenerateImports(grpc_generator::File* file,
|
||||
grpc_generator::Printer* printer, VARS& vars) {
|
||||
vars["filename"] = file->filename();
|
||||
printer->Print(vars,
|
||||
"//Generated by flatc compiler (version $flatc_version$)\n");
|
||||
@@ -64,7 +64,7 @@ static void GenerateImports(grpc_generator::File *file,
|
||||
// Adjust a method name prefix identifier to follow the JavaBean spec:
|
||||
// - decapitalize the first letter
|
||||
// - remove embedded underscores & capitalize the following letter
|
||||
static string MixedLower(const string &word) {
|
||||
static string MixedLower(const string& word) {
|
||||
string w;
|
||||
w += static_cast<string::value_type>(tolower(word[0]));
|
||||
bool after_underscore = false;
|
||||
@@ -84,7 +84,7 @@ 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) {
|
||||
static string ToAllUpperCase(const string& word) {
|
||||
string w;
|
||||
for (size_t i = 0; i < word.length(); ++i) {
|
||||
w += static_cast<string::value_type>(toupper(word[i]));
|
||||
@@ -95,49 +95,48 @@ static string ToAllUpperCase(const string &word) {
|
||||
return w;
|
||||
}
|
||||
|
||||
static inline string LowerMethodName(const MethodDescriptor *method) {
|
||||
static inline string LowerMethodName(const MethodDescriptor* method) {
|
||||
return MixedLower(method->name());
|
||||
}
|
||||
|
||||
static inline string MethodPropertiesFieldName(const MethodDescriptor *method) {
|
||||
static inline string MethodPropertiesFieldName(const MethodDescriptor* method) {
|
||||
return "METHOD_" + ToAllUpperCase(method->name());
|
||||
}
|
||||
|
||||
static inline string MethodPropertiesGetterName(
|
||||
const MethodDescriptor *method) {
|
||||
const MethodDescriptor* method) {
|
||||
return MixedLower("get_" + method->name() + "_method");
|
||||
}
|
||||
|
||||
static inline string MethodIdFieldName(const MethodDescriptor *method) {
|
||||
static inline string MethodIdFieldName(const MethodDescriptor* method) {
|
||||
return "METHODID_" + ToAllUpperCase(method->name());
|
||||
}
|
||||
|
||||
static inline string JavaClassName(VARS &vars, const string &name) {
|
||||
static inline string JavaClassName(VARS& vars, const string& name) {
|
||||
// string name = google::protobuf::compiler::java::ClassName(desc);
|
||||
return vars["Package"] + name;
|
||||
}
|
||||
|
||||
static inline string ServiceClassName(const string &service_name) {
|
||||
static inline string ServiceClassName(const string& service_name) {
|
||||
return service_name + "Grpc";
|
||||
}
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in
|
||||
// distribution.
|
||||
template<typename ITR>
|
||||
static void GrpcSplitStringToIteratorUsing(const string &full,
|
||||
const char *delim, ITR &result) {
|
||||
template <typename ITR>
|
||||
static void GrpcSplitStringToIteratorUsing(const string& full,
|
||||
const char* delim, ITR& result) {
|
||||
// Optimize the common case where delim is a single character.
|
||||
if (delim[0] != '\0' && delim[1] == '\0') {
|
||||
char c = delim[0];
|
||||
const char *p = full.data();
|
||||
const char *end = p + full.size();
|
||||
const char* p = full.data();
|
||||
const char* end = p + full.size();
|
||||
while (p != end) {
|
||||
if (*p == c) {
|
||||
++p;
|
||||
} else {
|
||||
const char *start = p;
|
||||
while (++p != end && *p != c)
|
||||
;
|
||||
const char* start = p;
|
||||
while (++p != end && *p != c);
|
||||
*result++ = string(start, p - start);
|
||||
}
|
||||
}
|
||||
@@ -157,13 +156,13 @@ static void GrpcSplitStringToIteratorUsing(const string &full,
|
||||
}
|
||||
}
|
||||
|
||||
static void GrpcSplitStringUsing(const string &full, const char *delim,
|
||||
std::vector<string> *result) {
|
||||
static void GrpcSplitStringUsing(const string& full, const char* delim,
|
||||
std::vector<string>* result) {
|
||||
std::back_insert_iterator<std::vector<string>> it(*result);
|
||||
GrpcSplitStringToIteratorUsing(full, delim, it);
|
||||
}
|
||||
|
||||
static std::vector<string> GrpcSplit(const string &full, const char *delim) {
|
||||
static std::vector<string> GrpcSplit(const string& full, const char* delim) {
|
||||
std::vector<string> result;
|
||||
GrpcSplitStringUsing(full, delim, &result);
|
||||
return result;
|
||||
@@ -171,7 +170,7 @@ static std::vector<string> GrpcSplit(const string &full, const char *delim) {
|
||||
|
||||
// TODO(nmittler): Remove once protobuf includes javadoc methods in
|
||||
// distribution.
|
||||
static string GrpcEscapeJavadoc(const string &input) {
|
||||
static string GrpcEscapeJavadoc(const string& input) {
|
||||
string result;
|
||||
result.reserve(input.size() * 2);
|
||||
|
||||
@@ -218,7 +217,9 @@ static string GrpcEscapeJavadoc(const string &input) {
|
||||
// Java interprets Unicode escape sequences anywhere!
|
||||
result.append("\");
|
||||
break;
|
||||
default: result.push_back(c); break;
|
||||
default:
|
||||
result.push_back(c);
|
||||
break;
|
||||
}
|
||||
|
||||
prev = c;
|
||||
@@ -227,7 +228,7 @@ static string GrpcEscapeJavadoc(const string &input) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::vector<string> GrpcGetDocLines(const string &comments) {
|
||||
static std::vector<string> GrpcGetDocLines(const 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
|
||||
@@ -238,23 +239,27 @@ static std::vector<string> GrpcGetDocLines(const string &comments) {
|
||||
string escapedComments = GrpcEscapeJavadoc(comments);
|
||||
|
||||
std::vector<string> lines = GrpcSplit(escapedComments, "\n");
|
||||
while (!lines.empty() && lines.back().empty()) { lines.pop_back(); }
|
||||
while (!lines.empty() && lines.back().empty()) {
|
||||
lines.pop_back();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
return std::vector<string>();
|
||||
}
|
||||
|
||||
static std::vector<string> GrpcGetDocLinesForDescriptor(
|
||||
const DescriptorType *descriptor) {
|
||||
const DescriptorType* descriptor) {
|
||||
return descriptor->GetAllComments();
|
||||
// return GrpcGetDocLines(descriptor->GetLeadingComments("///"));
|
||||
}
|
||||
|
||||
static void GrpcWriteDocCommentBody(Printer *printer, VARS &vars,
|
||||
const std::vector<string> &lines,
|
||||
static void GrpcWriteDocCommentBody(Printer* printer, VARS& vars,
|
||||
const std::vector<string>& lines,
|
||||
bool surroundWithPreTag) {
|
||||
if (!lines.empty()) {
|
||||
if (surroundWithPreTag) { printer->Print(" * <pre>\n"); }
|
||||
if (surroundWithPreTag) {
|
||||
printer->Print(" * <pre>\n");
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < lines.size(); i++) {
|
||||
// Most lines should start with a space. Watch out for lines that start
|
||||
@@ -268,28 +273,30 @@ static void GrpcWriteDocCommentBody(Printer *printer, VARS &vars,
|
||||
}
|
||||
}
|
||||
|
||||
if (surroundWithPreTag) { printer->Print(" * </pre>\n"); }
|
||||
if (surroundWithPreTag) {
|
||||
printer->Print(" * </pre>\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void GrpcWriteDocComment(Printer *printer, VARS &vars,
|
||||
const string &comments) {
|
||||
static void GrpcWriteDocComment(Printer* printer, VARS& vars,
|
||||
const string& comments) {
|
||||
printer->Print("/**\n");
|
||||
std::vector<string> lines = GrpcGetDocLines(comments);
|
||||
GrpcWriteDocCommentBody(printer, vars, lines, false);
|
||||
printer->Print(" */\n");
|
||||
}
|
||||
|
||||
static void GrpcWriteServiceDocComment(Printer *printer, VARS &vars,
|
||||
const ServiceDescriptor *service) {
|
||||
static void GrpcWriteServiceDocComment(Printer* printer, VARS& vars,
|
||||
const ServiceDescriptor* service) {
|
||||
printer->Print("/**\n");
|
||||
std::vector<string> lines = GrpcGetDocLinesForDescriptor(service);
|
||||
GrpcWriteDocCommentBody(printer, vars, lines, true);
|
||||
printer->Print(" */\n");
|
||||
}
|
||||
|
||||
static void GrpcWriteMethodDocComment(Printer *printer, VARS &vars,
|
||||
const MethodDescriptor *method) {
|
||||
static void GrpcWriteMethodDocComment(Printer* printer, VARS& vars,
|
||||
const MethodDescriptor* method) {
|
||||
printer->Print("/**\n");
|
||||
std::vector<string> lines = GrpcGetDocLinesForDescriptor(method);
|
||||
GrpcWriteDocCommentBody(printer, vars, lines, true);
|
||||
@@ -298,7 +305,7 @@ static void GrpcWriteMethodDocComment(Printer *printer, VARS &vars,
|
||||
|
||||
// outputs static singleton extractor for type stored in "extr_type" and
|
||||
// "extr_type_name" vars
|
||||
static void PrintTypeExtractor(Printer *p, VARS &vars) {
|
||||
static void PrintTypeExtractor(Printer* p, VARS& vars) {
|
||||
p->Print(vars,
|
||||
"private static volatile FlatbuffersUtils.FBExtactor<$extr_type$> "
|
||||
"extractorOf$extr_type_name$;\n"
|
||||
@@ -320,8 +327,8 @@ static void PrintTypeExtractor(Printer *p, VARS &vars) {
|
||||
" }\n"
|
||||
"}\n\n");
|
||||
}
|
||||
static void PrintMethodFields(Printer *p, VARS &vars,
|
||||
const ServiceDescriptor *service) {
|
||||
static void PrintMethodFields(Printer* p, VARS& vars,
|
||||
const ServiceDescriptor* service) {
|
||||
p->Print("// Static method descriptors that strictly reflect the proto.\n");
|
||||
vars["service_name"] = service->name();
|
||||
|
||||
@@ -443,11 +450,11 @@ enum StubType {
|
||||
|
||||
enum CallType { ASYNC_CALL = 0, BLOCKING_CALL = 1, FUTURE_CALL = 2 };
|
||||
|
||||
static void PrintBindServiceMethodBody(Printer *p, VARS &vars,
|
||||
const ServiceDescriptor *service);
|
||||
static void PrintBindServiceMethodBody(Printer* p, VARS& vars,
|
||||
const ServiceDescriptor* service);
|
||||
|
||||
// Prints a client interface or implementation class, or a server interface.
|
||||
static void PrintStub(Printer *p, VARS &vars, const ServiceDescriptor *service,
|
||||
static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service,
|
||||
StubType type) {
|
||||
const string service_name = service->name();
|
||||
vars["service_name"] = service_name;
|
||||
@@ -493,7 +500,9 @@ static void PrintStub(Printer *p, VARS &vars, const ServiceDescriptor *service,
|
||||
vars["client_name"] = client_name;
|
||||
|
||||
// Class head
|
||||
if (!interface) { GrpcWriteServiceDocComment(p, vars, service); }
|
||||
if (!interface) {
|
||||
GrpcWriteServiceDocComment(p, vars, service);
|
||||
}
|
||||
if (impl_base) {
|
||||
p->Print(vars,
|
||||
"public static abstract class $abstract_name$ implements "
|
||||
@@ -555,7 +564,9 @@ static void PrintStub(Printer *p, VARS &vars, const ServiceDescriptor *service,
|
||||
p->Print("\n");
|
||||
// TODO(nmittler): Replace with WriteMethodDocComment once included by the
|
||||
// protobuf distro.
|
||||
if (!interface) { GrpcWriteMethodDocComment(p, vars, &*method); }
|
||||
if (!interface) {
|
||||
GrpcWriteMethodDocComment(p, vars, &*method);
|
||||
}
|
||||
p->Print("public ");
|
||||
switch (call_type) {
|
||||
case BLOCKING_CALL:
|
||||
@@ -620,7 +631,8 @@ static void PrintStub(Printer *p, VARS &vars, const ServiceDescriptor *service,
|
||||
"responseObserver);\n");
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (!interface) {
|
||||
switch (call_type) {
|
||||
@@ -695,15 +707,15 @@ static void PrintStub(Printer *p, VARS &vars, const ServiceDescriptor *service,
|
||||
}
|
||||
|
||||
static bool CompareMethodClientStreaming(
|
||||
const std::unique_ptr<const grpc_generator::Method> &method1,
|
||||
const std::unique_ptr<const grpc_generator::Method> &method2) {
|
||||
const std::unique_ptr<const grpc_generator::Method>& method1,
|
||||
const std::unique_ptr<const grpc_generator::Method>& method2) {
|
||||
return method1->ClientStreaming() < method2->ClientStreaming();
|
||||
}
|
||||
|
||||
// Place all method invocations into a single class to reduce memory footprint
|
||||
// on Android.
|
||||
static void PrintMethodHandlerClass(Printer *p, VARS &vars,
|
||||
const ServiceDescriptor *service) {
|
||||
static void PrintMethodHandlerClass(Printer* p, VARS& vars,
|
||||
const ServiceDescriptor* service) {
|
||||
// Sort method ids based on ClientStreaming() so switch tables are compact.
|
||||
std::vector<std::unique_ptr<const grpc_generator::Method>> sorted_methods(
|
||||
service->method_count());
|
||||
@@ -713,7 +725,7 @@ static void PrintMethodHandlerClass(Printer *p, VARS &vars,
|
||||
stable_sort(sorted_methods.begin(), sorted_methods.end(),
|
||||
CompareMethodClientStreaming);
|
||||
for (size_t i = 0; i < sorted_methods.size(); i++) {
|
||||
auto &method = sorted_methods[i];
|
||||
auto& method = sorted_methods[i];
|
||||
vars["method_id"] = to_string(i);
|
||||
vars["method_id_name"] = MethodIdFieldName(&*method);
|
||||
p->Print(vars,
|
||||
@@ -746,7 +758,9 @@ static void PrintMethodHandlerClass(Printer *p, VARS &vars,
|
||||
|
||||
for (int i = 0; i < service->method_count(); ++i) {
|
||||
auto method = service->method(i);
|
||||
if (method->ClientStreaming() || method->BidiStreaming()) { continue; }
|
||||
if (method->ClientStreaming() || method->BidiStreaming()) {
|
||||
continue;
|
||||
}
|
||||
vars["method_id_name"] = MethodIdFieldName(&*method);
|
||||
vars["lower_method_name"] = LowerMethodName(&*method);
|
||||
vars["input_type"] = JavaClassName(vars, method->get_input_type_name());
|
||||
@@ -778,7 +792,9 @@ static void PrintMethodHandlerClass(Printer *p, VARS &vars,
|
||||
|
||||
for (int i = 0; i < service->method_count(); ++i) {
|
||||
auto method = service->method(i);
|
||||
if (!(method->ClientStreaming() || method->BidiStreaming())) { continue; }
|
||||
if (!(method->ClientStreaming() || method->BidiStreaming())) {
|
||||
continue;
|
||||
}
|
||||
vars["method_id_name"] = MethodIdFieldName(&*method);
|
||||
vars["lower_method_name"] = LowerMethodName(&*method);
|
||||
vars["input_type"] = JavaClassName(vars, method->get_input_type_name());
|
||||
@@ -803,8 +819,8 @@ static void PrintMethodHandlerClass(Printer *p, VARS &vars,
|
||||
p->Print("}\n\n");
|
||||
}
|
||||
|
||||
static void PrintGetServiceDescriptorMethod(Printer *p, VARS &vars,
|
||||
const ServiceDescriptor *service) {
|
||||
static void PrintGetServiceDescriptorMethod(Printer* p, VARS& vars,
|
||||
const ServiceDescriptor* service) {
|
||||
vars["service_name"] = service->name();
|
||||
// vars["proto_base_descriptor_supplier"] = service->name() +
|
||||
// "BaseDescriptorSupplier"; vars["proto_file_descriptor_supplier"] =
|
||||
@@ -896,8 +912,8 @@ static void PrintGetServiceDescriptorMethod(Printer *p, VARS &vars,
|
||||
p->Print("}\n");
|
||||
}
|
||||
|
||||
static void PrintBindServiceMethodBody(Printer *p, VARS &vars,
|
||||
const ServiceDescriptor *service) {
|
||||
static void PrintBindServiceMethodBody(Printer* p, VARS& vars,
|
||||
const ServiceDescriptor* service) {
|
||||
vars["service_name"] = service->name();
|
||||
p->Indent();
|
||||
p->Print(vars,
|
||||
@@ -949,8 +965,8 @@ static void PrintBindServiceMethodBody(Printer *p, VARS &vars,
|
||||
p->Outdent();
|
||||
}
|
||||
|
||||
static void PrintService(Printer *p, VARS &vars,
|
||||
const ServiceDescriptor *service,
|
||||
static void PrintService(Printer* p, VARS& vars,
|
||||
const ServiceDescriptor* service,
|
||||
bool disable_version) {
|
||||
vars["service_name"] = service->name();
|
||||
vars["service_class_name"] = ServiceClassName(service->name());
|
||||
@@ -1030,7 +1046,7 @@ static void PrintService(Printer *p, VARS &vars,
|
||||
p->Print("}\n");
|
||||
}
|
||||
|
||||
static void PrintStaticImports(Printer *p) {
|
||||
static void PrintStaticImports(Printer* p) {
|
||||
p->Print(
|
||||
"import java.nio.ByteBuffer;\n"
|
||||
"import static "
|
||||
@@ -1063,9 +1079,9 @@ static void PrintStaticImports(Printer *p) {
|
||||
"io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;\n\n");
|
||||
}
|
||||
|
||||
static void GenerateService(const grpc_generator::Service *service,
|
||||
grpc_generator::Printer *printer, VARS &vars,
|
||||
bool disable_version) {
|
||||
static void GenerateService(const grpc_generator::Service* service,
|
||||
grpc_generator::Printer* printer, VARS& vars,
|
||||
bool disable_version) {
|
||||
// All non-generated classes must be referred by fully qualified names to
|
||||
// avoid collision with generated classes.
|
||||
vars["String"] = "java.lang.String";
|
||||
@@ -1098,11 +1114,11 @@ static void GenerateService(const grpc_generator::Service *service,
|
||||
|
||||
PrintService(printer, vars, service, disable_version);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
grpc::string GenerateServiceSource(
|
||||
grpc_generator::File *file, const grpc_generator::Service *service,
|
||||
grpc_java_generator::Parameters *parameters) {
|
||||
grpc_generator::File* file, const grpc_generator::Service* service,
|
||||
grpc_java_generator::Parameters* parameters) {
|
||||
grpc::string out;
|
||||
auto printer = file->CreatePrinter(&out);
|
||||
VARS vars;
|
||||
|
||||
Reference in New Issue
Block a user