Преглед изворни кода

reflect/prototype: print {Enum,Message,Extension}Type.GoType

Add GoType to the list of accessors that can be pretty-printed.
Useful for debugging.

Change-Id: Ib2a240249ca5bf0176cb77fa5edc639d44ae0561
Reviewed-on: https://go-review.googlesource.com/c/150537
Reviewed-by: Herbie Ong <herbie@google.com>
Joe Tsai пре 7 година
родитељ
комит
ccf645912d
2 измењених фајлова са 12 додато и 1 уклоњено
  1. 9 0
      reflect/prototype/go_type.go
  2. 3 1
      reflect/prototype/stringer.go

+ 9 - 0
reflect/prototype/go_type.go

@@ -42,6 +42,9 @@ func (t *goEnum) New(n protoreflect.EnumNumber) protoreflect.ProtoEnum {
 	}
 	return e
 }
+func (t *goEnum) Format(s fmt.State, r rune) {
+	formatDesc(s, r, t)
+}
 
 // GoMessage creates a new protoreflect.MessageType by combining the provided
 // protoreflect.MessageDescriptor with the provided constructor function.
@@ -74,6 +77,9 @@ func (t *goMessage) New() protoreflect.ProtoMessage {
 	}
 	return m
 }
+func (t *goMessage) Format(s fmt.State, r rune) {
+	formatDesc(s, r, t)
+}
 
 // GoExtension creates a new protoreflect.ExtensionType.
 //
@@ -187,6 +193,9 @@ func (t *goExtension) InterfaceOf(pv protoreflect.Value) interface{} {
 	}
 	return v
 }
+func (t *goExtension) Format(s fmt.State, r rune) {
+	formatDesc(s, r, t)
+}
 func (t *goExtension) lazyInit() {
 	t.once.Do(func() {
 		switch t.Cardinality() {

+ 3 - 1
reflect/prototype/stringer.go

@@ -135,7 +135,9 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
 		} else {
 			rs.Append(rv, descriptorAccessors[rt]...)
 		}
-		// TODO: Print GoType
+		if rv.MethodByName("GoType").IsValid() {
+			rs.Append(rv, "GoType")
+		}
 	}
 	return start + rs.Join() + end
 }