(recordNode: SyntaxNode, ctx: ExtractorContext)
| 262 | // synthesized: `new Point(…)` already links to the record via `instantiates`. |
| 263 | // Varargs components (`String... rest`) are skipped. |
| 264 | function synthesizeRecordComponents(recordNode: SyntaxNode, ctx: ExtractorContext): void { |
| 265 | const params = getChildByField(recordNode, 'parameters'); |
| 266 | if (!params) return; |
| 267 | const recordId = ctx.nodeStack[ctx.nodeStack.length - 1]; |
| 268 | const recordQN = ctx.nodes.find((n) => n.id === recordId)?.qualifiedName; |
| 269 | const takenMethods = new Set<string>(); |
| 270 | const takenFields = new Set<string>(); |
| 271 | if (recordQN) { |
| 272 | for (const n of ctx.nodes) { |
| 273 | if (n.filePath === ctx.filePath && n.qualifiedName === `${recordQN}::${n.name}`) { |
| 274 | if (n.kind === 'method' || n.kind === 'function') takenMethods.add(n.name); |
| 275 | else if (n.kind === 'field' || n.kind === 'variable' || n.kind === 'constant' || n.kind === 'property') { |
| 276 | takenFields.add(n.name); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | for (const param of params.namedChildren) { |
| 282 | if (param.type !== 'formal_parameter') continue; |
| 283 | const nameNode = getChildByField(param, 'name'); |
| 284 | const typeNode = getChildByField(param, 'type'); |
| 285 | if (!nameNode || !typeNode) continue; |
| 286 | const name = getNodeText(nameNode, ctx.source).trim(); |
| 287 | const typeText = getNodeText(typeNode, ctx.source).trim(); |
| 288 | if (!name) continue; |
| 289 | if (!takenFields.has(name)) { |
| 290 | takenFields.add(name); |
| 291 | ctx.createNode('field', name, nameNode, { |
| 292 | visibility: 'private', |
| 293 | isStatic: false, |
| 294 | signature: `${typeText} ${name}`, |
| 295 | }); |
| 296 | } |
| 297 | if (!takenMethods.has(name)) { |
| 298 | takenMethods.add(name); |
| 299 | ctx.createNode('method', name, nameNode, { |
| 300 | visibility: 'public', |
| 301 | isStatic: false, |
| 302 | signature: `${typeText} ${name}()`, |
| 303 | docstring: IMPLICIT_RECORD_ACCESSOR_DOC, |
| 304 | returnType: normalizeJavaType(typeNode, ctx.source), |
| 305 | }); |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | function synthesizeJavaMembers(classNode: SyntaxNode, ctx: ExtractorContext): void { |
| 311 | if (classNode.type === 'record_declaration') synthesizeRecordComponents(classNode, ctx); |
no test coverage detected