reflect/protoreflect: add HasJSONName, ReservedRanges, and ReservedNames

These properties of descriptors are currently missing and makes it impossible
to convert a FileDescriptorProto into one of the structured Go representations
and convert it back to a proto message without loss of information.

Furthermore, ReservedRanges and ReservedNames has semantic importance
to text serialization.

Change-Id: Ic33c30020ad51912b143156b95f47a4fb8da3503
Reviewed-on: https://go-review.googlesource.com/c/153019
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/reflect/protodesc/protodesc.go b/reflect/protodesc/protodesc.go
index 65cbf87..2467a92 100644
--- a/reflect/protodesc/protodesc.go
+++ b/reflect/protodesc/protodesc.go
@@ -58,7 +58,7 @@
 func NewFile(fd *descriptorpb.FileDescriptorProto, r *protoregistry.Files) (protoreflect.FileDescriptor, error) {
 	var f prototype.File
 	switch fd.GetSyntax() {
-	case "", "proto2":
+	case "proto2", "":
 		f.Syntax = protoreflect.Proto2
 	case "proto3":
 		f.Syntax = protoreflect.Proto3
@@ -172,6 +172,15 @@
 				Options: od.Options,
 			})
 		}
+		for _, s := range md.GetReservedName() {
+			m.ReservedNames = append(m.ReservedNames, protoreflect.Name(s))
+		}
+		for _, rr := range md.GetReservedRange() {
+			m.ReservedRanges = append(m.ReservedRanges, [2]protoreflect.FieldNumber{
+				protoreflect.FieldNumber(rr.GetStart()),
+				protoreflect.FieldNumber(rr.GetEnd()),
+			})
+		}
 		for _, xr := range md.GetExtensionRange() {
 			m.ExtensionRanges = append(m.ExtensionRanges, [2]protoreflect.FieldNumber{
 				protoreflect.FieldNumber(xr.GetStart()),
@@ -210,6 +219,15 @@
 				Options: vd.Options,
 			})
 		}
+		for _, s := range ed.GetReservedName() {
+			e.ReservedNames = append(e.ReservedNames, protoreflect.Name(s))
+		}
+		for _, rr := range ed.GetReservedRange() {
+			e.ReservedRanges = append(e.ReservedRanges, [2]protoreflect.EnumNumber{
+				protoreflect.EnumNumber(rr.GetStart()),
+				protoreflect.EnumNumber(rr.GetEnd()),
+			})
+		}
 		es = append(es, e)
 	}
 	return es, nil
diff --git a/reflect/protoreflect/proto.go b/reflect/protoreflect/proto.go
index 6ef9e89..0746c11 100644
--- a/reflect/protoreflect/proto.go
+++ b/reflect/protoreflect/proto.go
@@ -300,6 +300,18 @@
 // EnumNumber is the numeric value for an enum.
 type EnumNumber int32
 
+// EnumRanges represent a list of enum number ranges.
+type EnumRanges interface {
+	// Len reports the number of ranges in the list.
+	Len() int
+	// Get returns the ith range. It panics if out of bounds.
+	Get(i int) [2]EnumNumber // start inclusive; end inclusive
+	// Has reports whether n is within any of the ranges.
+	Has(n EnumNumber) bool
+
+	doNotImplement
+}
+
 var (
 	regexName     = regexp.MustCompile(`^[_a-zA-Z][_a-zA-Z0-9]*$`)
 	regexFullName = regexp.MustCompile(`^[_a-zA-Z][_a-zA-Z0-9]*(\.[_a-zA-Z][_a-zA-Z0-9]*)*$`)
@@ -315,6 +327,18 @@
 	return regexName.MatchString(string(n))
 }
 
+// Names represent a list of names.
+type Names interface {
+	// Len reports the number of names in the list.
+	Len() int
+	// Get returns the ith name. It panics if out of bounds.
+	Get(i int) Name
+	// Has reports whether s matches any names in the list.
+	Has(s Name) bool
+
+	doNotImplement
+}
+
 // FullName is a qualified name that uniquely identifies a proto declaration.
 // A qualified name is the concatenation of the proto package along with the
 // fully-declared name (i.e., name of parent preceding the name of the child),
