diff options
Diffstat (limited to 'src/compiler/java_plugin.cc')
-rw-r--r-- | src/compiler/java_plugin.cc | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/compiler/java_plugin.cc b/src/compiler/java_plugin.cc deleted file mode 100644 index f6f327291b..0000000000 --- a/src/compiler/java_plugin.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Copyright 2014, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -// Generates Java gRPC service interface out of Protobuf IDL. -// -// This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto -// and net/proto2/compiler/public/plugin.h for more information on plugins. - -#include <memory> - -#include "src/compiler/java_generator.h" -#include <google/protobuf/compiler/code_generator.h> -#include <google/protobuf/compiler/plugin.h> -#include <google/protobuf/io/zero_copy_stream.h> -#include <google/protobuf/descriptor.h> - -static string JavaPackageToDir(const string& package_name) { - string package_dir = package_name; - for (size_t i = 0; i < package_dir.size(); ++i) { - if (package_dir[i] == '.') { - package_dir[i] = '/'; - } - } - if (!package_dir.empty()) package_dir += "/"; - return package_dir; -} - -class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator { - public: - JavaGrpcGenerator() {} - virtual ~JavaGrpcGenerator() {} - - virtual bool Generate(const google::protobuf::FileDescriptor* file, - const string& parameter, - google::protobuf::compiler::GeneratorContext* context, - string* error) const { - string package_name = java_grpc_generator::ServiceJavaPackage(file); - 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 - + java_grpc_generator::ServiceClassName(service) + ".java"; - std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output( - context->Open(filename)); - java_grpc_generator::GenerateService(service, output.get()); - } - return true; - } -}; - -int main(int argc, char* argv[]) { - JavaGrpcGenerator generator; - return google::protobuf::compiler::PluginMain(argc, argv, &generator); -} |