From 8b8cc2af279314ec106a0017bcd98c36a36064b9 Mon Sep 17 00:00:00 2001 From: Cory Slep Date: Sat, 5 Jan 2019 23:12:42 +0100 Subject: [PATCH] Fix value qualified statements in interfaces. Also fix the qualified interface name for non-functional properties in the LessThan method. --- tools/exp/convert/convert.go | 8 ++------ tools/exp/props/nonfuncprop.go | 2 +- tools/exp/rdf/data.go | 4 +++- tools/exp/rdf/ontology.go | 5 +++-- tools/exp/rdf/xsd/ontology.go | 21 ++++++++++++++------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/tools/exp/convert/convert.go b/tools/exp/convert/convert.go index 091cd33..7159cc7 100644 --- a/tools/exp/convert/convert.go +++ b/tools/exp/convert/convert.go @@ -446,8 +446,8 @@ func (c Converter) convertValue(v rdf.VocabularyValue) (k *props.Kind) { k = &props.Kind{ Name: c.toIdentifier(v), // TODO: Add Qualifier - ConcreteKind: jen.Id(v.DefinitionType), - Nilable: c.isNilable(v.DefinitionType), + ConcreteKind: v.DefinitionType, + Nilable: v.IsNilable, SerializeFn: s.QualifiedName(), DeserializeFn: d.QualifiedName(), LessFn: l.QualifiedName(), @@ -643,10 +643,6 @@ func (c Converter) toIdentifier(n rdf.NameGetter) props.Identifier { } } -func (c Converter) isNilable(goType string) bool { - return goType[0] == '*' -} - func allExtendsAreIn(t rdf.VocabularyType, v map[string]*props.TypeGenerator) bool { for _, e := range t.Extends { if len(e.Vocab) != 0 { diff --git a/tools/exp/props/nonfuncprop.go b/tools/exp/props/nonfuncprop.go index 324685e..9087952 100644 --- a/tools/exp/props/nonfuncprop.go +++ b/tools/exp/props/nonfuncprop.go @@ -277,7 +277,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method { p.GetPrivatePackage().Path(), compareLessMethod, p.StructName(), - []jen.Code{jen.Id("o").Id(p.InterfaceName())}, + []jen.Code{jen.Id("o").Qual(p.GetPublicPackage().Path(), p.InterfaceName())}, []jen.Code{jen.Bool()}, []jen.Code{ lessCode, diff --git a/tools/exp/rdf/data.go b/tools/exp/rdf/data.go index ae7961e..d23ae8f 100644 --- a/tools/exp/rdf/data.go +++ b/tools/exp/rdf/data.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "github.com/cjslep/activity/tools/exp/codegen" + "github.com/dave/jennifer/jen" "net/url" ) @@ -104,8 +105,9 @@ func (v *Vocabulary) SetValue(name string, a *VocabularyValue) error { type VocabularyValue struct { Name string URI *url.URL - DefinitionType string + DefinitionType *jen.Statement Zero string + IsNilable bool SerializeFn *codegen.Function DeserializeFn *codegen.Function LessFn *codegen.Function diff --git a/tools/exp/rdf/ontology.go b/tools/exp/rdf/ontology.go index 485704d..5b245bc 100644 --- a/tools/exp/rdf/ontology.go +++ b/tools/exp/rdf/ontology.go @@ -155,8 +155,9 @@ func (l *langstring) Apply(key string, value interface{}, ctx *ParsingContext) ( e = ctx.Result.GetReference(rdfSpec).SetValue(langstringSpec, &VocabularyValue{ Name: langstringSpec, URI: u, - DefinitionType: "map[string]string", - Zero: "nil", + DefinitionType: jen.Map(jen.String()).String(), + Zero: "make(map[string]string)", + IsNilable: true, SerializeFn: SerializeValueFunction( l.pkg, langstringSpec, diff --git a/tools/exp/rdf/xsd/ontology.go b/tools/exp/rdf/xsd/ontology.go index 3f8dfd9..579e863 100644 --- a/tools/exp/rdf/xsd/ontology.go +++ b/tools/exp/rdf/xsd/ontology.go @@ -197,8 +197,9 @@ func (a *anyURI) Apply(key string, value interface{}, ctx *rdf.ParsingContext) ( val := &rdf.VocabularyValue{ Name: anyURISpec, URI: u, - DefinitionType: "*url.URL", + DefinitionType: jen.Op("*").Qual("net/url", "URL"), Zero: "&url.URL{}", + IsNilable: true, SerializeFn: rdf.SerializeValueFunction( a.pkg, anyURISpec, @@ -288,8 +289,9 @@ func (d *dateTime) Apply(key string, value interface{}, ctx *rdf.ParsingContext) val := &rdf.VocabularyValue{ Name: dateTimeSpec, URI: u, - DefinitionType: "time.Time", + DefinitionType: jen.Qual("time", "Time"), Zero: "&time.Time{}", + IsNilable: false, SerializeFn: rdf.SerializeValueFunction( d.pkg, dateTimeSpec, @@ -390,8 +392,9 @@ func (f *float) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (b val := &rdf.VocabularyValue{ Name: floatSpec, URI: u, - DefinitionType: "float32", + DefinitionType: jen.Float32(), Zero: "0.0", + IsNilable: false, SerializeFn: rdf.SerializeValueFunction( f.pkg, floatSpec, @@ -469,8 +472,9 @@ func (s *xmlString) Apply(key string, value interface{}, ctx *rdf.ParsingContext val := &rdf.VocabularyValue{ Name: stringSpec, URI: u, - DefinitionType: "string", + DefinitionType: jen.String(), Zero: "\"\"", + IsNilable: false, SerializeFn: rdf.SerializeValueFunction( s.pkg, stringSpec, @@ -548,8 +552,9 @@ func (b *boolean) Apply(key string, value interface{}, ctx *rdf.ParsingContext) val := &rdf.VocabularyValue{ Name: booleanSpec, URI: u, - DefinitionType: "bool", + DefinitionType: jen.Bool(), Zero: "false", + IsNilable: false, SerializeFn: rdf.SerializeValueFunction( b.pkg, booleanSpec, @@ -658,8 +663,9 @@ func (n *nonNegativeInteger) Apply(key string, value interface{}, ctx *rdf.Parsi val := &rdf.VocabularyValue{ Name: nonNegativeIntegerSpec, URI: u, - DefinitionType: "int", + DefinitionType: jen.Int(), Zero: "0", + IsNilable: false, SerializeFn: rdf.SerializeValueFunction( n.pkg, nonNegativeIntegerSpec, @@ -750,8 +756,9 @@ func (d *duration) Apply(key string, value interface{}, ctx *rdf.ParsingContext) val := &rdf.VocabularyValue{ Name: durationSpec, URI: u, - DefinitionType: "time.Duration", + DefinitionType: jen.Qual("time", "Duration"), Zero: "time.Duration(0)", + IsNilable: false, SerializeFn: rdf.SerializeValueFunction( d.pkg, durationSpec,