Class Descriptors.EnumDescriptor
java.lang.Object
com.google.protobuf.Descriptors.GenericDescriptor
com.google.protobuf.Descriptors.EnumDescriptor
- All Implemented Interfaces:
Internal.EnumLiteMap<Descriptors.EnumValueDescriptor>
- Enclosing class:
Descriptors
public static final class Descriptors.EnumDescriptor
extends Descriptors.GenericDescriptor
implements Internal.EnumLiteMap<Descriptors.EnumValueDescriptor>
Describes an enum type.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final Stringprivate final intprivate DescriptorProtos.EnumOptionsprivate final Descriptors.GenericDescriptorprivate final booleanprivate Map<Integer, WeakReference<Descriptors.EnumValueDescriptor>> private final Descriptors.EnumValueDescriptor[]private final Descriptors.EnumValueDescriptor[]Fields inherited from class Descriptors.GenericDescriptor
features -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateEnumDescriptor(DescriptorProtos.EnumDescriptorProto proto, Descriptors.FileDescriptor file, Descriptors.Descriptor parent, int index) privateEnumDescriptor(String fullName) -
Method Summary
Modifier and TypeMethodDescriptionfindValueByName(String name) Find an enum value by name.findValueByNumber(int number) Find an enum value by number.findValueByNumberCreatingIfUnknown(int number) Get the enum value for a number.If this is a nested type, get the outer descriptor, otherwise null.getFile()Get theDescriptors.FileDescriptorcontaining this descriptor.Get the type's fully-qualified name.intgetIndex()Get the index of this descriptor within its parent.getName()Get the type's unqualified name.Get theEnumOptions, defined indescriptor.proto.(package private) Descriptors.GenericDescriptor(package private) intgetValue(int index) intGet a list of defined values for this enum.booleanisClosed()Determines if the given enum is closed.booleanbooleanisReservedName(String name) Determines if the given field name is reserved.booleanisReservedNumber(int number) Determines if the given field number is reserved.private voidSee.invalid reference
FileDescriptor#resolveAllFeaturesprivate voidtoProto()Convert the descriptor to its protocol message representation.Methods inherited from class Descriptors.GenericDescriptor
getFeatures, inferLegacyProtoFeatures, resolveFeatures, validateFeatures
-
Field Details
-
index
private final int index -
proto
-
options
-
fullName
-
parent
-
values
-
valuesSortedByNumber
-
distinctNumbers
private final int distinctNumbers -
unknownValues
-
cleanupQueue
-
placeholder
private final boolean placeholder
-
-
Constructor Details
-
EnumDescriptor
-
EnumDescriptor
private EnumDescriptor(DescriptorProtos.EnumDescriptorProto proto, Descriptors.FileDescriptor file, Descriptors.Descriptor parent, int index) throws Descriptors.DescriptorValidationException
-
-
Method Details
-
getIndex
public int getIndex()Get the index of this descriptor within its parent.- See Also:
-
toProto
Convert the descriptor to its protocol message representation.- Specified by:
toProtoin classDescriptors.GenericDescriptor
-
getName
Get the type's unqualified name.- Specified by:
getNamein classDescriptors.GenericDescriptor
-
getFullName
Get the type's fully-qualified name.- Specified by:
getFullNamein classDescriptors.GenericDescriptor- See Also:
-
getFile
Get theDescriptors.FileDescriptorcontaining this descriptor.- Specified by:
getFilein classDescriptors.GenericDescriptor
-
getParent
Descriptors.GenericDescriptor getParent()- Specified by:
getParentin classDescriptors.GenericDescriptor
-
isPlaceholder
public boolean isPlaceholder() -
isClosed
public boolean isClosed()Determines if the given enum is closed.Closed enum means that it:
- Has a fixed set of values, rather than being equivalent to an int32.
- Encountering values not in this set causes them to be treated as unknown fields.
- The first value (i.e., the default) may be nonzero.
WARNING: Some runtimes currently have a quirk where non-closed enums are treated as closed when used as the type of fields defined in a `syntax = proto2;` file. This quirk is not present in all runtimes; as of writing, we know that:
- C++, Java, and C++-based Python share this quirk.
- UPB and UPB-based Python do not.
- PHP and Ruby treat all enums as open regardless of declaration.
Care should be taken when using this function to respect the target runtime's enum handling quirks.
-
getContainingType
If this is a nested type, get the outer descriptor, otherwise null. -
getOptions
Get theEnumOptions, defined indescriptor.proto. -
getValues
Get a list of defined values for this enum. -
getValueCount
public int getValueCount() -
getValue
-
isReservedNumber
public boolean isReservedNumber(int number) Determines if the given field number is reserved. -
isReservedName
Determines if the given field name is reserved. -
findValueByName
Find an enum value by name.- Parameters:
name- the unqualified name of the value such as "FOO"- Returns:
- the value's descriptor, or
nullif not found
-
findValueByNumber
Find an enum value by number. If multiple enum values have the same number, this returns the first defined value with that number.- Specified by:
findValueByNumberin interfaceInternal.EnumLiteMap<Descriptors.EnumValueDescriptor>- Parameters:
number- The value's number.- Returns:
- the value's descriptor, or
nullif not found.
-
findValueByNumberCreatingIfUnknown
Get the enum value for a number. If no enum value has this number, construct an EnumValueDescriptor for it. -
getUnknownEnumValueDescriptorCount
int getUnknownEnumValueDescriptorCount() -
resolveAllFeatures
See.invalid reference
FileDescriptor#resolveAllFeatures -
setProto
private void setProto(DescriptorProtos.EnumDescriptorProto proto) throws Descriptors.DescriptorValidationException
-