Skip to content

Scala language support#5869

Merged
jkschneider merged 1 commit intomainfrom
rewrite-scal
Mar 28, 2026
Merged

Scala language support#5869
jkschneider merged 1 commit intomainfrom
rewrite-scal

Conversation

@jkschneider
Copy link
Copy Markdown
Member

@jkschneider jkschneider commented Aug 6, 2025

Summary

Scala 3 language support for OpenRewrite, enabling automated refactoring of Scala source code using the existing Java recipe ecosystem.

Parser

  • Parses Scala 3 source files via the Dotty compiler into OpenRewrite's Lossless Semantic Tree (LST)
  • Maps Scala syntax to J (Java) LST types wherever possible, with Scala-specific S types only where Java has no equivalent (S.CompilationUnit, S.TuplePattern, S.Wildcard, S.BlockExpression)
  • Scala-specific markers for constructs that map structurally to Java but print differently (SObject, InfixNotation, FunctionApplication, ScalaForLoop, etc.)
  • Full printer (ScalaPrinter) that round-trips Scala syntax faithfully (square bracket type params, val/var, trait, => lambdas, etc.)

Type Attribution

  • Batch compilation through the Dotty typer phase for type information
  • ScalaTypeMapping maps Dotty types/symbols to OpenRewrite's JavaType model
  • Span-based lookup from the untyped tree into the typed tree via TreeTraverser
  • Name-based fallback for identifiers and method names
  • ShallowClass for library types to avoid deep recursive type hierarchies
  • Companion object $ suffix stripping for Java recipe compatibility

Recipe Compatibility

Proven working with standard Java recipes on Scala code:

  • FindTypes — find type references by FQN pattern
  • FindMethods — find method invocations (including static calls like Collections.emptyList())
  • ChangeMethodName — rename methods across Scala source
  • ChangeType — change type references (including java.lang types)
  • OrderImports — alphabetical import ordering

Test Coverage

  • 329 tests, 0 failures, 0 disabled
  • 261 parser/printer round-trip tests covering all major Scala constructs
  • 5 type attribution assertion tests
  • 9 recipe compatibility tests
  • Tests for classes, objects, traits, vals, vars, methods, lambdas, pattern matching, for-comprehensions, imports, annotations, generics, and more

Test plan

  • ./gradlew :rewrite-scala:test — all 329 tests pass
  • Recipe compatibility verified: FindTypes, FindMethods, ChangeMethodName, ChangeType, OrderImports
  • Type attribution verified: identifiers, class declarations, method invocations, NewClass, field access

@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 90 days with no activity. Remove stale label or comment or this will be closed in two weeks. PRs may be reopened when there is renewed interest.

@github-actions github-actions Bot added the Stale label Nov 24, 2025
@github-actions github-actions Bot removed the Stale label Dec 15, 2025
@jkschneider jkschneider marked this pull request as ready for review March 13, 2026 15:17
@jkschneider jkschneider merged commit 3a0a9ea into main Mar 28, 2026
1 check passed
@jkschneider jkschneider deleted the rewrite-scal branch March 28, 2026 21:41
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Mar 28, 2026
jkschneider added a commit that referenced this pull request Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants