Make property members private.
このコミットが含まれているのは:
コミット
c8cec42c57
|
@ -355,14 +355,14 @@ func (c Converter) convertType(t rdf.VocabularyType,
|
||||||
name := c.convertTypeToName(t)
|
name := c.convertTypeToName(t)
|
||||||
var rangeProps []props.Property
|
var rangeProps []props.Property
|
||||||
for _, prop := range existingFProps {
|
for _, prop := range existingFProps {
|
||||||
for _, kind := range prop.Kinds {
|
for _, kind := range prop.GetKinds() {
|
||||||
if kind.Name.LowerName == name {
|
if kind.Name.LowerName == name {
|
||||||
rangeProps = append(rangeProps, prop)
|
rangeProps = append(rangeProps, prop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, prop := range existingNFProps {
|
for _, prop := range existingNFProps {
|
||||||
for _, kind := range prop.Kinds {
|
for _, kind := range prop.GetKinds() {
|
||||||
if kind.Name.LowerName == name {
|
if kind.Name.LowerName == name {
|
||||||
rangeProps = append(rangeProps, prop)
|
rangeProps = append(rangeProps, prop)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,11 @@ func NewFunctionalPropertyGenerator(vocabName string,
|
||||||
return &FunctionalPropertyGenerator{
|
return &FunctionalPropertyGenerator{
|
||||||
PropertyGenerator: PropertyGenerator{
|
PropertyGenerator: PropertyGenerator{
|
||||||
vocabName: vocabName,
|
vocabName: vocabName,
|
||||||
PackageManager: pm,
|
packageManager: pm,
|
||||||
HasNaturalLanguageMap: hasNaturalLanguageMap,
|
hasNaturalLanguageMap: hasNaturalLanguageMap,
|
||||||
Name: name,
|
name: name,
|
||||||
Comment: comment,
|
comment: comment,
|
||||||
Kinds: kinds,
|
kinds: kinds,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func (p *FunctionalPropertyGenerator) InterfaceDefinition(pkg Package) *codegen.
|
||||||
// isSingleTypeDef determines whether a special-case API can be generated for
|
// isSingleTypeDef determines whether a special-case API can be generated for
|
||||||
// one allowed Kind.
|
// one allowed Kind.
|
||||||
func (p *FunctionalPropertyGenerator) isSingleTypeDef() bool {
|
func (p *FunctionalPropertyGenerator) isSingleTypeDef() bool {
|
||||||
return len(p.Kinds) == 1
|
return len(p.kinds) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Definition produces the Go Struct code definition, which can generate its Go
|
// Definition produces the Go Struct code definition, which can generate its Go
|
||||||
|
@ -88,7 +88,7 @@ func (p *FunctionalPropertyGenerator) singleTypeClearNonLanguageMapMembers() []j
|
||||||
jen.Id(codegen.This()).Dot(unknownMemberName).Op("=").Nil(),
|
jen.Id(codegen.This()).Dot(unknownMemberName).Op("=").Nil(),
|
||||||
jen.Id(codegen.This()).Dot(iriMember).Op("=").Nil(),
|
jen.Id(codegen.This()).Dot(iriMember).Op("=").Nil(),
|
||||||
}
|
}
|
||||||
if p.Kinds[0].Nilable {
|
if p.kinds[0].Nilable {
|
||||||
clearCode = append(clearCode, jen.Id(codegen.This()).Dot(p.memberName(0)).Op("=").Nil())
|
clearCode = append(clearCode, jen.Id(codegen.This()).Dot(p.memberName(0)).Op("=").Nil())
|
||||||
} else {
|
} else {
|
||||||
clearCode = append(clearCode, jen.Id(codegen.This()).Dot(p.hasMemberName(0)).Op("=").False())
|
clearCode = append(clearCode, jen.Id(codegen.This()).Dot(p.hasMemberName(0)).Op("=").False())
|
||||||
|
@ -99,8 +99,8 @@ func (p *FunctionalPropertyGenerator) singleTypeClearNonLanguageMapMembers() []j
|
||||||
// multiTypeClearNonLanguageMapMembers generates code to clear all members for
|
// multiTypeClearNonLanguageMapMembers generates code to clear all members for
|
||||||
// a property with multiple Kinds.
|
// a property with multiple Kinds.
|
||||||
func (p *FunctionalPropertyGenerator) multiTypeClearNonLanguageMapMembers() []jen.Code {
|
func (p *FunctionalPropertyGenerator) multiTypeClearNonLanguageMapMembers() []jen.Code {
|
||||||
clearLine := make([]jen.Code, len(p.Kinds)+2) // +2 for the unknown, and maybe language map
|
clearLine := make([]jen.Code, len(p.kinds)+2) // +2 for the unknown, and maybe language map
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
if kind.Nilable {
|
if kind.Nilable {
|
||||||
clearLine[i] = jen.Id(codegen.This()).Dot(p.memberName(i)).Op("=").Nil()
|
clearLine[i] = jen.Id(codegen.This()).Dot(p.memberName(i)).Op("=").Nil()
|
||||||
} else {
|
} else {
|
||||||
|
@ -114,8 +114,8 @@ func (p *FunctionalPropertyGenerator) multiTypeClearNonLanguageMapMembers() []je
|
||||||
|
|
||||||
// funcs produces the methods needed for the functional property.
|
// funcs produces the methods needed for the functional property.
|
||||||
func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method {
|
func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method {
|
||||||
kindIndexFns := make([]jen.Code, 0, len(p.Kinds)+1)
|
kindIndexFns := make([]jen.Code, 0, len(p.kinds)+1)
|
||||||
for i, _ := range p.Kinds {
|
for i, _ := range p.kinds {
|
||||||
kindIndexFns = append(kindIndexFns, jen.If(
|
kindIndexFns = append(kindIndexFns, jen.If(
|
||||||
jen.Id(codegen.This()).Dot(p.isMethodName(i)).Call(),
|
jen.Id(codegen.This()).Dot(p.isMethodName(i)).Call(),
|
||||||
).Block(
|
).Block(
|
||||||
|
@ -142,7 +142,7 @@ func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method {
|
||||||
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),
|
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 {
|
if p.hasNaturalLanguageMap {
|
||||||
// IsLanguageMap Method
|
// IsLanguageMap Method
|
||||||
methods = append(methods,
|
methods = append(methods,
|
||||||
codegen.NewCommentedValueMethod(
|
codegen.NewCommentedValueMethod(
|
||||||
|
@ -261,7 +261,7 @@ func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method {
|
||||||
// encoding.
|
// encoding.
|
||||||
func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *codegen.Function) {
|
func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *codegen.Function) {
|
||||||
serializeFns := jen.Empty()
|
serializeFns := jen.Empty()
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
serializeFns = serializeFns.Else()
|
serializeFns = serializeFns.Else()
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co
|
||||||
typeDeserializeFns := jen.Empty()
|
typeDeserializeFns := jen.Empty()
|
||||||
foundValue := false
|
foundValue := false
|
||||||
foundType := false
|
foundType := false
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
values := jen.Dict{
|
values := jen.Dict{
|
||||||
jen.Id(p.memberName(i)): jen.Id("v"),
|
jen.Id(p.memberName(i)): jen.Id("v"),
|
||||||
}
|
}
|
||||||
|
@ -400,13 +400,13 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co
|
||||||
func (p *FunctionalPropertyGenerator) singleTypeDef() *codegen.Struct {
|
func (p *FunctionalPropertyGenerator) singleTypeDef() *codegen.Struct {
|
||||||
var comment string
|
var comment string
|
||||||
var kindMembers []jen.Code
|
var kindMembers []jen.Code
|
||||||
if p.Kinds[0].Nilable {
|
if p.kinds[0].Nilable {
|
||||||
comment = fmt.Sprintf("%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 {
|
if p.asIterator {
|
||||||
comment = fmt.Sprintf("%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{
|
kindMembers = []jen.Code{
|
||||||
jen.Id(p.memberName(0)).Add(p.Kinds[0].ConcreteKind),
|
jen.Id(p.memberName(0)).Add(p.kinds[0].ConcreteKind),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
comment = fmt.Sprintf("%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())
|
||||||
|
@ -414,13 +414,13 @@ func (p *FunctionalPropertyGenerator) singleTypeDef() *codegen.Struct {
|
||||||
comment = fmt.Sprintf("%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{
|
kindMembers = []jen.Code{
|
||||||
jen.Id(p.memberName(0)).Add(p.Kinds[0].ConcreteKind),
|
jen.Id(p.memberName(0)).Add(p.kinds[0].ConcreteKind),
|
||||||
jen.Id(p.hasMemberName(0)).Bool(),
|
jen.Id(p.hasMemberName(0)).Bool(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kindMembers = append(kindMembers, p.unknownMemberDef())
|
kindMembers = append(kindMembers, p.unknownMemberDef())
|
||||||
kindMembers = append(kindMembers, p.iriMemberDef())
|
kindMembers = append(kindMembers, p.iriMemberDef())
|
||||||
if p.HasNaturalLanguageMap {
|
if p.hasNaturalLanguageMap {
|
||||||
kindMembers = append(kindMembers, jen.Id(langMapMember).Map(jen.String()).String())
|
kindMembers = append(kindMembers, jen.Id(langMapMember).Map(jen.String()).String())
|
||||||
}
|
}
|
||||||
var methods []*codegen.Method
|
var methods []*codegen.Method
|
||||||
|
@ -455,7 +455,7 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
))
|
))
|
||||||
// Is Method
|
// Is Method
|
||||||
hasComment := fmt.Sprintf("%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 {
|
if p.hasNaturalLanguageMap {
|
||||||
hasComment = fmt.Sprintf(
|
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.",
|
"%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),
|
p.isMethodName(0),
|
||||||
|
@ -464,7 +464,7 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
isLanguageMapMethod,
|
isLanguageMapMethod,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if p.Kinds[0].Nilable {
|
if p.kinds[0].Nilable {
|
||||||
methods = append(methods, codegen.NewCommentedValueMethod(
|
methods = append(methods, codegen.NewCommentedValueMethod(
|
||||||
p.GetPrivatePackage().Path(),
|
p.GetPrivatePackage().Path(),
|
||||||
p.isMethodName(0),
|
p.isMethodName(0),
|
||||||
|
@ -501,7 +501,7 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
p.getFnName(0),
|
p.getFnName(0),
|
||||||
p.StructName(),
|
p.StructName(),
|
||||||
/*params=*/ nil,
|
/*params=*/ nil,
|
||||||
[]jen.Code{p.Kinds[0].ConcreteKind},
|
[]jen.Code{p.kinds[0].ConcreteKind},
|
||||||
[]jen.Code{jen.Return(jen.Id(codegen.This()).Dot(p.memberName(0)))},
|
[]jen.Code{jen.Return(jen.Id(codegen.This()).Dot(p.memberName(0)))},
|
||||||
getComment,
|
getComment,
|
||||||
))
|
))
|
||||||
|
@ -516,7 +516,7 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
))
|
))
|
||||||
// Set Method
|
// Set Method
|
||||||
setComment := fmt.Sprintf("%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 {
|
if p.hasNaturalLanguageMap {
|
||||||
setComment = fmt.Sprintf(
|
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.",
|
"%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),
|
p.setFnName(0),
|
||||||
|
@ -524,12 +524,12 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
isLanguageMapMethod,
|
isLanguageMapMethod,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if p.Kinds[0].Nilable {
|
if p.kinds[0].Nilable {
|
||||||
methods = append(methods, codegen.NewCommentedPointerMethod(
|
methods = append(methods, codegen.NewCommentedPointerMethod(
|
||||||
p.GetPrivatePackage().Path(),
|
p.GetPrivatePackage().Path(),
|
||||||
p.setFnName(0),
|
p.setFnName(0),
|
||||||
p.StructName(),
|
p.StructName(),
|
||||||
[]jen.Code{jen.Id("v").Add(p.Kinds[0].ConcreteKind)},
|
[]jen.Code{jen.Id("v").Add(p.kinds[0].ConcreteKind)},
|
||||||
/*ret=*/ nil,
|
/*ret=*/ nil,
|
||||||
[]jen.Code{
|
[]jen.Code{
|
||||||
jen.Id(codegen.This()).Dot(p.clearMethodName()).Call(),
|
jen.Id(codegen.This()).Dot(p.clearMethodName()).Call(),
|
||||||
|
@ -542,7 +542,7 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
p.GetPrivatePackage().Path(),
|
p.GetPrivatePackage().Path(),
|
||||||
p.setFnName(0),
|
p.setFnName(0),
|
||||||
p.StructName(),
|
p.StructName(),
|
||||||
[]jen.Code{jen.Id("v").Add(p.Kinds[0].ConcreteKind)},
|
[]jen.Code{jen.Id("v").Add(p.kinds[0].ConcreteKind)},
|
||||||
/*ret=*/ nil,
|
/*ret=*/ nil,
|
||||||
[]jen.Code{
|
[]jen.Code{
|
||||||
jen.Id(codegen.This()).Dot(p.clearMethodName()).Call(),
|
jen.Id(codegen.This()).Dot(p.clearMethodName()).Call(),
|
||||||
|
@ -567,7 +567,7 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
// Clear Method
|
// Clear Method
|
||||||
clearComment := fmt.Sprintf("%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()
|
clearCode := p.singleTypeClearNonLanguageMapMembers()
|
||||||
if p.HasNaturalLanguageMap {
|
if p.hasNaturalLanguageMap {
|
||||||
clearComment = fmt.Sprintf(
|
clearComment = fmt.Sprintf(
|
||||||
"%s ensures no value and no language map for this property is set. Calling %s or %s afterwards will return false.",
|
"%s ensures no value and no language map for this property is set. Calling %s or %s afterwards will return false.",
|
||||||
p.clearMethodName(),
|
p.clearMethodName(),
|
||||||
|
@ -586,7 +586,7 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
clearComment,
|
clearComment,
|
||||||
))
|
))
|
||||||
// LessThan Method
|
// LessThan Method
|
||||||
lessCode := p.Kinds[0].lessFnCode(jen.Id(codegen.This()).Dot(p.getFnName(0)).Call(), jen.Id("o").Dot(p.getFnName(0)).Call())
|
lessCode := p.kinds[0].lessFnCode(jen.Id(codegen.This()).Dot(p.getFnName(0)).Call(), jen.Id("o").Dot(p.getFnName(0)).Call())
|
||||||
methods = append(methods, codegen.NewCommentedValueMethod(
|
methods = append(methods, codegen.NewCommentedValueMethod(
|
||||||
p.GetPrivatePackage().Path(),
|
p.GetPrivatePackage().Path(),
|
||||||
compareLessMethod,
|
compareLessMethod,
|
||||||
|
@ -641,18 +641,18 @@ func (p *FunctionalPropertyGenerator) singleTypeFuncs() []*codegen.Method {
|
||||||
// multiTypeDef generates an API for a functional property that can be multiple
|
// multiTypeDef generates an API for a functional property that can be multiple
|
||||||
// Kinds of value.
|
// Kinds of value.
|
||||||
func (p *FunctionalPropertyGenerator) multiTypeDef() *codegen.Struct {
|
func (p *FunctionalPropertyGenerator) multiTypeDef() *codegen.Struct {
|
||||||
kindMembers := make([]jen.Code, 0, len(p.Kinds))
|
kindMembers := make([]jen.Code, 0, len(p.kinds))
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
if kind.Nilable {
|
if kind.Nilable {
|
||||||
kindMembers = append(kindMembers, jen.Id(p.memberName(i)).Add(p.Kinds[i].ConcreteKind))
|
kindMembers = append(kindMembers, jen.Id(p.memberName(i)).Add(p.kinds[i].ConcreteKind))
|
||||||
} else {
|
} else {
|
||||||
kindMembers = append(kindMembers, jen.Id(p.memberName(i)).Add(p.Kinds[i].ConcreteKind))
|
kindMembers = append(kindMembers, jen.Id(p.memberName(i)).Add(p.kinds[i].ConcreteKind))
|
||||||
kindMembers = append(kindMembers, jen.Id(p.hasMemberName(i)).Bool())
|
kindMembers = append(kindMembers, jen.Id(p.hasMemberName(i)).Bool())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kindMembers = append(kindMembers, p.unknownMemberDef())
|
kindMembers = append(kindMembers, p.unknownMemberDef())
|
||||||
kindMembers = append(kindMembers, p.iriMemberDef())
|
kindMembers = append(kindMembers, p.iriMemberDef())
|
||||||
if p.HasNaturalLanguageMap {
|
if p.hasNaturalLanguageMap {
|
||||||
kindMembers = append(kindMembers, jen.Id(langMapMember).Map(jen.String()).String())
|
kindMembers = append(kindMembers, jen.Id(langMapMember).Map(jen.String()).String())
|
||||||
}
|
}
|
||||||
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."
|
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."
|
||||||
|
@ -689,15 +689,15 @@ func (p *FunctionalPropertyGenerator) multiTypeDef() *codegen.Struct {
|
||||||
func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
||||||
var methods []*codegen.Method
|
var methods []*codegen.Method
|
||||||
// HasAny Method
|
// HasAny Method
|
||||||
isLine := make([]jen.Code, len(p.Kinds)+1)
|
isLine := make([]jen.Code, len(p.kinds)+1)
|
||||||
for i := range p.Kinds {
|
for i := range p.kinds {
|
||||||
isLine[i] = jen.Id(codegen.This()).Dot(p.isMethodName(i)).Call().Op("||")
|
isLine[i] = jen.Id(codegen.This()).Dot(p.isMethodName(i)).Call().Op("||")
|
||||||
}
|
}
|
||||||
isLine[len(isLine)-1] = jen.Id(codegen.This()).Dot(iriMember).Op("!=").Nil()
|
isLine[len(isLine)-1] = jen.Id(codegen.This()).Dot(iriMember).Op("!=").Nil()
|
||||||
hasAnyComment := fmt.Sprintf(
|
hasAnyComment := fmt.Sprintf(
|
||||||
"%s returns true if any of the different values is set.", hasAnyMethod,
|
"%s returns true if any of the different values is set.", hasAnyMethod,
|
||||||
)
|
)
|
||||||
if p.HasNaturalLanguageMap {
|
if p.hasNaturalLanguageMap {
|
||||||
hasAnyComment = fmt.Sprintf(
|
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.",
|
"%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,
|
hasAnyMethod,
|
||||||
|
@ -718,7 +718,7 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
||||||
"%s ensures no value of this property is set. Calling %s or any of the 'Is' methods afterwards will return false.", p.clearMethodName(), hasAnyMethod,
|
"%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()
|
clearLine := p.multiTypeClearNonLanguageMapMembers()
|
||||||
if p.HasNaturalLanguageMap {
|
if p.hasNaturalLanguageMap {
|
||||||
clearComment = fmt.Sprintf(
|
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.",
|
"%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(),
|
p.clearMethodName(),
|
||||||
|
@ -736,7 +736,7 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
||||||
clearComment,
|
clearComment,
|
||||||
))
|
))
|
||||||
// Is Method
|
// Is Method
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
isComment := fmt.Sprintf(
|
isComment := fmt.Sprintf(
|
||||||
"%s returns true if this property has a type of %q. When true, use the %s and %s methods to access and set this property.",
|
"%s returns true if this property has a type of %q. When true, use the %s and %s methods to access and set this property.",
|
||||||
p.isMethodName(i),
|
p.isMethodName(i),
|
||||||
|
@ -744,7 +744,7 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
||||||
p.getFnName(i),
|
p.getFnName(i),
|
||||||
p.setFnName(i),
|
p.setFnName(i),
|
||||||
)
|
)
|
||||||
if p.HasNaturalLanguageMap {
|
if p.hasNaturalLanguageMap {
|
||||||
isComment = fmt.Sprintf(
|
isComment = fmt.Sprintf(
|
||||||
"%s. To determine if the property was set as a natural language map, use the %s method instead.",
|
"%s. To determine if the property was set as a natural language map, use the %s method instead.",
|
||||||
isComment,
|
isComment,
|
||||||
|
@ -787,9 +787,9 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
||||||
setIRIMethod,
|
setIRIMethod,
|
||||||
)))
|
)))
|
||||||
// Set Method
|
// Set Method
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
setComment := fmt.Sprintf("%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 {
|
if p.hasNaturalLanguageMap {
|
||||||
setComment = fmt.Sprintf(
|
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.",
|
"%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),
|
p.setFnName(i),
|
||||||
|
@ -839,7 +839,7 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
||||||
fmt.Sprintf("%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
|
// Get Method
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
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))
|
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(
|
methods = append(methods, codegen.NewCommentedValueMethod(
|
||||||
p.GetPrivatePackage().Path(),
|
p.GetPrivatePackage().Path(),
|
||||||
|
@ -869,7 +869,7 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
||||||
).Else().If(jen.Id("idx1").Op(">").Id("idx2")).Block(
|
).Else().If(jen.Id("idx1").Op(">").Id("idx2")).Block(
|
||||||
jen.Return(jen.False()),
|
jen.Return(jen.False()),
|
||||||
))
|
))
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
lessCode.Add(
|
lessCode.Add(
|
||||||
jen.Else().If(
|
jen.Else().If(
|
||||||
jen.Id(codegen.This()).Dot(p.isMethodName(i)).Call(),
|
jen.Id(codegen.This()).Dot(p.isMethodName(i)).Call(),
|
||||||
|
@ -993,7 +993,7 @@ func (p *FunctionalPropertyGenerator) wrapDeserializeCode(valueExisting, typeExi
|
||||||
|
|
||||||
// hasURIKind returns true if this property already has a Kind that is a URI.
|
// hasURIKind returns true if this property already has a Kind that is a URI.
|
||||||
func (p *FunctionalPropertyGenerator) hasURIKind() bool {
|
func (p *FunctionalPropertyGenerator) hasURIKind() bool {
|
||||||
for _, k := range p.Kinds {
|
for _, k := range p.kinds {
|
||||||
if k.IsURI {
|
if k.IsURI {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -1003,7 +1003,7 @@ func (p *FunctionalPropertyGenerator) hasURIKind() bool {
|
||||||
|
|
||||||
// hasTypeKind returns true if this property has a Kind that is a type.
|
// hasTypeKind returns true if this property has a Kind that is a type.
|
||||||
func (p *FunctionalPropertyGenerator) hasTypeKind() bool {
|
func (p *FunctionalPropertyGenerator) hasTypeKind() bool {
|
||||||
for _, k := range p.Kinds {
|
for _, k := range p.kinds {
|
||||||
if !k.isValue() {
|
if !k.isValue() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1013,7 @@ func (p *FunctionalPropertyGenerator) hasTypeKind() bool {
|
||||||
|
|
||||||
// hasValueKind returns true if this property has a Kind that is a Value.
|
// hasValueKind returns true if this property has a Kind that is a Value.
|
||||||
func (p *FunctionalPropertyGenerator) hasValueKind() bool {
|
func (p *FunctionalPropertyGenerator) hasValueKind() bool {
|
||||||
for _, k := range p.Kinds {
|
for _, k := range p.kinds {
|
||||||
if k.isValue() {
|
if k.isValue() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,11 @@ func NewNonFunctionalPropertyGenerator(vocabName string,
|
||||||
return &NonFunctionalPropertyGenerator{
|
return &NonFunctionalPropertyGenerator{
|
||||||
PropertyGenerator: PropertyGenerator{
|
PropertyGenerator: PropertyGenerator{
|
||||||
vocabName: vocabName,
|
vocabName: vocabName,
|
||||||
PackageManager: pm,
|
packageManager: pm,
|
||||||
HasNaturalLanguageMap: hasNaturalLanguageMap,
|
hasNaturalLanguageMap: hasNaturalLanguageMap,
|
||||||
Name: name,
|
name: name,
|
||||||
Comment: comment,
|
comment: comment,
|
||||||
Kinds: kinds,
|
kinds: kinds,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,10 +87,10 @@ func (p *NonFunctionalPropertyGenerator) iteratorInterfaceName() string {
|
||||||
func (p *NonFunctionalPropertyGenerator) elementTypeGenerator() *FunctionalPropertyGenerator {
|
func (p *NonFunctionalPropertyGenerator) elementTypeGenerator() *FunctionalPropertyGenerator {
|
||||||
return &FunctionalPropertyGenerator{
|
return &FunctionalPropertyGenerator{
|
||||||
PropertyGenerator: PropertyGenerator{
|
PropertyGenerator: PropertyGenerator{
|
||||||
PackageManager: p.PropertyGenerator.PackageManager,
|
packageManager: p.PropertyGenerator.packageManager,
|
||||||
Name: p.iteratorTypeName(),
|
name: p.iteratorTypeName(),
|
||||||
Kinds: p.Kinds,
|
kinds: p.kinds,
|
||||||
HasNaturalLanguageMap: p.PropertyGenerator.HasNaturalLanguageMap,
|
hasNaturalLanguageMap: p.PropertyGenerator.hasNaturalLanguageMap,
|
||||||
asIterator: true,
|
asIterator: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func (p *NonFunctionalPropertyGenerator) elementTypeGenerator() *FunctionalPrope
|
||||||
func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method {
|
func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method {
|
||||||
var methods []*codegen.Method
|
var methods []*codegen.Method
|
||||||
less := jen.Empty()
|
less := jen.Empty()
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
dict := jen.Dict{
|
dict := jen.Dict{
|
||||||
jen.Id(p.memberName(i)): jen.Id("v"),
|
jen.Id(p.memberName(i)): jen.Id("v"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,17 +126,14 @@ func (k Kind) isValue() bool {
|
||||||
//
|
//
|
||||||
// It also properly handles the concept of generating Go code for property
|
// It also properly handles the concept of generating Go code for property
|
||||||
// iterators, which are needed for NonFunctional properties.
|
// iterators, which are needed for NonFunctional properties.
|
||||||
//
|
|
||||||
// TODO: Make this type private
|
|
||||||
type PropertyGenerator struct {
|
type PropertyGenerator struct {
|
||||||
vocabName string
|
vocabName string
|
||||||
managerMethods []*codegen.Method
|
managerMethods []*codegen.Method
|
||||||
// TODO: Make these private
|
packageManager *PackageManager
|
||||||
PackageManager *PackageManager
|
name Identifier
|
||||||
Name Identifier
|
comment string
|
||||||
Comment string
|
kinds []Kind
|
||||||
Kinds []Kind
|
hasNaturalLanguageMap bool
|
||||||
HasNaturalLanguageMap bool
|
|
||||||
asIterator bool
|
asIterator bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,14 +142,19 @@ func (p *PropertyGenerator) VocabName() string {
|
||||||
return p.vocabName
|
return p.vocabName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetKinds gets this property's kinds.
|
||||||
|
func (p *PropertyGenerator) GetKinds() []Kind {
|
||||||
|
return p.kinds
|
||||||
|
}
|
||||||
|
|
||||||
// GetPrivatePackage gets this property's private Package.
|
// GetPrivatePackage gets this property's private Package.
|
||||||
func (p *PropertyGenerator) GetPrivatePackage() Package {
|
func (p *PropertyGenerator) GetPrivatePackage() Package {
|
||||||
return p.PackageManager.PrivatePackage()
|
return p.packageManager.PrivatePackage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPublicPackage gets this property's public Package.
|
// GetPublicPackage gets this property's public Package.
|
||||||
func (p *PropertyGenerator) GetPublicPackage() Package {
|
func (p *PropertyGenerator) GetPublicPackage() Package {
|
||||||
return p.PackageManager.PublicPackage()
|
return p.packageManager.PublicPackage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetKindFns allows TypeGenerators to later notify this Property what functions
|
// SetKindFns allows TypeGenerators to later notify this Property what functions
|
||||||
|
@ -162,7 +164,7 @@ func (p *PropertyGenerator) GetPublicPackage() Package {
|
||||||
//
|
//
|
||||||
// This feels very hacky.
|
// This feels very hacky.
|
||||||
func (p *PropertyGenerator) SetKindFns(name string, qualKind *jen.Statement, deser *codegen.Method) error {
|
func (p *PropertyGenerator) SetKindFns(name string, qualKind *jen.Statement, deser *codegen.Method) error {
|
||||||
for i, kind := range p.Kinds {
|
for i, kind := range p.kinds {
|
||||||
if kind.Name.LowerName == name {
|
if kind.Name.LowerName == name {
|
||||||
if kind.SerializeFn != nil || kind.DeserializeFn != nil || kind.LessFn != nil {
|
if kind.SerializeFn != nil || kind.DeserializeFn != nil || kind.LessFn != nil {
|
||||||
return fmt.Errorf("property kind already has serialization functions set for %q", name)
|
return fmt.Errorf("property kind already has serialization functions set for %q", name)
|
||||||
|
@ -170,7 +172,7 @@ func (p *PropertyGenerator) SetKindFns(name string, qualKind *jen.Statement, des
|
||||||
kind.ConcreteKind = qualKind
|
kind.ConcreteKind = qualKind
|
||||||
kind.DeserializeFn = deser.On(managerInitName())
|
kind.DeserializeFn = deser.On(managerInitName())
|
||||||
p.managerMethods = append(p.managerMethods, deser)
|
p.managerMethods = append(p.managerMethods, deser)
|
||||||
p.Kinds[i] = kind
|
p.kinds[i] = kind
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,16 +189,16 @@ func (p *PropertyGenerator) getAllManagerMethods() []*codegen.Method {
|
||||||
// to generate.
|
// to generate.
|
||||||
func (p *PropertyGenerator) StructName() string {
|
func (p *PropertyGenerator) StructName() string {
|
||||||
if p.asIterator {
|
if p.asIterator {
|
||||||
return p.Name.CamelName
|
return p.name.CamelName
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%sProperty", p.Name.CamelName)
|
return fmt.Sprintf("%sProperty", p.name.CamelName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// iteratorTypeName determines the identifier to use for the iterator type.
|
// iteratorTypeName determines the identifier to use for the iterator type.
|
||||||
func (p *PropertyGenerator) iteratorTypeName() Identifier {
|
func (p *PropertyGenerator) iteratorTypeName() Identifier {
|
||||||
return Identifier{
|
return Identifier{
|
||||||
LowerName: p.Name.LowerName,
|
LowerName: p.name.LowerName,
|
||||||
CamelName: fmt.Sprintf("%sPropertyIterator", p.Name.CamelName),
|
CamelName: fmt.Sprintf("%sPropertyIterator", p.name.CamelName),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,27 +211,27 @@ func (p *PropertyGenerator) InterfaceName() string {
|
||||||
// specifications. It is not suitable for use in generated code function
|
// specifications. It is not suitable for use in generated code function
|
||||||
// identifiers.
|
// identifiers.
|
||||||
func (p *PropertyGenerator) PropertyName() string {
|
func (p *PropertyGenerator) PropertyName() string {
|
||||||
return p.Name.LowerName
|
return p.name.LowerName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments returns the comment for this property.
|
// Comments returns the comment for this property.
|
||||||
func (p *PropertyGenerator) Comments() string {
|
func (p *PropertyGenerator) Comments() string {
|
||||||
return p.Comment
|
return p.comment
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeserializeFnName returns the identifier of the function that deserializes
|
// DeserializeFnName returns the identifier of the function that deserializes
|
||||||
// raw JSON into the generated Go type.
|
// raw JSON into the generated Go type.
|
||||||
func (p *PropertyGenerator) DeserializeFnName() string {
|
func (p *PropertyGenerator) DeserializeFnName() string {
|
||||||
if p.asIterator {
|
if p.asIterator {
|
||||||
return fmt.Sprintf("%s%s", deserializeIteratorMethod, p.Name.CamelName)
|
return fmt.Sprintf("%s%s", deserializeIteratorMethod, p.name.CamelName)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s%sProperty", deserializeMethod, p.Name.CamelName)
|
return fmt.Sprintf("%s%sProperty", deserializeMethod, p.name.CamelName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getFnName returns the identifier of the function that fetches concrete types
|
// getFnName returns the identifier of the function that fetches concrete types
|
||||||
// of the property.
|
// of the property.
|
||||||
func (p *PropertyGenerator) getFnName(i int) string {
|
func (p *PropertyGenerator) getFnName(i int) string {
|
||||||
if len(p.Kinds) == 1 {
|
if len(p.kinds) == 1 {
|
||||||
return getMethod
|
return getMethod
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s%s", getMethod, p.kindCamelName(i))
|
return fmt.Sprintf("%s%s", getMethod, p.kindCamelName(i))
|
||||||
|
@ -238,7 +240,7 @@ func (p *PropertyGenerator) getFnName(i int) string {
|
||||||
// setFnName returns the identifier of the function that sets concrete types
|
// setFnName returns the identifier of the function that sets concrete types
|
||||||
// of the property.
|
// of the property.
|
||||||
func (p *PropertyGenerator) setFnName(i int) string {
|
func (p *PropertyGenerator) setFnName(i int) string {
|
||||||
if len(p.Kinds) == 1 {
|
if len(p.kinds) == 1 {
|
||||||
return setMethod
|
return setMethod
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s%s", setMethod, p.kindCamelName(i))
|
return fmt.Sprintf("%s%s", setMethod, p.kindCamelName(i))
|
||||||
|
@ -258,24 +260,24 @@ func (p *PropertyGenerator) serializeFnName() string {
|
||||||
//
|
//
|
||||||
// It will panic if 'i' is out of range.
|
// It will panic if 'i' is out of range.
|
||||||
func (p *PropertyGenerator) kindCamelName(i int) string {
|
func (p *PropertyGenerator) kindCamelName(i int) string {
|
||||||
return p.Kinds[i].Name.CamelName
|
return p.kinds[i].Name.CamelName
|
||||||
}
|
}
|
||||||
|
|
||||||
// memberName returns the identifier to use for the kind at the specified index.
|
// memberName returns the identifier to use for the kind at the specified index.
|
||||||
//
|
//
|
||||||
// It will panic if 'i' is out of range.
|
// It will panic if 'i' is out of range.
|
||||||
func (p *PropertyGenerator) memberName(i int) string {
|
func (p *PropertyGenerator) memberName(i int) string {
|
||||||
return fmt.Sprintf("%sMember", p.Kinds[i].Name.LowerName)
|
return fmt.Sprintf("%sMember", p.kinds[i].Name.LowerName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasMemberName returns the identifier to use for struct members that determine
|
// hasMemberName returns the identifier to use for struct members that determine
|
||||||
// whether non-nilable types have been set. Panics if called for a Kind that is
|
// whether non-nilable types have been set. Panics if called for a Kind that is
|
||||||
// nilable.
|
// nilable.
|
||||||
func (p *PropertyGenerator) hasMemberName(i int) string {
|
func (p *PropertyGenerator) hasMemberName(i int) string {
|
||||||
if len(p.Kinds) == 1 && p.Kinds[0].Nilable {
|
if len(p.kinds) == 1 && p.kinds[0].Nilable {
|
||||||
panic("PropertyGenerator.hasMemberName called for nilable single value")
|
panic("PropertyGenerator.hasMemberName called for nilable single value")
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("has%sMember", p.Kinds[i].Name.CamelName)
|
return fmt.Sprintf("has%sMember", p.kinds[i].Name.CamelName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clearMethodName returns the identifier to use for methods that clear all
|
// clearMethodName returns the identifier to use for methods that clear all
|
||||||
|
|
読み込み中…
新しいイシューから参照