diff --git a/reflect/protoreflect/type.go b/reflect/protoreflect/type.go
index ba65813..d58232c 100644
--- a/reflect/protoreflect/type.go
+++ b/reflect/protoreflect/type.go
@@ -229,6 +229,10 @@
 	// Oneofs is a list of nested oneof declarations.
 	Oneofs() OneofDescriptors
 
+	// ReservedNames is a list of reserved field names.
+	ReservedNames() Names
+	// ReservedRanges is a list of reserved ranges of field numbers.
+	ReservedRanges() FieldRanges
 	// RequiredNumbers is a list of required field numbers.
 	// In Proto3, it is always an empty list.
 	RequiredNumbers() FieldNumbers
@@ -295,6 +299,9 @@
 	// Kind reports the basic kind for this field.
 	Kind() Kind
 
+	// HasJSONName reports whether this field has an explicitly set JSON name.
+	HasJSONName() bool
+
 	// JSONName reports the name used for JSON serialization.
 	// It is usually the camel-cased form of the field name.
 	JSONName() string
@@ -316,6 +323,9 @@
 	// and MessageDescriptor.IsMapEntry is true.
 	IsMap() bool
 
+	// HasDefault reports whether this field has a default value.
+	HasDefault() bool
+
 	// Default returns the default value for scalar fields.
 	// For proto2, it is the default value as specified in the proto file,
 	// or the zero value if unspecified.
@@ -327,9 +337,6 @@
 	// of an enum field, and is nil for any other kind of field.
 	DefaultEnumValue() EnumValueDescriptor
 
-	// HasDefault reports whether this field has a default value.
-	HasDefault() bool
-
 	// OneofType is the containing oneof that this field belongs to,
 	// and is nil if this field is not part of a oneof.
 	OneofType() OneofDescriptor
@@ -478,6 +485,11 @@
 	// Values is a list of nested enum value declarations.
 	Values() EnumValueDescriptors
 
+	// ReservedNames is a list of reserved enum names.
+	ReservedNames() Names
+	// ReservedRanges is a list of reserved ranges of enum numbers.
+	ReservedRanges() EnumRanges
+
 	isEnumDescriptor
 }
 type isEnumDescriptor interface{ ProtoType(EnumDescriptor) }
diff --git a/reflect/prototype/desc_test.go b/reflect/prototype/desc_test.go
index a8f956e..a071a10 100644
--- a/reflect/prototype/desc_test.go
+++ b/reflect/prototype/desc_test.go
@@ -26,11 +26,13 @@
 
 		[]pref.FileImports{(*fileImports)(nil)},
 		[]pref.MessageDescriptors{(*messages)(nil)},
+		[]pref.Names{(*names)(nil)},
 		[]pref.FieldNumbers{(*numbers)(nil)},
-		[]pref.FieldRanges{(*ranges)(nil)},
+		[]pref.FieldRanges{(*fieldRanges)(nil)},
 		[]pref.FieldDescriptors{(*fields)(nil), (*oneofFields)(nil)},
 		[]pref.OneofDescriptors{(*oneofs)(nil)},
 		[]pref.ExtensionDescriptors{(*extensions)(nil)},
+		[]pref.EnumRanges{(*enumRanges)(nil)},
 		[]pref.EnumDescriptors{(*enums)(nil)},
 		[]pref.EnumValueDescriptors{(*enumValues)(nil)},
 		[]pref.ServiceDescriptors{(*services)(nil)},
diff --git a/reflect/prototype/placeholder_type.go b/reflect/prototype/placeholder_type.go
index 761c600..57fc620 100644
--- a/reflect/prototype/placeholder_type.go
+++ b/reflect/prototype/placeholder_type.go
@@ -13,16 +13,18 @@
 )
 
 var (
-	emptyFiles      fileImports
-	emptyMessages   messages
-	emptyFields     fields
-	emptyOneofs     oneofs
-	emptyNumbers    numbers
-	emptyRanges     ranges
-	emptyEnums      enums
-	emptyEnumValues enumValues
-	emptyExtensions extensions
-	emptyServices   services
+	emptyFiles       fileImports
+	emptyMessages    messages
+	emptyFields      fields
+	emptyOneofs      oneofs
+	emptyNames       names
+	emptyNumbers     numbers
+	emptyFieldRanges fieldRanges
+	emptyEnums       enums
+	emptyEnumValues  enumValues
+	emptyEnumRanges  enumRanges
+	emptyExtensions  extensions
+	emptyServices    services
 )
 
 type placeholderName pref.FullName
