1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
15
var templateFix = fix{
19
`Rewrite calls to template.ParseFile to template.ParseFiles
21
http://codereview.appspot.com/5433048
25
var templateSetGlobals = []string{
34
var templateSetMethods = []string{
41
var templateTypeConfig = &TypeConfig{
42
Type: map[string]*Type{
43
"template.Template": {
44
Method: map[string]string{
45
"Funcs": "func() *template.Template",
46
"Delims": "func() *template.Template",
47
"Parse": "func() (*template.Template, error)",
48
"ParseFile": "func() (*template.Template, error)",
49
"ParseInSet": "func() (*template.Template, error)",
53
Method: map[string]string{
54
"ParseSetFiles": "func() (*template.Set, error)",
55
"ParseSetGlob": "func() (*template.Set, error)",
56
"ParseTemplateFiles": "func() (*template.Set, error)",
57
"ParseTemplateGlob": "func() (*template.Set, error)",
62
Func: map[string]string{
63
"template.New": "*template.Template",
64
"template.Must": "(*template.Template, error)",
65
"template.SetMust": "(*template.Set, error)",
69
func template(f *ast.File) bool {
70
if !imports(f, "text/template") && !imports(f, "html/template") {
76
typeof, _ := typecheck(templateTypeConfig, f)
78
// Now update the names used by importers.
79
walk(f, func(n interface{}) {
80
if sel, ok := n.(*ast.SelectorExpr); ok {
81
// Reference to top-level function ParseFile.
82
if isPkgDot(sel, "template", "ParseFile") {
83
sel.Sel.Name = "ParseFiles"
87
// Reference to ParseFiles method.
88
if typeof[sel.X] == "*template.Template" && sel.Sel.Name == "ParseFile" {
89
sel.Sel.Name = "ParseFiles"
93
// The Set type and its functions are now gone.
94
for _, name := range templateSetGlobals {
95
if isPkgDot(sel, "template", name) {
96
warn(sel.Pos(), "reference to template.%s must be fixed manually", name)
100
// The methods of Set are now gone.
101
for _, name := range templateSetMethods {
102
if typeof[sel.X] == "*template.Set" && sel.Sel.Name == name {
103
warn(sel.Pos(), "reference to template.*Set.%s must be fixed manually", name)