Exemple #1
0
func DeleteUnusedLabels(ctxt *grinder.Context, pkg *grinder.Package) {
	grinder.GrindFuncDecls(ctxt, pkg, func(ctxt *grinder.Context, pkg *grinder.Package, edit *grinder.EditBuffer, fn *ast.FuncDecl) {
		if fn.Body == nil {
			return
		}
		blocks := block.Build(pkg.FileSet, fn.Body)
		ast.Inspect(fn.Body, func(x ast.Node) bool {
			switch x := x.(type) {
			case *ast.LabeledStmt:
				if len(blocks.Goto[x.Label.Name])+len(blocks.Break[x.Label.Name])+len(blocks.Continue[x.Label.Name]) == 0 {
					edit.DeleteLine(x.Pos(), x.Colon+1)
				}
			case ast.Expr:
				return false
			}
			return true
		})
	})
}
Exemple #2
0
func Grind(ctxt *grinder.Context, pkg *grinder.Package) {
	grinder.GrindFuncDecls(ctxt, pkg, grindFunc)
}