@@ -61,8 +63,10 @@
 func (t placeholderMessage) IsMapEntry() bool                            { return false }
 func (t placeholderMessage) Fields() pref.FieldDescriptors               { return &emptyFields }
 func (t placeholderMessage) Oneofs() pref.OneofDescriptors               { return &emptyOneofs }
+func (t placeholderMessage) ReservedNames() pref.Names                   { return &emptyNames }
+func (t placeholderMessage) ReservedRanges() pref.FieldRanges            { return &emptyFieldRanges }
 func (t placeholderMessage) RequiredNumbers() pref.FieldNumbers          { return &emptyNumbers }
-func (t placeholderMessage) ExtensionRanges() pref.FieldRanges           { return &emptyRanges }
+func (t placeholderMessage) ExtensionRanges() pref.FieldRanges           { return &emptyFieldRanges }
 func (t placeholderMessage) ExtensionRangeOptions(int) pref.ProtoMessage { panic("out of bounds") }
 func (t placeholderMessage) Enums() pref.EnumDescriptors                 { return &emptyEnums }
 func (t placeholderMessage) Messages() pref.MessageDescriptors           { return &emptyMessages }
@@ -76,5 +80,7 @@
 
 func (t placeholderEnum) Options() pref.ProtoMessage        { return optionTypes.Enum }
 func (t placeholderEnum) Values() pref.EnumValueDescriptors { return &emptyEnumValues }
+func (t placeholderEnum) ReservedNames() pref.Names         { return &emptyNames }
+func (t placeholderEnum) ReservedRanges() pref.EnumRanges   { return &emptyEnumRanges }
 func (t placeholderEnum) Format(s fmt.State, r rune)        { pfmt.FormatDesc(s, r, t) }
 func (t placeholderEnum) ProtoType(pref.EnumDescriptor)     {}
diff --git a/reflect/prototype/protofile.go b/reflect/prototype/protofile.go
index d2f68c0..d7dca23 100644
--- a/reflect/prototype/protofile.go
+++ b/reflect/prototype/protofile.go
@@ -98,6 +98,8 @@
 	Name                  protoreflect.Name
 	Fields                []Field
 	Oneofs                []Oneof
+	ReservedNames         []protoreflect.Name
+	ReservedRanges        [][2]protoreflect.FieldNumber
 	ExtensionRanges       [][2]protoreflect.FieldNumber
 	ExtensionRangeOptions []protoreflect.ProtoMessage
 	Options               protoreflect.ProtoMessage
@@ -158,9 +160,11 @@
 
 // Enum is a constructor for protoreflect.EnumDescriptor.
 type Enum struct {
-	Name    protoreflect.Name
-	Values  []EnumValue
-	Options protoreflect.ProtoMessage
+	Name           protoreflect.Name
+	Values         []EnumValue
+	ReservedNames  []protoreflect.Name
+	ReservedRanges [][2]protoreflect.EnumNumber
+	Options        protoreflect.ProtoMessage
 
 	*enumMeta
 }
