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

Function extractSpringConfig

src/resolution/frameworks/java.ts:351–447  ·  view source on GitHub ↗

* Parse a Spring config file (YAML or .properties) and emit one `constant` * node per LEAF key, with `qualifiedName` = the dotted path. Leaf keys are * what `@Value("${k}")` references hit; intermediate keys aren't bound by * Spring's `@Value` (a `@ConfigurationProperties` class binds a SUBTREE,

(
  filePath: string,
  content: string,
)

Source from the content-addressed store, hash-verified

349 * those references are resolved at lookup time by prefix-suffix matching).
350 */
351function extractSpringConfig(
352 filePath: string,
353 content: string,
354): { nodes: Node[]; references: UnresolvedRef[] } {
355 const nodes: Node[] = [];
356 const isProperties = /\.properties$/i.test(filePath);
357 const lang = isProperties ? 'properties' : 'yaml';
358 const now = Date.now();
359
360 const emitLeaf = (dottedKey: string, line: number, valueText: string) => {
361 if (!dottedKey) return;
362 nodes.push({
363 id: `spring-config:${filePath}:${line}:${dottedKey}`,
364 kind: 'constant',
365 name: dottedKey.split('.').pop() ?? dottedKey,
366 qualifiedName: dottedKey,
367 filePath,
368 startLine: line,
369 endLine: line,
370 startColumn: 0,
371 endColumn: valueText.length,
372 language: lang,
373 signature: dottedKey,
374 // SECURITY (#383): store the KEY only, never the value. Config files
375 // routinely hold secrets (DB passwords, API keys, JDBC URLs with embedded
376 // credentials), and surfacing the value here pushes it into agent context
377 // unbidden (it lands in codegraph_node/explore output via the docstring).
378 // The key is all `@Value`/`@ConfigurationProperties` resolution needs; an
379 // agent that genuinely needs a value can read the file directly.
380 updatedAt: now,
381 });
382 };
383
384 if (isProperties) {
385 // Properties format: `k1.k2.k3 = value` (or `:` separator, or no value).
386 // Lines starting with `#`/`!` are comments. Backslash continuations are
387 // valid but rare; we don't try to join them (a continued value is still
388 // a value of the same key).
389 const lines = content.split(/\r?\n/);
390 for (let i = 0; i < lines.length; i++) {
391 const raw = lines[i] ?? '';
392 const trimmed = raw.trim();
393 if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('!')) continue;
394 const sep = (() => {
395 for (let j = 0; j < raw.length; j++) {
396 const ch = raw[j];
397 if (ch === '=' || ch === ':') return j;
398 if (ch === '\\' && raw[j + 1]) { j++; continue; }
399 }
400 return -1;
401 })();
402 if (sep < 0) continue;
403 const key = raw.slice(0, sep).trim();
404 const val = raw.slice(sep + 1).trim();
405 emitLeaf(key, i + 1, val);
406 }
407 return { nodes, references: [] };
408 }

Callers 1

extractFunction · 0.85

Calls 4

emitLeafFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected