* Create edges from resolved references
(resolved: ResolvedRef[])
| 2272 | * Create edges from resolved references |
| 2273 | */ |
| 2274 | createEdges(resolved: ResolvedRef[]): Edge[] { |
| 2275 | return resolved.flatMap((ref) => { |
| 2276 | // `function_ref` (#756) is internal-only: it persists as a `references` |
| 2277 | // edge (the registration site depends on the callback), distinguishable |
| 2278 | // by metadata.resolvedBy === 'function-ref'. callers/impact already |
| 2279 | // traverse `references`, so registration sites surface with no |
| 2280 | // graph-layer changes. |
| 2281 | let kind: Edge['kind'] = |
| 2282 | ref.edgeKind ?? |
| 2283 | (ref.original.referenceKind === 'function_ref' ? 'references' : ref.original.referenceKind); |
| 2284 | |
| 2285 | // Promote "extends" to "implements" when a class/struct targets an interface |
| 2286 | if (kind === 'extends') { |
| 2287 | const targetNode = this.nodeById(ref.targetNodeId); |
| 2288 | if (targetNode && (targetNode.kind === 'interface' || targetNode.kind === 'protocol')) { |
| 2289 | const sourceNode = this.nodeById(ref.original.fromNodeId); |
| 2290 | if (sourceNode && sourceNode.kind !== 'interface' && sourceNode.kind !== 'protocol') { |
| 2291 | kind = 'implements'; |
| 2292 | } |
| 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | // A Go call whose callee is a type is a conversion — `Category(s)`, |
| 2297 | // `(*Pair)(p)`, `model.Kind(3)` — which uses the type, and calls or |
| 2298 | // instantiates nothing (#2581). |
| 2299 | if (kind === 'calls' && ref.original.language === 'go') { |
| 2300 | const targetNode = this.nodeById(ref.targetNodeId); |
| 2301 | if (targetNode && GO_TYPE_KINDS.has(targetNode.kind)) kind = 'references'; |
| 2302 | } |
| 2303 | |
| 2304 | // A Pascal call written with a bare name that resolves to a type is a |
| 2305 | // typecast: `TButton(Sender).Caption`, `PInt64Rec(P)^.Lo`, `F := |
| 2306 | // TFoo(Obj)`. Delphi builds an object only through a constructor |
| 2307 | // (`TFoo.Create`), so the code refers to the type and creates nothing. |
| 2308 | if ( |
| 2309 | kind === 'calls' && |
| 2310 | ref.original.language === 'pascal' && |
| 2311 | !ref.original.referenceName.includes('.') && |
| 2312 | PASCAL_CAST_TARGET_KINDS.has(this.nodeById(ref.targetNodeId)?.kind ?? '') |
| 2313 | ) { |
| 2314 | kind = 'references'; |
| 2315 | } |
| 2316 | |
| 2317 | // Promote "calls" to "instantiates" when the resolved target is a |
| 2318 | // class/struct/union. Languages without a `new` keyword (Python, Ruby) |
| 2319 | // express instantiation as `Foo()` — extraction can't tell that |
| 2320 | // apart from a function call without symbol info, but resolution |
| 2321 | // can: if `Foo` resolves to a class, the call IS an instantiation. |
| 2322 | if (kind === 'calls') { |
| 2323 | const targetNode = this.nodeById(ref.targetNodeId); |
| 2324 | if ( |
| 2325 | targetNode && |
| 2326 | (targetNode.kind === 'class' || targetNode.kind === 'struct' || targetNode.kind === 'union') |
| 2327 | ) { |
| 2328 | kind = 'instantiates'; |
| 2329 | } |
| 2330 | } |
| 2331 |
no test coverage detected