diff --git a/reflect/prototype/protofile_list.go b/reflect/prototype/protofile_list.go
index 0b3b5ba..188be49 100644
--- a/reflect/prototype/protofile_list.go
+++ b/reflect/prototype/protofile_list.go
@@ -14,6 +14,21 @@
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
+type names []pref.Name
+
+func (p *names) Len() int            { return len(*p) }
+func (p *names) Get(i int) pref.Name { return (*p)[i] }
+func (p *names) Has(s pref.Name) bool {
+	for _, n := range *p {
+		if s == n {
+			return true
+		}
+	}
+	return false
+}
+func (p *names) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
+func (p *names) ProtoInternal(pragma.DoNotImplement) {}
+
 type numbersMeta struct {
 	once sync.Once
 	ns   []pref.FieldNumber
@@ -38,11 +53,11 @@
 func (p *numbers) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
 func (p *numbers) ProtoInternal(pragma.DoNotImplement) {}
 
-type ranges [][2]pref.FieldNumber
+type fieldRanges [][2]pref.FieldNumber
 
-func (p *ranges) Len() int                      { return len(*p) }
-func (p *ranges) Get(i int) [2]pref.FieldNumber { return (*p)[i] }
-func (p *ranges) Has(n pref.FieldNumber) bool {
+func (p *fieldRanges) Len() int                      { return len(*p) }
+func (p *fieldRanges) Get(i int) [2]pref.FieldNumber { return (*p)[i] }
+func (p *fieldRanges) Has(n pref.FieldNumber) bool {
 	for _, r := range *p {
 		if r[0] <= n && n < r[1] {
 			return true
@@ -50,8 +65,23 @@
 	}
 	return false
 }
-func (p *ranges) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
-func (p *ranges) ProtoInternal(pragma.DoNotImplement) {}
+func (p *fieldRanges) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
+func (p *fieldRanges) ProtoInternal(pragma.DoNotImplement) {}
+
+type enumRanges [][2]pref.EnumNumber
+
+func (p *enumRanges) Len() int                     { return len(*p) }
+func (p *enumRanges) Get(i int) [2]pref.EnumNumber { return (*p)[i] }
+func (p *enumRanges) Has(n pref.EnumNumber) bool {
+	for _, r := range *p {
+		if r[0] <= n && n <= r[1] {
+			return true
+		}
+	}
+	return false
+}
+func (p *enumRanges) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
+func (p *enumRanges) ProtoInternal(pragma.DoNotImplement) {}
 
 type fileImports []pref.FileImport
 
diff --git a/reflect/prototype/protofile_type.go b/reflect/prototype/protofile_type.go
index 83b676e..c3ac34c 100644
--- a/reflect/prototype/protofile_type.go
+++ b/reflect/prototype/protofile_type.go
@@ -181,8 +181,10 @@
 func (t messageDesc) IsMapEntry() bool                      { return t.m.mo.lazyInit(t).isMapEntry }
 func (t messageDesc) Fields() pref.FieldDescriptors         { return t.m.fs.lazyInit(t, t.m.Fields) }
 func (t messageDesc) Oneofs() pref.OneofDescriptors         { return t.m.os.lazyInit(t, t.m.Oneofs) }
+func (t messageDesc) ReservedNames() pref.Names             { return (*names)(&t.m.ReservedNames) }
+func (t messageDesc) ReservedRanges() pref.FieldRanges      { return (*fieldRanges)(&t.m.ReservedRanges) }
 func (t messageDesc) RequiredNumbers() pref.FieldNumbers    { return t.m.ns.lazyInit(t.m.Fields) }
-func (t messageDesc) ExtensionRanges() pref.FieldRanges     { return (*ranges)(&t.m.ExtensionRanges) }
+func (t messageDesc) ExtensionRanges() pref.FieldRanges     { return (*fieldRanges)(&t.m.ExtensionRanges) }
 func (t messageDesc) ExtensionRangeOptions(i int) pref.ProtoMessage {
 	return extensionRangeOptions(i, len(t.m.ExtensionRanges), t.m.ExtensionRangeOptions)
 }
@@ -246,13 +248,14 @@
 func (t fieldDesc) Number() pref.FieldNumber                   { return t.f.Number }
 func (t fieldDesc) Cardinality() pref.Cardinality              { return t.f.Cardinality }
 func (t fieldDesc) Kind() pref.Kind                            { return t.f.Kind }
+func (t fieldDesc) HasJSONName() bool                          { return t.f.JSONName != "" }
 func (t fieldDesc) JSONName() string                           { return t.f.js.lazyInit(t.f) }
 func (t fieldDesc) IsPacked() bool                             { return t.f.fo.lazyInit(t).isPacked }
 func (t fieldDesc) IsWeak() bool                               { return t.f.fo.lazyInit(t).isWeak }
 func (t fieldDesc) IsMap() bool                                { return t.f.fo.lazyInit(t).isMap }
+func (t fieldDesc) HasDefault() bool                           { return t.f.Default.IsValid() }
 func (t fieldDesc) Default() pref.Value                        { return t.f.dv.value(t, t.f.Default) }
 func (t fieldDesc) DefaultEnumValue() pref.EnumValueDescriptor { return t.f.dv.enum(t, t.f.Default) }
-func (t fieldDesc) HasDefault() bool                           { return t.f.Default.IsValid() }
 func (t fieldDesc) OneofType() pref.OneofDescriptor            { return t.f.ot.lazyInit(t, t.f.OneofName) }
 func (t fieldDesc) ExtendedType() pref.MessageDescriptor       { return nil }
 func (t fieldDesc) MessageType() pref.MessageDescriptor        { return t.f.mt.lazyInit(t, &t.f.MessageType) }
@@ -261,13 +264,17 @@
 func (t fieldDesc) ProtoType(pref.FieldDescriptor)             {}
 func (t fieldDesc) ProtoInternal(pragma.DoNotImplement)        {}
 
-type jsonName struct{ once sync.Once }
+type jsonName struct {
+	once sync.Once
+	name string
+}
 
 func (p *jsonName) lazyInit(f *Field) string {
 	p.once.Do(func() {
 		// TODO: We may need to share this logic with jsonpb for implementation
 		// of the FieldMask well-known type.
 		if f.JSONName != "" {
+			p.name = f.JSONName
 			return
 		}
 		var b []byte
@@ -283,9 +290,9 @@
 			}
 			wasUnderscore = c == '_'
 		}
-		f.JSONName = string(b)
+		p.name = string(b)
 	})
-	return f.JSONName
+	return p.name
 }
 
 // oneofReference resolves the name of a oneof by searching the parent
@@ -418,13 +425,14 @@
 func (t extensionDesc) Number() pref.FieldNumber                   { return t.x.Number }
 func (t extensionDesc) Cardinality() pref.Cardinality              { return t.x.Cardinality }
 func (t extensionDesc) Kind() pref.Kind                            { return t.x.Kind }
+func (t extensionDesc) HasJSONName() bool                          { return false }
 func (t extensionDesc) JSONName() string                           { return "" }
 func (t extensionDesc) IsPacked() bool                             { return isPacked(t.Options()) }
 func (t extensionDesc) IsWeak() bool                               { return false }
 func (t extensionDesc) IsMap() bool                                { return false }
+func (t extensionDesc) HasDefault() bool                           { return t.x.Default.IsValid() }
 func (t extensionDesc) Default() pref.Value                        { return t.x.dv.value(t, t.x.Default) }
 func (t extensionDesc) DefaultEnumValue() pref.EnumValueDescriptor { return t.x.dv.enum(t, t.x.Default) }
-func (t extensionDesc) HasDefault() bool                           { return t.x.Default.IsValid() }
 func (t extensionDesc) OneofType() pref.OneofDescriptor            { return nil }
 func (t extensionDesc) ExtendedType() pref.MessageDescriptor {
 	return t.x.xt.lazyInit(t, &t.x.ExtendedType)
@@ -453,6 +461,8 @@
 func (t enumDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t enumDesc) Options() pref.ProtoMessage            { return altOptions(t.e.Options, optionTypes.Enum) }
 func (t enumDesc) Values() pref.EnumValueDescriptors     { return t.e.vs.lazyInit(t, t.e.Values) }
+func (t enumDesc) ReservedNames() pref.Names             { return (*names)(&t.e.ReservedNames) }
+func (t enumDesc) ReservedRanges() pref.EnumRanges       { return (*enumRanges)(&t.e.ReservedRanges) }
 func (t enumDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t enumDesc) ProtoType(pref.EnumDescriptor)         {}
 func (t enumDesc) ProtoInternal(pragma.DoNotImplement)   {}
diff --git a/reflect/prototype/standalone.go b/reflect/prototype/standalone.go
index b9f6b5e..c934c5c 100644
--- a/reflect/prototype/standalone.go
+++ b/reflect/prototype/standalone.go
@@ -19,6 +19,8 @@
 	FullName              protoreflect.FullName
 	Fields                []Field
 	Oneofs                []Oneof
+	ReservedNames         []protoreflect.Name
+	ReservedRanges        [][2]protoreflect.FieldNumber
 	ExtensionRanges       [][2]protoreflect.FieldNumber
 	ExtensionRangeOptions []protoreflect.ProtoMessage
 	Options               protoreflect.ProtoMessage
@@ -83,10 +85,12 @@
 // StandaloneEnum is a constructor for a protoreflect.EnumDescriptor
 // that does not have a parent.
 type StandaloneEnum struct {
-	Syntax   protoreflect.Syntax
-	FullName protoreflect.FullName
-	Values   []EnumValue
-	Options  protoreflect.ProtoMessage
+	Syntax         protoreflect.Syntax
+	FullName       protoreflect.FullName
+	Values         []EnumValue
+	ReservedNames  []protoreflect.Name
+	ReservedRanges [][2]protoreflect.EnumNumber
+	Options        protoreflect.ProtoMessage
 
 	vals enumValuesMeta
 }
diff --git a/reflect/prototype/standalone_type.go b/reflect/prototype/standalone_type.go
index 041cc1a..e1fea48 100644
--- a/reflect/prototype/standalone_type.go
+++ b/reflect/prototype/standalone_type.go
@@ -24,11 +24,17 @@
 func (t standaloneMessage) Options() pref.ProtoMessage {
 	return altOptions(t.m.Options, optionTypes.Message)
 }
-func (t standaloneMessage) IsMapEntry() bool                   { return t.m.options.lazyInit(t).isMapEntry }
-func (t standaloneMessage) Fields() pref.FieldDescriptors      { return t.m.fields.lazyInit(t, t.m.Fields) }
-func (t standaloneMessage) Oneofs() pref.OneofDescriptors      { return t.m.oneofs.lazyInit(t, t.m.Oneofs) }
+func (t standaloneMessage) IsMapEntry() bool              { return t.m.options.lazyInit(t).isMapEntry }
+func (t standaloneMessage) Fields() pref.FieldDescriptors { return t.m.fields.lazyInit(t, t.m.Fields) }
+func (t standaloneMessage) Oneofs() pref.OneofDescriptors { return t.m.oneofs.lazyInit(t, t.m.Oneofs) }
+func (t standaloneMessage) ReservedNames() pref.Names     { return (*names)(&t.m.ReservedNames) }
+func (t standaloneMessage) ReservedRanges() pref.FieldRanges {
+	return (*fieldRanges)(&t.m.ReservedRanges)
+}
 func (t standaloneMessage) RequiredNumbers() pref.FieldNumbers { return t.m.nums.lazyInit(t.m.Fields) }
-func (t standaloneMessage) ExtensionRanges() pref.FieldRanges  { return (*ranges)(&t.m.ExtensionRanges) }
+func (t standaloneMessage) ExtensionRanges() pref.FieldRanges {
+	return (*fieldRanges)(&t.m.ExtensionRanges)
+}
 func (t standaloneMessage) ExtensionRangeOptions(i int) pref.ProtoMessage {
 	return extensionRangeOptions(i, len(t.m.ExtensionRanges), t.m.ExtensionRangeOptions)
 }
@@ -50,6 +56,8 @@
 func (t standaloneEnum) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t standaloneEnum) Options() pref.ProtoMessage            { return altOptions(t.e.Options, optionTypes.Enum) }
 func (t standaloneEnum) Values() pref.EnumValueDescriptors     { return t.e.vals.lazyInit(t, t.e.Values) }
+func (t standaloneEnum) ReservedNames() pref.Names             { return (*names)(&t.e.ReservedNames) }
+func (t standaloneEnum) ReservedRanges() pref.EnumRanges       { return (*enumRanges)(&t.e.ReservedRanges) }
 func (t standaloneEnum) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t standaloneEnum) ProtoType(pref.EnumDescriptor)         {}
 func (t standaloneEnum) ProtoInternal(pragma.DoNotImplement)   {}
