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

Function resolve

src/resolution/frameworks/java.ts:61–212  ·  view source on GitHub ↗
(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

59 },
60
61 resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null {
62 // A route's handler is the method its mapping annotation is written on,
63 // told apart from an overload by position: under a tall `@Operation` /
64 // `@ApiResponses` stack, the next overload's declaration can be nearer the
65 // annotation than the method it annotates (#851).
66 const handler = routeHandlerAt(ref, context);
67 if (handler) return { original: ref, targetNodeId: handler.id, confidence: 0.95, resolvedBy: 'framework' };
68
69 // Spring config-key references — `@Value("${key}")` (single leaf) and
70 // `@ConfigurationProperties(prefix="X")` (entire subtree, marked with the
71 // `:prefix` suffix in extractSpringValueBindings). Lookup goes through
72 // Spring's relaxed binding (kebab/camel/snake → canonical lowercase).
73 if (ref.referenceName.endsWith(':prefix')) {
74 const prefix = ref.referenceName.slice(0, -':prefix'.length);
75 const canonPrefix = canonicalConfigKey(prefix);
76 // Prefer an exact prefix match (one node = the prefix subtree). Without
77 // node-level subtree representation we map to the closest matching key.
78 const candidates = context.getNodesByKind('constant').filter(
79 (n) => (n.language === 'yaml' || n.language === 'properties')
80 && canonicalConfigKey(n.qualifiedName).startsWith(canonPrefix),
81 );
82 if (candidates.length === 0) return null;
83 // Pick the SHORTEST canonical name — it's the closest binding point
84 // (`app.cache` over `app.cache.name.user-token` for prefix=`app.cache`).
85 const best = candidates.reduce((a, b) =>
86 canonicalConfigKey(a.qualifiedName).length <= canonicalConfigKey(b.qualifiedName).length ? a : b,
87 );
88 return { original: ref, targetNodeId: best.id, confidence: 0.85, resolvedBy: 'framework' };
89 }
90 if (ref.referenceName.includes('.') && ref.language !== 'java' && ref.language !== 'kotlin') {
91 // Spring config dotted key — only when the source language is Java/Kotlin
92 // (the bindings come from `@Value`). Skip non-Spring refs that happen to
93 // have dots in them.
94 }
95 // Spring config-key resolution: `@Value("${a.b.c}")` and
96 // `@ConfigurationProperties`. Gate on the `references` kind — those bindings
97 // are emitted as `references` by extractSpringValueBindings, whereas the far
98 // more numerous method-call refs (`list.add()`, `builder.build()`, every
99 // `receiver.method()`) are `calls`. A config key is NEVER a `calls` ref, so
100 // this loses no resolution. Without the gate, every dotted `calls` ref fell
101 // into the uncached getNodesByKind('constant') scan below — an
102 // O(dotted-calls × constant-nodes) cost that dominated resolution and made a
103 // full index take ~1h on large Java/Kotlin (Spring) monorepos (#1180). The
104 // old `split('.').length >= 2` heuristic couldn't separate keys from calls;
105 // the kind check does it exactly.
106 if (
107 ref.referenceKind === 'references' &&
108 (ref.language === 'java' || ref.language === 'kotlin') &&
109 ref.referenceName.includes('.') &&
110 !ref.referenceName.includes('::')
111 ) {
112 const canonRef = canonicalConfigKey(ref.referenceName);
113 const candidates = context.getNodesByKind('constant').filter(
114 (n) => n.kind === 'constant'
115 && (n.language === 'yaml' || n.language === 'properties')
116 && canonicalConfigKey(n.qualifiedName) === canonRef,
117 );
118 if (candidates.length === 1) {

Callers

nothing calls this directly

Calls 5

routeHandlerAtFunction · 0.85
canonicalConfigKeyFunction · 0.85
scoreFunction · 0.70
resolveByNameAndKindFunction · 0.70
getNodesByKindMethod · 0.65

Tested by

no test coverage detected