Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/java/java_enum_lite.cc

Issue 2599263002: third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Address comments Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
54 if (descriptor->options().unknown_fields().field_count() > 0) return true; 54 if (descriptor->options().unknown_fields().field_count() > 0) return true;
55 for (int i = 0; i < descriptor->value_count(); ++i) { 55 for (int i = 0; i < descriptor->value_count(); ++i) {
56 const EnumValueDescriptor* value = descriptor->value(i); 56 const EnumValueDescriptor* value = descriptor->value(i);
57 if (value->options().unknown_fields().field_count() > 0) return true; 57 if (value->options().unknown_fields().field_count() > 0) return true;
58 } 58 }
59 return false; 59 return false;
60 } 60 }
61 } // namespace 61 } // namespace
62 62
63 EnumLiteGenerator::EnumLiteGenerator(const EnumDescriptor* descriptor, 63 EnumLiteGenerator::EnumLiteGenerator(const EnumDescriptor* descriptor,
64 bool immutable_api, 64 bool immutable_api, Context* context)
65 Context* context) 65 : descriptor_(descriptor),
66 : descriptor_(descriptor), immutable_api_(immutable_api), 66 immutable_api_(immutable_api),
67 name_resolver_(context->GetNameResolver()) { 67 context_(context),
68 name_resolver_(context->GetNameResolver()) {
68 for (int i = 0; i < descriptor_->value_count(); i++) { 69 for (int i = 0; i < descriptor_->value_count(); i++) {
69 const EnumValueDescriptor* value = descriptor_->value(i); 70 const EnumValueDescriptor* value = descriptor_->value(i);
70 const EnumValueDescriptor* canonical_value = 71 const EnumValueDescriptor* canonical_value =
71 descriptor_->FindValueByNumber(value->number()); 72 descriptor_->FindValueByNumber(value->number());
72 73
73 if (value == canonical_value) { 74 if (value == canonical_value) {
74 canonical_values_.push_back(value); 75 canonical_values_.push_back(value);
75 } else { 76 } else {
76 Alias alias; 77 Alias alias;
77 alias.value = value; 78 alias.value = value;
78 alias.canonical_value = canonical_value; 79 alias.canonical_value = canonical_value;
79 aliases_.push_back(alias); 80 aliases_.push_back(alias);
80 } 81 }
81 } 82 }
82 } 83 }
83 84
84 EnumLiteGenerator::~EnumLiteGenerator() {} 85 EnumLiteGenerator::~EnumLiteGenerator() {}
85 86
86 void EnumLiteGenerator::Generate(io::Printer* printer) { 87 void EnumLiteGenerator::Generate(io::Printer* printer) {
87 WriteEnumDocComment(printer, descriptor_); 88 WriteEnumDocComment(printer, descriptor_);
89 MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_);
88 printer->Print( 90 printer->Print(
89 "public enum $classname$\n" 91 "public enum $classname$\n"
90 " implements com.google.protobuf.Internal.EnumLite {\n", 92 " implements com.google.protobuf.Internal.EnumLite {\n",
91 "classname", descriptor_->name()); 93 "classname", descriptor_->name());
94 printer->Annotate("classname", descriptor_);
92 printer->Indent(); 95 printer->Indent();
93 96
94 for (int i = 0; i < canonical_values_.size(); i++) { 97 for (int i = 0; i < canonical_values_.size(); i++) {
95 map<string, string> vars; 98 std::map<string, string> vars;
96 vars["name"] = canonical_values_[i]->name(); 99 vars["name"] = canonical_values_[i]->name();
97 vars["number"] = SimpleItoa(canonical_values_[i]->number()); 100 vars["number"] = SimpleItoa(canonical_values_[i]->number());
98 WriteEnumValueDocComment(printer, canonical_values_[i]); 101 WriteEnumValueDocComment(printer, canonical_values_[i]);
99 if (canonical_values_[i]->options().deprecated()) { 102 if (canonical_values_[i]->options().deprecated()) {
100 printer->Print("@java.lang.Deprecated\n"); 103 printer->Print("@java.lang.Deprecated\n");
101 } 104 }
102 printer->Print(vars, 105 printer->Print(vars,
103 "$name$($number$),\n"); 106 "$name$($number$),\n");
104 } 107 }
105 108
106 if (SupportUnknownEnumValue(descriptor_->file())) { 109 if (SupportUnknownEnumValue(descriptor_->file())) {
107 printer->Print("UNRECOGNIZED(-1),\n"); 110 printer->Print("UNRECOGNIZED(-1),\n");
108 } 111 }
109 112
110 printer->Print( 113 printer->Print(
111 ";\n" 114 ";\n"
112 "\n"); 115 "\n");
113 116
114 // ----------------------------------------------------------------- 117 // -----------------------------------------------------------------
115 118
116 for (int i = 0; i < aliases_.size(); i++) { 119 for (int i = 0; i < aliases_.size(); i++) {
117 map<string, string> vars; 120 std::map<string, string> vars;
118 vars["classname"] = descriptor_->name(); 121 vars["classname"] = descriptor_->name();
119 vars["name"] = aliases_[i].value->name(); 122 vars["name"] = aliases_[i].value->name();
120 vars["canonical_name"] = aliases_[i].canonical_value->name(); 123 vars["canonical_name"] = aliases_[i].canonical_value->name();
121 WriteEnumValueDocComment(printer, aliases_[i].value); 124 WriteEnumValueDocComment(printer, aliases_[i].value);
122 printer->Print(vars, 125 printer->Print(vars,
123 "public static final $classname$ $name$ = $canonical_name$;\n"); 126 "public static final $classname$ $name$ = $canonical_name$;\n");
124 } 127 }
125 128
126 for (int i = 0; i < descriptor_->value_count(); i++) { 129 for (int i = 0; i < descriptor_->value_count(); i++) {
127 map<string, string> vars; 130 std::map<string, string> vars;
128 vars["name"] = descriptor_->value(i)->name(); 131 vars["name"] = descriptor_->value(i)->name();
129 vars["number"] = SimpleItoa(descriptor_->value(i)->number()); 132 vars["number"] = SimpleItoa(descriptor_->value(i)->number());
130 WriteEnumValueDocComment(printer, descriptor_->value(i)); 133 WriteEnumValueDocComment(printer, descriptor_->value(i));
131 printer->Print(vars, 134 printer->Print(vars,
132 "public static final int $name$_VALUE = $number$;\n"); 135 "public static final int $name$_VALUE = $number$;\n");
133 } 136 }
134 printer->Print("\n"); 137 printer->Print("\n");
135 138
136 // ----------------------------------------------------------------- 139 // -----------------------------------------------------------------
137 140
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 return false; 212 return false;
210 } 213 }
211 } 214 }
212 return true; 215 return true;
213 } 216 }
214 217
215 } // namespace java 218 } // namespace java
216 } // namespace compiler 219 } // namespace compiler
217 } // namespace protobuf 220 } // namespace protobuf
218 } // namespace google 221 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698