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( | 64 void ExtensionGenerator::InitTemplateVars(const FieldDescriptor* descriptor, |
65 const FieldDescriptor* descriptor, const string& scope, bool immutable, | 65 const string& scope, |
66 ClassNameResolver* name_resolver, std::map<string, string>* vars_pointer) { | 66 bool immutable, |
67 std::map<string, string> &vars = *vars_pointer; | 67 ClassNameResolver* name_resolver, |
| 68 map<string, string>* vars_pointer) { |
| 69 map<string, string> &vars = *vars_pointer; |
68 vars["scope"] = scope; | 70 vars["scope"] = scope; |
69 vars["name"] = UnderscoresToCamelCase(descriptor); | 71 vars["name"] = UnderscoresToCamelCase(descriptor); |
70 vars["containing_type"] = | 72 vars["containing_type"] = |
71 name_resolver->GetClassName(descriptor->containing_type(), immutable); | 73 name_resolver->GetClassName(descriptor->containing_type(), immutable); |
72 vars["number"] = SimpleItoa(descriptor->number()); | 74 vars["number"] = SimpleItoa(descriptor->number()); |
73 vars["constant_name"] = FieldConstantName(descriptor); | 75 vars["constant_name"] = FieldConstantName(descriptor); |
74 vars["index"] = SimpleItoa(descriptor->index()); | 76 vars["index"] = SimpleItoa(descriptor->index()); |
75 vars["default"] = descriptor->is_repeated() ? | 77 vars["default"] = descriptor->is_repeated() ? |
76 "" : DefaultValue(descriptor, immutable, name_resolver); | 78 "" : DefaultValue(descriptor, immutable, name_resolver); |
77 vars["type_constant"] = FieldTypeName(GetType(descriptor)); | 79 vars["type_constant"] = FieldTypeName(GetType(descriptor)); |
(...skipping 23 matching lines...) Expand all Loading... |
101 default: | 103 default: |
102 singular_type = BoxedPrimitiveTypeName(java_type); | 104 singular_type = BoxedPrimitiveTypeName(java_type); |
103 break; | 105 break; |
104 } | 106 } |
105 vars["type"] = descriptor->is_repeated() ? | 107 vars["type"] = descriptor->is_repeated() ? |
106 "java.util.List<" + singular_type + ">" : singular_type; | 108 "java.util.List<" + singular_type + ">" : singular_type; |
107 vars["singular_type"] = singular_type; | 109 vars["singular_type"] = singular_type; |
108 } | 110 } |
109 | 111 |
110 void ImmutableExtensionGenerator::Generate(io::Printer* printer) { | 112 void ImmutableExtensionGenerator::Generate(io::Printer* printer) { |
111 std::map<string, string> vars; | 113 map<string, string> vars; |
112 const bool kUseImmutableNames = true; | 114 const bool kUseImmutableNames = true; |
113 InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, | 115 InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, |
114 &vars); | 116 &vars); |
115 printer->Print(vars, | 117 printer->Print(vars, |
116 "public static final int $constant_name$ = $number$;\n"); | 118 "public static final int $constant_name$ = $number$;\n"); |
117 | 119 |
118 WriteFieldDocComment(printer, descriptor_); | 120 WriteFieldDocComment(printer, descriptor_); |
119 if (descriptor_->extension_scope() == NULL) { | 121 if (descriptor_->extension_scope() == NULL) { |
120 // Non-nested | 122 // Non-nested |
121 printer->Print( | 123 printer->Print( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 "registry.add($scope$.$name$);\n", | 165 "registry.add($scope$.$name$);\n", |
164 "scope", scope_, | 166 "scope", scope_, |
165 "name", UnderscoresToCamelCase(descriptor_)); | 167 "name", UnderscoresToCamelCase(descriptor_)); |
166 return 7; | 168 return 7; |
167 } | 169 } |
168 | 170 |
169 } // namespace java | 171 } // namespace java |
170 } // namespace compiler | 172 } // namespace compiler |
171 } // namespace protobuf | 173 } // namespace protobuf |
172 } // namespace google | 174 } // namespace google |
OLD | NEW |