PageRenderTime 63ms CodeModel.GetById 55ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/issue1505.go

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