ScalaEmitter

zio.blocks.codegen.emit.ScalaEmitter
object 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
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def emit(file: ScalaFile, config: EmitterConfig = ...): String

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
def emitAbstractClass(ac: AbstractClass, config: EmitterConfig, indent: Int = ...): String

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
def emitAnnotation(annotation: Annotation): String

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
def emitCaseClass(cc: CaseClass, config: EmitterConfig, indent: Int = ...): String

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
def emitCompanionObject(name: String, companion: CompanionObject, config: EmitterConfig, indent: Int = ...): String

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
def emitEnum(en: Enum, config: EmitterConfig, indent: Int = ...): String

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
def emitField(field: Field, config: EmitterConfig): String

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
def emitImport(imp: Import): String

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
def emitImport(imp: Import, config: EmitterConfig): String

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
def emitMethod(method: Method, config: EmitterConfig, indent: Int = ...): String

Attributes

Source
ScalaEmitter.scala
def emitNewtype(nt: Newtype, config: EmitterConfig, indent: Int = ...): String

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
def emitObjectDef(obj: ObjectDef, config: EmitterConfig, indent: Int = ...): String

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
def emitObjectMember(member: ObjectMember, config: EmitterConfig, indent: Int = ...): String

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
def emitOpaqueType(ot: OpaqueType, config: EmitterConfig, indent: Int = ...): String

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
def emitPackageDecl(pkg: PackageDecl): String

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
def emitSealedTrait(st: SealedTrait, config: EmitterConfig, indent: Int = ...): String

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
def emitTrait(t: Trait, config: EmitterConfig, indent: Int = ...): String

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
def emitTypeAlias(ta: TypeAlias, config: EmitterConfig, indent: Int = ...): String

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
def emitTypeDefinition(typeDef: TypeDefinition, config: EmitterConfig, indent: Int = ...): String

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
def emitTypeParam(tp: TypeParam): String

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
def emitTypeRef(typeRef: TypeRef): String

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
def organizeImports(imports: List[Import], config: EmitterConfig): List[Import]

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