(ref: UnresolvedRef, context: ResolutionContext)
| 194 | * RTL's `TComponent.Create`), or when no overload takes the arguments. |
| 195 | */ |
| 196 | export function matchPascalInheritedCall(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null { |
| 197 | const m = INHERITED.exec(ref.referenceName); |
| 198 | if (!m) return null; |
| 199 | const cls = classByQualifiedName(m[2]!, ref.filePath!, context); |
| 200 | if (!cls) return null; |
| 201 | const lower = m[3]!.toLowerCase(); |
| 202 | const bare = m[1] !== undefined; |
| 203 | const count = bare ? Number(m[1]) : pascalCallArgumentCount(ref, context); |
| 204 | const caller = routineNode(ref.fromNodeId, context); |
| 205 | if (caller && classInitializer(caller, context)) return null; |
| 206 | // A bare call passes the routine's own parameters: an override's match the |
| 207 | // method it overrides, types and all. |
| 208 | const own = bare && caller && caller.name.toLowerCase() === lower ? pascalParameterTypes(caller.signature) : null; |
| 209 | for (const c of inheritedAncestry(cls, context)) { |
| 210 | const owner = c.qualifiedName.toLowerCase(); |
| 211 | const members = pascalNamed(lower, context).filter((n) => MEMBER_KINDS.has(n.kind) && n.filePath === c.filePath && ownerOf(n) === owner); |
| 212 | if (members.length === 0) continue; |
| 213 | if (!members.some(isRoutine)) return null; |
| 214 | const routines = members.filter((n) => isRoutine(n) && !classInitializer(n, context)); |
| 215 | const fitting = count === null ? routines : routines.filter((n) => { |
| 216 | const range = pascalParameterRange(n.signature); |
| 217 | return range === null || (count >= range[0] && count <= range[1]); |
| 218 | }); |
| 219 | if (fitting.length === 0) continue; |
| 220 | const exact = (n: Node): boolean => pascalParameterRange(n.signature)?.[1] === count; |
| 221 | const sameTypes = (n: Node): boolean => own !== null && String(pascalParameterTypes(n.signature)) === String(own); |
| 222 | const chosen = fitting.find(sameTypes) ?? (count === null ? fitting.find((n) => !needsArguments(n)) : fitting.find(exact)) ?? fitting[0]!; |
| 223 | context.rememberNode?.(chosen); |
| 224 | return { original: ref, targetNodeId: chosen.id, confidence: 0.9, resolvedBy: 'instance-method' }; |
| 225 | } |
| 226 | return null; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Whether a routine is a class constructor or destructor (`class constructor |
no test coverage detected