agentic-qe 3.7.8 → 3.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/debug-loop/SKILL.md +1 -1
- package/.claude/skills/enterprise-integration-testing/evals/enterprise-integration-testing.yaml +158 -0
- package/.claude/skills/enterprise-integration-testing/schemas/output.json +74 -0
- package/.claude/skills/enterprise-integration-testing/scripts/validate-config.json +25 -0
- package/.claude/skills/middleware-testing-patterns/evals/middleware-testing-patterns.yaml +153 -0
- package/.claude/skills/middleware-testing-patterns/schemas/output.json +58 -0
- package/.claude/skills/middleware-testing-patterns/scripts/validate-config.json +25 -0
- package/.claude/skills/observability-testing-patterns/evals/observability-testing-patterns.yaml +157 -0
- package/.claude/skills/observability-testing-patterns/schemas/output.json +58 -0
- package/.claude/skills/observability-testing-patterns/scripts/validate-config.json +25 -0
- package/.claude/skills/pr-review/SKILL.md +1 -1
- package/.claude/skills/qcsd-cicd-swarm/evals/qcsd-cicd-swarm.yaml +211 -0
- package/.claude/skills/qcsd-cicd-swarm/schemas/output.json +86 -0
- package/.claude/skills/qcsd-cicd-swarm/scripts/validate-config.json +30 -0
- package/.claude/skills/qcsd-development-swarm/evals/qcsd-development-swarm.yaml +162 -0
- package/.claude/skills/qcsd-development-swarm/schemas/output.json +72 -0
- package/.claude/skills/qcsd-development-swarm/scripts/validate-config.json +25 -0
- package/.claude/skills/skills-manifest.json +1 -1
- package/.claude/skills/trust-tier-manifest.json +78 -7
- package/CHANGELOG.md +20 -0
- package/assets/skills/a11y-ally/SKILL.md +1664 -1658
- package/assets/skills/a11y-ally/evals/a11y-ally.yaml +376 -0
- package/assets/skills/a11y-ally/schemas/output.json +549 -0
- package/assets/skills/a11y-ally/scripts/validate-config.json +42 -0
- package/assets/skills/brutal-honesty-review/SKILL.md +5 -0
- package/assets/skills/brutal-honesty-review/schemas/output.json +291 -0
- package/assets/skills/brutal-honesty-review/scripts/validate-config.json +34 -0
- package/assets/skills/cicd-pipeline-qe-orchestrator/README.md +1 -1
- package/assets/skills/cicd-pipeline-qe-orchestrator/SKILL.md +6 -0
- package/assets/skills/cicd-pipeline-qe-orchestrator/evals/cicd-pipeline-qe-orchestrator.yaml +157 -0
- package/assets/skills/cicd-pipeline-qe-orchestrator/schemas/output.json +542 -0
- package/assets/skills/cicd-pipeline-qe-orchestrator/scripts/validate-config.json +42 -0
- package/assets/skills/debug-loop/SKILL.md +1 -1
- package/assets/skills/enterprise-integration-testing/evals/enterprise-integration-testing.yaml +158 -0
- package/assets/skills/enterprise-integration-testing/schemas/output.json +74 -0
- package/assets/skills/enterprise-integration-testing/scripts/validate-config.json +25 -0
- package/assets/skills/middleware-testing-patterns/evals/middleware-testing-patterns.yaml +153 -0
- package/assets/skills/middleware-testing-patterns/schemas/output.json +58 -0
- package/assets/skills/middleware-testing-patterns/scripts/validate-config.json +25 -0
- package/assets/skills/n8n-expression-testing/SKILL.md +6 -0
- package/assets/skills/n8n-expression-testing/evals/n8n-expression-testing.yaml +450 -0
- package/assets/skills/n8n-expression-testing/schemas/output.json +369 -0
- package/assets/skills/n8n-expression-testing/scripts/validate-config.json +39 -0
- package/assets/skills/n8n-integration-testing-patterns/SKILL.md +6 -0
- package/assets/skills/n8n-integration-testing-patterns/evals/n8n-integration-testing-patterns.yaml +522 -0
- package/assets/skills/n8n-integration-testing-patterns/schemas/output.json +291 -0
- package/assets/skills/n8n-integration-testing-patterns/scripts/validate-config.json +34 -0
- package/assets/skills/n8n-security-testing/SKILL.md +6 -0
- package/assets/skills/n8n-security-testing/evals/n8n-security-testing.yaml +493 -0
- package/assets/skills/n8n-security-testing/schemas/output.json +293 -0
- package/assets/skills/n8n-security-testing/scripts/validate-config.json +34 -0
- package/assets/skills/n8n-trigger-testing-strategies/SKILL.md +6 -0
- package/assets/skills/n8n-trigger-testing-strategies/evals/n8n-trigger-testing-strategies.yaml +500 -0
- package/assets/skills/n8n-trigger-testing-strategies/schemas/output.json +295 -0
- package/assets/skills/n8n-trigger-testing-strategies/scripts/validate-config.json +34 -0
- package/assets/skills/n8n-workflow-testing-fundamentals/SKILL.md +6 -0
- package/assets/skills/n8n-workflow-testing-fundamentals/evals/n8n-workflow-testing-fundamentals.yaml +497 -0
- package/assets/skills/n8n-workflow-testing-fundamentals/schemas/output.json +254 -0
- package/assets/skills/n8n-workflow-testing-fundamentals/scripts/validate-config.json +35 -0
- package/assets/skills/observability-testing-patterns/evals/observability-testing-patterns.yaml +157 -0
- package/assets/skills/observability-testing-patterns/schemas/output.json +58 -0
- package/assets/skills/observability-testing-patterns/scripts/validate-config.json +25 -0
- package/assets/skills/pentest-validation/scripts/validate-config.json +12 -0
- package/assets/skills/pr-review/SKILL.md +1 -1
- package/assets/skills/qcsd-cicd-swarm/evals/qcsd-cicd-swarm.yaml +211 -0
- package/assets/skills/qcsd-cicd-swarm/schemas/output.json +86 -0
- package/assets/skills/qcsd-cicd-swarm/scripts/validate-config.json +30 -0
- package/assets/skills/qcsd-development-swarm/evals/qcsd-development-swarm.yaml +162 -0
- package/assets/skills/qcsd-development-swarm/schemas/output.json +72 -0
- package/assets/skills/qcsd-development-swarm/scripts/validate-config.json +25 -0
- package/assets/skills/qcsd-ideation-swarm/evals/qcsd-ideation-swarm.yaml +138 -0
- package/assets/skills/qcsd-ideation-swarm/schemas/output.json +568 -0
- package/assets/skills/qcsd-ideation-swarm/scripts/validate-config.json +25 -0
- package/assets/skills/qcsd-production-swarm/SKILL.md +2781 -0
- package/assets/skills/qcsd-production-swarm/evals/qcsd-production-swarm.yaml +246 -0
- package/assets/skills/qcsd-production-swarm/schemas/output.json +505 -0
- package/assets/skills/qcsd-production-swarm/scripts/validate-config.json +25 -0
- package/assets/skills/qcsd-refinement-swarm/evals/qcsd-refinement-swarm.yaml +139 -0
- package/assets/skills/qcsd-refinement-swarm/schemas/output.json +811 -0
- package/assets/skills/qcsd-refinement-swarm/scripts/validate-config.json +25 -0
- package/assets/skills/security-visual-testing/scripts/validate-config.json +45 -0
- package/assets/skills/sherlock-review/SKILL.md +5 -0
- package/assets/skills/sherlock-review/schemas/output.json +297 -0
- package/assets/skills/sherlock-review/scripts/validate-config.json +35 -0
- package/assets/skills/testability-scoring/SKILL.md +5 -0
- package/assets/skills/testability-scoring/evals/testability-scoring.yaml +814 -0
- package/assets/skills/testability-scoring/schemas/output.json +606 -0
- package/assets/skills/testability-scoring/scripts/validate-config.json +42 -0
- package/assets/skills/trust-tier-manifest.json +2404 -0
- package/assets/skills/wms-testing-patterns/evals/wms-testing-patterns.yaml +165 -0
- package/assets/skills/wms-testing-patterns/schemas/output.json +150 -0
- package/assets/skills/wms-testing-patterns/scripts/validate-config.json +51 -0
- package/dist/benchmarks/performance-benchmarks.js +1 -1
- package/dist/cli/bundle.js +9130 -2283
- package/dist/cli/commands/hooks.d.ts.map +1 -1
- package/dist/cli/commands/hooks.js +92 -0
- package/dist/cli/commands/hooks.js.map +1 -1
- package/dist/cli/commands/migrate.js +2 -2
- package/dist/coordination/constants.d.ts +1 -1
- package/dist/coordination/constants.js +1 -1
- package/dist/coordination/handlers/coverage-handlers.js +1 -1
- package/dist/coordination/handlers/coverage-handlers.js.map +1 -1
- package/dist/domains/code-intelligence/services/semantic-analyzer.d.ts +1 -1
- package/dist/domains/code-intelligence/services/semantic-analyzer.d.ts.map +1 -1
- package/dist/domains/code-intelligence/services/semantic-analyzer.js +1 -1
- package/dist/domains/code-intelligence/services/semantic-analyzer.js.map +1 -1
- package/dist/domains/coverage-analysis/coordinator.js +1 -1
- package/dist/domains/coverage-analysis/services/coverage-analyzer.js +1 -1
- package/dist/domains/coverage-analysis/services/coverage-embedder.d.ts +1 -1
- package/dist/domains/coverage-analysis/services/coverage-embedder.js +1 -1
- package/dist/domains/coverage-analysis/services/gap-detector.js +1 -1
- package/dist/domains/coverage-analysis/services/ghost-coverage-analyzer.js +1 -1
- package/dist/domains/coverage-analysis/services/hnsw-index.d.ts +2 -2
- package/dist/domains/coverage-analysis/services/hnsw-index.js +3 -3
- package/dist/domains/coverage-analysis/services/sublinear-analyzer.d.ts +1 -1
- package/dist/domains/coverage-analysis/services/sublinear-analyzer.js +1 -1
- package/dist/domains/test-execution/services/test-prioritizer.js +1 -1
- package/dist/domains/test-generation/context/rust-context-builder.d.ts +31 -0
- package/dist/domains/test-generation/context/rust-context-builder.d.ts.map +1 -0
- package/dist/domains/test-generation/context/rust-context-builder.js +27 -0
- package/dist/domains/test-generation/context/rust-context-builder.js.map +1 -0
- package/dist/domains/test-generation/coordinator.js +3 -3
- package/dist/domains/test-generation/coordinator.js.map +1 -1
- package/dist/domains/test-generation/detectors/mobile-detector.d.ts +41 -0
- package/dist/domains/test-generation/detectors/mobile-detector.d.ts.map +1 -0
- package/dist/domains/test-generation/detectors/mobile-detector.js +111 -0
- package/dist/domains/test-generation/detectors/mobile-detector.js.map +1 -0
- package/dist/domains/test-generation/detectors/spring-detector.d.ts +22 -0
- package/dist/domains/test-generation/detectors/spring-detector.d.ts.map +1 -0
- package/dist/domains/test-generation/detectors/spring-detector.js +37 -0
- package/dist/domains/test-generation/detectors/spring-detector.js.map +1 -0
- package/dist/domains/test-generation/factories/test-generator-factory.d.ts +2 -1
- package/dist/domains/test-generation/factories/test-generator-factory.d.ts.map +1 -1
- package/dist/domains/test-generation/factories/test-generator-factory.js +33 -13
- package/dist/domains/test-generation/factories/test-generator-factory.js.map +1 -1
- package/dist/domains/test-generation/generators/flutter-test-generator.d.ts +107 -0
- package/dist/domains/test-generation/generators/flutter-test-generator.d.ts.map +1 -0
- package/dist/domains/test-generation/generators/flutter-test-generator.js +590 -0
- package/dist/domains/test-generation/generators/flutter-test-generator.js.map +1 -0
- package/dist/domains/test-generation/generators/go-test-generator.d.ts +139 -0
- package/dist/domains/test-generation/generators/go-test-generator.d.ts.map +1 -0
- package/dist/domains/test-generation/generators/go-test-generator.js +654 -0
- package/dist/domains/test-generation/generators/go-test-generator.js.map +1 -0
- package/dist/domains/test-generation/generators/index.d.ts +8 -0
- package/dist/domains/test-generation/generators/index.d.ts.map +1 -1
- package/dist/domains/test-generation/generators/index.js +8 -0
- package/dist/domains/test-generation/generators/index.js.map +1 -1
- package/dist/domains/test-generation/generators/jest-rn-generator.d.ts +95 -0
- package/dist/domains/test-generation/generators/jest-rn-generator.d.ts.map +1 -0
- package/dist/domains/test-generation/generators/jest-rn-generator.js +591 -0
- package/dist/domains/test-generation/generators/jest-rn-generator.js.map +1 -0
- package/dist/domains/test-generation/generators/junit5-generator.d.ts +107 -0
- package/dist/domains/test-generation/generators/junit5-generator.d.ts.map +1 -0
- package/dist/domains/test-generation/generators/junit5-generator.js +588 -0
- package/dist/domains/test-generation/generators/junit5-generator.js.map +1 -0
- package/dist/domains/test-generation/generators/kotlin-junit-generator.d.ts +109 -0
- package/dist/domains/test-generation/generators/kotlin-junit-generator.d.ts.map +1 -0
- package/dist/domains/test-generation/generators/kotlin-junit-generator.js +588 -0
- package/dist/domains/test-generation/generators/kotlin-junit-generator.js.map +1 -0
- package/dist/domains/test-generation/generators/pytest-generator.d.ts +8 -1
- package/dist/domains/test-generation/generators/pytest-generator.d.ts.map +1 -1
- package/dist/domains/test-generation/generators/pytest-generator.js +57 -0
- package/dist/domains/test-generation/generators/pytest-generator.js.map +1 -1
- package/dist/domains/test-generation/generators/rust-test-generator.d.ts +80 -0
- package/dist/domains/test-generation/generators/rust-test-generator.d.ts.map +1 -0
- package/dist/domains/test-generation/generators/rust-test-generator.js +442 -0
- package/dist/domains/test-generation/generators/rust-test-generator.js.map +1 -0
- package/dist/domains/test-generation/generators/swift-testing-generator.d.ts +97 -0
- package/dist/domains/test-generation/generators/swift-testing-generator.d.ts.map +1 -0
- package/dist/domains/test-generation/generators/swift-testing-generator.js +482 -0
- package/dist/domains/test-generation/generators/swift-testing-generator.js.map +1 -0
- package/dist/domains/test-generation/generators/xunit-generator.d.ts +110 -0
- package/dist/domains/test-generation/generators/xunit-generator.d.ts.map +1 -0
- package/dist/domains/test-generation/generators/xunit-generator.js +611 -0
- package/dist/domains/test-generation/generators/xunit-generator.js.map +1 -0
- package/dist/domains/test-generation/interfaces.d.ts +11 -2
- package/dist/domains/test-generation/interfaces.d.ts.map +1 -1
- package/dist/domains/test-generation/prompts/language-prompts.d.ts +29 -0
- package/dist/domains/test-generation/prompts/language-prompts.d.ts.map +1 -0
- package/dist/domains/test-generation/prompts/language-prompts.js +135 -0
- package/dist/domains/test-generation/prompts/language-prompts.js.map +1 -0
- package/dist/domains/test-generation/services/compilation-validator.d.ts +43 -0
- package/dist/domains/test-generation/services/compilation-validator.d.ts.map +1 -0
- package/dist/domains/test-generation/services/compilation-validator.js +134 -0
- package/dist/domains/test-generation/services/compilation-validator.js.map +1 -0
- package/dist/domains/test-generation/services/index.d.ts +2 -1
- package/dist/domains/test-generation/services/index.d.ts.map +1 -1
- package/dist/domains/test-generation/services/index.js +3 -1
- package/dist/domains/test-generation/services/index.js.map +1 -1
- package/dist/domains/test-generation/services/test-file-resolver.d.ts +32 -0
- package/dist/domains/test-generation/services/test-file-resolver.d.ts.map +1 -0
- package/dist/domains/test-generation/services/test-file-resolver.js +159 -0
- package/dist/domains/test-generation/services/test-file-resolver.js.map +1 -0
- package/dist/domains/test-generation/services/test-generator.d.ts +10 -0
- package/dist/domains/test-generation/services/test-generator.d.ts.map +1 -1
- package/dist/domains/test-generation/services/test-generator.js +87 -10
- package/dist/domains/test-generation/services/test-generator.js.map +1 -1
- package/dist/governance/feature-flags.js +2 -2
- package/dist/governance/feature-flags.js.map +1 -1
- package/dist/governance/shard-embeddings.js +1 -1
- package/dist/init/init-wizard-hooks.d.ts.map +1 -1
- package/dist/init/init-wizard-hooks.js +0 -1
- package/dist/init/init-wizard-hooks.js.map +1 -1
- package/dist/init/phases/07-hooks.d.ts.map +1 -1
- package/dist/init/phases/07-hooks.js +0 -2
- package/dist/init/phases/07-hooks.js.map +1 -1
- package/dist/init/phases/08-mcp.d.ts +8 -4
- package/dist/init/phases/08-mcp.d.ts.map +1 -1
- package/dist/init/phases/08-mcp.js +13 -31
- package/dist/init/phases/08-mcp.js.map +1 -1
- package/dist/init/phases/10-workers.js +2 -2
- package/dist/init/phases/10-workers.js.map +1 -1
- package/dist/init/settings-merge.d.ts.map +1 -1
- package/dist/init/settings-merge.js +0 -2
- package/dist/init/settings-merge.js.map +1 -1
- package/dist/init/token-bootstrap.js +1 -1
- package/dist/init/token-bootstrap.js.map +1 -1
- package/dist/integrations/rl-suite/algorithms/decision-transformer.js +1 -1
- package/dist/kernel/constants.d.ts +2 -2
- package/dist/kernel/constants.js +2 -2
- package/dist/kernel/hnsw-adapter.js +1 -1
- package/dist/kernel/progressive-hnsw-backend.d.ts +2 -2
- package/dist/kernel/progressive-hnsw-backend.js +2 -2
- package/dist/learning/dream/concept-graph.d.ts +1 -1
- package/dist/learning/dream/concept-graph.js +1 -1
- package/dist/learning/dream/dream-engine.d.ts +1 -1
- package/dist/learning/dream/dream-engine.js +1 -1
- package/dist/learning/dream/index.d.ts +1 -1
- package/dist/learning/dream/index.js +1 -1
- package/dist/learning/dream/types.d.ts +1 -1
- package/dist/learning/dream/types.d.ts.map +1 -1
- package/dist/learning/dream/types.js +1 -1
- package/dist/learning/dream/types.js.map +1 -1
- package/dist/learning/token-tracker.js +1 -1
- package/dist/learning/token-tracker.js.map +1 -1
- package/dist/mcp/bundle.js +7515 -893
- package/dist/routing/qe-agent-registry.js +4 -4
- package/dist/routing/qe-agent-registry.js.map +1 -1
- package/dist/routing/types.d.ts +5 -8
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/routing/types.js.map +1 -1
- package/dist/shared/embeddings/embedding-cache.js +2 -2
- package/dist/shared/embeddings/index.d.ts +2 -2
- package/dist/shared/embeddings/index.js +2 -2
- package/dist/shared/embeddings/nomic-embedder.d.ts +4 -4
- package/dist/shared/embeddings/nomic-embedder.js +2 -2
- package/dist/shared/embeddings/ollama-client.d.ts +1 -1
- package/dist/shared/embeddings/ollama-client.js +2 -2
- package/dist/shared/embeddings/ollama-client.js.map +1 -1
- package/dist/shared/embeddings/types.d.ts +2 -2
- package/dist/shared/embeddings/types.js +2 -2
- package/dist/shared/language-detector.d.ts +46 -0
- package/dist/shared/language-detector.d.ts.map +1 -0
- package/dist/shared/language-detector.js +183 -0
- package/dist/shared/language-detector.js.map +1 -0
- package/dist/shared/llm/providers/ollama.js +1 -1
- package/dist/shared/metrics/code-metrics.d.ts.map +1 -1
- package/dist/shared/metrics/code-metrics.js +24 -1
- package/dist/shared/metrics/code-metrics.js.map +1 -1
- package/dist/shared/parsers/index.d.ts +2 -0
- package/dist/shared/parsers/index.d.ts.map +1 -1
- package/dist/shared/parsers/index.js +2 -0
- package/dist/shared/parsers/index.js.map +1 -1
- package/dist/shared/parsers/interfaces.d.ts +81 -0
- package/dist/shared/parsers/interfaces.d.ts.map +1 -0
- package/dist/shared/parsers/interfaces.js +6 -0
- package/dist/shared/parsers/interfaces.js.map +1 -0
- package/dist/shared/parsers/multi-language-parser.d.ts +144 -0
- package/dist/shared/parsers/multi-language-parser.d.ts.map +1 -0
- package/dist/shared/parsers/multi-language-parser.js +1232 -0
- package/dist/shared/parsers/multi-language-parser.js.map +1 -0
- package/dist/shared/parsers/rust-ownership-analyzer.d.ts +45 -0
- package/dist/shared/parsers/rust-ownership-analyzer.d.ts.map +1 -0
- package/dist/shared/parsers/rust-ownership-analyzer.js +52 -0
- package/dist/shared/parsers/rust-ownership-analyzer.js.map +1 -0
- package/dist/shared/parsers/typescript-parser.d.ts +16 -0
- package/dist/shared/parsers/typescript-parser.d.ts.map +1 -1
- package/dist/shared/parsers/typescript-parser.js +85 -0
- package/dist/shared/parsers/typescript-parser.js.map +1 -1
- package/dist/shared/types/test-frameworks.d.ts +25 -0
- package/dist/shared/types/test-frameworks.d.ts.map +1 -0
- package/dist/shared/types/test-frameworks.js +111 -0
- package/dist/shared/types/test-frameworks.js.map +1 -0
- package/package.json +1 -1
- package/scripts/prepare-assets.sh +8 -2
|
@@ -0,0 +1,1232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Language Parser Registry (ADR-076)
|
|
3
|
+
* Regex-based parsers for non-TypeScript languages.
|
|
4
|
+
* Extracts function/class/import declarations for test generation.
|
|
5
|
+
*
|
|
6
|
+
* Uses two key utilities to handle complex syntax that naive line-by-line regex misses:
|
|
7
|
+
* 1. joinMultiLineSignatures — collapses multi-line function/class declarations into single logical lines
|
|
8
|
+
* 2. matchBalancedBrackets — handles nested generics like Map<String, List<Foo>> correctly
|
|
9
|
+
*/
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Shared Parsing Utilities
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Join multi-line signatures into single logical lines.
|
|
15
|
+
* Handles: function params spanning lines, class declarations with long implements lists,
|
|
16
|
+
* multi-line annotations/attributes, and continuation lines.
|
|
17
|
+
*
|
|
18
|
+
* Returns { logicalLines, lineMap } where lineMap[logicalIndex] = originalStartLine (1-based).
|
|
19
|
+
*/
|
|
20
|
+
export function joinMultiLineSignatures(content) {
|
|
21
|
+
const rawLines = content.split('\n');
|
|
22
|
+
const logicalLines = [];
|
|
23
|
+
const lineMap = [];
|
|
24
|
+
let buffer = '';
|
|
25
|
+
let bufferStartLine = 0;
|
|
26
|
+
let openParens = 0;
|
|
27
|
+
let openAngles = 0;
|
|
28
|
+
let openSquare = 0;
|
|
29
|
+
for (let i = 0; i < rawLines.length; i++) {
|
|
30
|
+
const line = rawLines[i];
|
|
31
|
+
const trimmed = line.trim();
|
|
32
|
+
// Skip pure comment/blank lines — emit them as-is
|
|
33
|
+
if (trimmed === '' || trimmed.startsWith('//') || trimmed.startsWith('#') || trimmed.startsWith('*')) {
|
|
34
|
+
if (buffer) {
|
|
35
|
+
// Inside a continuation — keep accumulating
|
|
36
|
+
buffer += ' ' + trimmed;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
logicalLines.push(line);
|
|
40
|
+
lineMap.push(i + 1);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (!buffer) {
|
|
44
|
+
bufferStartLine = i + 1;
|
|
45
|
+
}
|
|
46
|
+
buffer = buffer ? buffer + ' ' + trimmed : line;
|
|
47
|
+
// Count bracket balance (ignoring strings/comments for simplicity — good enough for declarations)
|
|
48
|
+
for (const ch of trimmed) {
|
|
49
|
+
if (ch === '(')
|
|
50
|
+
openParens++;
|
|
51
|
+
else if (ch === ')')
|
|
52
|
+
openParens = Math.max(0, openParens - 1);
|
|
53
|
+
else if (ch === '<')
|
|
54
|
+
openAngles++;
|
|
55
|
+
else if (ch === '>')
|
|
56
|
+
openAngles = Math.max(0, openAngles - 1);
|
|
57
|
+
else if (ch === '[')
|
|
58
|
+
openSquare++;
|
|
59
|
+
else if (ch === ']')
|
|
60
|
+
openSquare = Math.max(0, openSquare - 1);
|
|
61
|
+
}
|
|
62
|
+
// Line is complete when all brackets are balanced
|
|
63
|
+
if (openParens === 0 && openAngles === 0 && openSquare === 0) {
|
|
64
|
+
logicalLines.push(buffer);
|
|
65
|
+
lineMap.push(bufferStartLine);
|
|
66
|
+
buffer = '';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Flush remaining buffer
|
|
70
|
+
if (buffer) {
|
|
71
|
+
logicalLines.push(buffer);
|
|
72
|
+
lineMap.push(bufferStartLine);
|
|
73
|
+
}
|
|
74
|
+
return { logicalLines, lineMap };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Extract balanced bracket content starting at a given position.
|
|
78
|
+
* Handles nested brackets: Map<String, List<Foo>> returns "String, List<Foo>"
|
|
79
|
+
*
|
|
80
|
+
* @param str - The string to scan
|
|
81
|
+
* @param startIdx - Index of the opening bracket character
|
|
82
|
+
* @param open - Opening bracket char (default '<')
|
|
83
|
+
* @param close - Closing bracket char (default '>')
|
|
84
|
+
* @returns The content between brackets (excluding the brackets), or undefined if unbalanced
|
|
85
|
+
*/
|
|
86
|
+
export function matchBalancedBrackets(str, startIdx, open = '<', close = '>') {
|
|
87
|
+
if (str[startIdx] !== open)
|
|
88
|
+
return undefined;
|
|
89
|
+
let depth = 1;
|
|
90
|
+
let i = startIdx + 1;
|
|
91
|
+
while (i < str.length && depth > 0) {
|
|
92
|
+
if (str[i] === open)
|
|
93
|
+
depth++;
|
|
94
|
+
else if (str[i] === close)
|
|
95
|
+
depth--;
|
|
96
|
+
i++;
|
|
97
|
+
}
|
|
98
|
+
if (depth !== 0)
|
|
99
|
+
return undefined;
|
|
100
|
+
return str.substring(startIdx + 1, i - 1);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Extract the full type expression starting at an index, handling nested generics.
|
|
104
|
+
* E.g., from "Map<String, List<Foo>> remaining" extracts "Map<String, List<Foo>>"
|
|
105
|
+
*/
|
|
106
|
+
export function extractFullType(str, startIdx = 0) {
|
|
107
|
+
let i = startIdx;
|
|
108
|
+
// Skip whitespace
|
|
109
|
+
while (i < str.length && str[i] === ' ')
|
|
110
|
+
i++;
|
|
111
|
+
const typeStart = i;
|
|
112
|
+
// Walk through identifier chars
|
|
113
|
+
while (i < str.length && /[\w.]/.test(str[i]))
|
|
114
|
+
i++;
|
|
115
|
+
// If next char is '<', consume balanced generics
|
|
116
|
+
if (i < str.length && str[i] === '<') {
|
|
117
|
+
const inner = matchBalancedBrackets(str, i);
|
|
118
|
+
if (inner !== undefined) {
|
|
119
|
+
i += inner.length + 2; // +2 for < and >
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Handle array suffixes [], ?, !, etc.
|
|
123
|
+
while (i < str.length && /[[\]?!*&]/.test(str[i]))
|
|
124
|
+
i++;
|
|
125
|
+
return str.substring(typeStart, i).trim();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Collect decorators/attributes by scanning backwards from a line index.
|
|
129
|
+
* Handles multi-line attribute chains like:
|
|
130
|
+
* #[derive(Debug)]
|
|
131
|
+
* #[serde(rename_all = "camelCase")]
|
|
132
|
+
* pub struct Foo { ... }
|
|
133
|
+
*
|
|
134
|
+
* @param lines - Array of source lines
|
|
135
|
+
* @param lineIdx - Index of the declaration line (0-based)
|
|
136
|
+
* @param prefix - Decorator prefix to look for ('@', '#[', '[')
|
|
137
|
+
*/
|
|
138
|
+
export function collectDecorators(lines, lineIdx, prefix) {
|
|
139
|
+
const decorators = [];
|
|
140
|
+
for (let j = lineIdx - 1; j >= 0; j--) {
|
|
141
|
+
const trimmed = lines[j].trim();
|
|
142
|
+
if (trimmed.startsWith(prefix)) {
|
|
143
|
+
decorators.unshift(trimmed);
|
|
144
|
+
}
|
|
145
|
+
else if (trimmed === '' || trimmed.startsWith('//') || trimmed.startsWith('*') || trimmed.startsWith('#')) {
|
|
146
|
+
// Allow blank lines and comments between decorators
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return decorators;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Parse a balanced parenthesized parameter string.
|
|
157
|
+
* Unlike regex [^)]*, this handles nested parens/generics inside parameter types.
|
|
158
|
+
* Input: content after opening '(' — e.g. "id: Long, filter: Map<String, List<Int>>"
|
|
159
|
+
*/
|
|
160
|
+
export function extractParenContent(line, openIdx) {
|
|
161
|
+
return matchBalancedBrackets(line, openIdx, '(', ')');
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Split a parameter string by commas, respecting nested generics depth.
|
|
165
|
+
* "String id, Map<String, List<Foo>> map" -> ["String id", "Map<String, List<Foo>> map"]
|
|
166
|
+
*/
|
|
167
|
+
function splitParamsGenericAware(paramsStr) {
|
|
168
|
+
const params = [];
|
|
169
|
+
let depth = 0;
|
|
170
|
+
let current = '';
|
|
171
|
+
for (const ch of paramsStr) {
|
|
172
|
+
if (ch === '<' || ch === '(')
|
|
173
|
+
depth++;
|
|
174
|
+
else if (ch === '>' || ch === ')')
|
|
175
|
+
depth--;
|
|
176
|
+
if (ch === ',' && depth === 0) {
|
|
177
|
+
params.push(current.trim());
|
|
178
|
+
current = '';
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
current += ch;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (current.trim())
|
|
185
|
+
params.push(current.trim());
|
|
186
|
+
return params;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Count braces in a line to track nesting depth.
|
|
190
|
+
* Returns the delta (opens - closes).
|
|
191
|
+
*/
|
|
192
|
+
function countBraceDelta(line) {
|
|
193
|
+
let delta = 0;
|
|
194
|
+
let inString = false;
|
|
195
|
+
let stringChar = '';
|
|
196
|
+
for (let i = 0; i < line.length; i++) {
|
|
197
|
+
const ch = line[i];
|
|
198
|
+
if (inString) {
|
|
199
|
+
if (ch === stringChar && line[i - 1] !== '\\')
|
|
200
|
+
inString = false;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (ch === '"' || ch === '\'' || ch === '`') {
|
|
204
|
+
inString = true;
|
|
205
|
+
stringChar = ch;
|
|
206
|
+
}
|
|
207
|
+
else if (ch === '{') {
|
|
208
|
+
delta++;
|
|
209
|
+
}
|
|
210
|
+
else if (ch === '}') {
|
|
211
|
+
delta--;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return delta;
|
|
215
|
+
}
|
|
216
|
+
// --- Python Parser ---
|
|
217
|
+
class PythonParser {
|
|
218
|
+
language = 'python';
|
|
219
|
+
supportedExtensions = ['.py'];
|
|
220
|
+
async parseFile(content, filePath) {
|
|
221
|
+
return {
|
|
222
|
+
functions: this.extractFunctions(content),
|
|
223
|
+
classes: this.extractClasses(content),
|
|
224
|
+
imports: this.extractImports(content),
|
|
225
|
+
language: 'python',
|
|
226
|
+
filePath,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
extractFunctions(content) {
|
|
230
|
+
const functions = [];
|
|
231
|
+
const rawLines = content.split('\n');
|
|
232
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
233
|
+
// Match: def function_name(params) -> return_type:
|
|
234
|
+
// or: async def function_name(params) -> return_type:
|
|
235
|
+
const funcRegex = /^(\s*)(async\s+)?def\s+(\w+)\s*\(([^)]*)\)(?:\s*->\s*([^:]+))?\s*:/;
|
|
236
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
237
|
+
const match = logicalLines[i].match(funcRegex);
|
|
238
|
+
if (match) {
|
|
239
|
+
const indent = match[1].length;
|
|
240
|
+
const isAsync = !!match[2];
|
|
241
|
+
const name = match[3];
|
|
242
|
+
const paramsStr = match[4];
|
|
243
|
+
const returnType = match[5]?.trim();
|
|
244
|
+
const origLine = lineMap[i] - 1; // 0-based index into rawLines
|
|
245
|
+
// Find end of function (next line at same or lower indent, or end of file)
|
|
246
|
+
let endLine = origLine + 1;
|
|
247
|
+
for (let j = origLine + 1; j < rawLines.length; j++) {
|
|
248
|
+
const line = rawLines[j];
|
|
249
|
+
if (line.trim() === '' || line.trim().startsWith('#'))
|
|
250
|
+
continue;
|
|
251
|
+
const lineIndent = line.match(/^(\s*)/)?.[1].length ?? 0;
|
|
252
|
+
if (lineIndent <= indent && line.trim() !== '') {
|
|
253
|
+
endLine = j;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
endLine = j + 1;
|
|
257
|
+
}
|
|
258
|
+
const decorators = collectDecorators(rawLines, origLine, '@');
|
|
259
|
+
functions.push({
|
|
260
|
+
name,
|
|
261
|
+
parameters: this.parseParams(paramsStr),
|
|
262
|
+
returnType,
|
|
263
|
+
isAsync,
|
|
264
|
+
isPublic: !name.startsWith('_'),
|
|
265
|
+
complexity: 1,
|
|
266
|
+
decorators,
|
|
267
|
+
genericParams: [],
|
|
268
|
+
startLine: lineMap[i],
|
|
269
|
+
endLine,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return functions;
|
|
274
|
+
}
|
|
275
|
+
extractClasses(content) {
|
|
276
|
+
const classes = [];
|
|
277
|
+
const rawLines = content.split('\n');
|
|
278
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
279
|
+
const classRegex = /^(\s*)class\s+(\w+)(?:\(([^)]*)\))?\s*:/;
|
|
280
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
281
|
+
const match = logicalLines[i].match(classRegex);
|
|
282
|
+
if (match) {
|
|
283
|
+
const indent = match[1].length;
|
|
284
|
+
const name = match[2];
|
|
285
|
+
const bases = match[3]
|
|
286
|
+
? match[3].split(',').map((b) => b.trim())
|
|
287
|
+
: [];
|
|
288
|
+
const origLine = lineMap[i] - 1;
|
|
289
|
+
// Find end of class
|
|
290
|
+
let endLine = origLine + 1;
|
|
291
|
+
for (let j = origLine + 1; j < rawLines.length; j++) {
|
|
292
|
+
const line = rawLines[j];
|
|
293
|
+
if (line.trim() === '' || line.trim().startsWith('#'))
|
|
294
|
+
continue;
|
|
295
|
+
const lineIndent = line.match(/^(\s*)/)?.[1].length ?? 0;
|
|
296
|
+
if (lineIndent <= indent && line.trim() !== '') {
|
|
297
|
+
endLine = j;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
endLine = j + 1;
|
|
301
|
+
}
|
|
302
|
+
// Extract methods within class
|
|
303
|
+
const classContent = rawLines.slice(origLine + 1, endLine).join('\n');
|
|
304
|
+
const methods = this.extractFunctions(classContent).map((f) => ({
|
|
305
|
+
...f,
|
|
306
|
+
startLine: f.startLine + origLine,
|
|
307
|
+
endLine: f.endLine + origLine,
|
|
308
|
+
}));
|
|
309
|
+
const decorators = collectDecorators(rawLines, origLine, '@');
|
|
310
|
+
classes.push({
|
|
311
|
+
name,
|
|
312
|
+
methods,
|
|
313
|
+
properties: [],
|
|
314
|
+
isPublic: !name.startsWith('_'),
|
|
315
|
+
implements: [],
|
|
316
|
+
extends: bases[0] || undefined,
|
|
317
|
+
decorators,
|
|
318
|
+
startLine: lineMap[i],
|
|
319
|
+
endLine,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return classes;
|
|
324
|
+
}
|
|
325
|
+
extractImports(content) {
|
|
326
|
+
const imports = [];
|
|
327
|
+
const lines = content.split('\n');
|
|
328
|
+
for (const line of lines) {
|
|
329
|
+
// from module import name1, name2
|
|
330
|
+
const fromMatch = line.match(/^\s*from\s+(\S+)\s+import\s+(.+)/);
|
|
331
|
+
if (fromMatch) {
|
|
332
|
+
const names = fromMatch[2]
|
|
333
|
+
.split(',')
|
|
334
|
+
.map((n) => n.trim().split(/\s+as\s+/)[0]);
|
|
335
|
+
imports.push({
|
|
336
|
+
module: fromMatch[1],
|
|
337
|
+
namedImports: names,
|
|
338
|
+
isTypeOnly: false,
|
|
339
|
+
});
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
// import module
|
|
343
|
+
const importMatch = line.match(/^\s*import\s+(\S+)/);
|
|
344
|
+
if (importMatch) {
|
|
345
|
+
imports.push({
|
|
346
|
+
module: importMatch[1],
|
|
347
|
+
namedImports: [],
|
|
348
|
+
isTypeOnly: false,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return imports;
|
|
353
|
+
}
|
|
354
|
+
parseParams(paramsStr) {
|
|
355
|
+
if (!paramsStr.trim())
|
|
356
|
+
return [];
|
|
357
|
+
return splitParamsGenericAware(paramsStr)
|
|
358
|
+
.map((p) => p.trim())
|
|
359
|
+
.filter((p) => p && p !== 'self' && p !== 'cls')
|
|
360
|
+
.map((p) => {
|
|
361
|
+
const [nameDefault, type] = p.split(':').map((s) => s.trim());
|
|
362
|
+
const [name, defaultValue] = nameDefault
|
|
363
|
+
.split('=')
|
|
364
|
+
.map((s) => s.trim());
|
|
365
|
+
return {
|
|
366
|
+
name,
|
|
367
|
+
type: type?.split('=')[0].trim() || undefined,
|
|
368
|
+
isOptional: !!defaultValue || name.startsWith('*'),
|
|
369
|
+
defaultValue: defaultValue || undefined,
|
|
370
|
+
};
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
// --- Java Parser ---
|
|
375
|
+
class JavaParser {
|
|
376
|
+
language = 'java';
|
|
377
|
+
supportedExtensions = ['.java'];
|
|
378
|
+
async parseFile(content, filePath) {
|
|
379
|
+
return {
|
|
380
|
+
functions: this.extractFunctions(content),
|
|
381
|
+
classes: this.extractClasses(content),
|
|
382
|
+
imports: this.extractImports(content),
|
|
383
|
+
language: 'java',
|
|
384
|
+
filePath,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
extractFunctions(content) {
|
|
388
|
+
const functions = [];
|
|
389
|
+
const rawLines = content.split('\n');
|
|
390
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
391
|
+
// Match method declarations — use a simpler regex without <[^>]+> so generics don't break
|
|
392
|
+
const methodRegex = /^\s*(public|private|protected)?\s*(static)?\s*(async)?\s*(?:<\S+>\s+)?([\w<>,.\s[\]?]+)\s+(\w+)\s*\(([^)]*)\)/;
|
|
393
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
394
|
+
const line = logicalLines[i];
|
|
395
|
+
if (line.includes(' class ') || line.includes(' interface '))
|
|
396
|
+
continue;
|
|
397
|
+
const match = line.match(methodRegex);
|
|
398
|
+
if (match) {
|
|
399
|
+
const visibility = match[1] || 'default';
|
|
400
|
+
const name = match[5];
|
|
401
|
+
const paramsStr = match[6];
|
|
402
|
+
// Extract the full return type with balanced generics
|
|
403
|
+
const returnTypeRaw = match[4]?.trim();
|
|
404
|
+
let returnType = returnTypeRaw;
|
|
405
|
+
// If the raw return type was truncated by the regex, try to extract full type
|
|
406
|
+
if (returnTypeRaw && returnTypeRaw.includes('<')) {
|
|
407
|
+
const angleIdx = returnTypeRaw.indexOf('<');
|
|
408
|
+
const inner = matchBalancedBrackets(returnTypeRaw, angleIdx);
|
|
409
|
+
if (inner !== undefined) {
|
|
410
|
+
returnType = returnTypeRaw.substring(0, angleIdx) + '<' + inner + '>';
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const origLine = lineMap[i] - 1;
|
|
414
|
+
const decorators = collectDecorators(rawLines, origLine, '@');
|
|
415
|
+
functions.push({
|
|
416
|
+
name,
|
|
417
|
+
parameters: this.parseParams(paramsStr),
|
|
418
|
+
returnType: returnType === 'void' ? undefined : returnType,
|
|
419
|
+
isAsync: returnType?.includes('CompletableFuture') || false,
|
|
420
|
+
isPublic: visibility === 'public',
|
|
421
|
+
complexity: 1,
|
|
422
|
+
decorators,
|
|
423
|
+
genericParams: [],
|
|
424
|
+
startLine: lineMap[i],
|
|
425
|
+
endLine: lineMap[i],
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return functions;
|
|
430
|
+
}
|
|
431
|
+
extractClasses(content) {
|
|
432
|
+
const classes = [];
|
|
433
|
+
const rawLines = content.split('\n');
|
|
434
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
435
|
+
const classRegex = /^\s*(public|private|protected)?\s*(abstract)?\s*class\s+(\w+)(?:<[^{]*>)?(?:\s+extends\s+(\w+))?(?:\s+implements\s+([^{]+))?\s*\{?/;
|
|
436
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
437
|
+
const match = logicalLines[i].match(classRegex);
|
|
438
|
+
if (match) {
|
|
439
|
+
const name = match[3];
|
|
440
|
+
const extendsName = match[4];
|
|
441
|
+
const implementsList = match[5]
|
|
442
|
+
? match[5].split(',').map((s) => s.trim())
|
|
443
|
+
: [];
|
|
444
|
+
const origLine = lineMap[i] - 1;
|
|
445
|
+
const decorators = collectDecorators(rawLines, origLine, '@');
|
|
446
|
+
classes.push({
|
|
447
|
+
name,
|
|
448
|
+
methods: [],
|
|
449
|
+
properties: [],
|
|
450
|
+
isPublic: (match[1] || 'default') === 'public',
|
|
451
|
+
implements: implementsList,
|
|
452
|
+
extends: extendsName,
|
|
453
|
+
decorators,
|
|
454
|
+
startLine: lineMap[i],
|
|
455
|
+
endLine: lineMap[i],
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return classes;
|
|
460
|
+
}
|
|
461
|
+
extractImports(content) {
|
|
462
|
+
const imports = [];
|
|
463
|
+
const lines = content.split('\n');
|
|
464
|
+
for (const line of lines) {
|
|
465
|
+
const match = line.match(/^\s*import\s+(static\s+)?([^;]+);/);
|
|
466
|
+
if (match) {
|
|
467
|
+
const module = match[2].trim();
|
|
468
|
+
const parts = module.split('.');
|
|
469
|
+
const name = parts[parts.length - 1];
|
|
470
|
+
imports.push({
|
|
471
|
+
module,
|
|
472
|
+
namedImports: name === '*' ? [] : [name],
|
|
473
|
+
isTypeOnly: false,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return imports;
|
|
478
|
+
}
|
|
479
|
+
parseParams(paramsStr) {
|
|
480
|
+
if (!paramsStr.trim())
|
|
481
|
+
return [];
|
|
482
|
+
return splitParamsGenericAware(paramsStr).map((p) => {
|
|
483
|
+
const parts = p.trim().split(/\s+/);
|
|
484
|
+
// Handle annotations: @NotNull String name
|
|
485
|
+
const filtered = parts.filter((part) => !part.startsWith('@'));
|
|
486
|
+
const name = filtered[filtered.length - 1] || '';
|
|
487
|
+
const type = filtered.slice(0, -1).join(' ') || undefined;
|
|
488
|
+
return { name, type, isOptional: false, defaultValue: undefined };
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// --- C# Parser ---
|
|
493
|
+
class CSharpParser {
|
|
494
|
+
language = 'csharp';
|
|
495
|
+
supportedExtensions = ['.cs'];
|
|
496
|
+
async parseFile(content, filePath) {
|
|
497
|
+
return {
|
|
498
|
+
functions: this.extractMethods(content),
|
|
499
|
+
classes: this.extractClasses(content),
|
|
500
|
+
imports: this.extractImports(content),
|
|
501
|
+
language: 'csharp',
|
|
502
|
+
filePath,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
extractMethods(content) {
|
|
506
|
+
const functions = [];
|
|
507
|
+
const rawLines = content.split('\n');
|
|
508
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
509
|
+
const methodRegex = /^\s*(public|private|protected|internal)?\s*(static)?\s*(async)?\s*([\w<>,.\s[\]?]+)\s+(\w+)\s*\(([^)]*)\)/;
|
|
510
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
511
|
+
const line = logicalLines[i];
|
|
512
|
+
if (line.includes(' class ') || line.includes(' interface ') || line.includes(' namespace '))
|
|
513
|
+
continue;
|
|
514
|
+
const match = line.match(methodRegex);
|
|
515
|
+
if (match) {
|
|
516
|
+
const visibility = match[1] || 'private';
|
|
517
|
+
const isAsync = !!match[3] || match[4]?.includes('Task') || false;
|
|
518
|
+
const returnTypeRaw = match[4]?.trim();
|
|
519
|
+
let returnType = returnTypeRaw;
|
|
520
|
+
// Extract full generic type
|
|
521
|
+
if (returnTypeRaw && returnTypeRaw.includes('<')) {
|
|
522
|
+
const angleIdx = returnTypeRaw.indexOf('<');
|
|
523
|
+
const inner = matchBalancedBrackets(returnTypeRaw, angleIdx);
|
|
524
|
+
if (inner !== undefined) {
|
|
525
|
+
returnType = returnTypeRaw.substring(0, angleIdx) + '<' + inner + '>';
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const name = match[5];
|
|
529
|
+
const paramsStr = match[6];
|
|
530
|
+
const origLine = lineMap[i] - 1;
|
|
531
|
+
const decorators = collectDecorators(rawLines, origLine, '[');
|
|
532
|
+
functions.push({
|
|
533
|
+
name,
|
|
534
|
+
parameters: this.parseParams(paramsStr),
|
|
535
|
+
returnType: returnType === 'void' ? undefined : returnType,
|
|
536
|
+
isAsync,
|
|
537
|
+
isPublic: visibility === 'public',
|
|
538
|
+
complexity: 1,
|
|
539
|
+
decorators,
|
|
540
|
+
genericParams: [],
|
|
541
|
+
startLine: lineMap[i],
|
|
542
|
+
endLine: lineMap[i],
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return functions;
|
|
547
|
+
}
|
|
548
|
+
extractClasses(content) {
|
|
549
|
+
const classes = [];
|
|
550
|
+
const rawLines = content.split('\n');
|
|
551
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
552
|
+
const classRegex = /^\s*(public|private|protected|internal)?\s*(abstract|sealed|static|partial)?\s*class\s+(\w+)(?:<[^{]*>)?(?:\s*:\s*([^{]+))?\s*\{?/;
|
|
553
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
554
|
+
const match = logicalLines[i].match(classRegex);
|
|
555
|
+
if (match) {
|
|
556
|
+
const name = match[3];
|
|
557
|
+
const bases = match[4]
|
|
558
|
+
? match[4].split(',').map((s) => s.trim())
|
|
559
|
+
: [];
|
|
560
|
+
const origLine = lineMap[i] - 1;
|
|
561
|
+
const decorators = collectDecorators(rawLines, origLine, '[');
|
|
562
|
+
classes.push({
|
|
563
|
+
name,
|
|
564
|
+
methods: [],
|
|
565
|
+
properties: [],
|
|
566
|
+
isPublic: (match[1] || 'internal') === 'public',
|
|
567
|
+
implements: bases.slice(1),
|
|
568
|
+
extends: bases[0] || undefined,
|
|
569
|
+
decorators,
|
|
570
|
+
startLine: lineMap[i],
|
|
571
|
+
endLine: lineMap[i],
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return classes;
|
|
576
|
+
}
|
|
577
|
+
extractImports(content) {
|
|
578
|
+
const imports = [];
|
|
579
|
+
const lines = content.split('\n');
|
|
580
|
+
for (const line of lines) {
|
|
581
|
+
const match = line.match(/^\s*using\s+(static\s+)?([^;]+);/);
|
|
582
|
+
if (match) {
|
|
583
|
+
imports.push({
|
|
584
|
+
module: match[2].trim(),
|
|
585
|
+
namedImports: [],
|
|
586
|
+
isTypeOnly: false,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return imports;
|
|
591
|
+
}
|
|
592
|
+
parseParams(paramsStr) {
|
|
593
|
+
if (!paramsStr.trim())
|
|
594
|
+
return [];
|
|
595
|
+
return splitParamsGenericAware(paramsStr).map((p) => {
|
|
596
|
+
const parts = p.trim().split(/\s+/);
|
|
597
|
+
const name = parts[parts.length - 1] || '';
|
|
598
|
+
const type = parts.slice(0, -1).join(' ') || undefined;
|
|
599
|
+
return {
|
|
600
|
+
name,
|
|
601
|
+
type,
|
|
602
|
+
isOptional: type?.endsWith('?') || false,
|
|
603
|
+
defaultValue: undefined,
|
|
604
|
+
};
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
// --- Go Parser ---
|
|
609
|
+
class GoParser {
|
|
610
|
+
language = 'go';
|
|
611
|
+
supportedExtensions = ['.go'];
|
|
612
|
+
async parseFile(content, filePath) {
|
|
613
|
+
return {
|
|
614
|
+
functions: this.extractFunctions(content),
|
|
615
|
+
classes: this.extractStructs(content),
|
|
616
|
+
imports: this.extractImports(content),
|
|
617
|
+
language: 'go',
|
|
618
|
+
filePath,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
extractFunctions(content) {
|
|
622
|
+
const functions = [];
|
|
623
|
+
const rawLines = content.split('\n');
|
|
624
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
625
|
+
// func Name(params) returnType {
|
|
626
|
+
// func (r *Receiver) Name(params) returnType {
|
|
627
|
+
const funcRegex = /^\s*func\s+(?:\((\w+)\s+\*?(\w+)\)\s+)?(\w+)\s*\(([^)]*)\)\s*([\w*[\](),\s]*)\s*\{?/;
|
|
628
|
+
// Track brace depth to filter nested function literals (Go closures).
|
|
629
|
+
// Go methods use receiver syntax at top level, so only depth 0 is valid.
|
|
630
|
+
let braceDepth = 0;
|
|
631
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
632
|
+
const line = logicalLines[i];
|
|
633
|
+
const match = line.match(funcRegex);
|
|
634
|
+
if (match && braceDepth === 0) {
|
|
635
|
+
const name = match[3];
|
|
636
|
+
const paramsStr = match[4];
|
|
637
|
+
const returnType = match[5]?.trim() || undefined;
|
|
638
|
+
functions.push({
|
|
639
|
+
name,
|
|
640
|
+
parameters: this.parseParams(paramsStr),
|
|
641
|
+
returnType: returnType || undefined,
|
|
642
|
+
isAsync: false,
|
|
643
|
+
isPublic: name[0] === name[0].toUpperCase(),
|
|
644
|
+
complexity: 1,
|
|
645
|
+
decorators: [],
|
|
646
|
+
genericParams: [],
|
|
647
|
+
startLine: lineMap[i],
|
|
648
|
+
endLine: lineMap[i],
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
// Update brace depth after checking for function match
|
|
652
|
+
braceDepth += countBraceDelta(line);
|
|
653
|
+
if (braceDepth < 0)
|
|
654
|
+
braceDepth = 0;
|
|
655
|
+
}
|
|
656
|
+
return functions;
|
|
657
|
+
}
|
|
658
|
+
extractStructs(content) {
|
|
659
|
+
const structs = [];
|
|
660
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
661
|
+
const structRegex = /^\s*type\s+(\w+)\s+struct\s*\{/;
|
|
662
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
663
|
+
const match = logicalLines[i].match(structRegex);
|
|
664
|
+
if (match) {
|
|
665
|
+
const name = match[1];
|
|
666
|
+
structs.push({
|
|
667
|
+
name,
|
|
668
|
+
methods: [],
|
|
669
|
+
properties: [],
|
|
670
|
+
isPublic: name[0] === name[0].toUpperCase(),
|
|
671
|
+
implements: [],
|
|
672
|
+
extends: undefined,
|
|
673
|
+
decorators: [],
|
|
674
|
+
startLine: lineMap[i],
|
|
675
|
+
endLine: lineMap[i],
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return structs;
|
|
680
|
+
}
|
|
681
|
+
extractImports(content) {
|
|
682
|
+
const imports = [];
|
|
683
|
+
const singleImport = /^\s*import\s+"([^"]+)"/;
|
|
684
|
+
const multiImportStart = /^\s*import\s*\(/;
|
|
685
|
+
const multiImportLine = /^\s*"([^"]+)"/;
|
|
686
|
+
const lines = content.split('\n');
|
|
687
|
+
let inMultiImport = false;
|
|
688
|
+
for (const line of lines) {
|
|
689
|
+
if (inMultiImport) {
|
|
690
|
+
if (line.includes(')')) {
|
|
691
|
+
inMultiImport = false;
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
const match = line.match(multiImportLine);
|
|
695
|
+
if (match)
|
|
696
|
+
imports.push({
|
|
697
|
+
module: match[1],
|
|
698
|
+
namedImports: [],
|
|
699
|
+
isTypeOnly: false,
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
const single = line.match(singleImport);
|
|
704
|
+
if (single) {
|
|
705
|
+
imports.push({
|
|
706
|
+
module: single[1],
|
|
707
|
+
namedImports: [],
|
|
708
|
+
isTypeOnly: false,
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
else if (multiImportStart.test(line)) {
|
|
712
|
+
inMultiImport = true;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return imports;
|
|
717
|
+
}
|
|
718
|
+
parseParams(paramsStr) {
|
|
719
|
+
if (!paramsStr.trim())
|
|
720
|
+
return [];
|
|
721
|
+
return splitParamsGenericAware(paramsStr).map((p) => {
|
|
722
|
+
const parts = p.trim().split(/\s+/);
|
|
723
|
+
const name = parts[0] || '';
|
|
724
|
+
const type = parts.slice(1).join(' ') || undefined;
|
|
725
|
+
return { name, type, isOptional: false, defaultValue: undefined };
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
// --- Rust Parser ---
|
|
730
|
+
class RustParser {
|
|
731
|
+
language = 'rust';
|
|
732
|
+
supportedExtensions = ['.rs'];
|
|
733
|
+
async parseFile(content, filePath) {
|
|
734
|
+
return {
|
|
735
|
+
functions: this.extractFunctions(content),
|
|
736
|
+
classes: this.extractStructsAndImpls(content),
|
|
737
|
+
imports: this.extractImports(content),
|
|
738
|
+
language: 'rust',
|
|
739
|
+
filePath,
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
extractFunctions(content) {
|
|
743
|
+
const functions = [];
|
|
744
|
+
const rawLines = content.split('\n');
|
|
745
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
746
|
+
// Updated regex: use [^{]* instead of [^>]+ for generics to handle lifetimes
|
|
747
|
+
const fnRegex = /^\s*(pub(?:\(crate\))?\s+)?(async\s+)?fn\s+(\w+)(?:<[^{]*>)?\s*\(([^)]*)\)(?:\s*->\s*([^{]+))?\s*(?:where\s+[^{]*)?\s*\{?/;
|
|
748
|
+
// Track brace depth to filter nested closures.
|
|
749
|
+
// Rust functions at depth 0 (top-level) and depth 1 (inside impl/mod blocks) are valid.
|
|
750
|
+
let braceDepth = 0;
|
|
751
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
752
|
+
const line = logicalLines[i];
|
|
753
|
+
const match = line.match(fnRegex);
|
|
754
|
+
if (match && braceDepth <= 1) {
|
|
755
|
+
const isPub = !!match[1];
|
|
756
|
+
const isAsync = !!match[2];
|
|
757
|
+
const name = match[3];
|
|
758
|
+
const paramsStr = match[4];
|
|
759
|
+
const returnType = match[5]?.trim();
|
|
760
|
+
const origLine = lineMap[i] - 1;
|
|
761
|
+
const decorators = collectDecorators(rawLines, origLine, '#[');
|
|
762
|
+
functions.push({
|
|
763
|
+
name,
|
|
764
|
+
parameters: this.parseParams(paramsStr),
|
|
765
|
+
returnType,
|
|
766
|
+
isAsync,
|
|
767
|
+
isPublic: isPub,
|
|
768
|
+
complexity: 1,
|
|
769
|
+
decorators,
|
|
770
|
+
genericParams: [],
|
|
771
|
+
startLine: lineMap[i],
|
|
772
|
+
endLine: lineMap[i],
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
// Update brace depth after checking for function match
|
|
776
|
+
braceDepth += countBraceDelta(line);
|
|
777
|
+
if (braceDepth < 0)
|
|
778
|
+
braceDepth = 0;
|
|
779
|
+
}
|
|
780
|
+
return functions;
|
|
781
|
+
}
|
|
782
|
+
extractStructsAndImpls(content) {
|
|
783
|
+
const structs = [];
|
|
784
|
+
const rawLines = content.split('\n');
|
|
785
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
786
|
+
// Updated: use [^{]* for generics with lifetimes
|
|
787
|
+
const structRegex = /^\s*(pub(?:\(crate\))?\s+)?struct\s+(\w+)(?:<[^{]*>)?\s*/;
|
|
788
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
789
|
+
const match = logicalLines[i].match(structRegex);
|
|
790
|
+
if (match) {
|
|
791
|
+
const origLine = lineMap[i] - 1;
|
|
792
|
+
const decorators = collectDecorators(rawLines, origLine, '#[');
|
|
793
|
+
structs.push({
|
|
794
|
+
name: match[2],
|
|
795
|
+
methods: [],
|
|
796
|
+
properties: [],
|
|
797
|
+
isPublic: !!match[1],
|
|
798
|
+
implements: [],
|
|
799
|
+
extends: undefined,
|
|
800
|
+
decorators,
|
|
801
|
+
startLine: lineMap[i],
|
|
802
|
+
endLine: lineMap[i],
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return structs;
|
|
807
|
+
}
|
|
808
|
+
extractImports(content) {
|
|
809
|
+
const imports = [];
|
|
810
|
+
const lines = content.split('\n');
|
|
811
|
+
for (const line of lines) {
|
|
812
|
+
const match = line.match(/^\s*use\s+([^;]+);/);
|
|
813
|
+
if (match) {
|
|
814
|
+
imports.push({
|
|
815
|
+
module: match[1].trim(),
|
|
816
|
+
namedImports: [],
|
|
817
|
+
isTypeOnly: false,
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return imports;
|
|
822
|
+
}
|
|
823
|
+
parseParams(paramsStr) {
|
|
824
|
+
if (!paramsStr.trim())
|
|
825
|
+
return [];
|
|
826
|
+
return splitParamsGenericAware(paramsStr)
|
|
827
|
+
.map((p) => p.trim())
|
|
828
|
+
.filter((p) => p && p !== '&self' && p !== '&mut self' && p !== 'self')
|
|
829
|
+
.map((p) => {
|
|
830
|
+
const colonIdx = p.indexOf(':');
|
|
831
|
+
if (colonIdx === -1)
|
|
832
|
+
return {
|
|
833
|
+
name: p,
|
|
834
|
+
type: undefined,
|
|
835
|
+
isOptional: false,
|
|
836
|
+
defaultValue: undefined,
|
|
837
|
+
};
|
|
838
|
+
const name = p.substring(0, colonIdx).trim();
|
|
839
|
+
const type = p.substring(colonIdx + 1).trim();
|
|
840
|
+
return { name, type, isOptional: false, defaultValue: undefined };
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
// --- Swift Parser ---
|
|
845
|
+
class SwiftParser {
|
|
846
|
+
language = 'swift';
|
|
847
|
+
supportedExtensions = ['.swift'];
|
|
848
|
+
async parseFile(content, filePath) {
|
|
849
|
+
return {
|
|
850
|
+
functions: this.extractFunctions(content),
|
|
851
|
+
classes: this.extractClasses(content),
|
|
852
|
+
imports: this.extractImports(content),
|
|
853
|
+
language: 'swift',
|
|
854
|
+
filePath,
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
extractFunctions(content) {
|
|
858
|
+
const functions = [];
|
|
859
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
860
|
+
const funcRegex = /^\s*(public|private|internal|open)?\s*(static)?\s*func\s+(\w+)(?:<[^{]*>)?\s*\(([^)]*)\)(?:\s*(async))?\s*(?:throws\s+)?(?:->\s*([^{]+))?\s*\{?/;
|
|
861
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
862
|
+
const match = logicalLines[i].match(funcRegex);
|
|
863
|
+
if (match) {
|
|
864
|
+
const visibility = match[1] || 'internal';
|
|
865
|
+
const isAsync = !!match[5];
|
|
866
|
+
const name = match[3];
|
|
867
|
+
const paramsStr = match[4];
|
|
868
|
+
const returnType = match[6]?.trim();
|
|
869
|
+
functions.push({
|
|
870
|
+
name,
|
|
871
|
+
parameters: this.parseParams(paramsStr),
|
|
872
|
+
returnType,
|
|
873
|
+
isAsync,
|
|
874
|
+
isPublic: visibility === 'public' || visibility === 'open',
|
|
875
|
+
complexity: 1,
|
|
876
|
+
decorators: [],
|
|
877
|
+
genericParams: [],
|
|
878
|
+
startLine: lineMap[i],
|
|
879
|
+
endLine: lineMap[i],
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
return functions;
|
|
884
|
+
}
|
|
885
|
+
extractClasses(content) {
|
|
886
|
+
const classes = [];
|
|
887
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
888
|
+
const classRegex = /^\s*(public|private|internal|open)?\s*(class|struct|protocol)\s+(\w+)(?:<[^{]*>)?(?:\s*:\s*([^{]+))?\s*\{?/;
|
|
889
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
890
|
+
const match = logicalLines[i].match(classRegex);
|
|
891
|
+
if (match) {
|
|
892
|
+
const name = match[3];
|
|
893
|
+
const conformances = match[4]
|
|
894
|
+
? match[4].split(',').map((s) => s.trim())
|
|
895
|
+
: [];
|
|
896
|
+
classes.push({
|
|
897
|
+
name,
|
|
898
|
+
methods: [],
|
|
899
|
+
properties: [],
|
|
900
|
+
isPublic: (match[1] || 'internal') === 'public' || match[1] === 'open',
|
|
901
|
+
implements: conformances.slice(1),
|
|
902
|
+
extends: conformances[0] || undefined,
|
|
903
|
+
decorators: [],
|
|
904
|
+
startLine: lineMap[i],
|
|
905
|
+
endLine: lineMap[i],
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return classes;
|
|
910
|
+
}
|
|
911
|
+
extractImports(content) {
|
|
912
|
+
const imports = [];
|
|
913
|
+
const lines = content.split('\n');
|
|
914
|
+
for (const line of lines) {
|
|
915
|
+
const match = line.match(/^\s*import\s+(\w+)/);
|
|
916
|
+
if (match)
|
|
917
|
+
imports.push({
|
|
918
|
+
module: match[1],
|
|
919
|
+
namedImports: [],
|
|
920
|
+
isTypeOnly: false,
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
return imports;
|
|
924
|
+
}
|
|
925
|
+
parseParams(paramsStr) {
|
|
926
|
+
if (!paramsStr.trim())
|
|
927
|
+
return [];
|
|
928
|
+
return splitParamsGenericAware(paramsStr).map((p) => {
|
|
929
|
+
const parts = p.trim().split(':');
|
|
930
|
+
const labelAndName = parts[0]?.trim().split(/\s+/) || [];
|
|
931
|
+
const name = labelAndName[labelAndName.length - 1] || '';
|
|
932
|
+
const type = parts.slice(1).join(':').trim();
|
|
933
|
+
return {
|
|
934
|
+
name,
|
|
935
|
+
type: type || undefined,
|
|
936
|
+
isOptional: type?.endsWith('?') || false,
|
|
937
|
+
defaultValue: undefined,
|
|
938
|
+
};
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
// --- Kotlin Parser ---
|
|
943
|
+
class KotlinParser {
|
|
944
|
+
language = 'kotlin';
|
|
945
|
+
supportedExtensions = ['.kt', '.kts'];
|
|
946
|
+
async parseFile(content, filePath) {
|
|
947
|
+
return {
|
|
948
|
+
functions: this.extractFunctions(content),
|
|
949
|
+
classes: this.extractClasses(content),
|
|
950
|
+
imports: this.extractImports(content),
|
|
951
|
+
language: 'kotlin',
|
|
952
|
+
filePath,
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
extractFunctions(content) {
|
|
956
|
+
const functions = [];
|
|
957
|
+
const rawLines = content.split('\n');
|
|
958
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
959
|
+
const funcRegex = /^\s*(public|private|protected|internal)?\s*(suspend)?\s*fun\s+(?:<[^{]*>\s+)?(\w+)\s*\(([^)]*)\)(?:\s*:\s*([^{=]+))?\s*/;
|
|
960
|
+
// Track brace depth to filter nested lambdas that look like functions.
|
|
961
|
+
// Kotlin functions at depth 0 (top-level) and depth 1 (inside class bodies) are valid.
|
|
962
|
+
let braceDepth = 0;
|
|
963
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
964
|
+
const line = logicalLines[i];
|
|
965
|
+
const match = line.match(funcRegex);
|
|
966
|
+
if (match && braceDepth <= 1) {
|
|
967
|
+
const visibility = match[1] || 'public';
|
|
968
|
+
const isSuspend = !!match[2];
|
|
969
|
+
const name = match[3];
|
|
970
|
+
const paramsStr = match[4];
|
|
971
|
+
let returnType = match[5]?.trim();
|
|
972
|
+
// Extract full generic return type
|
|
973
|
+
if (returnType && returnType.includes('<')) {
|
|
974
|
+
const angleIdx = returnType.indexOf('<');
|
|
975
|
+
const inner = matchBalancedBrackets(returnType, angleIdx);
|
|
976
|
+
if (inner !== undefined) {
|
|
977
|
+
returnType = returnType.substring(0, angleIdx) + '<' + inner + '>';
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
const origLine = lineMap[i] - 1;
|
|
981
|
+
const decorators = collectDecorators(rawLines, origLine, '@');
|
|
982
|
+
functions.push({
|
|
983
|
+
name,
|
|
984
|
+
parameters: this.parseParams(paramsStr),
|
|
985
|
+
returnType,
|
|
986
|
+
isAsync: isSuspend,
|
|
987
|
+
isPublic: visibility === 'public',
|
|
988
|
+
complexity: 1,
|
|
989
|
+
decorators,
|
|
990
|
+
genericParams: [],
|
|
991
|
+
startLine: lineMap[i],
|
|
992
|
+
endLine: lineMap[i],
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
// Update brace depth after checking for function match
|
|
996
|
+
braceDepth += countBraceDelta(line);
|
|
997
|
+
if (braceDepth < 0)
|
|
998
|
+
braceDepth = 0;
|
|
999
|
+
}
|
|
1000
|
+
return functions;
|
|
1001
|
+
}
|
|
1002
|
+
extractClasses(content) {
|
|
1003
|
+
const classes = [];
|
|
1004
|
+
const rawLines = content.split('\n');
|
|
1005
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
1006
|
+
const classRegex = /^\s*(public|private|protected|internal)?\s*(data|sealed|abstract|open)?\s*class\s+(\w+)(?:<[^{]*>)?(?:\s*(?:\([^)]*\))?\s*:\s*([^{]+))?\s*\{?/;
|
|
1007
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
1008
|
+
const match = logicalLines[i].match(classRegex);
|
|
1009
|
+
if (match) {
|
|
1010
|
+
const name = match[3];
|
|
1011
|
+
const bases = match[4]
|
|
1012
|
+
? match[4]
|
|
1013
|
+
.split(',')
|
|
1014
|
+
.map((s) => s.trim().split('(')[0].trim())
|
|
1015
|
+
: [];
|
|
1016
|
+
const origLine = lineMap[i] - 1;
|
|
1017
|
+
const decorators = collectDecorators(rawLines, origLine, '@');
|
|
1018
|
+
classes.push({
|
|
1019
|
+
name,
|
|
1020
|
+
methods: [],
|
|
1021
|
+
properties: [],
|
|
1022
|
+
isPublic: (match[1] || 'public') === 'public',
|
|
1023
|
+
implements: bases.slice(1),
|
|
1024
|
+
extends: bases[0] || undefined,
|
|
1025
|
+
decorators,
|
|
1026
|
+
startLine: lineMap[i],
|
|
1027
|
+
endLine: lineMap[i],
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
return classes;
|
|
1032
|
+
}
|
|
1033
|
+
extractImports(content) {
|
|
1034
|
+
const imports = [];
|
|
1035
|
+
const lines = content.split('\n');
|
|
1036
|
+
for (const line of lines) {
|
|
1037
|
+
const match = line.match(/^\s*import\s+([^\s]+)/);
|
|
1038
|
+
if (match)
|
|
1039
|
+
imports.push({
|
|
1040
|
+
module: match[1],
|
|
1041
|
+
namedImports: [],
|
|
1042
|
+
isTypeOnly: false,
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
return imports;
|
|
1046
|
+
}
|
|
1047
|
+
parseParams(paramsStr) {
|
|
1048
|
+
if (!paramsStr.trim())
|
|
1049
|
+
return [];
|
|
1050
|
+
return splitParamsGenericAware(paramsStr).map((p) => {
|
|
1051
|
+
// Split on first colon only, since types can contain colons in rare cases
|
|
1052
|
+
const colonIdx = p.indexOf(':');
|
|
1053
|
+
if (colonIdx === -1) {
|
|
1054
|
+
const cleaned = p.replace('val ', '').replace('var ', '').trim();
|
|
1055
|
+
return { name: cleaned, type: undefined, isOptional: false, defaultValue: undefined };
|
|
1056
|
+
}
|
|
1057
|
+
const nameWithVal = p.substring(0, colonIdx)
|
|
1058
|
+
.replace('val ', '')
|
|
1059
|
+
.replace('var ', '')
|
|
1060
|
+
.trim();
|
|
1061
|
+
const typeAndDefault = p.substring(colonIdx + 1).trim();
|
|
1062
|
+
const eqIdx = typeAndDefault.indexOf('=');
|
|
1063
|
+
const type = eqIdx >= 0 ? typeAndDefault.substring(0, eqIdx).trim() : typeAndDefault;
|
|
1064
|
+
const hasDefault = eqIdx >= 0;
|
|
1065
|
+
return {
|
|
1066
|
+
name: nameWithVal,
|
|
1067
|
+
type,
|
|
1068
|
+
isOptional: hasDefault || type?.endsWith('?') || false,
|
|
1069
|
+
defaultValue: undefined,
|
|
1070
|
+
};
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
// --- Dart Parser ---
|
|
1075
|
+
class DartParser {
|
|
1076
|
+
language = 'dart';
|
|
1077
|
+
supportedExtensions = ['.dart'];
|
|
1078
|
+
async parseFile(content, filePath) {
|
|
1079
|
+
return {
|
|
1080
|
+
functions: this.extractFunctions(content),
|
|
1081
|
+
classes: this.extractClasses(content),
|
|
1082
|
+
imports: this.extractImports(content),
|
|
1083
|
+
language: 'dart',
|
|
1084
|
+
filePath,
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
extractFunctions(content) {
|
|
1088
|
+
const functions = [];
|
|
1089
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
1090
|
+
const funcRegex = /^\s*([\w<>,.\s?]+)\s+(\w+)\s*\(([^)]*)\)(?:\s*(async))?\s*\{/;
|
|
1091
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
1092
|
+
const line = logicalLines[i];
|
|
1093
|
+
if (line.includes(' class '))
|
|
1094
|
+
continue;
|
|
1095
|
+
const match = line.match(funcRegex);
|
|
1096
|
+
if (match) {
|
|
1097
|
+
const returnTypeRaw = match[1].trim();
|
|
1098
|
+
let returnType = returnTypeRaw;
|
|
1099
|
+
// Extract full generic return type
|
|
1100
|
+
if (returnTypeRaw && returnTypeRaw.includes('<')) {
|
|
1101
|
+
const angleIdx = returnTypeRaw.indexOf('<');
|
|
1102
|
+
const inner = matchBalancedBrackets(returnTypeRaw, angleIdx);
|
|
1103
|
+
if (inner !== undefined) {
|
|
1104
|
+
returnType = returnTypeRaw.substring(0, angleIdx) + '<' + inner + '>';
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
const name = match[2];
|
|
1108
|
+
const paramsStr = match[3];
|
|
1109
|
+
const isAsync = !!match[4] || returnType.includes('Future');
|
|
1110
|
+
functions.push({
|
|
1111
|
+
name,
|
|
1112
|
+
parameters: this.parseParams(paramsStr),
|
|
1113
|
+
returnType: returnType === 'void' ? undefined : returnType,
|
|
1114
|
+
isAsync,
|
|
1115
|
+
isPublic: !name.startsWith('_'),
|
|
1116
|
+
complexity: 1,
|
|
1117
|
+
decorators: [],
|
|
1118
|
+
genericParams: [],
|
|
1119
|
+
startLine: lineMap[i],
|
|
1120
|
+
endLine: lineMap[i],
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return functions;
|
|
1125
|
+
}
|
|
1126
|
+
extractClasses(content) {
|
|
1127
|
+
const classes = [];
|
|
1128
|
+
const { logicalLines, lineMap } = joinMultiLineSignatures(content);
|
|
1129
|
+
const classRegex = /^\s*(abstract\s+)?class\s+(\w+)(?:<[^{]*>)?(?:\s+extends\s+(\w+))?(?:\s+(?:with|implements)\s+([^{]+))?\s*\{/;
|
|
1130
|
+
for (let i = 0; i < logicalLines.length; i++) {
|
|
1131
|
+
const match = logicalLines[i].match(classRegex);
|
|
1132
|
+
if (match) {
|
|
1133
|
+
const name = match[2];
|
|
1134
|
+
const extendsName = match[3];
|
|
1135
|
+
const mixinsAndInterfaces = match[4]
|
|
1136
|
+
? match[4].split(',').map((s) => s.trim())
|
|
1137
|
+
: [];
|
|
1138
|
+
classes.push({
|
|
1139
|
+
name,
|
|
1140
|
+
methods: [],
|
|
1141
|
+
properties: [],
|
|
1142
|
+
isPublic: !name.startsWith('_'),
|
|
1143
|
+
implements: mixinsAndInterfaces,
|
|
1144
|
+
extends: extendsName,
|
|
1145
|
+
decorators: [],
|
|
1146
|
+
startLine: lineMap[i],
|
|
1147
|
+
endLine: lineMap[i],
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return classes;
|
|
1152
|
+
}
|
|
1153
|
+
extractImports(content) {
|
|
1154
|
+
const imports = [];
|
|
1155
|
+
const lines = content.split('\n');
|
|
1156
|
+
for (const line of lines) {
|
|
1157
|
+
const match = line.match(/^\s*import\s+'([^']+)'/);
|
|
1158
|
+
if (match)
|
|
1159
|
+
imports.push({
|
|
1160
|
+
module: match[1],
|
|
1161
|
+
namedImports: [],
|
|
1162
|
+
isTypeOnly: false,
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
return imports;
|
|
1166
|
+
}
|
|
1167
|
+
parseParams(paramsStr) {
|
|
1168
|
+
if (!paramsStr.trim())
|
|
1169
|
+
return [];
|
|
1170
|
+
// Remove curly/square brackets for named/optional params
|
|
1171
|
+
const clean = paramsStr.replace(/[{}[\]]/g, '');
|
|
1172
|
+
return splitParamsGenericAware(clean)
|
|
1173
|
+
.map((p) => p.trim())
|
|
1174
|
+
.filter((p) => p)
|
|
1175
|
+
.map((p) => {
|
|
1176
|
+
const parts = p
|
|
1177
|
+
.replace('required ', '')
|
|
1178
|
+
.trim()
|
|
1179
|
+
.split(/\s+/);
|
|
1180
|
+
const name = parts[parts.length - 1] || '';
|
|
1181
|
+
const type = parts.slice(0, -1).join(' ') || undefined;
|
|
1182
|
+
return {
|
|
1183
|
+
name,
|
|
1184
|
+
type,
|
|
1185
|
+
isOptional: p.includes('?') || p.includes('{'),
|
|
1186
|
+
defaultValue: undefined,
|
|
1187
|
+
};
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
// ============================================================================
|
|
1192
|
+
// Parser Registry
|
|
1193
|
+
// ============================================================================
|
|
1194
|
+
/**
|
|
1195
|
+
* Registry of all language parsers.
|
|
1196
|
+
* Provides regex-based parsing for Python, Java, C#, Go, Rust, Swift, Kotlin, Dart.
|
|
1197
|
+
*/
|
|
1198
|
+
export class TreeSitterParserRegistry {
|
|
1199
|
+
parsers = new Map();
|
|
1200
|
+
constructor() {
|
|
1201
|
+
this.register(new PythonParser());
|
|
1202
|
+
this.register(new JavaParser());
|
|
1203
|
+
this.register(new CSharpParser());
|
|
1204
|
+
this.register(new GoParser());
|
|
1205
|
+
this.register(new RustParser());
|
|
1206
|
+
this.register(new SwiftParser());
|
|
1207
|
+
this.register(new KotlinParser());
|
|
1208
|
+
this.register(new DartParser());
|
|
1209
|
+
}
|
|
1210
|
+
register(parser) {
|
|
1211
|
+
this.parsers.set(parser.language, parser);
|
|
1212
|
+
}
|
|
1213
|
+
getParser(language) {
|
|
1214
|
+
return this.parsers.get(language);
|
|
1215
|
+
}
|
|
1216
|
+
async parseFile(content, filePath, language) {
|
|
1217
|
+
const parser = this.parsers.get(language);
|
|
1218
|
+
if (!parser)
|
|
1219
|
+
return undefined;
|
|
1220
|
+
return parser.parseFile(content, filePath);
|
|
1221
|
+
}
|
|
1222
|
+
getSupportedLanguages() {
|
|
1223
|
+
return Array.from(this.parsers.keys());
|
|
1224
|
+
}
|
|
1225
|
+
supportsLanguage(language) {
|
|
1226
|
+
return this.parsers.has(language);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
export const treeSitterRegistry = new TreeSitterParserRegistry();
|
|
1230
|
+
// Export individual parsers for direct use
|
|
1231
|
+
export { PythonParser, JavaParser, CSharpParser, GoParser, RustParser, SwiftParser, KotlinParser, DartParser, };
|
|
1232
|
+
//# sourceMappingURL=multi-language-parser.js.map
|