MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / synthesizeRecordComponents

Function synthesizeRecordComponents

src/extraction/languages/java.ts:264–308  ·  view source on GitHub ↗
(recordNode: SyntaxNode, ctx: ExtractorContext)

Source from the content-addressed store, hash-verified

262// synthesized: `new Point(…)` already links to the record via `instantiates`.
263// Varargs components (`String... rest`) are skipped.
264function 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
310function synthesizeJavaMembers(classNode: SyntaxNode, ctx: ExtractorContext): void {
311 if (classNode.type === 'record_declaration') synthesizeRecordComponents(classNode, ctx);

Callers 1

synthesizeJavaMembersFunction · 0.85

Calls 6

getChildByFieldFunction · 0.90
getNodeTextFunction · 0.90
normalizeJavaTypeFunction · 0.85
hasMethod · 0.80
createNodeMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected