Pretty-print attributes in lumi pack info
command
This change pretty-prints attribute metadata in `lumi pack info`. For example: package "basic/decorators" { dependencies [] module "index" { exports [] method ".main": () class "TestDecorators" [@basic/decorators:index:classDecorate] { property "a" [public, @basic/decorators:index:propertyDecorate]: string method "m1" [public, @basic/decorators:index:methodDecorate]: (): string } } } It also includes support for printing property getters/setters: property "p1" [public]: string { method "get" [public, @basic/decorators:index:methodDecorate]: (): string method "set" [public]: (v: string) }
This commit is contained in:
parent
acdab34d7a
commit
7879032e88
|
@ -273,6 +273,11 @@ func printClass(tok tokens.Type, class *ast.Class, exportOnly bool, indent strin
|
|||
if class.Interface != nil && *class.Interface {
|
||||
mods = append(mods, "interface")
|
||||
}
|
||||
if class.Attributes != nil {
|
||||
for _, att := range *class.Attributes {
|
||||
mods = append(mods, "@"+att.Decorator.Tok.String())
|
||||
}
|
||||
}
|
||||
fmt.Printf(modString(mods))
|
||||
|
||||
if class.Extends != nil {
|
||||
|
@ -303,16 +308,16 @@ func printClassMember(tok tokens.ClassMember, member ast.ClassMember, exportOnly
|
|||
if !exportOnly || (acc != nil && *acc == tokens.PublicAccessibility) {
|
||||
switch member.GetKind() {
|
||||
case ast.ClassPropertyKind:
|
||||
printClassProperty(tok, member.(*ast.ClassProperty), indent)
|
||||
printClassProperty(tok.Name(), member.(*ast.ClassProperty), indent)
|
||||
case ast.ClassMethodKind:
|
||||
printClassMethod(tok, member.(*ast.ClassMethod), indent)
|
||||
printClassMethod(tok.Name(), member.(*ast.ClassMethod), indent)
|
||||
default:
|
||||
contract.Failf("Unexpected ClassMember kind: %v\n", member.GetKind())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printClassProperty(tok tokens.ClassMember, prop *ast.ClassProperty, indent string) {
|
||||
func printClassProperty(name tokens.ClassMemberName, prop *ast.ClassProperty, indent string) {
|
||||
var mods []string
|
||||
if prop.Access != nil {
|
||||
mods = append(mods, string(*prop.Access))
|
||||
|
@ -323,14 +328,31 @@ func printClassProperty(tok tokens.ClassMember, prop *ast.ClassProperty, indent
|
|||
if prop.Readonly != nil && *prop.Readonly {
|
||||
mods = append(mods, "readonly")
|
||||
}
|
||||
fmt.Printf("%vproperty \"%v\"%v", indent, tok.Name(), modString(mods))
|
||||
if prop.Attributes != nil {
|
||||
for _, att := range *prop.Attributes {
|
||||
mods = append(mods, "@"+att.Decorator.Tok.String())
|
||||
}
|
||||
}
|
||||
fmt.Printf("%vproperty \"%v\"%v", indent, name, modString(mods))
|
||||
if prop.Type != nil {
|
||||
fmt.Printf(": %v", prop.Type.Tok)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
|
||||
if prop.Getter != nil || prop.Setter != nil {
|
||||
fmt.Printf(" {\n")
|
||||
if prop.Getter != nil {
|
||||
printClassMethod(tokens.ClassMemberName("get"), prop.Getter, indent+" ")
|
||||
}
|
||||
if prop.Setter != nil {
|
||||
printClassMethod(tokens.ClassMemberName("set"), prop.Setter, indent+" ")
|
||||
}
|
||||
fmt.Printf("%v}\n", indent)
|
||||
} else {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
|
||||
func printClassMethod(tok tokens.ClassMember, meth *ast.ClassMethod, indent string) {
|
||||
func printClassMethod(name tokens.ClassMemberName, meth *ast.ClassMethod, indent string) {
|
||||
var mods []string
|
||||
if meth.Access != nil {
|
||||
mods = append(mods, string(*meth.Access))
|
||||
|
@ -344,7 +366,12 @@ func printClassMethod(tok tokens.ClassMember, meth *ast.ClassMethod, indent stri
|
|||
if meth.Abstract != nil && *meth.Abstract {
|
||||
mods = append(mods, "abstract")
|
||||
}
|
||||
fmt.Printf("%vmethod \"%v\"%v: %v\n", indent, tok.Name(), modString(mods), funcSig(meth))
|
||||
if meth.Attributes != nil {
|
||||
for _, att := range *meth.Attributes {
|
||||
mods = append(mods, "@"+att.Decorator.Tok.String())
|
||||
}
|
||||
}
|
||||
fmt.Printf("%vmethod \"%v\"%v: %v\n", indent, name, modString(mods), funcSig(meth))
|
||||
}
|
||||
|
||||
func printModuleMethod(tok tokens.ModuleMember, meth *ast.ModuleMethod, indent string) {
|
||||
|
@ -397,6 +424,15 @@ func funcSig(fun ast.Function) string {
|
|||
sig += ", "
|
||||
}
|
||||
sig += string(param.Name.Ident)
|
||||
|
||||
var mods []string
|
||||
if param.Attributes != nil {
|
||||
for _, att := range *param.Attributes {
|
||||
mods = append(mods, "@"+att.Decorator.Tok.String())
|
||||
}
|
||||
}
|
||||
sig += modString(mods)
|
||||
|
||||
if param.Type != nil {
|
||||
sig += ": " + string(param.Type.Tok)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue