|
| 1 | +import { |
| 2 | + type DependencyManifest, |
| 3 | + metricCharacterCount, |
| 4 | + metricCodeCharacterCount, |
| 5 | + metricCodeLineCount, |
| 6 | + metricCyclomaticComplexity, |
| 7 | + metricDependencyCount, |
| 8 | + metricDependentCount, |
| 9 | + metricLinesCount, |
| 10 | + type SymbolDependencyManifest, |
| 11 | + type SymbolType, |
| 12 | +} from "@napi/shared"; |
| 13 | +import { JavaDependencyFormatter } from "../../../languagePlugins/java/dependencyFormatting/index.ts"; |
| 14 | +// import { JavaMetricsAnalyzer } from "../../../languagePlugins/java/metrics/index.ts"; |
| 15 | +import { javaLanguage } from "../../../helpers/treeSitter/parsers.ts"; |
| 16 | + |
| 17 | +export function generateJavaDependencyManifest( |
| 18 | + files: Map<string, { path: string; content: string }>, |
| 19 | +): DependencyManifest { |
| 20 | + console.time("generateJavaDependencyManifest"); |
| 21 | + console.info("Processing project..."); |
| 22 | + const formatter = new JavaDependencyFormatter(files); |
| 23 | + const manifest: DependencyManifest = {}; |
| 24 | + const filecount = files.size; |
| 25 | + let i = 0; |
| 26 | + for (const [, { path }] of files) { |
| 27 | + console.info(`Processing ${path} (${++i}/${filecount})`); |
| 28 | + const fm = formatter.formatFile(path); |
| 29 | + const cSyms = fm.symbols; |
| 30 | + const symbols: Record<string, SymbolDependencyManifest> = {}; |
| 31 | + for (const [symName, symbol] of Object.entries(cSyms)) { |
| 32 | + const symType = symbol.type; |
| 33 | + const dependencies = symbol.dependencies; |
| 34 | + symbols[symName] = { |
| 35 | + id: symName, |
| 36 | + type: symType as SymbolType, |
| 37 | + metrics: { |
| 38 | + [metricCharacterCount]: symbol.characterCount, |
| 39 | + [metricCodeCharacterCount]: 0, // TODO : metrics |
| 40 | + [metricLinesCount]: symbol.lineCount, |
| 41 | + [metricCodeLineCount]: 0, // TODO : metrics |
| 42 | + [metricDependencyCount]: Object.keys(dependencies).length, |
| 43 | + [metricDependentCount]: 0, |
| 44 | + [metricCyclomaticComplexity]: 0, // TODO : metrics |
| 45 | + }, |
| 46 | + dependencies: dependencies, |
| 47 | + dependents: {}, |
| 48 | + }; |
| 49 | + } |
| 50 | + manifest[path] = { |
| 51 | + id: fm.id, |
| 52 | + filePath: fm.filePath, |
| 53 | + language: javaLanguage, |
| 54 | + metrics: { |
| 55 | + [metricCharacterCount]: fm.characterCount, |
| 56 | + [metricCodeCharacterCount]: 0, // TODO : metrics |
| 57 | + [metricLinesCount]: fm.lineCount, |
| 58 | + [metricCodeLineCount]: 0, // TODO : metrics |
| 59 | + [metricDependencyCount]: Object.keys(fm.dependencies).length, |
| 60 | + [metricDependentCount]: 0, |
| 61 | + [metricCyclomaticComplexity]: 0, // TODO : metrics |
| 62 | + }, |
| 63 | + dependencies: fm.dependencies, |
| 64 | + symbols: symbols, |
| 65 | + dependents: {}, |
| 66 | + }; |
| 67 | + } |
| 68 | + console.info("Populating dependents..."); |
| 69 | + i = 0; |
| 70 | + for (const fm of Object.values(manifest)) { |
| 71 | + const path = fm.filePath; |
| 72 | + console.info(`Populating dependents for ${path} (${++i}/${filecount})`); |
| 73 | + for (const symbol of Object.values(fm.symbols)) { |
| 74 | + for (const dpncy of Object.values(symbol.dependencies)) { |
| 75 | + for (const depsymbol of Object.values(dpncy.symbols)) { |
| 76 | + const otherFile = manifest[dpncy.id]; |
| 77 | + const otherSymbol = otherFile.symbols[depsymbol]; |
| 78 | + if (!otherSymbol.dependents[fm.id]) { |
| 79 | + otherSymbol.dependents[fm.id] = { |
| 80 | + id: fm.id, |
| 81 | + symbols: {}, |
| 82 | + }; |
| 83 | + } |
| 84 | + otherSymbol.dependents[fm.id].symbols[symbol.id] = symbol.id; |
| 85 | + fm.metrics[metricDependentCount]++; |
| 86 | + symbol.metrics[metricDependentCount]++; |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + console.timeEnd("generateJavaDependencyManifest"); |
| 92 | + return manifest; |
| 93 | +} |
0 commit comments