|
||||
File indexing completed on 2025-01-31 10:11:58
0001 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_COMMON_H__ 0002 #define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_COMMON_H__ 0003 0004 #include <string> 0005 0006 #include "google/protobuf/descriptor.h" 0007 0008 namespace google { 0009 namespace protobuf { 0010 namespace compiler { 0011 namespace java { 0012 0013 // Field information used in FieldGenerators. 0014 struct FieldGeneratorInfo { 0015 std::string name; 0016 std::string capitalized_name; 0017 std::string disambiguated_reason; 0018 }; 0019 0020 // Oneof information used in OneofFieldGenerators. 0021 struct OneofGeneratorInfo { 0022 std::string name; 0023 std::string capitalized_name; 0024 }; 0025 0026 // Set some common variables used in variable FieldGenerators. 0027 void SetCommonFieldVariables( 0028 const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, 0029 absl::flat_hash_map<absl::string_view, std::string>* variables); 0030 0031 // Set some common oneof variables used in OneofFieldGenerators. 0032 void SetCommonOneofVariables( 0033 const FieldDescriptor* descriptor, const OneofGeneratorInfo* info, 0034 absl::flat_hash_map<absl::string_view, std::string>* variables); 0035 0036 // Print useful comments before a field's accessors. 0037 void PrintExtraFieldInfo( 0038 const absl::flat_hash_map<absl::string_view, std::string>& variables, 0039 io::Printer* printer); 0040 0041 // Returns the name by which the generated Java getters and setters should be 0042 // referenced from Kotlin as properties. In the simplest case, the original name 0043 // is something like `foo_bar`, which gets translated into `getFooBar()` etc, 0044 // and that in turn can be referenced from Kotlin as `fooBar`. 0045 // 0046 // The algorithm for translating proto names into Java getters and setters is 0047 // straightforward. The first letter of each underscore-separated word gets 0048 // uppercased and the underscores are deleted. There are no other changes, so in 0049 // particular if the proto name has a string of capitals then those remain 0050 // as-is. 0051 // 0052 // The algorithm that the Kotlin compiler uses to derive the property name is 0053 // slightly more complicated. If the first character after `get` (etc) is a 0054 // capital and the second isn't, then the property name is just that string with 0055 // its first letter lowercased. So `getFoo` becomes `foo` and `getX` becomes 0056 // `x`. But if there is more than one capital, then all but the last get 0057 // lowercased. So `getHTMLPage` becomes `htmlPage`. If there are only capitals 0058 // then they all get lowercased, so `getID` becomes `id`. 0059 // TODO: move this to a Kotlin-specific location 0060 std::string GetKotlinPropertyName(std::string capitalized_name); 0061 0062 } // namespace java 0063 } // namespace compiler 0064 } // namespace protobuf 0065 } // namespace google 0066 0067 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_COMMON_H__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |