/issue1505.go
https://code.google.com/p/dbgo/ · Go · 41 lines · 34 code · 4 blank · 3 comment · 1 complexity · a428c5be574823f1bd8d9998eb72eb65 MD5 · raw file
- package main
- import (
- "go/token"
- "go/ast"
- )
- type v struct{}
- //nil .Doc, .Comment, .Comments
- func (v v) Visit(n ast.Node) ast.Visitor {
- switch t := n.(type) {
- case *ast.Field:
- t.Doc = nil
- t.Comment = nil
- case *ast.File:
- t.Doc = nil
- t.Comments = []*ast.CommentGroup{}
- case *ast.FuncDecl:
- t.Doc = nil
- case *ast.GenDecl:
- t.Doc = nil
- case *ast.ImportSpec:
- t.Doc = nil
- t.Comment = nil
- case *ast.TypeSpec:
- t.Doc = nil
- t.Comment = nil
- case *ast.ValueSpec:
- t.Doc = nil
- t.Comment = nil
- }
- return v
- }
- //This fixes the AST so we can output file with go/printer without the comments
- //interspersing in the middle of funcs and ruining all the output.
- func Issue1505(fs *token.FileSet, file *ast.File) *ast.File {
- ast.Walk(v{}, file)
- return file
- }