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 // Generates Kotlin code for a given .proto file. 9 10 #ifndef GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__ 11 #define GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__ 12 13 #include <cstdint> 14 #include <string> 15 #include <vector> 16 17 #include "google/protobuf/compiler/java/java_features.pb.h" 18 #include "google/protobuf/compiler/code_generator.h" 19 #include "google/protobuf/descriptor.pb.h" 20 21 // Must be included last. 22 #include "google/protobuf/port_def.inc" 23 24 namespace google { 25 namespace protobuf { 26 namespace compiler { 27 namespace kotlin { 28 29 // CodeGenerator implementation which generates Kotlin code. If you create your 30 // own protocol compiler binary and you want it to support Kotlin output, you 31 // can do so by registering an instance of this CodeGenerator with the 32 // CommandLineInterface in your main() function. 33 class PROTOC_EXPORT KotlinGenerator : public CodeGenerator { 34 public: 35 KotlinGenerator(); 36 KotlinGenerator(const KotlinGenerator&) = delete; 37 KotlinGenerator& operator=(const KotlinGenerator&) = delete; 38 ~KotlinGenerator() override; 39 40 // implements CodeGenerator ---------------------------------------- 41 bool Generate(const FileDescriptor* file, const std::string& parameter, 42 GeneratorContext* context, std::string* error) const override; 43 44 uint64_t GetSupportedFeatures() const override; 45 GetMinimumEdition()46 Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } GetMaximumEdition()47 Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } 48 GetFeatureExtensions()49 std::vector<const FieldDescriptor*> GetFeatureExtensions() const override { 50 return {GetExtensionReflection(pb::java)}; 51 } 52 53 using CodeGenerator::GetResolvedSourceFeatures; 54 }; 55 56 } // namespace kotlin 57 } // namespace compiler 58 } // namespace protobuf 59 } // namespace google 60 61 #include "google/protobuf/port_undef.inc" 62 63 #endif // GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__ 64