Exemple #1
0
func (v *trimVisitor) Visit(node ast.Node) ast.Visitor {
	var list *[]ast.Stmt
	switch node := node.(type) {
	case *ast.File:
		var replaced []ast.Decl
		for _, decl := range node.Decls {
			// Remove non-func declarations and funcs that were not covered
			if f, ok := decl.(*ast.FuncDecl); ok && v.p.Funcs[f] {
				replaced = append(replaced, decl)
			}
		}
		node.Decls = replaced

	// Node types containing lists of statements
	case *ast.BlockStmt:
		list = &node.List
	case *ast.CommClause:
		list = &node.Body
	case *ast.CaseClause:
		list = &node.Body
	}

	if list != nil {
		var replaced []ast.Stmt
		for _, stmt := range *list {
			replaced = append(replaced, v.replaceStmt(stmt)...)
		}

		*list = replaced
	}
	return v
}