@@ -69,15 +77,16 @@
 func (t standaloneExtension) Number() pref.FieldNumber      { return t.x.Number }
 func (t standaloneExtension) Cardinality() pref.Cardinality { return t.x.Cardinality }
 func (t standaloneExtension) Kind() pref.Kind               { return t.x.Kind }
+func (t standaloneExtension) HasJSONName() bool             { return false }
 func (t standaloneExtension) JSONName() string              { return "" }
 func (t standaloneExtension) IsPacked() bool                { return isPacked(t.Options()) }
 func (t standaloneExtension) IsWeak() bool                  { return false }
 func (t standaloneExtension) IsMap() bool                   { return false }
+func (t standaloneExtension) HasDefault() bool              { return t.x.Default.IsValid() }
 func (t standaloneExtension) Default() pref.Value           { return t.x.dv.value(t, t.x.Default) }
 func (t standaloneExtension) DefaultEnumValue() pref.EnumValueDescriptor {
 	return t.x.dv.enum(t, t.x.Default)
 }
-func (t standaloneExtension) HasDefault() bool                     { return t.x.Default.IsValid() }
 func (t standaloneExtension) OneofType() pref.OneofDescriptor      { return nil }
 func (t standaloneExtension) MessageType() pref.MessageDescriptor  { return t.x.MessageType }
 func (t standaloneExtension) EnumType() pref.EnumDescriptor        { return t.x.EnumType }
