Skip to content

Commit

Permalink
Rename confusing method names LHS and RHS
Browse files Browse the repository at this point in the history
I confused left and right in f709571
somehow or other.
  • Loading branch information
yugui committed Apr 16, 2018
1 parent 485afe2 commit a120768
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
22 changes: 11 additions & 11 deletions protoc-gen-grpc-gateway/descriptor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ type Body struct {
FieldPath FieldPath
}

// RHS returns a right-hand-side expression in go to be used to initialize method request object.
// AssignableExpr returns an assignable expression in Go to be used to initialize method request object.
// It starts with "msgExpr", which is the go expression of the method request object.
func (b Body) RHS(msgExpr string) string {
return b.FieldPath.RHS(msgExpr)
func (b Body) AssignableExpr(msgExpr string) string {
return b.FieldPath.AssignableExpr(msgExpr)
}

// FieldPath is a path to a field from a request message.
Expand All @@ -242,20 +242,20 @@ func (p FieldPath) IsNestedProto3() bool {
return false
}

// RHS is a right-hand-side expression in go to be used to assign a value to the target field.
// AssignableExpr is an assignable expression in Go to be used to assign a value to the target field.
// It starts with "msgExpr", which is the go expression of the method request object.
func (p FieldPath) RHS(msgExpr string) string {
func (p FieldPath) AssignableExpr(msgExpr string) string {
l := len(p)
if l == 0 {
return msgExpr
}
components := []string{msgExpr}
for i, c := range p {
if i == l-1 {
components = append(components, c.RHS())
components = append(components, c.AssignableExpr())
continue
}
components = append(components, c.LHS())
components = append(components, c.ValueExpr())
}
return strings.Join(components, ".")
}
Expand All @@ -269,13 +269,13 @@ type FieldPathComponent struct {
Target *Field
}

// RHS returns a right-hand-side expression in go for this field.
func (c FieldPathComponent) RHS() string {
// AssignableExpr returns an assignable expression in go for this field.
func (c FieldPathComponent) AssignableExpr() string {
return gogen.CamelCase(c.Name)
}

// LHS returns a left-hand-side expression in go for this field.
func (c FieldPathComponent) LHS() string {
// ValueExpr returns an expression in go for this field.
func (c FieldPathComponent) ValueExpr() string {
if c.Target.Message.File.proto2() {
return fmt.Sprintf("Get%s()", gogen.CamelCase(c.Name))
}
Expand Down
28 changes: 14 additions & 14 deletions protoc-gen-grpc-gateway/descriptor/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,22 @@ func TestFieldPath(t *testing.T) {
Name: "nest_field",
Target: nest2.Fields[0],
}
if got, want := c1.LHS(), "GetNestField()"; got != want {
t.Errorf("c1.LHS() = %q; want %q", got, want)
if got, want := c1.ValueExpr(), "GetNestField()"; got != want {
t.Errorf("c1.ValueExpr() = %q; want %q", got, want)
}
if got, want := c1.RHS(), "NestField"; got != want {
t.Errorf("c1.RHS() = %q; want %q", got, want)
if got, want := c1.AssignableExpr(), "NestField"; got != want {
t.Errorf("c1.AssignableExpr() = %q; want %q", got, want)
}

c2 := FieldPathComponent{
Name: "nest2_field",
Target: nest.Fields[0],
}
if got, want := c2.LHS(), "Nest2Field"; got != want {
t.Errorf("c2.LHS() = %q; want %q", got, want)
if got, want := c2.ValueExpr(), "Nest2Field"; got != want {
t.Errorf("c2.ValueExpr() = %q; want %q", got, want)
}
if got, want := c2.LHS(), "Nest2Field"; got != want {
t.Errorf("c2.LHS() = %q; want %q", got, want)
if got, want := c2.ValueExpr(), "Nest2Field"; got != want {
t.Errorf("c2.ValueExpr() = %q; want %q", got, want)
}

fp := FieldPath{
Expand All @@ -185,8 +185,8 @@ func TestFieldPath(t *testing.T) {
Target: nest.Fields[1],
},
}
if got, want := fp.RHS("resp"), "resp.GetNestField().Nest2Field.GetNestField().TerminalField"; got != want {
t.Errorf("fp.RHS(%q) = %q; want %q", "resp", got, want)
if got, want := fp.AssignableExpr("resp"), "resp.GetNestField().Nest2Field.GetNestField().TerminalField"; got != want {
t.Errorf("fp.AssignableExpr(%q) = %q; want %q", "resp", got, want)
}

fp2 := FieldPath{
Expand All @@ -195,12 +195,12 @@ func TestFieldPath(t *testing.T) {
Target: nest2.Fields[1],
},
}
if got, want := fp2.RHS("resp"), "resp.Nest2Field.GetNestField().Nest2Field.TerminalField"; got != want {
t.Errorf("fp2.RHS(%q) = %q; want %q", "resp", got, want)
if got, want := fp2.AssignableExpr("resp"), "resp.Nest2Field.GetNestField().Nest2Field.TerminalField"; got != want {
t.Errorf("fp2.AssignableExpr(%q) = %q; want %q", "resp", got, want)
}

var fpEmpty FieldPath
if got, want := fpEmpty.RHS("resp"), "resp"; got != want {
t.Errorf("fpEmpty.RHS(%q) = %q; want %q", "resp", got, want)
if got, want := fpEmpty.AssignableExpr("resp"), "resp"; got != want {
t.Errorf("fpEmpty.AssignableExpr(%q) = %q; want %q", "resp", got, want)
}
}
4 changes: 2 additions & 2 deletions protoc-gen-grpc-gateway/gengateway/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ var (
var metadata runtime.ServerMetadata
{{if .Body}}
if req.ContentLength > 0 {
if err := marshaler.NewDecoder(req.Body).Decode(&{{.Body.RHS "protoReq"}}); err != nil {
if err := marshaler.NewDecoder(req.Body).Decode(&{{.Body.AssignableExpr "protoReq"}}); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
}
Expand All @@ -228,7 +228,7 @@ var (
{{if $param.IsNestedProto3 }}
err = runtime.PopulateFieldFromPath(&protoReq, {{$param | printf "%q"}}, val)
{{else}}
{{$param.RHS "protoReq"}}, err = {{$param.ConvertFuncExpr}}(val)
{{$param.AssignableExpr "protoReq"}}, err = {{$param.ConvertFuncExpr}}(val)
{{end}}
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", {{$param | printf "%q"}}, err)
Expand Down

0 comments on commit a120768

Please sign in to comment.