com.google.protobuf
Class Descriptors.FieldDescriptor

java.lang.Object
  extended by com.google.protobuf.Descriptors.FieldDescriptor
All Implemented Interfaces:
FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>, java.lang.Comparable<Descriptors.FieldDescriptor>
Enclosing class:
Descriptors

public static final class Descriptors.FieldDescriptor
extends java.lang.Object
implements java.lang.Comparable<Descriptors.FieldDescriptor>, FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>

Describes a field of a message type.


Nested Class Summary
static class Descriptors.FieldDescriptor.JavaType
           
static class Descriptors.FieldDescriptor.Type
           
 
Method Summary
 int compareTo(Descriptors.FieldDescriptor other)
          Compare with another FieldDescriptor.
 Descriptors.Descriptor getContainingType()
          Get the field's containing type.
 java.lang.Object getDefaultValue()
          Returns the field's default value.
 Descriptors.EnumDescriptor getEnumType()
          For enum fields, gets the field's type.
 Descriptors.Descriptor getExtensionScope()
          For extensions defined nested within message types, gets the outer type.
 Descriptors.FileDescriptor getFile()
          Get the FileDescriptor containing this descriptor.
 java.lang.String getFullName()
          Get the field's fully-qualified name.
 int getIndex()
          Get the index of this descriptor within its parent.
 Descriptors.FieldDescriptor.JavaType getJavaType()
          Get the field's java type.
 WireFormat.JavaType getLiteJavaType()
          For internal use only.
 WireFormat.FieldType getLiteType()
          For internal use only.
 Descriptors.Descriptor getMessageType()
          For embedded message and group fields, gets the field's type.
 java.lang.String getName()
          Get the field's unqualified name.
 int getNumber()
          Get the field's number.
 DescriptorProtos.FieldOptions getOptions()
          Get the FieldOptions, defined in descriptor.proto.
 Descriptors.FieldDescriptor.Type getType()
          Get the field's declared type.
 boolean hasDefaultValue()
          Returns true if the field had an explicitly-defined default value.
 MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from)
          For internal use only.
 boolean isExtension()
          Is this field an extension?
 boolean isOptional()
          Is this field declared optional?
 boolean isPacked()
          Does this field have the [packed = true] option?
 boolean isRepeated()
          Is this field declared repeated?
 boolean isRequired()
          Is this field declared required?
 DescriptorProtos.FieldDescriptorProto toProto()
          Convert the descriptor to its protocol message representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getIndex

public int getIndex()
Get the index of this descriptor within its parent.

See Also:
Descriptor#getIndex()

toProto

public DescriptorProtos.FieldDescriptorProto toProto()
Convert the descriptor to its protocol message representation.


getName

public java.lang.String getName()
Get the field's unqualified name.


getNumber

public int getNumber()
Get the field's number.

Specified by:
getNumber in interface FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>

getFullName

public java.lang.String getFullName()
Get the field's fully-qualified name.

See Also:
Descriptor#getFullName()

getJavaType

public Descriptors.FieldDescriptor.JavaType getJavaType()
Get the field's java type. This is just for convenience. Every FieldDescriptorProto.Type maps to exactly one Java type.


getLiteJavaType

public WireFormat.JavaType getLiteJavaType()
For internal use only.

Specified by:
getLiteJavaType in interface FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>

getFile

public Descriptors.FileDescriptor getFile()
Get the FileDescriptor containing this descriptor.


getType

public Descriptors.FieldDescriptor.Type getType()
Get the field's declared type.


getLiteType

public WireFormat.FieldType getLiteType()
For internal use only.

Specified by:
getLiteType in interface FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>

isRequired

public boolean isRequired()
Is this field declared required?


isOptional

public boolean isOptional()
Is this field declared optional?


isRepeated

public boolean isRepeated()
Is this field declared repeated?

Specified by:
isRepeated in interface FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>

isPacked

public boolean isPacked()
Does this field have the [packed = true] option?

Specified by:
isPacked in interface FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>

hasDefaultValue

public boolean hasDefaultValue()
Returns true if the field had an explicitly-defined default value.


getDefaultValue

public java.lang.Object getDefaultValue()
Returns the field's default value. Valid for all types except for messages and groups. For all other types, the object returned is of the same class that would returned by Message.getField(this).


getOptions

public DescriptorProtos.FieldOptions getOptions()
Get the FieldOptions, defined in descriptor.proto.


isExtension

public boolean isExtension()
Is this field an extension?


getContainingType

public Descriptors.Descriptor getContainingType()
Get the field's containing type. For extensions, this is the type being extended, not the location where the extension was defined. See getExtensionScope().


getExtensionScope

public Descriptors.Descriptor getExtensionScope()
For extensions defined nested within message types, gets the outer type. Not valid for non-extension fields. For example, consider this .proto file:
   message Foo {
     extensions 1000 to max;
   }
   extend Foo {
     optional int32 baz = 1234;
   }
   message Bar {
     extend Foo {
       optional int32 qux = 4321;
     }
   }
 
Both baz's and qux's containing type is Foo. However, baz's extension scope is null while qux's extension scope is Bar.


getMessageType

public Descriptors.Descriptor getMessageType()
For embedded message and group fields, gets the field's type.


getEnumType

public Descriptors.EnumDescriptor getEnumType()
For enum fields, gets the field's type.

Specified by:
getEnumType in interface FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>

compareTo

public int compareTo(Descriptors.FieldDescriptor other)
Compare with another FieldDescriptor. This orders fields in "canonical" order, which simply means ascending order by field number. other must be a field of the same type -- i.e. getContainingType() must return the same Descriptor for both fields.

Specified by:
compareTo in interface java.lang.Comparable<Descriptors.FieldDescriptor>
Returns:
negative, zero, or positive if this is less than, equal to, or greater than other, respectively.

internalMergeFrom

public MessageLite.Builder internalMergeFrom(MessageLite.Builder to,
                                             MessageLite from)
For internal use only. This is to satisfy the FieldDescriptorLite interface.

Specified by:
internalMergeFrom in interface FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>


Copyright © 2008-2009 Google. All Rights Reserved.