Package com.google.protobuf
Class Descriptors.FileDescriptor
- java.lang.Object
-
- com.google.protobuf.Descriptors.GenericDescriptor
-
- com.google.protobuf.Descriptors.FileDescriptor
-
- Enclosing class:
- Descriptors
public static final class Descriptors.FileDescriptor extends Descriptors.GenericDescriptor
Describes a.protofile, including everything defined within. That includes, in particular, descriptors for all the messages and file descriptors for all other imported.protofiles (dependencies).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDescriptors.FileDescriptor.InternalDescriptorAssignerDeprecated.static classDescriptors.FileDescriptor.SyntaxDeprecated.
-
Field Summary
Fields Modifier and Type Field Description private Descriptors.FileDescriptor[]dependenciesprivate Descriptors.EnumDescriptor[]enumTypesprivate Descriptors.FieldDescriptor[]extensionsprivate Descriptors.Descriptor[]messageTypesprivate Descriptors.DescriptorPoolpoolprivate DescriptorProtos.FileDescriptorProtoprotoprivate Descriptors.FileDescriptor[]publicDependenciesprivate Descriptors.ServiceDescriptor[]services
-
Constructor Summary
Constructors Modifier Constructor Description privateFileDescriptor(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, Descriptors.DescriptorPool pool, boolean allowUnknownDependencies)(package private)FileDescriptor(java.lang.String packageName, Descriptors.Descriptor message)Create a placeholder FileDescriptor for a message Descriptor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Descriptors.FileDescriptorbuildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies)Construct aFileDescriptor.static Descriptors.FileDescriptorbuildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, boolean allowUnknownDependencies)Construct aFileDescriptor.voidcopyHeadingTo(DescriptorProtos.FileDescriptorProto.Builder protoBuilder)private voidcrossLink()Look up and cross-link all field types, etc.private static Descriptors.FileDescriptor[]findDescriptors(java.lang.Class<?> descriptorOuterClass, java.lang.String[] dependencyClassNames, java.lang.String[] dependencyFileNames)Descriptors.EnumDescriptorfindEnumTypeByName(java.lang.String name)Find an enum type in the file by name.Descriptors.FieldDescriptorfindExtensionByName(java.lang.String name)Find an extension in the file by name.Descriptors.DescriptorfindMessageTypeByName(java.lang.String name)Find a message type in the file by name.Descriptors.ServiceDescriptorfindServiceByName(java.lang.String name)Find a service type in the file by name.java.util.List<Descriptors.FileDescriptor>getDependencies()Get a list of this file's dependencies (imports).DescriptorProtos.EditiongetEdition()Get the edition of the .proto file.java.lang.StringgetEditionName()Gets the name of the edition as specified in the .proto file.java.util.List<Descriptors.EnumDescriptor>getEnumTypes()Get a list of top-level enum types declared in this file.java.util.List<Descriptors.FieldDescriptor>getExtensions()Get a list of top-level extensions declared in this file.Descriptors.FileDescriptorgetFile()Returns this object.java.lang.StringgetFullName()Returns the same as getName().java.util.List<Descriptors.Descriptor>getMessageTypes()Get a list of top-level message types declared in this file.java.lang.StringgetName()Get the file name.DescriptorProtos.FileOptionsgetOptions()Get theFileOptions, defined indescriptor.proto.java.lang.StringgetPackage()Get the proto package name.java.util.List<Descriptors.FileDescriptor>getPublicDependencies()Get a list of this file's public dependencies (public imports).java.util.List<Descriptors.ServiceDescriptor>getServices()Get a list of top-level services declared in this file.Descriptors.FileDescriptor.SyntaxgetSyntax()Deprecated.static Descriptors.FileDescriptorinternalBuildGeneratedFileFrom(java.lang.String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies)This method is to be called by generated code only.static voidinternalBuildGeneratedFileFrom(java.lang.String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner)Deprecated.static Descriptors.FileDescriptorinternalBuildGeneratedFileFrom(java.lang.String[] descriptorDataParts, java.lang.Class<?> descriptorOuterClass, java.lang.String[] dependencyClassNames, java.lang.String[] dependencyFileNames)This method is to be called by generated code only.static voidinternalBuildGeneratedFileFrom(java.lang.String[] descriptorDataParts, java.lang.Class<?> descriptorOuterClass, java.lang.String[] dependencyClassNames, java.lang.String[] dependencyFileNames, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner)Deprecated.static voidinternalUpdateFileDescriptor(Descriptors.FileDescriptor descriptor, ExtensionRegistry registry)This method is to be called by generated code only.private static byte[]latin1Cat(java.lang.String[] strings)private voidsetProto(DescriptorProtos.FileDescriptorProto proto)Replace ourDescriptorProtos.FileDescriptorProtowith the given one, which is identical except that it might contain extensions that weren't present in the original.DescriptorProtos.FileDescriptorPrototoProto()Convert the descriptor to its protocol message representation.
-
-
-
Field Detail
-
proto
private DescriptorProtos.FileDescriptorProto proto
-
messageTypes
private final Descriptors.Descriptor[] messageTypes
-
enumTypes
private final Descriptors.EnumDescriptor[] enumTypes
-
services
private final Descriptors.ServiceDescriptor[] services
-
extensions
private final Descriptors.FieldDescriptor[] extensions
-
dependencies
private final Descriptors.FileDescriptor[] dependencies
-
publicDependencies
private final Descriptors.FileDescriptor[] publicDependencies
-
pool
private final Descriptors.DescriptorPool pool
-
-
Constructor Detail
-
FileDescriptor
private FileDescriptor(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, Descriptors.DescriptorPool pool, boolean allowUnknownDependencies) throws Descriptors.DescriptorValidationException
-
FileDescriptor
FileDescriptor(java.lang.String packageName, Descriptors.Descriptor message) throws Descriptors.DescriptorValidationExceptionCreate a placeholder FileDescriptor for a message Descriptor.
-
-
Method Detail
-
toProto
public DescriptorProtos.FileDescriptorProto toProto()
Convert the descriptor to its protocol message representation.- Specified by:
toProtoin classDescriptors.GenericDescriptor
-
getName
public java.lang.String getName()
Get the file name.- Specified by:
getNamein classDescriptors.GenericDescriptor
-
getFile
public Descriptors.FileDescriptor getFile()
Returns this object.- Specified by:
getFilein classDescriptors.GenericDescriptor
-
getFullName
public java.lang.String getFullName()
Returns the same as getName().- Specified by:
getFullNamein classDescriptors.GenericDescriptor
-
getPackage
public java.lang.String getPackage()
Get the proto package name. This is the package name given by thepackagestatement in the.protofile, which differs from the Java package.
-
getOptions
public DescriptorProtos.FileOptions getOptions()
Get theFileOptions, defined indescriptor.proto.
-
getMessageTypes
public java.util.List<Descriptors.Descriptor> getMessageTypes()
Get a list of top-level message types declared in this file.
-
getEnumTypes
public java.util.List<Descriptors.EnumDescriptor> getEnumTypes()
Get a list of top-level enum types declared in this file.
-
getServices
public java.util.List<Descriptors.ServiceDescriptor> getServices()
Get a list of top-level services declared in this file.
-
getExtensions
public java.util.List<Descriptors.FieldDescriptor> getExtensions()
Get a list of top-level extensions declared in this file.
-
getDependencies
public java.util.List<Descriptors.FileDescriptor> getDependencies()
Get a list of this file's dependencies (imports).
-
getPublicDependencies
public java.util.List<Descriptors.FileDescriptor> getPublicDependencies()
Get a list of this file's public dependencies (public imports).
-
getSyntax
@Deprecated public Descriptors.FileDescriptor.Syntax getSyntax()
Deprecated.Get the syntax of the .proto file.
-
getEdition
public DescriptorProtos.Edition getEdition()
Get the edition of the .proto file.
-
getEditionName
public java.lang.String getEditionName()
Gets the name of the edition as specified in the .proto file.
-
copyHeadingTo
public void copyHeadingTo(DescriptorProtos.FileDescriptorProto.Builder protoBuilder)
-
findMessageTypeByName
public Descriptors.Descriptor findMessageTypeByName(java.lang.String name)
Find a message type in the file by name. Does not find nested types.- Parameters:
name- The unqualified type name to look for.- Returns:
- The message type's descriptor, or
nullif not found.
-
findEnumTypeByName
public Descriptors.EnumDescriptor findEnumTypeByName(java.lang.String name)
Find an enum type in the file by name. Does not find nested types.- Parameters:
name- The unqualified type name to look for.- Returns:
- The enum type's descriptor, or
nullif not found.
-
findServiceByName
public Descriptors.ServiceDescriptor findServiceByName(java.lang.String name)
Find a service type in the file by name.- Parameters:
name- The unqualified type name to look for.- Returns:
- The service type's descriptor, or
nullif not found.
-
findExtensionByName
public Descriptors.FieldDescriptor findExtensionByName(java.lang.String name)
Find an extension in the file by name. Does not find extensions nested inside message types.- Parameters:
name- The unqualified extension name to look for.- Returns:
- The extension's descriptor, or
nullif not found.
-
buildFrom
public static Descriptors.FileDescriptor buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies) throws Descriptors.DescriptorValidationException
Construct aFileDescriptor.- Parameters:
proto- the protocol message form of the FileDescriptortdependencies-FileDescriptors corresponding to all of the file's dependencies- Throws:
Descriptors.DescriptorValidationException-protois not a valid descriptor. This can occur for a number of reasons; for instance, because a field has an undefined type or because two messages were defined with the same name.
-
buildFrom
public static Descriptors.FileDescriptor buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, boolean allowUnknownDependencies) throws Descriptors.DescriptorValidationException
Construct aFileDescriptor.- Parameters:
proto- the protocol message form of the FileDescriptordependencies-FileDescriptors corresponding to all of the file's dependenciesallowUnknownDependencies- if true, non-existing dependencies will be ignored and undefined message types will be replaced with a placeholder type. Undefined enum types still cause a DescriptorValidationException.- Throws:
Descriptors.DescriptorValidationException-protois not a valid descriptor. This can occur for a number of reasons; for instance, because a field has an undefined type or because two messages were defined with the same name.
-
latin1Cat
private static byte[] latin1Cat(java.lang.String[] strings)
-
findDescriptors
private static Descriptors.FileDescriptor[] findDescriptors(java.lang.Class<?> descriptorOuterClass, java.lang.String[] dependencyClassNames, java.lang.String[] dependencyFileNames)
-
internalBuildGeneratedFileFrom
@Deprecated public static void internalBuildGeneratedFileFrom(java.lang.String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner)Deprecated.This method is for backward compatibility with generated code which passed an InternalDescriptorAssigner.
-
internalBuildGeneratedFileFrom
public static Descriptors.FileDescriptor internalBuildGeneratedFileFrom(java.lang.String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies)
This method is to be called by generated code only. It is equivalent tobuildFromexcept that theFileDescriptorProtois encoded in protocol buffer wire format.
-
internalBuildGeneratedFileFrom
@Deprecated public static void internalBuildGeneratedFileFrom(java.lang.String[] descriptorDataParts, java.lang.Class<?> descriptorOuterClass, java.lang.String[] dependencyClassNames, java.lang.String[] dependencyFileNames, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner)Deprecated.This method is for backward compatibility with generated code which passed an InternalDescriptorAssigner.
-
internalBuildGeneratedFileFrom
public static Descriptors.FileDescriptor internalBuildGeneratedFileFrom(java.lang.String[] descriptorDataParts, java.lang.Class<?> descriptorOuterClass, java.lang.String[] dependencyClassNames, java.lang.String[] dependencyFileNames)
This method is to be called by generated code only. It uses Java reflection to load the dependencies' descriptors.
-
internalUpdateFileDescriptor
public static void internalUpdateFileDescriptor(Descriptors.FileDescriptor descriptor, ExtensionRegistry registry)
This method is to be called by generated code only. It updates the FileDescriptorProto associated with the descriptor by parsing it again with the given ExtensionRegistry. This is needed to recognize custom options.
-
crossLink
private void crossLink() throws Descriptors.DescriptorValidationExceptionLook up and cross-link all field types, etc.
-
setProto
private void setProto(DescriptorProtos.FileDescriptorProto proto)
Replace ourDescriptorProtos.FileDescriptorProtowith the given one, which is identical except that it might contain extensions that weren't present in the original. This method is needed for bootstrapping when a file defines custom options. The options may be defined in the file itself, so we can't actually parse them until we've constructed the descriptors, but to construct the descriptors we have to have parsed the descriptor protos. So, we have to parse the descriptor protos a second time after constructing the descriptors.
-
-