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

Function mybatisJavaXmlEdges

src/resolution/callback-synthesizer.ts:3432–3494  ·  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

3430 * mapper interfaces are typically uniquely named within a project.
3431 */
3432async function mybatisJavaXmlEdges(queries: QueryBuilder, onYield: MaybeYield): Promise<Edge[]> {
3433 let scanned255 = 0;
3434 const edges: Edge[] = [];
3435 const seen = new Set<string>();
3436 // Collect the XML side FIRST (mapper `<select id=…>` statements extracted as
3437 // xml-language method nodes): if the project has none — every Java+XML repo
3438 // that doesn't use MyBatis — return before paying the full java-method
3439 // stream below. Same rowid stream order as matching inline, so the edge
3440 // output is byte-identical when mappers do exist.
3441 const xmlMethods: Node[] = [];
3442 for (const m of queries.iterateNodesByKindIn('method', ['xml'])) {
3443 if ((++scanned255 & 63) === 0) await onYield();
3444 xmlMethods.push(m);
3445 }
3446 if (xmlMethods.length === 0) return edges;
3447
3448 // Index Java methods by `<ClassName>::<methodName>` for O(1) lookup.
3449 const javaIndex = new Map<string, Node[]>();
3450 for (const m of queries.iterateNodesByKindIn('method', ['java', 'kotlin'])) {
3451 if ((++scanned255 & 63) === 0) await onYield();
3452 const parts = m.qualifiedName.split('::');
3453 const last = parts[parts.length - 1];
3454 const cls = parts[parts.length - 2];
3455 if (!last || !cls) continue;
3456 const key = `${cls}::${last}`;
3457 const arr = javaIndex.get(key);
3458 if (arr) arr.push(m); else javaIndex.set(key, [m]);
3459 }
3460
3461 for (const xml of xmlMethods) {
3462 if ((++scanned255 & 63) === 0) await onYield();
3463 // Qualified name: `<namespace>::<id>`. Extract the simple class name.
3464 const colonIdx = xml.qualifiedName.lastIndexOf('::');
3465 if (colonIdx < 0) continue;
3466 const namespace = xml.qualifiedName.slice(0, colonIdx);
3467 const id = xml.qualifiedName.slice(colonIdx + 2);
3468 if (!namespace || !id) continue;
3469 const dotIdx = namespace.lastIndexOf('.');
3470 const className = dotIdx >= 0 ? namespace.slice(dotIdx + 1) : namespace;
3471 const candidates = javaIndex.get(`${className}::${id}`);
3472 if (!candidates || candidates.length === 0) continue;
3473 // Drop ambiguous matches (multiple same-name classes); the user can
3474 // disambiguate by adding the package-suffix match in a future enhancement.
3475 if (candidates.length > 1) continue;
3476 const java = candidates[0]!;
3477 const key = `${java.id}>${xml.id}`;
3478 if (seen.has(key)) continue;
3479 seen.add(key);
3480 edges.push({
3481 source: java.id,
3482 target: xml.id,
3483 kind: 'calls',
3484 line: java.startLine,
3485 provenance: 'heuristic',
3486 metadata: {
3487 synthesizedBy: 'mybatis-java-xml',
3488 via: `${className}.${id}`,
3489 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