Fix file writing locations.
Also write interfaces into public sections. Lots of TODOs and more work to add. Will need to look into how to simplify this logic -- there is a lot of redundancy and kludgy-feeling things. Will definitely need to address the converter part as it is very redundant.
このコミットが含まれているのは:
コミット
3da311641b
|
@ -100,6 +100,7 @@ func (c Converter) convertToFiles(v vocabulary) (f []*File, e error) {
|
|||
if e != nil {
|
||||
return
|
||||
}
|
||||
// Implementation
|
||||
dir := pm.PrivatePackage().Path()
|
||||
file := jen.NewFilePath(dir)
|
||||
file.Add(i.Definition().Definition())
|
||||
|
@ -108,6 +109,15 @@ func (c Converter) convertToFiles(v vocabulary) (f []*File, e error) {
|
|||
FileName: fmt.Sprintf("gen_%s.go", i.PropertyName()),
|
||||
Directory: dir,
|
||||
})
|
||||
// Interface
|
||||
dir = pm.PublicPackage().Path()
|
||||
file = jen.NewFilePath(dir)
|
||||
file.Add(i.InterfaceDefinition(pm.PublicPackage()).Definition())
|
||||
f = append(f, &File{
|
||||
F: file,
|
||||
FileName: fmt.Sprintf("gen_%s_interface.go", i.PropertyName()),
|
||||
Directory: dir,
|
||||
})
|
||||
}
|
||||
for _, i := range v.NFProps {
|
||||
var pm *props.PackageManager
|
||||
|
@ -115,6 +125,7 @@ func (c Converter) convertToFiles(v vocabulary) (f []*File, e error) {
|
|||
if e != nil {
|
||||
return
|
||||
}
|
||||
// Implementation
|
||||
dir := pm.PrivatePackage().Path()
|
||||
file := jen.NewFilePath(dir)
|
||||
s, t := i.Definitions()
|
||||
|
@ -124,6 +135,17 @@ func (c Converter) convertToFiles(v vocabulary) (f []*File, e error) {
|
|||
FileName: fmt.Sprintf("gen_%s.go", i.PropertyName()),
|
||||
Directory: dir,
|
||||
})
|
||||
// TODO: Interface
|
||||
dir = pm.PublicPackage().Path()
|
||||
file = jen.NewFilePath(dir)
|
||||
for _, intf := range i.InterfaceDefinitions(pm.PublicPackage()) {
|
||||
file.Add(intf.Definition())
|
||||
}
|
||||
f = append(f, &File{
|
||||
F: file,
|
||||
FileName: fmt.Sprintf("gen_%s_interface.go", i.PropertyName()),
|
||||
Directory: dir,
|
||||
})
|
||||
}
|
||||
for _, i := range v.Types {
|
||||
var pm *props.PackageManager
|
||||
|
@ -131,6 +153,7 @@ func (c Converter) convertToFiles(v vocabulary) (f []*File, e error) {
|
|||
if e != nil {
|
||||
return
|
||||
}
|
||||
// Implementation
|
||||
dir := pm.PrivatePackage().Path()
|
||||
file := jen.NewFilePath(dir)
|
||||
file.Add(i.Definition().Definition())
|
||||
|
@ -139,14 +162,23 @@ func (c Converter) convertToFiles(v vocabulary) (f []*File, e error) {
|
|||
FileName: fmt.Sprintf("gen_%s.go", i.TypeName()),
|
||||
Directory: dir,
|
||||
})
|
||||
// TODO: Interface
|
||||
dir = pm.PublicPackage().Path()
|
||||
file = jen.NewFilePath(dir)
|
||||
file.Add(i.InterfaceDefinition(pm.PublicPackage()).Definition())
|
||||
f = append(f, &File{
|
||||
F: file,
|
||||
FileName: fmt.Sprintf("gen_%s_interface.go", i.TypeName()),
|
||||
Directory: dir,
|
||||
})
|
||||
}
|
||||
// TODO: For Manager
|
||||
dir := c.VocabularyRoot.PrivatePackage().Path()
|
||||
file := jen.NewFilePath(dir)
|
||||
file.Add(v.Manager.PrivateManager().Definition())
|
||||
f = append(f, &File{
|
||||
F: file,
|
||||
FileName: "gen_manager.go",
|
||||
F: file,
|
||||
FileName: "gen_manager.go",
|
||||
Directory: dir,
|
||||
})
|
||||
return
|
||||
|
@ -342,6 +374,7 @@ func (c Converter) convertFunctionalProperty(p rdf.VocabularyProperty,
|
|||
fp = props.NewFunctionalPropertyGenerator(
|
||||
pkg,
|
||||
c.toIdentifier(p),
|
||||
p.Notes,
|
||||
k,
|
||||
p.NaturalLanguageMap)
|
||||
return
|
||||
|
@ -372,9 +405,9 @@ func (c Converter) convertNonFunctionalProperty(p rdf.VocabularyProperty,
|
|||
|
||||
func (c Converter) convertValue(v rdf.VocabularyValue) (k *props.Kind) {
|
||||
k = &props.Kind{
|
||||
Name: c.toIdentifier(v),
|
||||
ConcreteKind: v.DefinitionType,
|
||||
Nilable: c.isNilable(v.DefinitionType),
|
||||
Name: c.toIdentifier(v),
|
||||
ConcreteKind: v.DefinitionType,
|
||||
Nilable: c.isNilable(v.DefinitionType),
|
||||
// TODO
|
||||
SerializeFn: jen.Empty().Add(v.SerializeFn.Call()),
|
||||
DeserializeFn: jen.Empty().Add(v.DeserializeFn.Call()),
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"github.com/cjslep/activity/tools/exp/convert"
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
"github.com/cjslep/activity/tools/exp/props"
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
"github.com/cjslep/activity/tools/exp/rdf/owl"
|
||||
"github.com/cjslep/activity/tools/exp/rdf/rdfs"
|
||||
"github.com/cjslep/activity/tools/exp/rdf/schema"
|
||||
|
@ -82,11 +82,11 @@ func main() {
|
|||
}
|
||||
c := &convert.Converter{
|
||||
Registry: registry,
|
||||
VocabularyRoot: props.NewPackageManager("as"),
|
||||
VocabularyRoot: props.NewPackageManager("gen/as"),
|
||||
PropertyPackagePolicy: convert.PropertyFlatUnderRoot,
|
||||
PropertyPackageRoot: props.NewPackageManager("props"),
|
||||
PropertyPackageRoot: props.NewPackageManager("gen/as/props"),
|
||||
TypePackagePolicy: convert.TypeFlatUnderRoot,
|
||||
TypePackageRoot: props.NewPackageManager("types"),
|
||||
TypePackageRoot: props.NewPackageManager("gen/as/types"),
|
||||
}
|
||||
f, err := c.Convert(p)
|
||||
if err != nil {
|
||||
|
@ -98,7 +98,7 @@ func main() {
|
|||
if e := os.MkdirAll("./"+file.Directory, 0777); e != nil {
|
||||
panic(e)
|
||||
}
|
||||
if e := file.F.Save("./" + file.Directory + file.FileName); e != nil {
|
||||
if e := file.F.Save("./" + file.Directory + "/" + file.FileName); e != nil {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ type FunctionalPropertyGenerator struct {
|
|||
// other generators are constructed.
|
||||
func NewFunctionalPropertyGenerator(pkg Package,
|
||||
name Identifier,
|
||||
comment string,
|
||||
kinds []Kind,
|
||||
hasNaturalLanguageMap bool) *FunctionalPropertyGenerator {
|
||||
return &FunctionalPropertyGenerator{
|
||||
|
@ -31,17 +32,26 @@ func NewFunctionalPropertyGenerator(pkg Package,
|
|||
Package: pkg,
|
||||
HasNaturalLanguageMap: hasNaturalLanguageMap,
|
||||
Name: name,
|
||||
Comment: comment,
|
||||
Kinds: kinds,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// toInterface creates the interface version of the definition generated.
|
||||
//
|
||||
// TODO: Remove -- redundant?
|
||||
func (p *FunctionalPropertyGenerator) toInterface(pkg Package) *codegen.Interface {
|
||||
s := p.Definition()
|
||||
return s.ToInterface(pkg.Path(), p.InterfaceName(), "")
|
||||
}
|
||||
|
||||
// InterfaceDefinition creates an interface definition in the provided package.
|
||||
func (p *FunctionalPropertyGenerator) InterfaceDefinition(pkg Package) *codegen.Interface {
|
||||
s := p.Definition()
|
||||
return s.ToInterface(pkg.Path(), p.InterfaceName(), p.Comments())
|
||||
}
|
||||
|
||||
// isSingleTypeDef determines whether a special-case API can be generated for
|
||||
// one allowed Kind.
|
||||
func (p *FunctionalPropertyGenerator) isSingleTypeDef() bool {
|
||||
|
|
|
@ -38,11 +38,23 @@ func NewNonFunctionalPropertyGenerator(pkg Package,
|
|||
}
|
||||
|
||||
// toInterfaces creates the interface versions of the definitions generated.
|
||||
//
|
||||
// TODO: Remove -- redundant?
|
||||
func (p *NonFunctionalPropertyGenerator) toInterfaces(pkg Package) []*codegen.Interface {
|
||||
s, t := p.Definitions()
|
||||
return []*codegen.Interface{
|
||||
s.ToInterface(pkg.Path(), p.InterfaceName(), ""),
|
||||
t.ToInterface(pkg.Path(), p.elementTypeGenerator().InterfaceName(), ""),
|
||||
s.ToInterface(pkg.Path(), p.elementTypeGenerator().InterfaceName(), ""),
|
||||
t.ToInterface(pkg.Path(), p.InterfaceName(), ""),
|
||||
}
|
||||
}
|
||||
|
||||
// InterfaceDefinitions creates interface definitions in the provided package.
|
||||
func (p *NonFunctionalPropertyGenerator) InterfaceDefinitions(pkg Package) []*codegen.Interface {
|
||||
s, t := p.Definitions()
|
||||
return []*codegen.Interface{
|
||||
// TODO: Comments
|
||||
s.ToInterface(pkg.Path(), p.elementTypeGenerator().InterfaceName(), ""),
|
||||
t.ToInterface(pkg.Path(), p.InterfaceName(), p.Comments()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ type PropertyGenerator struct {
|
|||
// TODO: Make these private
|
||||
Package Package
|
||||
Name Identifier
|
||||
Comment string
|
||||
Kinds []Kind
|
||||
HasNaturalLanguageMap bool
|
||||
asIterator bool
|
||||
|
@ -133,6 +134,11 @@ func (p *PropertyGenerator) PropertyName() string {
|
|||
return p.Name.LowerName
|
||||
}
|
||||
|
||||
// Comments returns the comment for this property.
|
||||
func (p *PropertyGenerator) Comments() string {
|
||||
return p.Comment
|
||||
}
|
||||
|
||||
// DeserializeFnName returns the identifier of the function that deserializes
|
||||
// raw JSON into the generated Go type.
|
||||
func (p *PropertyGenerator) DeserializeFnName() string {
|
||||
|
|
|
@ -145,7 +145,7 @@ func (t *TypeGenerator) Package() Package {
|
|||
}
|
||||
|
||||
// Comment returns the comment for this type.
|
||||
func (t *TypeGenerator) Comment() string {
|
||||
func (t *TypeGenerator) Comments() string {
|
||||
return t.comment
|
||||
}
|
||||
|
||||
|
@ -227,11 +227,22 @@ func (t *TypeGenerator) lessFnName() string {
|
|||
// toInterface creates the interface version of the definition generated.
|
||||
//
|
||||
// Requires apply to have already been called.
|
||||
//
|
||||
// TODO: Delete -- redundant?
|
||||
func (t *TypeGenerator) toInterface(pkg Package) *codegen.Interface {
|
||||
s := t.Definition()
|
||||
return s.ToInterface(pkg.Path(), t.InterfaceName(), "")
|
||||
}
|
||||
|
||||
// InterfaceDefinition creates the interface of this type in the specified
|
||||
// package.
|
||||
//
|
||||
// Requires ManagerGenerator to have been created.
|
||||
func (t *TypeGenerator) InterfaceDefinition(pkg Package) *codegen.Interface {
|
||||
s := t.Definition()
|
||||
return s.ToInterface(pkg.Path(), t.InterfaceName(), t.Comments())
|
||||
}
|
||||
|
||||
// Definition generates the golang code for this ActivityStreams type.
|
||||
func (t *TypeGenerator) Definition() *codegen.Struct {
|
||||
t.cacheOnce.Do(func() {
|
||||
|
@ -240,7 +251,7 @@ func (t *TypeGenerator) Definition() *codegen.Struct {
|
|||
ser, deser, less := t.kindSerializationFuncs()
|
||||
extendsFn, extendsMethod := t.extendsDefinition()
|
||||
t.cachedStruct = codegen.NewStruct(
|
||||
jen.Commentf(t.Comment()),
|
||||
jen.Commentf(t.Comments()),
|
||||
t.TypeName(),
|
||||
[]*codegen.Method{
|
||||
t.nameDefinition(),
|
||||
|
|
読み込み中…
新しいイシューから参照