Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 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 "go/ast" | 7 import "go/ast" |
8 | 8 |
9 func init() { | 9 func init() { |
10 register(netipv6zoneFix) | 10 register(netipv6zoneFix) |
11 } | 11 } |
12 | 12 |
13 var netipv6zoneFix = fix{ | 13 var netipv6zoneFix = fix{ |
14 "netipv6zone", | 14 "netipv6zone", |
15 » "2012-11-14", | 15 » "2012-11-26", |
16 netipv6zone, | 16 netipv6zone, |
17 `Adapt element key to IPNet, IPAddr, UDPAddr or TCPAddr composite litera ls. | 17 `Adapt element key to IPNet, IPAddr, UDPAddr or TCPAddr composite litera ls. |
18 | 18 |
19 https://codereview.appspot.com/6849045/ | 19 https://codereview.appspot.com/6849045/ |
20 `, | 20 `, |
21 } | 21 } |
22 | 22 |
23 func netipv6zone(f *ast.File) bool { | 23 func netipv6zone(f *ast.File) bool { |
24 if !imports(f, "net") { | 24 if !imports(f, "net") { |
25 return false | 25 return false |
26 } | 26 } |
27 | 27 |
28 fixed := false | 28 fixed := false |
29 walk(f, func(n interface{}) { | 29 walk(f, func(n interface{}) { |
30 cl, ok := n.(*ast.CompositeLit) | 30 cl, ok := n.(*ast.CompositeLit) |
31 if !ok { | 31 if !ok { |
32 return | 32 return |
33 } | 33 } |
34 se, ok := cl.Type.(*ast.SelectorExpr) | 34 se, ok := cl.Type.(*ast.SelectorExpr) |
35 if !ok { | 35 if !ok { |
36 return | 36 return |
37 } | 37 } |
38 » » x, ok := se.X.(*ast.Ident) | 38 » » if !isTopName(se.X, "net") || se.Sel == nil { |
rsc
2012/11/26 15:23:15
Please use isTopName(se.X, "net"). That will avoid
mikio
2012/11/26 15:45:55
Done.
| |
39 » » if !ok { | |
40 » » » return | |
41 » » } | |
42 » » if x.Name != "net" || se.Sel == nil { | |
43 return | 39 return |
44 } | 40 } |
45 switch ss := se.Sel.String(); ss { | 41 switch ss := se.Sel.String(); ss { |
46 case "IPNet", "IPAddr", "UDPAddr", "TCPAddr": | 42 case "IPNet", "IPAddr", "UDPAddr", "TCPAddr": |
47 for i, e := range cl.Elts { | 43 for i, e := range cl.Elts { |
48 if _, ok := e.(*ast.KeyValueExpr); ok { | 44 if _, ok := e.(*ast.KeyValueExpr); ok { |
49 break | 45 break |
50 } | 46 } |
51 switch i { | 47 switch i { |
52 case 0: | 48 case 0: |
(...skipping 13 matching lines...) Expand all Loading... | |
66 Value: e, | 62 Value: e, |
67 } | 63 } |
68 } | 64 } |
69 } | 65 } |
70 fixed = true | 66 fixed = true |
71 } | 67 } |
72 } | 68 } |
73 }) | 69 }) |
74 return fixed | 70 return fixed |
75 } | 71 } |
LEFT | RIGHT |