/issue1505.go

https://code.google.com/p/dbgo/ · Go · 41 lines · 34 code · 4 blank · 3 comment · 1 complexity · a428c5be574823f1bd8d9998eb72eb65 MD5 · raw file

  1. package main
  2. import (
  3. "go/token"
  4. "go/ast"
  5. )
  6. type v struct{}
  7. //nil .Doc, .Comment, .Comments
  8. func (v v) Visit(n ast.Node) ast.Visitor {
  9. switch t := n.(type) {
  10. case *ast.Field:
  11. t.Doc = nil
  12. t.Comment = nil
  13. case *ast.File:
  14. t.Doc = nil
  15. t.Comments = []*ast.CommentGroup{}
  16. case *ast.FuncDecl:
  17. t.Doc = nil
  18. case *ast.GenDecl:
  19. t.Doc = nil
  20. case *ast.ImportSpec:
  21. t.Doc = nil
  22. t.Comment = nil
  23. case *ast.TypeSpec:
  24. t.Doc = nil
  25. t.Comment = nil
  26. case *ast.ValueSpec:
  27. t.Doc = nil
  28. t.Comment = nil
  29. }
  30. return v
  31. }
  32. //This fixes the AST so we can output file with go/printer without the comments
  33. //interspersing in the middle of funcs and ruining all the output.
  34. func Issue1505(fs *token.FileSet, file *ast.File) *ast.File {
  35. ast.Walk(v{}, file)
  36. return file
  37. }