Phase 4: Fetch source code for Scala class #6

Merged
mprihoda merged 4 commits from JMC-1-phase-04 into JMC-1 2025-12-29 15:01:30 +00:00
mprihoda commented 2025-12-29 14:57:51 +00:00 (Migrated from github.com)

Phase 4: Fetch source code for Scala class

Goals: Enable get_source tool to fetch Scala source code from Maven Central with .scala extension support and fallback to .java for mixed-source projects.

Scenarios: 6 verified
Tests: 5 unit, 2 integration, 3 E2E (10 new tests)

Changes

  • Add toScalaSourcePath() method to ClassName with DRY refactoring
  • Update SourceCodeService to try .scala first for Scala artifacts
  • Fall back to .java if .scala not found (mixed-source projects)
  • Java artifacts continue to use .java only (no regression)

Key Implementation

// DRY path helper in ClassName
private def toPath(extension: String): String = {
  val outerClass = fullyQualifiedName.split('$').head
  outerClass.replace('.', '/') + extension
}

def toScalaSourcePath: String = toPath(".scala")

// Elegant fallback in SourceCodeService
if coords.scalaArtifact then
  reader.readEntry(jar, className.toScalaSourcePath)
    .orElse(reader.readEntry(jar, className.toSourcePath))
else
  reader.readEntry(jar, className.toSourcePath)

Test Results

All tests passing. New tests verify:

  • .scala extension generation
  • Fallback to .java when .scala missing
  • Real Maven Central fetches (cats-effect, ZIO)
  • E2E MCP protocol flow

Full review packet

🤖 Generated with Claude Code

## Phase 4: Fetch source code for Scala class **Goals**: Enable `get_source` tool to fetch Scala source code from Maven Central with `.scala` extension support and fallback to `.java` for mixed-source projects. **Scenarios**: 6 verified **Tests**: 5 unit, 2 integration, 3 E2E (10 new tests) ## Changes - Add `toScalaSourcePath()` method to `ClassName` with DRY refactoring - Update `SourceCodeService` to try `.scala` first for Scala artifacts - Fall back to `.java` if `.scala` not found (mixed-source projects) - Java artifacts continue to use `.java` only (no regression) ## Key Implementation ```scala // DRY path helper in ClassName private def toPath(extension: String): String = { val outerClass = fullyQualifiedName.split('$').head outerClass.replace('.', '/') + extension } def toScalaSourcePath: String = toPath(".scala") // Elegant fallback in SourceCodeService if coords.scalaArtifact then reader.readEntry(jar, className.toScalaSourcePath) .orElse(reader.readEntry(jar, className.toSourcePath)) else reader.readEntry(jar, className.toSourcePath) ``` ## Test Results All tests passing. New tests verify: - `.scala` extension generation - Fallback to `.java` when `.scala` missing - Real Maven Central fetches (cats-effect, ZIO) - E2E MCP protocol flow [Full review packet](./project-management/issues/JMC-1/review-packet-phase-04.md) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No description provided.