diff --git a/reflect/prototype/type_test.go b/reflect/prototype/type_test.go
index e82fae7..4bac6c6 100644
--- a/reflect/prototype/type_test.go
+++ b/reflect/prototype/type_test.go
@@ -109,6 +109,8 @@
 				},
 				{Name: "O2"}, // "test.B.O2"
 			},
+			ReservedNames:   []pref.Name{"fizz", "buzz"},
+			ReservedRanges:  [][2]pref.FieldNumber{{100, 200}, {300, 301}},
 			ExtensionRanges: [][2]pref.FieldNumber{{1000, 2000}, {3000, 3001}},
 			ExtensionRangeOptions: []pref.ProtoMessage{
 				0: (*descriptorpb.ExtensionRangeOptions)(nil),
@@ -145,6 +147,8 @@
 				},
 				{Name: "BAR", Number: 1},
 			},
+			ReservedNames:  []pref.Name{"FIZZ", "BUZZ"},
+			ReservedRanges: [][2]pref.EnumNumber{{10, 19}, {30, 30}},
 		}},
 		Extensions: []ptype.Extension{{
 			Name:         "X", // "test.X"
@@ -252,6 +256,11 @@
 				},
 				{Name: scalar.String("O2")},
 			},
+			ReservedName: []string{"fizz", "buzz"},
+			ReservedRange: []*descriptorpb.DescriptorProto_ReservedRange{
+				{Start: scalar.Int32(100), End: scalar.Int32(200)},
+				{Start: scalar.Int32(300), End: scalar.Int32(301)},
+			},
 			ExtensionRange: []*descriptorpb.DescriptorProto_ExtensionRange{
 				{Start: scalar.Int32(1000), End: scalar.Int32(2000)},
 				{Start: scalar.Int32(3000), End: scalar.Int32(3001), Options: new(descriptorpb.ExtensionRangeOptions)},
@@ -295,6 +304,11 @@
 				},
 				{Name: scalar.String("BAR"), Number: scalar.Int32(1)},
 			},
+			ReservedName: []string{"FIZZ", "BUZZ"},
+			ReservedRange: []*descriptorpb.EnumDescriptorProto_EnumReservedRange{
+				{Start: scalar.Int32(10), End: scalar.Int32(19)},
+				{Start: scalar.Int32(30), End: scalar.Int32(30)},
+			},
 		}},
 		Extension: []*descriptorpb.FieldDescriptorProto{{
 			Name:     scalar.String("X"),
@@ -381,6 +395,7 @@
 						"Cardinality":  pref.Optional,
 						"Kind":         pref.StringKind,
 						"Options":      &descriptorpb.FieldOptions{Deprecated: scalar.Bool(true)},
+						"HasJSONName":  false,
 						"JSONName":     "key",
 						"IsPacked":     false,
 						"IsMap":        false,
@@ -433,11 +448,12 @@
 					},
 					"ByJSONName:fieldTwo": nil,
 					"ByJSONName:Field2": M{
-						"Name":      pref.Name("field_two"),
-						"Index":     1,
-						"JSONName":  "Field2",
-						"Default":   pref.EnumNumber(1),
-						"OneofType": M{"Name": pref.Name("O2"), "IsPlaceholder": false},
+						"Name":        pref.Name("field_two"),
+						"Index":       1,
+						"HasJSONName": true,
+						"JSONName":    "Field2",
+						"Default":     pref.EnumNumber(1),
+						"OneofType":   M{"Name": pref.Name("O2"), "IsPlaceholder": false},
 					},
 					"ByName:fieldThree": nil,
 					"ByName:field_three": M{
@@ -490,6 +506,23 @@
 						},
 					},
 				},
