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

Function resolve

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

Source from the content-addressed store, hash-verified

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