http://codereview.appspot.com/5436051/diff/2002/src/cmd/gofix/template.go File src/cmd/gofix/template.go (right): http://codereview.appspot.com/5436051/diff/2002/src/cmd/gofix/template.go#newcode52 src/cmd/gofix/template.go:52: if sel.Sel.Name == "ParseFile" { This test is not ...
13 years, 3 months ago
(2011-11-22 20:05:43 UTC)
#2
To use the type checker, the first step is to write a TypeConfig that describes ...
13 years, 3 months ago
(2011-11-22 20:19:22 UTC)
#4
To use the type checker, the first step is to write a TypeConfig
that describes the types of interest, the return types of their
method calls, the return types of any functions of interest,
and the types of any variables of interest (probably none here):
var templateTypeConfig = &TypeConfig{
Type: map[string]*Type{
"template.Template": &Type{
Method: map[string]string{
"Delims": "*template.Template",
"Funcs": "*template.Template",
...
},
},
"template.Set": &Type{
Method: map[string]string{
...
},
},
},
Func: map[string]string{
"template.Must": "*template.Template,error",
"template.SetMust": "*template.Set,error",
...
},
Var: map[string]string{
// probably empty
},
}
The next step is to invoke the type checker at the top of the fix:
typeof, _ := typecheck(templateTypeConfig, f)
Then in the type checker, when you are looking at a selector
expression, you should be able to say
if typeof[sel.X] == "*template.Template" && sel.Name.Name == "ParseFiles" {
... do rewrite
}
to constrain the rewrite to an appropriate context.
I will not be surprised if you hit small bugs. Feel free to
ping me before getting too confused.
Russ
*** Submitted as http://code.google.com/p/go/source/detail?r=565dc56d5e30 *** gofix: trivial rewrite for template.ParseFiles Also warn about uses of ...
13 years, 3 months ago
(2011-11-24 04:17:41 UTC)
#9
Issue 5436051: code review 5436051: gofix: trivial rewrite for template.ParseFiles
(Closed)
Created 13 years, 3 months ago by r
Modified 13 years, 3 months ago
Reviewers:
Base URL:
Comments: 5