Browse Source

goprotobuf: Fix alias generation for enums.

We were emitting an obsolete function and missing a couple of real methods.

LGTM=nigeltao
R=nigeltao
CC=golang-codereviews
https://codereview.appspot.com/111470043
David Symonds 11 năm trước cách đây
mục cha
commit
b16d165ede
1 tập tin đã thay đổi với 3 bổ sung1 xóa
  1. 3 1
      protoc-gen-go/generator/generator.go

+ 3 - 1
protoc-gen-go/generator/generator.go

@@ -377,7 +377,9 @@ func (es enumSymbol) GenerateAlias(g *Generator, pkg string) {
 	g.P("type ", s, " ", pkg, ".", s)
 	g.P("var ", s, "_name = ", pkg, ".", s, "_name")
 	g.P("var ", s, "_value = ", pkg, ".", s, "_value")
-	g.P("func New", s, "(x ", s, ") *", s, " { e := ", s, "(x); return &e }")
+	g.P("func (x ", s, ") Enum() *", s, "{ return (*", s, ")((", pkg, ".", s, ")(x).Enum()) }")
+	g.P("func (x ", s, ") String() string { return (", pkg, ".", s, ")(x).String() }")
+	g.P("func (x *", s, ") UnmarshalJSON(data []byte) error { return (*", pkg, ".", s, ")(x).UnmarshalJSON(data) }")
 }
 
 type constOrVarSymbol struct {