48 lines
670 B
Go
48 lines
670 B
Go
package document
|
|
|
|
import (
|
|
"fmt"
|
|
"go/format"
|
|
)
|
|
|
|
type declaredType struct {
|
|
id string
|
|
t Type
|
|
}
|
|
|
|
func (d *declaredType) Nullable(v ...bool) Type {
|
|
return d
|
|
}
|
|
|
|
func (d *declaredType) IsNullable() bool {
|
|
return false
|
|
}
|
|
|
|
func (d *declaredType) Id() string {
|
|
return d.id
|
|
}
|
|
|
|
func (d *declaredType) Type() Type {
|
|
return d.t
|
|
}
|
|
|
|
func (d *declaredType) String() string {
|
|
s := fmt.Sprintf("type %s %s", d.id, d.t)
|
|
r, err := format.Source([]byte(s))
|
|
if err != nil {
|
|
return s
|
|
} else {
|
|
return string(r)
|
|
}
|
|
}
|
|
|
|
func NewDeclaredType(id string, t Type) DeclaredType {
|
|
if s, ok := t.(Struct); ok {
|
|
t = s.Nullable(false)
|
|
}
|
|
return &declaredType{
|
|
id: id,
|
|
t: t,
|
|
}
|
|
}
|