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

Function mybatisJavaXmlEdges

src/resolution/callback-synthesizer.ts:3474–3536  ·  view source on GitHub ↗

* MyBatis: link a Java mapper interface method to the XML statement that holds * its SQL. The XML extractor (`src/extraction/mybatis-extractor.ts`) qualifies * each ` ` as ` :: ` where * ` ` is the Java FQN of the mapper interface. A J

(queries: QueryBuilder, onYield: MaybeYield)

Source from the content-addressed store, hash-verified

3472 * mapper interfaces are typically uniquely named within a project.
3473 */
3474async function mybatisJavaXmlEdges(queries: QueryBuilder, onYield: MaybeYield): Promise<Edge[]> {
3475 let scanned255 = 0;
3476 const edges: Edge[] = [];
3477 const seen = new Set<string>();
3478 // Collect the XML side FIRST (mapper `<select id=…>` statements extracted as
3479 // xml-language method nodes): if the project has none — every Java+XML repo
3480 // that doesn't use MyBatis — return before paying the full java-method
3481 // stream below. Same rowid stream order as matching inline, so the edge
3482 // output is byte-identical when mappers do exist.
3483 const xmlMethods: Node[] = [];
3484 for (const m of queries.iterateNodesByKindIn('method', ['xml'])) {
3485 if ((++scanned255 & 63) === 0) await onYield();
3486 xmlMethods.push(m);
3487 }
3488 if (xmlMethods.length === 0) return edges;
3489
3490 // Index Java methods by `<ClassName>::<methodName>` for O(1) lookup.
3491 const javaIndex = new Map<string, Node[]>();
3492 for (const m of queries.iterateNodesByKindIn('method', ['java', 'kotlin'])) {
3493 if ((++scanned255 & 63) === 0) await onYield();
3494 const parts = m.qualifiedName.split('::');
3495 const last = parts[parts.length - 1];
3496 const cls = parts[parts.length - 2];
3497 if (!last || !cls) continue;
3498 const key = `${cls}::${last}`;
3499 const arr = javaIndex.get(key);
3500 if (arr) arr.push(m); else javaIndex.set(key, [m]);
3501 }
3502
3503 for (const xml of xmlMethods) {
3504 if ((++scanned255 & 63) === 0) await onYield();
3505 // Qualified name: `<namespace>::<id>`. Extract the simple class name.
3506 const colonIdx = xml.qualifiedName.lastIndexOf('::');
3507 if (colonIdx < 0) continue;
3508 const namespace = xml.qualifiedName.slice(0, colonIdx);
3509 const id = xml.qualifiedName.slice(colonIdx + 2);
3510 if (!namespace || !id) continue;
3511 const dotIdx = namespace.lastIndexOf('.');
3512 const className = dotIdx >= 0 ? namespace.slice(dotIdx + 1) : namespace;
3513 const candidates = javaIndex.get(`${className}::${id}`);
3514 if (!candidates || candidates.length === 0) continue;
3515 // Drop ambiguous matches (multiple same-name classes); the user can
3516 // disambiguate by adding the package-suffix match in a future enhancement.
3517 if (candidates.length > 1) continue;
3518 const java = candidates[0]!;
3519 const key = `${java.id}>${xml.id}`;
3520 if (seen.has(key)) continue;
3521 seen.add(key);
3522 edges.push({
3523 source: java.id,
3524 target: xml.id,
3525 kind: 'calls',
3526 line: java.startLine,
3527 provenance: 'heuristic',
3528 metadata: {
3529 synthesizedBy: 'mybatis-java-xml',
3530 via: `${className}.${id}`,
3531 registeredAt: `${xml.filePath}:${xml.startLine}`,

Callers 1

Calls 6

iterateNodesByKindInMethod · 0.80
pushMethod · 0.80
hasMethod · 0.80
getMethod · 0.65
setMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected