correlateNodes traverses the from and to API trees to build and return a map that translates all the nodes in from to to. This function requires the two trees to be symmetrical.
(from, to []*semantic.API)
| 105 | // that translates all the nodes in from to to. This function requires the two |
| 106 | // trees to be symmetrical. |
| 107 | func correlateNodes(from, to []*semantic.API) map[semantic.Node]semantic.Node { |
| 108 | out := make(map[semantic.Node]semantic.Node) |
| 109 | for i := range from { |
| 110 | f, t := collectNodes(from[i]), collectNodes(to[i]) |
| 111 | if len(f) != len(t) { |
| 112 | panic("APIs are not balanced") |
| 113 | } |
| 114 | for i, n := range f { |
| 115 | if reflect.TypeOf(n) != reflect.TypeOf(t[i]) { |
| 116 | panic("APIs are not symmetrical") |
| 117 | } |
| 118 | out[n] = t[i] |
| 119 | } |
| 120 | } |
| 121 | return out |
| 122 | } |
| 123 | |
| 124 | func collectNodes(n semantic.Node) []semantic.Node { |
| 125 | l := []semantic.Node{} |
no test coverage detected