ScalaEmitter
Emits Scala source code from the codegen IR.
This object provides methods for emitting type references, annotations, fields, imports, package declarations, and compound types (case classes, sealed traits, enums, objects, newtypes) as well as full file emission.
Attributes
- Source
- ScalaEmitter.scala
- Graph
-
- Supertypes
- Self type
-
ScalaEmitter.type
Members list
Value members
Concrete methods
Emits a complete Scala source file as a string.
Emits a complete Scala source file as a string.
Value parameters
- config
-
The emitter configuration (defaults to EmitterConfig.default)
- file
-
The ScalaFile IR node to emit
Attributes
- Returns
-
The complete Scala source code as a string
- Source
- ScalaEmitter.scala
Emits an abstract class definition.
Emits an abstract class definition.
Value parameters
- ac
-
The AbstractClass IR node
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
Attributes
- Returns
-
The emitted Scala abstract class code
- Source
- ScalaEmitter.scala
Emits a Scala annotation as a string.
Emits a Scala annotation as a string.
Value parameters
- annotation
-
The annotation to emit
Attributes
- Returns
-
The Scala annotation string (e.g., "@required", "@deprecated(message = "use v2")")
- Source
- ScalaEmitter.scala
Emits a case class definition.
Emits a case class definition.
Value parameters
- cc
-
The CaseClass IR node
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
Attributes
- Returns
-
The emitted Scala case class code
- Source
- ScalaEmitter.scala
Emits a companion object for a type.
Emits a companion object for a type.
Value parameters
- companion
-
The CompanionObject IR node
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- name
-
The name of the companion object (same as the type it accompanies)
Attributes
- Returns
-
The emitted Scala companion object code
- Source
- ScalaEmitter.scala
Emits an enum definition. Uses Scala 3 enum syntax when config.scala3Syntax is true; otherwise emits as sealed trait + companion.
Emits an enum definition. Uses Scala 3 enum syntax when config.scala3Syntax is true; otherwise emits as sealed trait + companion.
Value parameters
- config
-
The emitter configuration
- en
-
The Enum IR node
- indent
-
The current indentation level (defaults to 0)
Attributes
- Returns
-
The emitted Scala enum code
- Source
- ScalaEmitter.scala
Emits a case class field as a string, including annotations and default values.
Emits a case class field as a string, including annotations and default values.
Value parameters
- config
-
The emitter configuration
- field
-
The field to emit
Attributes
- Returns
-
The field string, with each annotation on its own line above the field declaration
- Source
- ScalaEmitter.scala
Emits a Scala import statement using Scala 3 syntax by default.
Emits a Scala import statement using Scala 3 syntax by default.
Value parameters
- imp
-
The import to emit
Attributes
- Returns
-
The Scala import string
- Source
- ScalaEmitter.scala
Emits a Scala import statement respecting the given configuration.
Emits a Scala import statement respecting the given configuration.
Value parameters
- config
-
The emitter configuration (controls Scala 2 vs 3 syntax)
- imp
-
The import to emit
Attributes
- Returns
-
The Scala import string
- Source
- ScalaEmitter.scala
Attributes
- Source
- ScalaEmitter.scala
Emits a newtype definition (object extending Newtype[T] + type alias).
Emits a newtype definition (object extending Newtype[T] + type alias).
Value parameters
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- nt
-
The Newtype IR node
Attributes
- Returns
-
The emitted Scala newtype code
- Source
- ScalaEmitter.scala
Emits an object definition.
Emits an object definition.
Value parameters
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- obj
-
The ObjectDef IR node
Attributes
- Returns
-
The emitted Scala object code
- Source
- ScalaEmitter.scala
Emits an object member (val, def, type alias, or nested type).
Emits an object member (val, def, type alias, or nested type).
Value parameters
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- member
-
The ObjectMember IR node
Attributes
- Returns
-
The emitted Scala member code
- Source
- ScalaEmitter.scala
Emits an opaque type definition.
Emits an opaque type definition.
In Scala 3 mode, emits opaque type Name = UnderlyingType. In Scala 2 mode, falls back to type Name = UnderlyingType.
Value parameters
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- ot
-
The OpaqueType IR node
Attributes
- Returns
-
The emitted Scala opaque type code
- Source
- ScalaEmitter.scala
Emits a Scala package declaration.
Emits a Scala package declaration.
Value parameters
- pkg
-
The package declaration to emit
Attributes
- Returns
-
The Scala package declaration string (e.g., "package com.example")
- Source
- ScalaEmitter.scala
Emits a sealed trait definition.
Emits a sealed trait definition.
Value parameters
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- st
-
The SealedTrait IR node
Attributes
- Returns
-
The emitted Scala sealed trait code
- Source
- ScalaEmitter.scala
Emits a non-sealed trait definition.
Emits a non-sealed trait definition.
Value parameters
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- t
-
The Trait IR node
Attributes
- Returns
-
The emitted Scala trait code
- Source
- ScalaEmitter.scala
Emits a method definition.
Emits a method definition.
Value parameters
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- method
-
The Method IR node
Attributes
- Returns
-
The emitted Scala method code
- Source
- ScalaEmitter.scala
Emits any TypeDefinition by dispatching to the appropriate method.
Emits any TypeDefinition by dispatching to the appropriate method.
Value parameters
- config
-
The emitter configuration
- indent
-
The current indentation level (defaults to 0)
- typeDef
-
The type definition to emit
Attributes
- Returns
-
The emitted Scala code for the type definition
- Source
- ScalaEmitter.scala
Emits a type parameter with optional variance and bounds.
Emits a type parameter with optional variance and bounds.
Value parameters
- tp
-
The TypeParam to emit
Attributes
- Returns
-
The Scala type parameter string (e.g., "+A", "A <: Serializable")
- Source
- ScalaEmitter.scala
Emits a Scala type reference as a string.
Emits a Scala type reference as a string.
Value parameters
- typeRef
-
The type reference to emit
Attributes
- Returns
-
The Scala type string (e.g., "String", "List[Int]", "Map[String, Int]")
- Source
- ScalaEmitter.scala
Organizes imports by deduplicating and optionally sorting them.
Organizes imports by deduplicating and optionally sorting them.
Value parameters
- config
-
The emitter configuration (controls whether sorting is applied)
- imports
-
The list of imports to organize
Attributes
- Returns
-
The organized list of imports
- Source
- ScalaEmitter.scala