Go to the documentation of this file.
54 bool immutable_api,
Context* context)
56 immutable_api_(immutable_api),
58 name_resolver_(context->GetNameResolver()) {
64 if (
value == canonical_value) {
81 "public enum $classname$\n"
82 " 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;
148 "public static final int ${$$name$_VALUE$}$ = $number$;\n");
151 printer->
Print(
"\n");
157 "public final int getNumber() {\n");
159 if (ordinal_is_index) {
161 " if (this == UNRECOGNIZED) {\n"
162 " throw new java.lang.IllegalArgumentException(\n"
163 " \"Can't get the number of an unknown enum value.\");\n"
167 " if (index == -1) {\n"
168 " throw new java.lang.IllegalArgumentException(\n"
169 " \"Can't get the number of an unknown enum value.\");\n"
178 " * @deprecated Use {@link #forNumber(int)} instead.\n"
180 "@java.lang.Deprecated\n"
181 "public static $classname$ valueOf(int value) {\n"
182 " return forNumber(value);\n"
185 "public static $classname$ forNumber(int value) {\n"
186 " switch (value) {\n",
192 printer->
Print(
"case $number$: return $name$;\n",
"name",
200 " default: return null;\n"
204 "public static com.google.protobuf.Internal.EnumLiteMap<$classname$>\n"
205 " internalGetValueMap() {\n"
206 " return internalValueMap;\n"
208 "private static final com.google.protobuf.Internal.EnumLiteMap<\n"
209 " $classname$> internalValueMap =\n"
210 " new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n"
211 " public $classname$ findValueByNumber(int number) {\n"
212 " return $classname$.forNumber(number);\n"
223 "public final com.google.protobuf.Descriptors.EnumValueDescriptor\n"
224 " getValueDescriptor() {\n"
225 " return getDescriptor().getValues().get($index_text$);\n"
227 "public final com.google.protobuf.Descriptors.EnumDescriptor\n"
228 " getDescriptorForType() {\n"
229 " return getDescriptor();\n"
231 "public static final com.google.protobuf.Descriptors.EnumDescriptor\n"
232 " getDescriptor() {\n",
233 "index_text", index_text);
243 " return $file$.getDescriptor().getEnumTypes().get($index$);\n",
249 " return $parent$.$descriptor$.getEnumTypes().get($index$);\n",
257 ?
"getDefaultInstance().getDescriptorForType()"
265 "private static final $classname$[] VALUES = ",
273 printer->
Print(
"values();\n");
288 "public static $classname$ valueOf(\n"
289 " com.google.protobuf.Descriptors.EnumValueDescriptor desc) {\n"
290 " if (desc.getType() != getDescriptor()) {\n"
291 " throw new java.lang.IllegalArgumentException(\n"
292 " \"EnumValueDescriptor is not for this type.\");\n"
297 " if (desc.getIndex() == -1) {\n"
298 " return UNRECOGNIZED;\n"
302 " return VALUES[desc.getIndex()];\n"
306 if (!ordinal_is_index) {
307 printer->
Print(
"private final int index;\n");
313 printer->
Print(
"private final int value;\n\n");
315 if (ordinal_is_index) {
316 printer->
Print(
"private $classname$(int value) {\n",
"classname",
319 printer->
Print(
"private $classname$(int index, int value) {\n",
"classname",
324 printer->
Print(
" this.index = index;\n");
327 " this.value = value;\n"
332 "// @@protoc_insertion_point(enum_scope:$full_name$)\n",
336 printer->
Print(
"}\n\n");
void Print(const std::map< std::string, std::string > &variables, const char *text)
void WriteEnumDocComment(io::Printer *printer, const EnumDescriptor *enum_)
MockGeneratorContext context_
void MaybePrintGeneratedAnnotation(Context *context, io::Printer *printer, Descriptor *descriptor, bool immutable, const std::string &suffix="")
GLuint const GLchar * name
const Descriptor::ReservedRange value
bool HasDescriptorMethods(const Descriptor *descriptor, bool enforce_lite)
const EnumValueDescriptor * value
string StrCat(const AlphaNum &a, const AlphaNum &b)
std::vector< const EnumValueDescriptor * > canonical_values_
void WriteEnumValueDocComment(io::Printer *printer, const EnumValueDescriptor *value)
GLsizei const GLchar *const * string
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< Alias > aliases_
const std::string & name() const
bool SupportUnknownEnumValue(const FileDescriptor *descriptor)
const FileDescriptor * file() const
const EnumValueDescriptor * value(int index) const
ClassNameResolver * name_resolver_
void Generate(io::Printer *printer)
void Annotate(const char *varname, const SomeDescriptor *descriptor)
const EnumDescriptor * descriptor_
const Descriptor * containing_type() const
const std::string & full_name() const
bool no_standard_descriptor_accessor() const
std::string GetClassName(const Descriptor *descriptor, bool immutable)
GLsizei const GLfloat * value
const Descriptor * descriptor_
const EnumValueDescriptor * canonical_value
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:54