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

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

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

Powered by Google App Engine
This is Rietveld 408576698