Add comments to nonfunctional properties.

このコミットが含まれているのは:
Cory Slep 2018-09-20 19:24:20 +02:00
コミット 1426f30be1
1個のファイルの変更28行の追加15行の削除

ファイルの表示

@ -5,7 +5,6 @@ import (
"github.com/dave/jennifer/jen" "github.com/dave/jennifer/jen"
) )
// TODO: Auto-generate documentation and comments for non-functional type.
// TODO: Break out into multiple files. // TODO: Break out into multiple files.
// TODO: Deserialize & generated structs preserve "unknown" elements. // TODO: Deserialize & generated structs preserve "unknown" elements.
// TODO: Satisfy the rest of the sort.Interface. // TODO: Satisfy the rest of the sort.Interface.
@ -525,8 +524,11 @@ func (p *NonFunctionalPropertyGenerator) funcs() *jen.Statement {
if !kind.Nilable { if !kind.Nilable {
dict[jen.Id(p.hasMemberName(i))] = jen.True() dict[jen.Id(p.hasMemberName(i))] = jen.True()
} }
prepend = append(prepend, memberPtrFunc.Clone().Id( prependMethodName := fmt.Sprintf("%s%s", prependMethod, p.kindCamelName(i))
fmt.Sprintf("%s%s", prependMethod, p.kindCamelName(i)), prepend = append(prepend, jen.Commentf(
"%s prepends a %s value to the front of a list of the property %q.", prependMethodName, kind.ConcreteKind, p.propertyName(),
).Line().Add(memberPtrFunc.Clone().Id(
prependMethodName,
).Params( ).Params(
jen.Id("v").Id(kind.ConcreteKind), jen.Id("v").Id(kind.ConcreteKind),
).Block( ).Block(
@ -536,9 +538,12 @@ func (p *NonFunctionalPropertyGenerator) funcs() *jen.Statement {
), ),
jen.Op("*").Id("t").Op("..."), jen.Op("*").Id("t").Op("..."),
), ),
)) )))
appendFns = append(appendFns, memberPtrFunc.Clone().Id( appendMethodName := fmt.Sprintf("%s%s", appendMethod, p.kindCamelName(i))
fmt.Sprintf("%s%s", appendMethod, p.kindCamelName(i)), appendFns = append(appendFns, jen.Commentf(
"%s appends a %s value to the back of a list of the property %q", appendMethodName, kind.ConcreteKind, p.propertyName(),
).Line().Add(memberPtrFunc.Clone().Id(
appendMethodName,
).Params( ).Params(
jen.Id("v").Id(kind.ConcreteKind), jen.Id("v").Id(kind.ConcreteKind),
).Block( ).Block(
@ -548,9 +553,11 @@ func (p *NonFunctionalPropertyGenerator) funcs() *jen.Statement {
dict, dict,
), ),
), ),
)) )))
} }
remove := memberPtrFunc.Clone().Id(removeMethod).Params( remove := jen.Commentf(
"%s deletes an element at the specified index from a list of the property %q, regardless of its type.", removeMethod, p.propertyName(),
).Line().Add(memberPtrFunc.Clone().Id(removeMethod).Params(
jen.Id("idx").Int(), jen.Id("idx").Int(),
).Block( ).Block(
jen.Copy( jen.Copy(
@ -578,8 +585,10 @@ func (p *NonFunctionalPropertyGenerator) funcs() *jen.Statement {
jen.Empty(), jen.Empty(),
jen.Len(jen.Op("*").Id("t")).Op("-").Lit(1), jen.Len(jen.Op("*").Id("t")).Op("-").Lit(1),
), ),
) ))
lenFn := memberFunc.Clone().Id(lenMethod).Params().Params( lenFn := jen.Commentf(
"%s returns the number of values that exist for the %s property.", lenMethod, p.propertyName(),
).Line().Add(memberFunc.Clone().Id(lenMethod).Params().Params(
jen.Id("length").Int(), jen.Id("length").Int(),
).Block( ).Block(
jen.Return( jen.Return(
@ -587,7 +596,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() *jen.Statement {
jen.Id("t"), jen.Id("t"),
), ),
), ),
) ))
return funcs.Line().Line().Add( return funcs.Line().Line().Add(
join(appendFns), join(appendFns),
).Line().Line().Add( ).Line().Line().Add(
@ -602,7 +611,9 @@ func (p *NonFunctionalPropertyGenerator) funcs() *jen.Statement {
} }
func (p *NonFunctionalPropertyGenerator) serializationFuncs() *jen.Statement { func (p *NonFunctionalPropertyGenerator) serializationFuncs() *jen.Statement {
serialize := jen.Func().Params( serialize := jen.Commentf(
"%s converts this into an interface representation suitable for marshalling into a text or binary format.", p.serializeFnName(),
).Line().Add(jen.Func().Params(
jen.Id("t").Id(p.structName()), jen.Id("t").Id(p.structName()),
).Id(p.serializeFnName()).Params().Params( ).Id(p.serializeFnName()).Params().Params(
jen.Interface(), jen.Interface(),
@ -641,7 +652,7 @@ func (p *NonFunctionalPropertyGenerator) serializationFuncs() *jen.Statement {
jen.Id("s"), jen.Id("s"),
jen.Nil(), jen.Nil(),
), ),
) ))
deserializeFn := func(variable string) jen.Code { deserializeFn := func(variable string) jen.Code {
return jen.If( return jen.If(
jen.List( jen.List(
@ -665,7 +676,9 @@ func (p *NonFunctionalPropertyGenerator) serializationFuncs() *jen.Statement {
), ),
) )
} }
deserialize := jen.Func().Id( deserialize := jen.Commentf(
"%s creates a %q property from an interface representation that has been unmarshalled from a text or binary format.", p.deserializeFnName(), p.propertyName(),
).Line().Add(jen.Func().Id(
p.deserializeFnName(), p.deserializeFnName(),
).Params( ).Params(
jen.Id("m").Map(jen.String()).Interface(), jen.Id("m").Map(jen.String()).Interface(),
@ -708,6 +721,6 @@ func (p *NonFunctionalPropertyGenerator) serializationFuncs() *jen.Statement {
jen.Id("t"), jen.Id("t"),
jen.Nil(), jen.Nil(),
), ),
) ))
return serialize.Line().Line().Add(deserialize) return serialize.Line().Line().Add(deserialize)
} }