LEFT | RIGHT |
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 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 oracle | 5 package oracle |
6 | 6 |
7 import ( | 7 import ( |
8 "go/token" | 8 "go/token" |
9 | 9 |
10 "code.google.com/p/go.tools/go/types" | 10 "code.google.com/p/go.tools/go/types" |
| 11 "code.google.com/p/go.tools/oracle/json" |
11 "code.google.com/p/go.tools/ssa" | 12 "code.google.com/p/go.tools/ssa" |
12 ) | 13 ) |
13 | 14 |
14 // Implements displays the 'implements" relation among all | 15 // Implements displays the 'implements" relation among all |
15 // package-level named types in the package containing the query | 16 // package-level named types in the package containing the query |
16 // position. | 17 // position. |
17 // | 18 // |
18 // TODO(adonovan): more features: | 19 // TODO(adonovan): more features: |
19 // - should we include pairs of types belonging to | 20 // - should we include pairs of types belonging to |
20 // different packages in the 'implements' relation? | 21 // different packages in the 'implements' relation? |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 var prevIface *types.Named | 84 var prevIface *types.Named |
84 for _, fact := range r.facts { | 85 for _, fact := range r.facts { |
85 if fact.iface != prevIface { | 86 if fact.iface != prevIface { |
86 printf(fact.iface.Obj(), "\tInterface %s:", fact.iface) | 87 printf(fact.iface.Obj(), "\tInterface %s:", fact.iface) |
87 prevIface = fact.iface | 88 prevIface = fact.iface |
88 } | 89 } |
89 printf(deref(fact.conc).(*types.Named).Obj(), "\t\t%s", fact.con
c) | 90 printf(deref(fact.conc).(*types.Named).Obj(), "\t\t%s", fact.con
c) |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
93 func (r *implementsResult) toJSON(res *ResultJSON, fset *token.FileSet) { | 94 func (r *implementsResult) toJSON(res *json.Result, fset *token.FileSet) { |
94 » var facts []*ImplementsJSON | 95 » var facts []*json.Implements |
95 for _, fact := range r.facts { | 96 for _, fact := range r.facts { |
96 » » facts = append(facts, &ImplementsJSON{ | 97 » » facts = append(facts, &json.Implements{ |
97 I: fact.iface.String(), | 98 I: fact.iface.String(), |
98 IPos: fset.Position(fact.iface.Obj().Pos()).String(), | 99 IPos: fset.Position(fact.iface.Obj().Pos()).String(), |
99 C: fact.conc.String(), | 100 C: fact.conc.String(), |
100 CPos: fset.Position(deref(fact.conc).(*types.Named).Obj(
).Pos()).String(), | 101 CPos: fset.Position(deref(fact.conc).(*types.Named).Obj(
).Pos()).String(), |
101 }) | 102 }) |
102 } | 103 } |
103 res.Implements = facts | 104 res.Implements = facts |
104 } | 105 } |
LEFT | RIGHT |