translateMapping translates the keys of mapping from the nodes of the from API tree to their equivalent in the to API tree.
(from, to []*semantic.API, mapping *semantic.Mappings)
| 83 | // translateMapping translates the keys of mapping from the nodes of the from |
| 84 | // API tree to their equivalent in the to API tree. |
| 85 | func translateMapping(from, to []*semantic.API, mapping *semantic.Mappings) { |
| 86 | out := &semantic.Mappings{} |
| 87 | remap := correlateNodes(from, to) |
| 88 | for sem, asts := range mapping.SemanticToAST { |
| 89 | if remapped, ok := remap[sem]; ok { |
| 90 | for _, ast := range asts { |
| 91 | out.Add(ast, remapped) |
| 92 | } |
| 93 | } else { |
| 94 | // If we hit this panic, we either have semantic nodes in the |
| 95 | // mapping that are not referenced by the API (which is bad), or |
| 96 | // we have nodes not being visited using semantic.Visit (which is |
| 97 | // also bad). |
| 98 | panic(fmt.Sprintf("No remap for %T %+v", sem, sem)) |
| 99 | } |
| 100 | } |
| 101 | *mapping = *out |
| 102 | } |
| 103 | |
| 104 | // correlateNodes traverses the from and to API trees to build and return a map |
| 105 | // that translates all the nodes in from to to. This function requires the two |
no test coverage detected