Go to the documentation of this file.
38 #include <google/protobuf/compiler/java/java_context.h>
39 #include <google/protobuf/compiler/java/java_doc_comment.h>
40 #include <google/protobuf/compiler/java/java_enum.h>
41 #include <google/protobuf/compiler/java/java_helpers.h>
42 #include <google/protobuf/compiler/java/java_name_resolver.h>
43 #include <google/protobuf/descriptor.pb.h>
44 #include <google/protobuf/io/printer.h>
45 #include <google/protobuf/stubs/strutil.h>
53 bool immutable_api, Context*
context)
55 immutable_api_(immutable_api),
57 name_resolver_(
context->GetNameResolver()) {
63 if (
value == canonical_value) {
68 alias.canonical_value = canonical_value;
80 "$deprecation$public enum $classname$\n"
81 " implements com.google.protobuf.ProtocolMessageEnum {\n",
87 bool ordinal_is_index =
true;
91 ordinal_is_index =
false;
98 std::map<std::string, std::string> vars;
104 printer->Print(
"@java.lang.Deprecated\n");
106 if (ordinal_is_index) {
107 printer->Print(vars,
"$name$($number$),\n");
109 printer->Print(vars,
"$name$($index$, $number$),\n");
115 if (ordinal_is_index) {
116 printer->Print(
"${$UNRECOGNIZED$}$(-1),\n",
"{",
"",
"}",
"");
118 printer->Print(
"${$UNRECOGNIZED$}$(-1, -1),\n",
"{",
"",
"}",
"");
130 std::map<std::string, std::string> vars;
132 vars[
"name"] =
aliases_[
i].value->name();
133 vars[
"canonical_name"] =
aliases_[
i].canonical_value->name();
136 vars,
"public static final $classname$ $name$ = $canonical_name$;\n");
141 std::map<std::string, std::string> vars;
147 ?
"@java.lang.Deprecated "
151 "$deprecation$public static final int ${$$name$_VALUE$}$ = "
155 printer->Print(
"\n");
161 "public final int getNumber() {\n");
163 if (ordinal_is_index) {
165 " if (this == UNRECOGNIZED) {\n"
166 " throw new java.lang.IllegalArgumentException(\n"
167 " \"Can't get the number of an unknown enum value.\");\n"
171 " if (index == -1) {\n"
172 " throw new java.lang.IllegalArgumentException(\n"
173 " \"Can't get the number of an unknown enum value.\");\n"
182 " * @param value The numeric wire value of the corresponding enum "
184 " * @return The enum associated with the given numeric wire value.\n"
185 " * @deprecated Use {@link #forNumber(int)} instead.\n"
187 "@java.lang.Deprecated\n"
188 "public static $classname$ valueOf(int value) {\n"
189 " return forNumber(value);\n"
193 " * @param value The numeric wire value of the corresponding enum "
195 " * @return The enum associated with the given numeric wire value.\n"
197 "public static $classname$ forNumber(int value) {\n"
198 " switch (value) {\n",
204 printer->Print(
"case $number$: return $name$;\n",
"name",
212 " default: return null;\n"
216 "public static com.google.protobuf.Internal.EnumLiteMap<$classname$>\n"
217 " internalGetValueMap() {\n"
218 " return internalValueMap;\n"
220 "private static final com.google.protobuf.Internal.EnumLiteMap<\n"
221 " $classname$> internalValueMap =\n"
222 " new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n"
223 " public $classname$ findValueByNumber(int number) {\n"
224 " return $classname$.forNumber(number);\n"
235 "public final com.google.protobuf.Descriptors.EnumValueDescriptor\n"
236 " getValueDescriptor() {\n");
238 if (ordinal_is_index) {
240 " if (this == UNRECOGNIZED) {\n"
241 " throw new java.lang.IllegalStateException(\n"
242 " \"Can't get the descriptor of an unrecognized enum "
247 " if (index == -1) {\n"
248 " throw new java.lang.IllegalStateException(\n"
249 " \"Can't get the descriptor of an unrecognized enum "
255 " return getDescriptor().getValues().get($index_text$);\n"
257 "public final com.google.protobuf.Descriptors.EnumDescriptor\n"
258 " getDescriptorForType() {\n"
259 " return getDescriptor();\n"
261 "public static final com.google.protobuf.Descriptors.EnumDescriptor\n"
262 " getDescriptor() {\n",
263 "index_text", index_text);
273 " return $file$.getDescriptor().getEnumTypes().get($index$);\n",
279 " return $parent$.$descriptor$.getEnumTypes().get($index$);\n",
287 ?
"getDefaultInstance().getDescriptorForType()"
295 "private static final $classname$[] VALUES = ",
303 printer->Print(
"values();\n");
305 printer->Print(
"getStaticValuesArray();\n");
306 printer->Print(
"private static $classname$[] getStaticValuesArray() {\n",
310 "return new $classname$[] {\n"
325 "public static $classname$ valueOf(\n"
326 " com.google.protobuf.Descriptors.EnumValueDescriptor desc) {\n"
327 " if (desc.getType() != getDescriptor()) {\n"
328 " throw new java.lang.IllegalArgumentException(\n"
329 " \"EnumValueDescriptor is not for this type.\");\n"
334 " if (desc.getIndex() == -1) {\n"
335 " return UNRECOGNIZED;\n"
339 " return VALUES[desc.getIndex()];\n"
343 if (!ordinal_is_index) {
344 printer->Print(
"private final int index;\n");
350 printer->Print(
"private final int value;\n\n");
352 if (ordinal_is_index) {
353 printer->Print(
"private $classname$(int value) {\n",
"classname",
356 printer->Print(
"private $classname$(int index, int value) {\n",
"classname",
361 printer->Print(
" this.index = index;\n");
364 " this.value = value;\n"
369 "// @@protoc_insertion_point(enum_scope:$full_name$)\n",
373 printer->Print(
"}\n\n");
void WriteEnumDocComment(io::Printer *printer, const EnumDescriptor *enum_)
void MaybePrintGeneratedAnnotation(Context *context, io::Printer *printer, Descriptor *descriptor, bool immutable, const std::string &suffix="")
const Descriptor::ReservedRange value
const EnumValueOptions & options() const
bool HasDescriptorMethods(const Descriptor *descriptor, bool enforce_lite)
const EnumDescriptor * descriptor_
ClassNameResolver * name_resolver_
void WriteEnumValueDocComment(io::Printer *printer, const EnumValueDescriptor *value)
GRPC_CUSTOM_PRINTER Printer
string StrCat(const AlphaNum &a, const AlphaNum &b)
const MessageOptions & options() const
const std::string & name() const
const EnumValueDescriptor * FindValueByNumber(int number) const
EnumGenerator(const EnumDescriptor *descriptor, bool immutable_api, Context *context)
std::vector< const EnumValueDescriptor * > canonical_values_
const std::string & name() const
bool SupportUnknownEnumValue(const FileDescriptor *descriptor)
const FileDescriptor * file() const
const EnumValueDescriptor * value(int index) const
void Generate(io::Printer *printer)
const Descriptor * containing_type() const
const std::string & full_name() const
const EnumOptions & options() const
bool no_standard_descriptor_accessor() const
grpc::ClientContext context
std::string GetClassName(const Descriptor *descriptor, bool immutable)
std::vector< Alias > aliases_
static const char descriptor[1336]
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:08