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

Function javaFileScope

src/resolution/name-matcher.ts:1859–1872  ·  view source on GitHub ↗

A Java file's package, its single-type imports and its on-demand (`.*`) imports, static ones included.

(file: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1857
1858/** A Java file's package, its single-type imports and its on-demand (`.*`) imports, static ones included. */
1859function javaFileScope(file: string, context: ResolutionContext): { pkg: string; single: Set<string>; demand: Set<string> } {
1860 let memo = JAVA_FILE_SCOPES.get(context);
1861 if (!memo) JAVA_FILE_SCOPES.set(context, (memo = new Map()));
1862 const hit = memo.get(file);
1863 if (hit) return hit;
1864 const text = stripCommentsForRegex(context.readFile(file) ?? '', 'java');
1865 const pkg = /^\s*package\s+([\w.]+)\s*;/m.exec(text)?.[1] ?? '';
1866 const single = new Set<string>();
1867 const demand = new Set<string>();
1868 for (const m of text.matchAll(/^\s*import\s+(?:static\s+)?([\w.]+?)(\.\*)?\s*;/gm)) (m[2] ? demand : single).add(m[1]!);
1869 const scope = { pkg, single, demand };
1870 memo.set(file, scope);
1871 return scope;
1872}
1873
1874/** The simple names of the Java types `qn` extends or implements, a few levels up. */
1875function javaAncestorNames(qn: string, context: ResolutionContext, depth = 0): Set<string> {

Callers 1

isJavaTypeVisibleFunction · 0.85

Calls 6

stripCommentsForRegexFunction · 0.90
readFileMethod · 0.80
addMethod · 0.80
getMethod · 0.65
execMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected