func _AttachAnnotation(node ast.Node, annotations ...*ast.Annotation) { anns := Annotations(node) anns = append(anns, annotations...) node.SetExtra(ExtraAnnotation, anns) }
// Annotations . func Annotations(node ast.Node) (anns []*ast.Annotation) { val, ok := node.GetExtra(ExtraAnnotation) if ok { anns = val.([]*ast.Annotation) } return }
// Annotations . func _RemoveAnnotation(node ast.Node, annotation *ast.Annotation) { anns := Annotations(node) var newanns []*ast.Annotation for _, ann := range anns { if ann == annotation { continue } newanns = append(newanns, ann) } node.SetExtra(ExtraAnnotation, anns) }
// Pos . func Pos(node ast.Node) (start lexer.Position, end lexer.Position) { val, ok := node.GetExtra(ExtraStartPos) if ok { start = val.(lexer.Position) } val, ok = node.GetExtra(ExtraEndPos) if ok { end = val.(lexer.Position) } return }
func _AttachComment(node ast.Node, comment *ast.Comment) bool { nodeStart, nodeEnd := Pos(node) commentStart, commentEnd := Pos(comment) if nodeStart.Lines == commentEnd.Lines || nodeStart.Lines == commentEnd.Lines+1 || nodeEnd.Lines == commentStart.Lines { node.SetExtra(ExtraComment, comment) return true } return false }
// FindAnnotations . func FindAnnotations(node ast.Node, name string) (retval []*ast.Annotation) { val, ok := node.GetExtra(ExtraAnnotation) if ok { anns := val.([]*ast.Annotation) for _, ann := range anns { if ann.Type.Ref == nil { continue } if ann.Type.Ref.FullName() == name { retval = append(retval, ann) } } } return }
// FindAnnotation . func FindAnnotation(node ast.Node, name string) (*ast.Annotation, bool) { val, ok := node.GetExtra(ExtraAnnotation) if ok { anns := val.([]*ast.Annotation) for _, ann := range anns { if ann.Type.Ref == nil { continue } if ann.Type.Ref.FullName() == name { return ann, true } } } return nil, false }
func _setNodePos(node ast.Node, start lexer.Position, end lexer.Position) { node.SetExtra(ExtraStartPos, start) node.SetExtra(ExtraEndPos, end) }