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 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ 13 #define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ 14 15 #include <string> 16 #include <vector> 17 18 #include "google/protobuf/compiler/java/generator_factory.h" 19 #include "google/protobuf/descriptor.h" 20 21 namespace google { 22 namespace protobuf { 23 namespace compiler { 24 namespace java { 25 class Context; // context.h 26 class ClassNameResolver; // name_resolver.h 27 } // namespace java 28 } // namespace compiler 29 namespace io { 30 class Printer; // printer.h 31 } 32 } // namespace protobuf 33 } // namespace google 34 35 namespace google { 36 namespace protobuf { 37 namespace compiler { 38 namespace java { 39 40 class EnumLiteGenerator : public EnumGenerator { 41 public: 42 EnumLiteGenerator(const EnumDescriptor* descriptor, bool immutable_api, 43 Context* context); 44 EnumLiteGenerator(const EnumLiteGenerator&) = delete; 45 EnumLiteGenerator& operator=(const EnumLiteGenerator&) = delete; 46 ~EnumLiteGenerator(); 47 48 void Generate(io::Printer* printer) override; 49 50 private: 51 const EnumDescriptor* descriptor_; 52 53 // The proto language allows multiple enum constants to have the same 54 // numeric value. Java, however, does not allow multiple enum constants to 55 // be considered equivalent. We treat the first defined constant for any 56 // given numeric value as "canonical" and the rest as aliases of that 57 // canonical value. 58 std::vector<const EnumValueDescriptor*> canonical_values_; 59 60 struct Alias { 61 const EnumValueDescriptor* value; 62 const EnumValueDescriptor* canonical_value; 63 }; 64 std::vector<Alias> aliases_; 65 66 bool immutable_api_; 67 68 Context* context_; 69 ClassNameResolver* name_resolver_; 70 }; 71 72 } // namespace java 73 } // namespace compiler 74 } // namespace protobuf 75 } // namespace google 76 77 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ 78