+				"ReservedNames": M{
+					"Len":         2,
+					"Get:0":       pref.Name("fizz"),
+					"Has:buzz":    true,
+					"Has:noexist": false,
+				},
+				"ReservedRanges": M{
+					"Len":     2,
+					"Get:0":   [2]pref.FieldNumber{100, 200},
+					"Has:99":  false,
+					"Has:100": true,
+					"Has:150": true,
+					"Has:199": true,
+					"Has:200": false,
+					"Has:300": true,
+					"Has:301": false,
+				},
 				"RequiredNumbers": M{
 					"Len":   1,
 					"Get:0": pref.FieldNumber(6),
@@ -505,6 +538,7 @@
 					"Has:1999": true,
 					"Has:2000": false,
 					"Has:3000": true,
+					"Has:3001": false,
 				},
 				"ExtensionRangeOptions:0": (*descriptorpb.ExtensionRangeOptions)(nil),
 				"ExtensionRangeOptions:1": new(descriptorpb.ExtensionRangeOptions),
@@ -541,6 +575,23 @@
 					"ByNumber:2": nil,
 					"ByNumber:1": M{"FullName": pref.FullName("test.BAR")},
 				},
+				"ReservedNames": M{
+					"Len":         2,
+					"Get:0":       pref.Name("FIZZ"),
+					"Has:BUZZ":    true,
+					"Has:NOEXIST": false,
+				},
+				"ReservedRanges": M{
+					"Len":    2,
+					"Get:0":  [2]pref.EnumNumber{10, 19},
+					"Has:9":  false,
+					"Has:10": true,
+					"Has:15": true,
+					"Has:19": true,
+					"Has:20": false,
+					"Has:30": true,
+					"Has:31": false,
+				},
 			},
 		},
 		"Extensions": M{
@@ -718,6 +769,7 @@
 			Number:      2
 			Cardinality: optional
 			Kind:        enum
+			HasJSONName: true
 			JSONName:    "Field2"
 			HasDefault:  true
 			Default:     1
@@ -736,6 +788,7 @@
 			Number:      4
 			Cardinality: repeated
 			Kind:        message
+			HasJSONName: true
 			JSONName:    "Field4"
 			IsMap:       true
 			MessageType: test.A
@@ -760,6 +813,8 @@
 			Name:   O2
 			Fields: [field_two, field_three]
 		}]
+		ReservedNames:   [fizz, buzz]
+		ReservedRanges:  [100:200, 300]
 		RequiredNumbers: [6]
 		ExtensionRanges: [1000:2000, 3000]
 	}, {
@@ -799,6 +854,8 @@
 			{Name: FOO}
 			{Name: BAR, Number: 1}
 		]
+		ReservedNames:  [FIZZ, BUZZ]
+		ReservedRanges: [10:20, 30]
 	}]
 	Extensions: [{
 		Name:         X