A Java file's package, its single-type imports and its on-demand (`.*`) imports, static ones included.
(file: string, context: ResolutionContext)
| 1857 | |
| 1858 | /** A Java file's package, its single-type imports and its on-demand (`.*`) imports, static ones included. */ |
| 1859 | function 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. */ |
| 1875 | function javaAncestorNames(qn: string, context: ResolutionContext, depth = 0): Set<string> { |
no test coverage detected