1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 // Author: kenton@google.com (Kenton Varda) 9 // Based on original Protocol Buffers design by 10 // Sanjay Ghemawat, Jeff Dean, and others. 11 // 12 // Generates Java code for a given .proto file. 13 14 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ 15 #define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ 16 17 #include <cstdint> 18 #include <string> 19 #include <vector> 20 21 #include "google/protobuf/compiler/java/java_features.pb.h" 22 #include "google/protobuf/compiler/code_generator.h" 23 #include "google/protobuf/descriptor.pb.h" 24 #include "google/protobuf/port.h" 25 26 // Must be included last. 27 #include "google/protobuf/port_def.inc" 28 29 namespace google { 30 namespace protobuf { 31 namespace compiler { 32 namespace java { 33 34 // CodeGenerator implementation which generates Java code. If you create your 35 // own protocol compiler binary and you want it to support Java output, you 36 // can do so by registering an instance of this CodeGenerator with the 37 // CommandLineInterface in your main() function. 38 class PROTOC_EXPORT JavaGenerator : public CodeGenerator { 39 public: 40 JavaGenerator(); 41 JavaGenerator(const JavaGenerator&) = delete; 42 JavaGenerator& operator=(const JavaGenerator&) = delete; 43 ~JavaGenerator() override; 44 45 // implements CodeGenerator ---------------------------------------- 46 bool Generate(const FileDescriptor* file, const std::string& parameter, 47 GeneratorContext* context, std::string* error) const override; 48 49 uint64_t GetSupportedFeatures() const override; 50 GetMinimumEdition()51 Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } GetMaximumEdition()52 Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } 53 GetFeatureExtensions()54 std::vector<const FieldDescriptor*> GetFeatureExtensions() const override { 55 return {GetExtensionReflection(pb::java)}; 56 } 57 set_opensource_runtime(bool opensource)58 void set_opensource_runtime(bool opensource) { 59 opensource_runtime_ = opensource; 60 } 61 62 using CodeGenerator::GetEdition; 63 using CodeGenerator::GetResolvedSourceFeatures; 64 65 private: 66 bool opensource_runtime_ = google::protobuf::internal::IsOss(); 67 }; 68 69 } // namespace java 70 } // namespace compiler 71 } // namespace protobuf 72 } // namespace google 73 74 #include "google/protobuf/port_undef.inc" 75 76 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ 77