OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 scope_ = name_resolver_->GetImmutableClassName( | 54 scope_ = name_resolver_->GetImmutableClassName( |
55 descriptor_->extension_scope()); | 55 descriptor_->extension_scope()); |
56 } else { | 56 } else { |
57 scope_ = name_resolver_->GetImmutableClassName(descriptor_->file()); | 57 scope_ = name_resolver_->GetImmutableClassName(descriptor_->file()); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {} | 61 ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {} |
62 | 62 |
63 // Initializes the vars referenced in the generated code templates. | 63 // Initializes the vars referenced in the generated code templates. |
64 void ExtensionGenerator::InitTemplateVars(const FieldDescriptor* descriptor, | 64 void ExtensionGenerator::InitTemplateVars( |
65 const string& scope, | 65 const FieldDescriptor* descriptor, const string& scope, bool immutable, |
66 bool immutable, | 66 ClassNameResolver* name_resolver, std::map<string, string>* vars_pointer) { |
67 ClassNameResolver* name_resolver, | 67 std::map<string, string> &vars = *vars_pointer; |
68 map<string, string>* vars_pointer) { | |
69 map<string, string> &vars = *vars_pointer; | |
70 vars["scope"] = scope; | 68 vars["scope"] = scope; |
71 vars["name"] = UnderscoresToCamelCase(descriptor); | 69 vars["name"] = UnderscoresToCamelCase(descriptor); |
72 vars["containing_type"] = | 70 vars["containing_type"] = |
73 name_resolver->GetClassName(descriptor->containing_type(), immutable); | 71 name_resolver->GetClassName(descriptor->containing_type(), immutable); |
74 vars["number"] = SimpleItoa(descriptor->number()); | 72 vars["number"] = SimpleItoa(descriptor->number()); |
75 vars["constant_name"] = FieldConstantName(descriptor); | 73 vars["constant_name"] = FieldConstantName(descriptor); |
76 vars["index"] = SimpleItoa(descriptor->index()); | 74 vars["index"] = SimpleItoa(descriptor->index()); |
77 vars["default"] = descriptor->is_repeated() ? | 75 vars["default"] = descriptor->is_repeated() ? |
78 "" : DefaultValue(descriptor, immutable, name_resolver); | 76 "" : DefaultValue(descriptor, immutable, name_resolver); |
79 vars["type_constant"] = FieldTypeName(GetType(descriptor)); | 77 vars["type_constant"] = FieldTypeName(GetType(descriptor)); |
(...skipping 23 matching lines...) Expand all Loading... |
103 default: | 101 default: |
104 singular_type = BoxedPrimitiveTypeName(java_type); | 102 singular_type = BoxedPrimitiveTypeName(java_type); |
105 break; | 103 break; |
106 } | 104 } |
107 vars["type"] = descriptor->is_repeated() ? | 105 vars["type"] = descriptor->is_repeated() ? |
108 "java.util.List<" + singular_type + ">" : singular_type; | 106 "java.util.List<" + singular_type + ">" : singular_type; |
109 vars["singular_type"] = singular_type; | 107 vars["singular_type"] = singular_type; |
110 } | 108 } |
111 | 109 |
112 void ImmutableExtensionGenerator::Generate(io::Printer* printer) { | 110 void ImmutableExtensionGenerator::Generate(io::Printer* printer) { |
113 map<string, string> vars; | 111 std::map<string, string> vars; |
114 const bool kUseImmutableNames = true; | 112 const bool kUseImmutableNames = true; |
115 InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, | 113 InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, |
116 &vars); | 114 &vars); |
117 printer->Print(vars, | 115 printer->Print(vars, |
118 "public static final int $constant_name$ = $number$;\n"); | 116 "public static final int $constant_name$ = $number$;\n"); |
119 | 117 |
120 WriteFieldDocComment(printer, descriptor_); | 118 WriteFieldDocComment(printer, descriptor_); |
121 if (descriptor_->extension_scope() == NULL) { | 119 if (descriptor_->extension_scope() == NULL) { |
122 // Non-nested | 120 // Non-nested |
123 printer->Print( | 121 printer->Print( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 "registry.add($scope$.$name$);\n", | 163 "registry.add($scope$.$name$);\n", |
166 "scope", scope_, | 164 "scope", scope_, |
167 "name", UnderscoresToCamelCase(descriptor_)); | 165 "name", UnderscoresToCamelCase(descriptor_)); |
168 return 7; | 166 return 7; |
169 } | 167 } |
170 | 168 |
171 } // namespace java | 169 } // namespace java |
172 } // namespace compiler | 170 } // namespace compiler |
173 } // namespace protobuf | 171 } // namespace protobuf |
174 } // namespace google | 172 } // namespace google |
OLD | NEW |