Fix astool bug to properly alias properties and types

This commit is contained in:
Cory Slep 2019-09-26 20:31:48 +02:00
parent bf196748f9
commit b5a6786f9e
3 changed files with 26 additions and 6 deletions

View file

@ -1202,8 +1202,16 @@ func (p *FunctionalPropertyGenerator) hasValueKind() bool {
// nameMethod returns the Name method for this functional property.
func (p *FunctionalPropertyGenerator) nameMethod() *codegen.Method {
nameImpl := jen.Return(
jen.Lit(p.PropertyName()),
nameImpl := jen.If(
jen.Len(jen.Id(codegen.This()).Dot(aliasMember)).Op(">").Lit(0),
).Block(
jen.Return(
jen.Id(codegen.This()).Dot(aliasMember).Op("+").Lit(":").Op("+").Lit(p.PropertyName()),
),
).Else().Block(
jen.Return(
jen.Lit(p.PropertyName()),
),
)
if p.hasNaturalLanguageMap {
nameImpl = jen.If(

View file

@ -1029,8 +1029,16 @@ func (p *NonFunctionalPropertyGenerator) thisIRI() *jen.Statement {
// nameMethod returns the Name method for this non-functional property.
func (p *NonFunctionalPropertyGenerator) nameMethod() *codegen.Method {
nameImpl := jen.Return(
jen.Lit(p.PropertyName()),
nameImpl := jen.If(
jen.Len(jen.Id(codegen.This()).Dot(aliasMember)).Op(">").Lit(0),
).Block(
jen.Return(
jen.Id(codegen.This()).Dot(aliasMember).Op("+").Lit(":").Op("+").Lit(p.PropertyName()),
),
).Else().Block(
jen.Return(
jen.Lit(p.PropertyName()),
),
)
if p.hasNaturalLanguageMap {
nameImpl = jen.If(
@ -1056,6 +1064,6 @@ func (p *NonFunctionalPropertyGenerator) nameMethod() *codegen.Method {
[]jen.Code{
nameImpl,
},
fmt.Sprintf("%s returns the name of this property: %q.", nameMethod, p.PropertyName()),
fmt.Sprintf("%s returns the name of this property (%q) with any alias.", nameMethod, p.PropertyName()),
)
}

View file

@ -1072,6 +1072,10 @@ func (t *TypeGenerator) getAllManagerMethods() (m []*codegen.Method) {
// constructorFn creates a constructor for this type.
func (t *TypeGenerator) constructorFn() *codegen.Function {
typeName := jen.Lit(t.TypeName())
if len(t.vocabAlias) > 0 {
typeName = jen.Lit(t.vocabAlias).Op("+").Lit(":").Op("+").Lit(t.TypeName())
}
return codegen.NewCommentedFunction(
t.PrivatePackage().Path(),
fmt.Sprintf("%s%s", constructorName, t.StructName()),
@ -1081,7 +1085,7 @@ func (t *TypeGenerator) constructorFn() *codegen.Function {
},
[]jen.Code{
jen.Id("typeProp").Op(":=").Id(typePropertyConstructorName()).Call(),
jen.Id("typeProp").Dot("AppendXMLSchemaString").Call(jen.Lit(t.TypeName())),
jen.Id("typeProp").Dot("AppendXMLSchemaString").Call(typeName),
jen.Return(
jen.Op("&").Qual(t.PrivatePackage().Path(), t.StructName()).Values(
jen.Dict{