Kindsys: Replace "Declaration" with "Definition" (#62515)
* s/Declaration/Definition/g * s/DeclForGen/DefForGen/g * Rename some local vars
This commit is contained in:
+22
-21
@@ -10,44 +10,45 @@ import (
|
||||
"github.com/grafana/thema"
|
||||
)
|
||||
|
||||
type OneToOne codejen.OneToOne[*DeclForGen]
|
||||
type OneToMany codejen.OneToMany[*DeclForGen]
|
||||
type ManyToOne codejen.ManyToOne[*DeclForGen]
|
||||
type ManyToMany codejen.ManyToMany[*DeclForGen]
|
||||
type OneToOne codejen.OneToOne[*DefForGen]
|
||||
type OneToMany codejen.OneToMany[*DefForGen]
|
||||
type ManyToOne codejen.ManyToOne[*DefForGen]
|
||||
type ManyToMany codejen.ManyToMany[*DefForGen]
|
||||
|
||||
// ForGen is a codejen input transformer that converts a pure kindsys.SomeDecl into
|
||||
// a DeclForGen by binding its contained lineage.
|
||||
func ForGen(rt *thema.Runtime, decl kindsys.SomeDecl) (*DeclForGen, error) {
|
||||
lin, err := decl.BindKindLineage(rt)
|
||||
// ForGen is a codejen input transformer that converts a pure kindsys.SomeDef into
|
||||
// a DefForGen by binding its contained lineage.
|
||||
func ForGen(rt *thema.Runtime, def kindsys.SomeDef) (*DefForGen, error) {
|
||||
lin, err := def.BindKindLineage(rt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DeclForGen{
|
||||
SomeDecl: decl,
|
||||
lin: lin,
|
||||
return &DefForGen{
|
||||
SomeDef: def,
|
||||
lin: lin,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeclForGen wraps [kindsys.SomeDecl] to provide trivial caching of
|
||||
// DefForGen wraps [kindsys.SomeDef] to provide trivial caching of
|
||||
// the lineage declared by the kind (nil for raw kinds).
|
||||
type DeclForGen struct {
|
||||
kindsys.SomeDecl
|
||||
// TODO this type is unneeded - kindsys.Kind is sufficient.
|
||||
type DefForGen struct {
|
||||
kindsys.SomeDef
|
||||
lin thema.Lineage
|
||||
}
|
||||
|
||||
// Lineage returns the [thema.Lineage] for the underlying [kindsys.SomeDecl].
|
||||
func (decl *DeclForGen) Lineage() thema.Lineage {
|
||||
return decl.lin
|
||||
// Lineage returns the [thema.Lineage] for the underlying [kindsys.SomeDef].
|
||||
func (def *DefForGen) Lineage() thema.Lineage {
|
||||
return def.lin
|
||||
}
|
||||
|
||||
// ForLatestSchema returns a [SchemaForGen] for the latest schema in this
|
||||
// DeclForGen's lineage.
|
||||
func (decl *DeclForGen) ForLatestSchema() SchemaForGen {
|
||||
comm := decl.Properties.Common()
|
||||
// DefForGen's lineage.
|
||||
func (def *DefForGen) ForLatestSchema() SchemaForGen {
|
||||
comm := def.Properties.Common()
|
||||
return SchemaForGen{
|
||||
Name: comm.Name,
|
||||
Schema: decl.Lineage().Latest(),
|
||||
Schema: def.Lineage().Latest(),
|
||||
IsGroup: comm.LineageIsGroup,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user