diff --git a/tools/exp/codegen/method.go b/tools/exp/codegen/method.go index 0eae7b9..2da1b26 100644 --- a/tools/exp/codegen/method.go +++ b/tools/exp/codegen/method.go @@ -28,13 +28,13 @@ type Function struct { params []jen.Code ret []jen.Code block []jen.Code - comment jen.Code + comment string } // NewCommentedFunction creates a new function with a comment. func NewCommentedFunction(pkg, name string, params, ret, block []jen.Code, - comment jen.Code) *Function { + comment string) *Function { return &Function{ qual: jen.Qual(pkg, name), name: name, @@ -49,12 +49,11 @@ func NewCommentedFunction(pkg, name string, func NewFunction(pkg, name string, params, ret, block []jen.Code) *Function { return &Function{ - qual: jen.Qual(pkg, name), - name: name, - params: params, - ret: ret, - block: block, - comment: nil, + qual: jen.Qual(pkg, name), + name: name, + params: params, + ret: ret, + block: block, } } @@ -70,8 +69,8 @@ func (m Function) CloneToPackage(pkg string) *Function { // function. func (m Function) Definition() jen.Code { stmts := jen.Empty() - if m.comment != nil { - stmts = jen.Empty().Add(m.comment).Line() + if len(m.comment) > 0 { + stmts = jen.Commentf(m.comment).Line() } return stmts.Add(jen.Func().Id(m.name).Params( m.params..., @@ -109,7 +108,7 @@ type Method struct { // NewCommentedValueMethod defines a commented method for the value of a type. func NewCommentedValueMethod(pkg, name, structName string, params, ret, block []jen.Code, - comment jen.Code) *Method { + comment string) *Method { return &Method{ member: valueMember, structName: structName, @@ -131,12 +130,11 @@ func NewValueMethod(pkg, name, structName string, member: valueMember, structName: structName, function: &Function{ - qual: jen.Qual(pkg, name), - name: name, - params: params, - ret: ret, - block: block, - comment: nil, + qual: jen.Qual(pkg, name), + name: name, + params: params, + ret: ret, + block: block, }, } } @@ -145,7 +143,7 @@ func NewValueMethod(pkg, name, structName string, // type. func NewCommentedPointerMethod(pkg, name, structName string, params, ret, block []jen.Code, - comment jen.Code) *Method { + comment string) *Method { return &Method{ member: pointerMember, structName: structName, @@ -168,12 +166,11 @@ func NewPointerMethod(pkg, name, structName string, member: pointerMember, structName: structName, function: &Function{ - qual: jen.Qual(pkg, name), - name: name, - params: params, - ret: ret, - block: block, - comment: nil, + qual: jen.Qual(pkg, name), + name: name, + params: params, + ret: ret, + block: block, }, } } @@ -182,8 +179,8 @@ func NewPointerMethod(pkg, name, structName string, // method. func (m Method) Definition() jen.Code { comment := jen.Empty() - if m.function.comment != nil { - comment = jen.Empty().Add(m.function.comment).Line() + if len(m.function.comment) > 0 { + comment = jen.Commentf(m.function.comment).Line() } funcDef := jen.Empty() switch m.member { @@ -229,8 +226,9 @@ func (m Method) Name() string { // ToFunctionSignature obtains this method's FunctionSignature. func (m Method) ToFunctionSignature() FunctionSignature { return FunctionSignature{ - Name: m.Name(), - Params: m.function.params, - Ret: m.function.ret, + Name: m.Name(), + Params: m.function.params, + Ret: m.function.ret, + Comment: m.function.comment, } } diff --git a/tools/exp/codegen/struct.go b/tools/exp/codegen/struct.go index 72c5b47..2ec5d1e 100644 --- a/tools/exp/codegen/struct.go +++ b/tools/exp/codegen/struct.go @@ -21,7 +21,7 @@ func join(s []jen.Code) *jen.Statement { // Struct defines a struct-based type, its functions, and its methods for Go // code generation. type Struct struct { - comment jen.Code + comment string name string methods map[string]*Method constructors map[string]*Function @@ -29,7 +29,7 @@ type Struct struct { } // NewStruct creates a new commented Struct type. -func NewStruct(comment jen.Code, +func NewStruct(comment string, name string, methods []*Method, constructors []*Function, @@ -54,8 +54,8 @@ func NewStruct(comment jen.Code, // struct, its methods, and its functions. func (s *Struct) Definition() jen.Code { comment := jen.Empty() - if s.comment != nil { - comment = jen.Empty().Add(s.comment).Line() + if len(s.comment) > 0 { + comment = jen.Commentf(s.comment).Line() } def := comment.Type().Id(s.name).Struct( join(s.members), diff --git a/tools/exp/codegen/typedef.go b/tools/exp/codegen/typedef.go index 1af5ad9..f289681 100644 --- a/tools/exp/codegen/typedef.go +++ b/tools/exp/codegen/typedef.go @@ -9,7 +9,7 @@ import ( // Typedef defines a non-struct-based type, its functions, and its methods for // Go code generation. type Typedef struct { - comment jen.Code + comment string name string concreteType jen.Code methods map[string]*Method @@ -17,7 +17,7 @@ type Typedef struct { } // NewTypedef creates a new commented Typedef. -func NewTypedef(comment jen.Code, +func NewTypedef(comment string, name string, concreteType jen.Code, methods []*Method, @@ -41,9 +41,11 @@ func NewTypedef(comment jen.Code, // Definition generates the Go code required to define and implement this type, // its methods, and its functions. func (t *Typedef) Definition() jen.Code { - def := jen.Empty().Add( - t.comment, - ).Line().Type().Id( + def := jen.Empty() + if len(t.comment) > 0 { + def = jen.Commentf(t.comment).Line() + } + def = def.Type().Id( t.name, ).Add( t.concreteType, diff --git a/tools/exp/props/funcprop.go b/tools/exp/props/funcprop.go index 871ca8b..a420f46 100644 --- a/tools/exp/props/funcprop.go +++ b/tools/exp/props/funcprop.go @@ -1,6 +1,7 @@ package props import ( + "fmt" "github.com/cjslep/activity/tools/exp/codegen" "github.com/dave/jennifer/jen" "sync" @@ -138,7 +139,7 @@ func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method { join(kindIndexFns), jen.Return(jen.Lit(noneOrUnknownKindIndex)), }, - jen.Commentf("%s computes an arbitrary value for indexing this kind of value. This is a leaky API detail only for folks looking to replace the go-fed implementation. Applications should not use this method.", kindIndexMethod), + fmt.Sprintf("%s computes an arbitrary value for indexing this kind of value. This is a leaky API detail only for folks looking to replace the go-fed implementation. Applications should not use this method.", kindIndexMethod), ), } if p.HasNaturalLanguageMap { @@ -153,19 +154,13 @@ func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method { []jen.Code{ jen.Return(jen.Id(codegen.This()).Dot(langMapMember).Op("!=").Nil()), }, - jen.Commentf( - "%s determines if this property is represented by a natural language map.", + fmt.Sprintf( + "%s determines if this property is represented by a natural language map. When true, use %s, %s, and %s methods to access and mutate the natural language map. The %s method can be used to clear the natural language map. Note that this method is only used for natural language representations, and does not determine the presence nor absence of other values for this property.", isLanguageMapMethod, - ).Line().Commentf("").Line().Commentf( - "When true, use %s, %s, and %s methods to access and mutate the natural language map.", hasLanguageMethod, getLanguageMethod, setLanguageMethod, - ).Line().Commentf( - "The %s method can be used to clear the natural language map.", p.clearMethodName(), - ).Line().Commentf("").Line().Commentf( - "Note that this method is only used for natural language representations, and does not determine the presence nor absence of other values for this property.", ))) // HasLanguage Method methods = append(methods, @@ -190,7 +185,7 @@ func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method { jen.Return(jen.Id("ok")), ), }, - jen.Commentf( + fmt.Sprintf( "%s returns true if the natural language map has an entry for the specified BCP47 language code.", hasLanguageMethod, ), @@ -222,7 +217,7 @@ func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method { jen.Return(jen.Lit("")), ), }, - jen.Commentf( + fmt.Sprintf( "%s returns the value for the specified BCP47 language code, or an empty string if it is either not a language map or no value is present.", getLanguageMethod, ), @@ -252,7 +247,7 @@ func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method { ).Op("=").Id("value"), }..., ), - jen.Commentf( + fmt.Sprintf( "%s sets the value for the specified BCP47 language code.", setLanguageMethod, ), @@ -310,7 +305,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co jen.Id(codegen.This()).Dot(unknownMemberName), jen.Nil(), )}, - jen.Commentf("%s converts this into an interface representation suitable for marshalling into a text or binary format.", p.serializeFnName())) + fmt.Sprintf("%s converts this into an interface representation suitable for marshalling into a text or binary format.", p.serializeFnName())) valueDeserializeFns := jen.Empty() typeDeserializeFns := jen.Empty() foundValue := false @@ -371,7 +366,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co ), ), }, - jen.Commentf("%s creates an iterator from an element that has been unmarshalled from a text or binary format.", p.DeserializeFnName())) + fmt.Sprintf("%s creates an iterator from an element that has been unmarshalled from a text or binary format.", p.DeserializeFnName())) } else { deserialize = codegen.NewCommentedFunction( p.GetPrivatePackage().Path(), @@ -395,7 +390,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co jen.Nil(), ), }, - 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())) + fmt.Sprintf("%s creates a %q property from an interface representation that has been unmarshalled from a text or binary format.", p.DeserializeFnName(), p.PropertyName())) } return serialize, deserialize } @@ -403,20 +398,20 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co // singleTypeDef generates a special-case simplified API for a functional // property that can only be a single Kind of value. func (p *FunctionalPropertyGenerator) singleTypeDef() *codegen.Struct { - var comment jen.Code + var comment string var kindMembers []jen.Code if p.Kinds[0].Nilable { - comment = jen.Commentf("%s is the functional property %q. It is permitted to be a single nilable value type.", p.StructName(), p.PropertyName()) + comment = fmt.Sprintf("%s is the functional property %q. It is permitted to be a single nilable value type.", p.StructName(), p.PropertyName()) if p.asIterator { - comment = jen.Commentf("%s is an iterator for a property. It is permitted to be a single nilable value type.", p.StructName()) + comment = fmt.Sprintf("%s is an iterator for a property. It is permitted to be a single nilable value type.", p.StructName()) } kindMembers = []jen.Code{ jen.Id(p.memberName(0)).Add(p.Kinds[0].ConcreteKind), } } else { - comment = jen.Commentf("%s is the functional property %q. It is permitted to be a single default-valued value type.", p.StructName(), p.PropertyName()) + comment = fmt.Sprintf("%s is the functional property %q. It is permitted to be a single default-valued value type.", p.StructName(), p.PropertyName()) if p.asIterator { - comment = jen.Commentf("%s is an iterator for a property. It is permitted to be a single default-valued value type.", p.StructName()) + comment = fmt.Sprintf("%s is an iterator for a property. It is permitted to be a single default-valued value type.", p.StructName()) } kindMembers = []jen.Code{ jen.Id(p.memberName(0)).Add(p.Kinds[0].ConcreteKind), @@ -456,20 +451,16 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method { /*params=*/ nil, []jen.Code{jen.Bool()}, []jen.Code{jen.Return(isLine)}, - jen.Commentf("%s returns true if the value or IRI is set.", hasAnyMethod), + fmt.Sprintf("%s returns true if the value or IRI is set.", hasAnyMethod), )) // Is Method - hasComment := jen.Commentf("%s returns true if this property is set and not an IRI.", p.isMethodName(0)) + hasComment := fmt.Sprintf("%s returns true if this property is set and not an IRI.", p.isMethodName(0)) if p.HasNaturalLanguageMap { - hasComment = jen.Commentf( - "%s returns true if this property is set and is not a natural language map.", + hasComment = fmt.Sprintf( + "%s returns true if this property is set and is not a natural language map. When true, the %s and %s methods may be used to access and set this property. To determine if the property was set as a natural language map, use the %s method instead.", p.isMethodName(0), - ).Line().Commentf("").Line().Commentf( - "When true, the %s and %s methods may be used to access and set this property.", getMethod, p.setFnName(0), - ).Line().Commentf("").Line().Commentf( - "To determine if the property was set as a natural language map, use the %s method instead.", isLanguageMapMethod, ) } @@ -501,10 +492,10 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method { /*params=*/ nil, []jen.Code{jen.Bool()}, []jen.Code{jen.Return(jen.Id(codegen.This()).Dot(iriMember).Op("!=").Nil())}, - jen.Commentf("%s returns true if this property is an IRI.", isIRIMethod), + fmt.Sprintf("%s returns true if this property is an IRI.", isIRIMethod), )) // Get Method - getComment := jen.Commentf("%s returns the value of this property. When %s returns false, %s will return any arbitrary value.", getMethod, p.isMethodName(0), getMethod) + getComment := fmt.Sprintf("%s returns the value of this property. When %s returns false, %s will return any arbitrary value.", getMethod, p.isMethodName(0), getMethod) methods = append(methods, codegen.NewCommentedValueMethod( p.GetPrivatePackage().Path(), p.getFnName(0), @@ -521,16 +512,14 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method { /*params=*/ nil, []jen.Code{jen.Op("*").Qual("net/url", "URL")}, []jen.Code{jen.Return(jen.Id(codegen.This()).Dot(iriMember))}, - jen.Commentf("%s returns the IRI of this property. When %s returns false, %s will return any arbitrary value.", getIRIMethod, isIRIMethod, getIRIMethod), + fmt.Sprintf("%s returns the IRI of this property. When %s returns false, %s will return any arbitrary value.", getIRIMethod, isIRIMethod, getIRIMethod), )) // Set Method - setComment := jen.Commentf("%s sets the value of this property. Calling %s afterwards will return true.", p.setFnName(0), p.isMethodName(0)) + setComment := fmt.Sprintf("%s sets the value of this property. Calling %s afterwards will return true.", p.setFnName(0), p.isMethodName(0)) if p.HasNaturalLanguageMap { - setComment = jen.Commentf( - "%s sets the value of this property and clears the natural language map.", + setComment = fmt.Sprintf( + "%s sets the value of this property and clears the natural language map. Calling %s afterwards will return true. Calling %s afterwards returns false.", p.setFnName(0), - ).Line().Commentf("").Line().Commentf( - "Calling %s afterwards will return true. Calling %s afterwards returns false.", p.isMethodName(0), isLanguageMapMethod, ) @@ -573,17 +562,15 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method { jen.Id(codegen.This()).Dot(p.clearMethodName()).Call(), jen.Id(codegen.This()).Dot(iriMember).Op("=").Id("v"), }, - jen.Commentf("%s sets the value of this property. Calling %s afterwards will return true.", setIRIMethod, isIRIMethod), + fmt.Sprintf("%s sets the value of this property. Calling %s afterwards will return true.", setIRIMethod, isIRIMethod), )) // Clear Method - clearComment := jen.Commentf("%s ensures no value of this property is set. Calling %s afterwards will return false.", p.clearMethodName(), p.isMethodName(0)) + clearComment := fmt.Sprintf("%s ensures no value of this property is set. Calling %s afterwards will return false.", p.clearMethodName(), p.isMethodName(0)) clearCode := p.singleTypeClearNonLanguageMapMembers() if p.HasNaturalLanguageMap { - clearComment = jen.Commentf( - "%s ensures no value and no language map for this property is set.", + clearComment = fmt.Sprintf( + "%s ensures no value and no language map for this property is set. Calling %s or %s afterwards will return false.", p.clearMethodName(), - ).Line().Commentf("").Line().Commentf( - "Calling %s or %s afterwards will return false.", p.isMethodName(0), isLanguageMapMethod, ) @@ -646,7 +633,7 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method { jen.Return(lessCode), ), }, - jen.Commentf("%s compares two instances of this property with an arbitrary but stable comparison.", compareLessMethod), + fmt.Sprintf("%s compares two instances of this property with an arbitrary but stable comparison.", compareLessMethod), )) return methods } @@ -668,22 +655,19 @@ func (p *FunctionalPropertyGenerator) multiTypeDef() *codegen.Struct { if p.HasNaturalLanguageMap { kindMembers = append(kindMembers, jen.Id(langMapMember).Map(jen.String()).String()) } - explanation := jen.Commentf( - "At most, one type of value can be present, or none at all. Setting a value will", - ).Line().Commentf( - "clear the other types of values so that only one of the 'Is' methods will return", - ).Line().Commentf( - "true.", - ).Line().Comment("").Line().Commentf( - "It is possible to clear all values, so that this property is empty.", + explanation := "At most, one type of value can be present, or none at all. Setting a value will clear the other types of values so that only one of the 'Is' methods will return true. It is possible to clear all values, so that this property is empty." + comment := fmt.Sprintf( + "%s is the functional property %q. It is permitted to be one of multiple value types. %s", + p.StructName(), + p.PropertyName(), + explanation, ) - comment := jen.Commentf( - "%s is the functional property %q. It is permitted to be one of multiple value types.", p.StructName(), p.PropertyName(), - ).Line().Comment("").Line().Add(explanation) if p.asIterator { - comment = jen.Commentf( - "%s is an iterator for a property. It is permitted to be one of multiple value types.", p.StructName(), - ).Line().Comment("").Line().Add(explanation) + comment = fmt.Sprintf( + "%s is an iterator for a property. It is permitted to be one of multiple value types. %s", + p.StructName(), + explanation, + ) } var methods []*codegen.Method var funcs []*codegen.Function @@ -710,17 +694,13 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method { isLine[i] = jen.Id(codegen.This()).Dot(p.isMethodName(i)).Call().Op("||") } isLine[len(isLine)-1] = jen.Id(codegen.This()).Dot(iriMember).Op("!=").Nil() - hasAnyComment := jen.Commentf( + hasAnyComment := fmt.Sprintf( "%s returns true if any of the different values is set.", hasAnyMethod, ) if p.HasNaturalLanguageMap { - hasAnyComment = jen.Commentf( - "%s returns true if any of the values are set, except for the natural language map", + hasAnyComment = fmt.Sprintf( + "%s returns true if any of the values are set, except for the natural language map. When true, the specific has, getter, and setter methods may be used to determine what kind of value there is to access and set this property. To determine if the property was set as a natural language map, use the %s method instead.", hasAnyMethod, - ).Line().Commentf("").Line().Commentf( - "When true, the specific has, getter, and setter methods may be used to determine what kind of value there is to access and set this property.", - ).Line().Commentf("").Line().Commentf( - "To determine if the property was set as a natural language map, use the %s method instead.", isLanguageMapMethod, ) } @@ -734,16 +714,14 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method { hasAnyComment, )) // Clear Method - clearComment := jen.Commentf( + clearComment := fmt.Sprintf( "%s ensures no value of this property is set. Calling %s or any of the 'Is' methods afterwards will return false.", p.clearMethodName(), hasAnyMethod, ) clearLine := p.multiTypeClearNonLanguageMapMembers() if p.HasNaturalLanguageMap { - clearComment = jen.Commentf( - "%s ensures no value and no language map for this property is set.", + clearComment = fmt.Sprintf( + "%s ensures no value and no language map for this property is set. Calling %s or any of the 'Is' methods afterwards will return false.", p.clearMethodName(), - ).Line().Commentf("").Line().Commentf( - "Calling %s or any of the 'Is' methods afterwards will return false.", hasAnyMethod, ) clearLine = append(clearLine, jen.Id(codegen.This()).Dot(langMapMember).Op("=").Nil()) @@ -759,14 +737,17 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method { )) // Is Method for i, kind := range p.Kinds { - isComment := jen.Commentf("%s returns true if this property has a type of value of %q.", p.isMethodName(i), kind.ConcreteKind).Line().Commentf("").Line().Commentf( - "When true, use the %s and %s methods to access and set this property.", + isComment := fmt.Sprintf( + "%s returns true if this property has a type of value of %q. When true, use the %s and %s methods to access and set this property.", + p.isMethodName(i), + kind.ConcreteKind, p.getFnName(i), p.setFnName(i), ) if p.HasNaturalLanguageMap { - isComment = isComment.Line().Commentf("").Line().Commentf( - "To determine if the property was set as a natural language map, use the %s method instead.", + isComment = fmt.Sprintf( + "%s. To determine if the property was set as a natural language map, use the %s method instead.", + isComment, isLanguageMapMethod, ) } @@ -799,17 +780,19 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method { /*params=*/ nil, []jen.Code{jen.Bool()}, []jen.Code{jen.Return(jen.Id(codegen.This()).Dot(iriMember).Op("!=").Nil())}, - jen.Commentf("%s returns true if this property is an IRI.", isIRIMethod).Line().Line().Commentf("When true, use %s and %s to access and set this property", getIRIMethod, setIRIMethod), - )) + fmt.Sprintf( + "%s returns true if this property is an IRI. When true, use %s and %s to access and set this property", + isIRIMethod, + getIRIMethod, + setIRIMethod, + ))) // Set Method for i, kind := range p.Kinds { - setComment := jen.Commentf("%s sets the value of this property. Calling %s afterwards returns true.", p.setFnName(i), p.isMethodName(i)) + setComment := fmt.Sprintf("%s sets the value of this property. Calling %s afterwards returns true.", p.setFnName(i), p.isMethodName(i)) if p.HasNaturalLanguageMap { - setComment = jen.Commentf( - "%s sets the value of this property and clears the natural language map.", + setComment = fmt.Sprintf( + "%s sets the value of this property and clears the natural language map. Calling %s afterwards will return true. Calling %s afterwards returns false.", p.setFnName(i), - ).Line().Commentf("").Line().Commentf( - "Calling %s afterwards will return true. Calling %s afterwards returns false.", p.isMethodName(i), isLanguageMapMethod, ) @@ -853,11 +836,11 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method { jen.Id(codegen.This()).Dot(p.clearMethodName()).Call(), jen.Id(codegen.This()).Dot(iriMember).Op("=").Id("v"), }, - jen.Commentf("%s sets the value of this property. Calling %s afterwards returns true.", setIRIMethod, isIRIMethod), + fmt.Sprintf("%s sets the value of this property. Calling %s afterwards returns true.", setIRIMethod, isIRIMethod), )) // Get Method for i, kind := range p.Kinds { - getComment := jen.Commentf("%s returns the value of this property. When %s returns false, %s will return an arbitrary value.", p.getFnName(i), p.isMethodName(i), p.getFnName(i)) + getComment := fmt.Sprintf("%s returns the value of this property. When %s returns false, %s will return an arbitrary value.", p.getFnName(i), p.isMethodName(i), p.getFnName(i)) methods = append(methods, codegen.NewCommentedValueMethod( p.GetPrivatePackage().Path(), p.getFnName(i), @@ -875,7 +858,7 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method { /*params=*/ nil, []jen.Code{jen.Op("*").Qual("net/url", "URL")}, []jen.Code{jen.Return(jen.Id(codegen.This()).Dot(iriMember))}, - jen.Commentf("%s returns the IRI of this property. When %s returns false, %s will return an arbitrary value.", getIRIMethod, isIRIMethod, getIRIMethod), + fmt.Sprintf("%s returns the IRI of this property. When %s returns false, %s will return an arbitrary value.", getIRIMethod, isIRIMethod, getIRIMethod), )) // LessThan Method lessCode := jen.Empty().Add( @@ -911,7 +894,7 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method { lessCode, jen.Return(jen.False()), }, - jen.Commentf("%s compares two instances of this property with an arbitrary but stable comparison.", compareLessMethod), + fmt.Sprintf("%s compares two instances of this property with an arbitrary but stable comparison.", compareLessMethod), )) return methods } diff --git a/tools/exp/props/manager.go b/tools/exp/props/manager.go index 99f0a3f..31120e9 100644 --- a/tools/exp/props/manager.go +++ b/tools/exp/props/manager.go @@ -150,7 +150,7 @@ func (m *ManagerGenerator) Definition() *codegen.Struct { methods = append(methods, nfp.deserializor) } s := codegen.NewStruct( - jen.Commentf(fmt.Sprintf("%s manages interface types and deserializations for use by generated code. Application code implicitly uses this manager at run-time to create concrete implementations of the interfaces.", managerName)), + fmt.Sprintf("%s manages interface types and deserializations for use by generated code. Application code implicitly uses this manager at run-time to create concrete implementations of the interfaces.", managerName), managerName, methods, /*functions=*/ nil, @@ -226,5 +226,5 @@ func (m *ManagerGenerator) createDeserializationMethod(deserName string, pubPkg, ), ), }, - jen.Commentf("%s returns the deserialization method for the %q non-functional property in the vocabulary %q", name, interfaceName, vocabName)) + fmt.Sprintf("%s returns the deserialization method for the %q non-functional property in the vocabulary %q", name, interfaceName, vocabName)) } diff --git a/tools/exp/props/nonfuncprop.go b/tools/exp/props/nonfuncprop.go index ec3dc61..e27c215 100644 --- a/tools/exp/props/nonfuncprop.go +++ b/tools/exp/props/nonfuncprop.go @@ -66,7 +66,7 @@ func (p *NonFunctionalPropertyGenerator) Definitions() (*codegen.Struct, *codege funcs = append(funcs, deser) methods = append(methods, p.funcs()...) property := codegen.NewTypedef( - jen.Commentf("%s is the non-functional property %q. It is permitted to have one or more values, and of different value types.", p.StructName(), p.PropertyName()), + fmt.Sprintf("%s is the non-functional property %q. It is permitted to have one or more values, and of different value types.", p.StructName(), p.PropertyName()), p.StructName(), jen.Index().Op("*").Id(p.iteratorTypeName().CamelName), methods, @@ -136,7 +136,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { jen.Op("*").Id(codegen.This()).Op("..."), ), }, - jen.Commentf("%s prepends a %s value to the front of a list of the property %q.", prependMethodName, kind.ConcreteKind, p.PropertyName()))) + fmt.Sprintf("%s prepends a %s value to the front of a list of the property %q.", prependMethodName, kind.ConcreteKind, p.PropertyName()))) // Append Method appendMethodName := fmt.Sprintf("%s%s", appendMethod, p.kindCamelName(i)) methods = append(methods, @@ -154,7 +154,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { ), ), }, - jen.Commentf("%s appends a %s value to the back of a list of the property %q", appendMethodName, kind.ConcreteKind, p.PropertyName()))) + fmt.Sprintf("%s appends a %s value to the back of a list of the property %q", appendMethodName, kind.ConcreteKind, p.PropertyName()))) // Less logic if i > 0 { less.Else() @@ -186,7 +186,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { jen.Op("*").Id(codegen.This()).Op("..."), ), }, - jen.Commentf("%sIRI prepends an IRI value to the front of a list of the property %q.", prependMethod, p.PropertyName()))) + fmt.Sprintf("%sIRI prepends an IRI value to the front of a list of the property %q.", prependMethod, p.PropertyName()))) methods = append(methods, codegen.NewCommentedPointerMethod( p.GetPrivatePackage().Path(), @@ -204,7 +204,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { ), ), }, - jen.Commentf("%sIRI appends an IRI value to the back of a list of the property %q", appendMethod, p.PropertyName()))) + fmt.Sprintf("%sIRI appends an IRI value to the back of a list of the property %q", appendMethod, p.PropertyName()))) less = less.Else().If( jen.Id("idx1").Op("==").Lit(iriKindIndex), ).Block( @@ -249,7 +249,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { jen.Len(jen.Op("*").Id(codegen.This())).Op("-").Lit(1), ), }, - jen.Commentf("%s deletes an element at the specified index from a list of the property %q, regardless of its type.", removeMethod, p.PropertyName()))) + fmt.Sprintf("%s deletes an element at the specified index from a list of the property %q, regardless of its type.", removeMethod, p.PropertyName()))) // Len Method methods = append(methods, codegen.NewCommentedValueMethod( @@ -265,7 +265,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { ), ), }, - jen.Commentf("%s returns the number of values that exist for the %q property.", lenMethod, p.PropertyName()))) + fmt.Sprintf("%s returns the number of values that exist for the %q property.", lenMethod, p.PropertyName()))) // Swap Method methods = append(methods, codegen.NewCommentedValueMethod( @@ -286,7 +286,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { jen.Id(codegen.This()).Index(jen.Id("i")), ), }, - jen.Commentf("%s swaps the location of values at two indices for the %q property.", swapMethod, p.PropertyName()))) + fmt.Sprintf("%s swaps the location of values at two indices for the %q property.", swapMethod, p.PropertyName()))) // Less Method methods = append(methods, codegen.NewCommentedValueMethod( @@ -308,7 +308,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { ), jen.Return(jen.False()), }, - jen.Commentf("%s computes whether another property is less than this one. Mixing types results in a consistent but arbitrary ordering", lessMethod))) + fmt.Sprintf("%s computes whether another property is less than this one. Mixing types results in a consistent but arbitrary ordering", lessMethod))) // KindIndex Method methods = append(methods, codegen.NewCommentedValueMethod( @@ -322,7 +322,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { jen.Id(codegen.This()).Index(jen.Id("idx")).Dot(kindIndexMethod).Call(), ), }, - jen.Commentf("%s computes an arbitrary value for indexing this kind of value.", kindIndexMethod))) + fmt.Sprintf("%s computes an arbitrary value for indexing this kind of value.", kindIndexMethod))) // LessThan Method lessCode := jen.Empty().Add( jen.Id("l1").Op(":=").Id(codegen.This()).Dot(lenMethod).Call().Line(), @@ -358,7 +358,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { ), jen.Return(jen.Id("l1").Op("<").Id("l2")), }, - jen.Commentf("%s compares two instances of this property with an arbitrary but stable comparison.", compareLessMethod), + fmt.Sprintf("%s compares two instances of this property with an arbitrary but stable comparison.", compareLessMethod), )) // At Method methods = append(methods, codegen.NewCommentedValueMethod( @@ -372,7 +372,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { jen.Id(codegen.This()).Index(jen.Id("index")), ), }, - jen.Commentf("%s returns the property value for the specified index.", atMethodName))) + fmt.Sprintf("%s returns the property value for the specified index.", atMethodName))) methods = append(methods, p.commonMethods()...) return methods } @@ -422,7 +422,7 @@ func (p *NonFunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, jen.Nil(), ), }, - jen.Commentf("%s converts this into an interface representation suitable for marshalling into a text or binary format.", p.serializeFnName())) + fmt.Sprintf("%s converts this into an interface representation suitable for marshalling into a text or binary format.", p.serializeFnName())) deserializeFn := func(variable string) jen.Code { return jen.If( jen.List( @@ -490,6 +490,6 @@ func (p *NonFunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, jen.Nil(), ), }, - 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())) + fmt.Sprintf("%s creates a %q property from an interface representation that has been unmarshalled from a text or binary format.", p.DeserializeFnName(), p.PropertyName())) return serialize, deserialize } diff --git a/tools/exp/props/pkg.go b/tools/exp/props/pkg.go index bac924e..032cf3c 100644 --- a/tools/exp/props/pkg.go +++ b/tools/exp/props/pkg.go @@ -153,7 +153,7 @@ func (t *TypePackageGenerator) PrivateDefinitions(tgs []*TypeGenerator) (*jen.St []jen.Code{ jen.Id(managerInitName()).Op("=").Id("m"), }, - jen.Commentf("%s sets the manager package-global variable. For internal use only, do not use as part of Application behavior. Must be called at golang init time.", setManagerFunctionName)) + fmt.Sprintf("%s sets the manager package-global variable. For internal use only, do not use as part of Application behavior. Must be called at golang init time.", setManagerFunctionName)) } // PropertyPackageGenerator manages generating one-time files needed for @@ -196,7 +196,7 @@ func (p *PropertyPackageGenerator) PrivateDefinitions(pgs []*PropertyGenerator) []jen.Code{ jen.Id(managerInitName()).Op("=").Id("m"), }, - jen.Commentf("%s sets the manager package-global variable. For internal use only, do not use as part of Application behavior. Must be called at golang init time.", setManagerFunctionName)) + fmt.Sprintf("%s sets the manager package-global variable. For internal use only, do not use as part of Application behavior. Must be called at golang init time.", setManagerFunctionName)) } // PackageGenerator maanges generating one-time files needed for both type and @@ -254,5 +254,5 @@ func (t *PackageGenerator) PrivateDefinitions(tgs []*TypeGenerator, pgs []*Prope []jen.Code{ jen.Id(managerInitName()).Op("=").Id("m"), }, - jen.Commentf("%s sets the manager package-global variable. For internal use only, do not use as part of Application behavior. Must be called at golang init time.", setManagerFunctionName)) + fmt.Sprintf("%s sets the manager package-global variable. For internal use only, do not use as part of Application behavior. Must be called at golang init time.", setManagerFunctionName)) } diff --git a/tools/exp/props/property.go b/tools/exp/props/property.go index 546fcdb..33b02e9 100644 --- a/tools/exp/props/property.go +++ b/tools/exp/props/property.go @@ -293,7 +293,7 @@ func (p *PropertyGenerator) commonMethods() []*codegen.Method { jen.Lit(p.PropertyName()), ), }, - jen.Commentf("%s returns the name of this property: %q.", nameMethod, p.PropertyName()), + fmt.Sprintf("%s returns the name of this property: %q.", nameMethod, p.PropertyName()), ), } } diff --git a/tools/exp/props/type.go b/tools/exp/props/type.go index eb53e2c..1db2e4d 100644 --- a/tools/exp/props/type.go +++ b/tools/exp/props/type.go @@ -247,7 +247,7 @@ func (t *TypeGenerator) Definition() *codegen.Struct { getters := t.allGetters() setters := t.allSetters() t.cachedStruct = codegen.NewStruct( - jen.Commentf(t.Comments()), + t.Comments(), t.TypeName(), append(append( []*codegen.Method{ @@ -341,7 +341,7 @@ func (t *TypeGenerator) nameDefinition() *codegen.Method { []jen.Code{ jen.Return(jen.Lit(t.TypeName())), }, - jen.Commentf("%s returns the name of this type.", typeNameMethod)) + fmt.Sprintf("%s returns the name of this type.", typeNameMethod)) } // getAllParentExtends recursively determines all the parent types that this @@ -387,7 +387,7 @@ func (t *TypeGenerator) extendsDefinition() (*codegen.Function, *codegen.Method) []jen.Code{jen.Id("other").Qual(t.PublicPackage().Path(), typeInterfaceName)}, []jen.Code{jen.Bool()}, impl, - jen.Commentf("%s returns true if the %s type extends from the other type.", t.extendsFnName(), t.TypeName())) + fmt.Sprintf("%s returns true if the %s type extends from the other type.", t.extendsFnName(), t.TypeName())) m := codegen.NewCommentedValueMethod( t.PrivatePackage().Path(), extendingMethod, @@ -399,7 +399,7 @@ func (t *TypeGenerator) extendsDefinition() (*codegen.Function, *codegen.Method) jen.Id(t.extendsFnName()).Call(jen.Id("other")), ), }, - jen.Commentf("%s returns true if the %s type extends from the other type.", extendingMethod, t.TypeName())) + fmt.Sprintf("%s returns true if the %s type extends from the other type.", extendingMethod, t.TypeName())) return f, m } @@ -443,7 +443,7 @@ func (t *TypeGenerator) extendedByDefinition() *codegen.Function { []jen.Code{jen.Id("other").Qual(t.PublicPackage().Path(), typeInterfaceName)}, []jen.Code{jen.Bool()}, impl, - jen.Commentf("%s returns true if the other provided type extends from the %s type.", t.extendedByFnName(), t.TypeName())) + fmt.Sprintf("%s returns true if the other provided type extends from the %s type.", t.extendedByFnName(), t.TypeName())) } // getAllChildrenDisjointWith recursivley determines all the child types that this @@ -492,7 +492,7 @@ func (t *TypeGenerator) disjointWithDefinition() *codegen.Function { []jen.Code{jen.Id("other").Qual(t.PublicPackage().Path(), typeInterfaceName)}, []jen.Code{jen.Bool()}, impl, - jen.Commentf("%s returns true if the other provided type is disjoint with the %s type.", t.disjointWithFnName(), t.TypeName())) + fmt.Sprintf("%s returns true if the other provided type is disjoint with the %s type.", t.disjointWithFnName(), t.TypeName())) } // serializationMethod returns the method needed to serialize a TypeGenerator as @@ -548,7 +548,7 @@ func (t *TypeGenerator) serializationMethod() (ser *codegen.Method) { unknownCode, jen.Return(jen.Id("m"), jen.Nil()), }, - jen.Commentf("%s converts this into an interface representation suitable for marshalling into a text or binary format.", serializeMethodName)) + fmt.Sprintf("%s converts this into an interface representation suitable for marshalling into a text or binary format.", serializeMethodName)) return } @@ -608,7 +608,7 @@ func (t *TypeGenerator) lessMethod() (less *codegen.Method) { jen.Commentf("All properties are the same."), jen.Return(jen.False()), }, - jen.Commentf("%s computes if this %s is lesser, with an arbitrary but stable determination.", compareLessMethod, t.TypeName())) + fmt.Sprintf("%s computes if this %s is lesser, with an arbitrary but stable determination.", compareLessMethod, t.TypeName())) return } @@ -666,7 +666,7 @@ func (t *TypeGenerator) kindDeserializationFunc() (deser *codegen.Function) { unknownCode, jen.Return(jen.Id(codegen.This()), jen.Nil()), }, - jen.Commentf("%s creates a %s from a map representation that has been unmarshalled from a text or binary format.", t.deserializationFnName(), t.TypeName())) + fmt.Sprintf("%s creates a %s from a map representation that has been unmarshalled from a text or binary format.", t.deserializationFnName(), t.TypeName())) return } @@ -683,7 +683,7 @@ func (t *TypeGenerator) getUnknownMethod() (get *codegen.Method) { []jen.Code{ jen.Return(jen.Id(codegen.This()).Dot(unknownMember)), }, - jen.Commentf(`%s returns the unknown properties for the %s type. + fmt.Sprintf(`%s returns the unknown properties for the %s type. Note that this should not be used by app developers. It is only used to help determine which implementation is LessThan the other. Developers who are creating a different @@ -707,7 +707,7 @@ func (t *TypeGenerator) allGetters() (m []*codegen.Method) { jen.Id(codegen.This()).Dot(t.memberName(property)), ), }, - jen.Commentf(getMethodFormat+" returns the %q property if it exists, and nil otherwise.", t.memberName(property), property.PropertyName()))) + fmt.Sprintf(getMethodFormat+" returns the %q property if it exists, and nil otherwise.", t.memberName(property), property.PropertyName()))) } return } @@ -724,7 +724,7 @@ func (t *TypeGenerator) allSetters() (m []*codegen.Method) { []jen.Code{ jen.Id(codegen.This()).Dot(t.memberName(property)).Op("=").Id("i"), }, - jen.Commentf("Set%s returns the %q property if it exists, and nil otherwise.", t.memberName(property), property.PropertyName()))) + fmt.Sprintf("Set%s returns the %q property if it exists, and nil otherwise.", t.memberName(property), property.PropertyName()))) } return } diff --git a/tools/exp/rdf/ontology.go b/tools/exp/rdf/ontology.go index 5b245bc..2b18187 100644 --- a/tools/exp/rdf/ontology.go +++ b/tools/exp/rdf/ontology.go @@ -24,7 +24,7 @@ func SerializeValueFunction(pkg, valueName string, []jen.Code{jen.Id(codegen.This()).Add(concreteType)}, []jen.Code{jen.Interface(), jen.Error()}, impl, - jen.Commentf("%s converts a %s value to an interface representation suitable for marshalling into a text or binary format.", name, valueName)) + fmt.Sprintf("%s converts a %s value to an interface representation suitable for marshalling into a text or binary format.", name, valueName)) } func DeserializeValueFunction(pkg, valueName string, @@ -37,7 +37,7 @@ func DeserializeValueFunction(pkg, valueName string, []jen.Code{jen.Id(codegen.This()).Interface()}, []jen.Code{concreteType, jen.Error()}, impl, - jen.Commentf("%s creates %s value from an interface representation that has been unmarshalled from a text or binary format.", name, valueName)) + fmt.Sprintf("%s creates %s value from an interface representation that has been unmarshalled from a text or binary format.", name, valueName)) } func LessFunction(pkg, valueName string, @@ -50,7 +50,7 @@ func LessFunction(pkg, valueName string, []jen.Code{jen.List(jen.Id("lhs"), jen.Id("rhs")).Add(concreteType)}, []jen.Code{jen.Bool()}, impl, - jen.Commentf("%s returns true if the left %s value is less than the right value.", name, valueName)) + fmt.Sprintf("%s returns true if the left %s value is less than the right value.", name, valueName)) } type RDFOntology struct {