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 "encoding/json" | |
9 "go/token" | 8 "go/token" |
10 | 9 |
11 "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" |
12 "code.google.com/p/go.tools/ssa" | 12 "code.google.com/p/go.tools/ssa" |
13 ) | 13 ) |
14 | 14 |
15 // Implements displays the 'implements" relation among all | 15 // Implements displays the 'implements" relation among all |
16 // package-level named types in the package containing the query | 16 // package-level named types in the package containing the query |
17 // position. | 17 // position. |
18 // | 18 // |
19 // TODO(adonovan): more features: | 19 // TODO(adonovan): more features: |
20 // - should we include pairs of types belonging to | 20 // - should we include pairs of types belonging to |
21 // 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... |
84 var prevIface *types.Named | 84 var prevIface *types.Named |
85 for _, fact := range r.facts { | 85 for _, fact := range r.facts { |
86 if fact.iface != prevIface { | 86 if fact.iface != prevIface { |
87 printf(fact.iface.Obj(), "\tInterface %s:", fact.iface) | 87 printf(fact.iface.Obj(), "\tInterface %s:", fact.iface) |
88 prevIface = fact.iface | 88 prevIface = fact.iface |
89 } | 89 } |
90 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) |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 func (r *implementsResult) MarshalJSON() ([]byte, error) { | 94 func (r *implementsResult) toJSON(res *json.Result, fset *token.FileSet) { |
95 » var facts []*ImplementsJSON | 95 » var facts []*json.Implements |
96 for _, fact := range r.facts { | 96 for _, fact := range r.facts { |
97 » » facts = append(facts, &ImplementsJSON{ | 97 » » facts = append(facts, &json.Implements{ |
98 I: fact.iface.String(), | 98 I: fact.iface.String(), |
99 » » » IPos: r.fset.Position(fact.iface.Obj().Pos()).String(), | 99 » » » IPos: fset.Position(fact.iface.Obj().Pos()).String(), |
100 C: fact.conc.String(), | 100 C: fact.conc.String(), |
101 » » » CPos: r.fset.Position(deref(fact.conc).(*types.Named).Ob
j().Pos()).String(), | 101 » » » CPos: fset.Position(deref(fact.conc).(*types.Named).Obj(
).Pos()).String(), |
102 }) | 102 }) |
103 } | 103 } |
104 » return json.Marshal(facts) | 104 » res.Implements = facts |
105 } | 105 } |
LEFT | RIGHT |