LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "go/ast" | 8 "go/ast" |
9 ) | 9 ) |
10 | 10 |
11 func init() { | 11 func init() { |
12 register(htmlerrFix) | 12 register(htmlerrFix) |
13 } | 13 } |
14 | 14 |
15 var htmlerrFix = fix{ | 15 var htmlerrFix = fix{ |
16 "htmlerr", | 16 "htmlerr", |
17 "2011-11-04", | 17 "2011-11-04", |
18 htmlerr, | 18 htmlerr, |
19 `Rename html's Tokenizer.Error method to Err. | 19 `Rename html's Tokenizer.Error method to Err. |
20 | 20 |
21 http://codereview.appspot.com/5327064/ | 21 http://codereview.appspot.com/5327064/ |
22 `, | 22 `, |
23 } | 23 } |
24 | 24 |
25 var htmlerrTypeConfig = &TypeConfig{ | 25 var htmlerrTypeConfig = &TypeConfig{ |
26 » Func: map[string]string{ | 26 » Func: { |
27 "html.NewTokenizer": "html.Tokenizer", | 27 "html.NewTokenizer": "html.Tokenizer", |
28 }, | 28 }, |
29 } | 29 } |
30 | 30 |
31 func htmlerr(f *ast.File) bool { | 31 func htmlerr(f *ast.File) bool { |
32 if !imports(f, "html") { | 32 if !imports(f, "html") { |
33 return false | 33 return false |
34 } | 34 } |
35 | 35 |
36 typeof, _ := typecheck(htmlerrTypeConfig, f) | 36 typeof, _ := typecheck(htmlerrTypeConfig, f) |
37 | 37 |
38 fixed := false | 38 fixed := false |
39 walk(f, func(n interface{}) { | 39 walk(f, func(n interface{}) { |
40 s, ok := n.(*ast.SelectorExpr) | 40 s, ok := n.(*ast.SelectorExpr) |
41 if ok && typeof[s.X] == "html.Tokenizer" && s.Sel.Name == "Error
" { | 41 if ok && typeof[s.X] == "html.Tokenizer" && s.Sel.Name == "Error
" { |
42 s.Sel.Name = "Err" | 42 s.Sel.Name = "Err" |
43 fixed = true | 43 fixed = true |
44 } | 44 } |
45 }) | 45 }) |
46 return fixed | 46 return fixed |
47 } | 47 } |
LEFT | RIGHT |