Trees

object Trees
class Object
trait Matchable
class Any

Type members

Classlikes

final case
class Alternative(trees: List[PatternTree])(span: Span) extends PatternTree

tree_1 | ... | tree_n

tree_1 | ... | tree_n

final case
class AnnotatedTypeTree(tpt: TypeTree, annotation: Tree)(span: Span) extends TypeTree

arg @annot

arg @annot

final case
class AppliedTypeTree(tycon: TypeTree, args: List[TypeTree])(span: Span) extends TypeTree

tpt[args] TypeBounds[Tree] for wildcard application: tpt[_], tpt[?]

tpt[args] TypeBounds[Tree] for wildcard application: tpt[_], tpt[?]

final case
class Apply(fun: TermTree, args: List[TermTree])(span: Span) extends TermTree

fun(args)

fun(args)

final case
class Assign(lhs: TermTree, rhs: TermTree)(span: Span) extends TermTree

name = arg, outside a parameter list

name = arg, outside a parameter list

final case
class Bind(name: Name, body: PatternTree, symbol: TermSymbol)(span: Span) extends PatternTree with DefTree

pattern in [[Unapply]]

pattern in [[Unapply]]

final case
class Block(stats: List[StatementTree], expr: TermTree)(span: Span) extends TermTree

{ stats; expr }

{ stats; expr }

final case
class BoundedTypeTree(bounds: TypeBoundsTree, alias: Option[TypeTree])(span: Span) extends TypeTree

: lo <: hi : lo <: hi = alias for RHS of bounded opaque type

final case
class ByNameTypeTree(result: TypeTree)(span: Span) extends TypeTree

=> T

=> T

final case
class CaseDef(pattern: PatternTree, guard: Option[TermTree], body: TermTree)(span: Span) extends Tree

case pattern if guard => body; only appears as child of a Match and Try

case pattern if guard => body; only appears as child of a Match and Try

final case
class ClassDef(name: TypeName, rhs: Template, symbol: ClassSymbol)(span: Span) extends TypeDef
final case
class DefDef(name: TermName, paramLists: List[ParamsClause], resultTpt: TypeTree, rhs: Option[TermTree], symbol: TermSymbol)(span: Span) extends ValOrDefDef

mods def nametparams...(vparams_n): tpt = rhs

mods def nametparams...(vparams_n): tpt = rhs

sealed
trait DefTree extends Tree
final case
class Export(expr: TermTree, selectors: List[ImportSelector])(span: Span) extends StatementTree

import expr.selectors

import expr.selectors

final case
class ExprPattern(expr: TermTree)(span: Span) extends PatternTree
final case
class Ident(name: TermName)(tpe: TermRef | PackageRef)(span: Span) extends TermTree

name

name

final case
class If(cond: TermTree, thenPart: TermTree, elsePart: TermTree)(span: Span) extends TermTree

if cond then thenp else elsep

if cond then thenp else elsep

final case
class Import(expr: TermTree, selectors: List[ImportSelector])(span: Span) extends StatementTree
final case
class ImportIdent(name: TermName)(span: Span) extends Tree

An identifier appearing in an import clause; it has no type.

An identifier appearing in an import clause; it has no type.

final case
class ImportSelector(imported: ImportIdent, renamed: Option[ImportIdent], bound: Option[TypeTree])(span: Span) extends Tree
final case
class InlineIf(cond: TermTree, thenPart: TermTree, elsePart: TermTree)(span: Span) extends TermTree
final case
class InlineMatch(selector: Option[TermTree], cases: List[CaseDef])(span: Span) extends TermTree
final case
class Inlined(expr: TermTree, caller: Option[TypeIdent], bindings: List[ValOrDefDef])(span: Span) extends TermTree

A tree representing inlined code.

A tree representing inlined code.

Value Params
bindings

Bindings for proxies to be used in the inlined code The full inlined code is equivalent to { bindings; expr }

caller

The toplevel class from which the call was inlined.

expr

The inlined tree, minus bindings.

final case
class Lambda(meth: TermTree, tpt: Option[TypeTree])(span: Span) extends TermTree
Value Params
meth

A reference to the method.

tpt

Defined only if the lambda's type is a SAMtype rather than a function type.

final case
class Literal(constant: Constant)(span: Span) extends TermTree
final case
class Match(selector: TermTree, cases: List[CaseDef])(span: Span) extends TermTree

selector match { cases }

selector match { cases }

final case
class MatchTypeTree(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(span: Span) extends TypeTree

[bound] selector match { cases }

[bound] selector match { cases }

final case
class NamedArg(name: Name, arg: TermTree)(span: Span) extends TermTree

name = arg, in a parameter list

name = arg, in a parameter list

final case
class NamedTypeBoundsTree(name: TypeName, bounds: TypeBounds)(span: Span) extends TypeTree
final case
class New(tpt: TypeTree)(span: Span) extends TermTree

new tpt, but no constructor call

new tpt, but no constructor call

final case
class PackageDef(pid: PackageSymbol, stats: List[TopLevelTree])(span: Span) extends TopLevelTree
sealed abstract
class PatternTree(span: Span) extends Tree
final case
class RefinedTypeTree(underlying: TypeTree, refinements: List[RefinementMemberDef], refinedCls: ClassSymbol)(span: Span) extends TypeTree
final case
class Return(expr: Option[TermTree], from: TermSymbol)(span: Span) extends TermTree
final case
class Select(qualifier: TermTree, name: TermName)(selectOwner: Option[TypeRef])(span: Span) extends TermTree

qualifier.termName

qualifier.termName

final case
class SelectTypeTree(qualifier: TypeTree, name: TypeName)(span: Span) extends TypeTree

qualifier#name

qualifier#name

final case
class SelfDef(name: TermName, tpt: TypeTree)(span: Span) extends Tree

Self type definition name: tpt =>.

Self type definition name: tpt =>.

final case
class SeqLiteral(elems: List[TermTree], elemtpt: TypeTree)(span: Span) extends TermTree

Seq(elems)

Seq(elems)

Value Params
tpt

The element type of the sequence.

final case
class SingletonTypeTree(ref: TermTree)(span: Span) extends TypeTree

ref.type

ref.type

sealed abstract
class StatementTree(span: Span) extends TopLevelTree
final case
class Super(qual: TermTree, mix: Option[TypeIdent])(span: Span) extends TermTree

C.super[mix], where qual = C.this

C.super[mix], where qual = C.this

final case
class Template(constr: DefDef, parents: List[Apply | Block | TypeTree], self: Option[SelfDef], body: List[StatementTree])(span: Span) extends Tree

constr extends parents { self => body }

constr extends parents { self => body }

holder for details of a Class definition

Value Params
classParent

-- the parent whose constructor is called. If the template defines a class, this is its only class parent.

parents

trait parents of the template and the class parent if the template defines a trait.

final case
class TermRefTypeTree(qualifier: TermTree, name: TermName)(span: Span) extends TypeTree

qualifier.name

qualifier.name

sealed abstract
class TermTree(span: Span) extends StatementTree
final case
class This(qualifier: TypeIdent)(span: Span) extends TermTree

qual.this

qual.this

final case
class Throw(expr: TermTree)(span: Span) extends TermTree

throw expr

throw expr

sealed abstract
class TopLevelTree(span: Span) extends Tree
sealed abstract
class Tree(val span: Span)
final case
class Try(expr: TermTree, cases: List[CaseDef], finalizer: Option[TermTree])(span: Span) extends TermTree

try block catch cases finally finalizer

try block catch cases finally finalizer

final case
class TypeApply(fun: TermTree, args: List[TypeTree])(span: Span) extends TermTree

fun[args]

fun[args]

final case
class TypeBoundsTree(low: TypeTree, high: TypeTree)(span: Span) extends Tree
final case
class TypeCaseDef(pattern: TypeTree, body: TypeTree)(span: Span) extends Tree
sealed abstract
class TypeDef(name: TypeName)(span: Span) extends StatementTree with DefTree

mods class name template or mods trait name template or mods type name = rhs or mods type name >: lo <: hi, if rhs = TypeBoundsTree(lo, hi) or mods type name >: lo <: hi = rhs if rhs = TypeBoundsTree(lo, hi, alias) and opaque in mods

mods class name template or mods trait name template or mods type name = rhs or mods type name >: lo <: hi, if rhs = TypeBoundsTree(lo, hi) or mods type name >: lo <: hi = rhs if rhs = TypeBoundsTree(lo, hi, alias) and opaque in mods

final case
class TypeIdent(name: TypeName)(tpe: Type)(span: Span) extends TypeTree
final case
class TypeLambdaTree(tparams: List[TypeParam], body: TypeTree)(span: Span) extends TypeTree
final case
class TypeMember(name: TypeName, rhs: TypeTree | TypeBounds, symbol: TypeMemberSymbol)(span: Span) extends TypeDef

A type member has a type tree rhs if the member is defined by the user, or typebounds if it's synthetic

A type member has a type tree rhs if the member is defined by the user, or typebounds if it's synthetic

final case
class TypeParam(name: TypeName, bounds: TypeBoundsTree | TypeBounds | TypeLambdaTree, symbol: TypeParamSymbol)(span: Span) extends TypeDef

The bounds are a type tree if the method is defined by the user and bounds-only if it's synthetic

The bounds are a type tree if the method is defined by the user and bounds-only if it's synthetic

final case
class TypeTest(body: PatternTree, tpt: TypeTree)(span: Span) extends PatternTree

Type-test pattern pat: T.

Type-test pattern pat: T.

sealed abstract
class TypeTree(span: Span) extends Tree
final case
class TypeTreeBind(name: TypeName, body: TypeTree, symbol: LocalTypeParamSymbol)(span: Span) extends TypeTree with DefTree
final case
class TypeWrapper(tp: Type)(span: Span) extends TypeTree
final case
class Typed(expr: TermTree, tpt: TypeTree)(span: Span) extends TermTree

expr : tpt

expr : tpt

final case
class Unapply(fun: TermTree, implicits: List[TermTree], patterns: List[PatternTree])(span: Span) extends PatternTree

extractor(patterns) in a pattern:

extractor(patterns) in a pattern:

Value Params
fun

is extractor.unapply (or, for backwards compatibility, extractor.unapplySeq) possibly with type parameters

implicits

Any implicit parameters passed to the unapply after the selector

patterns

The argument patterns in the pattern match. It is typed with same type as first fun argument Given a match selector sel a pattern UnApply(fun, implicits, patterns) is roughly translated as follows val result = fun(sel)(implicits) if (result.isDefined) "match patterns against result"

final case
class ValDef(name: TermName, tpt: TypeTree, rhs: Option[TermTree], symbol: TermSymbol)(span: Span) extends ValOrDefDef

mods val name: tpt = rhs

mods val name: tpt = rhs

sealed abstract
class ValOrDefDef()(span: Span) extends StatementTree with DefTree
final case
class While(cond: TermTree, body: TermTree)(span: Span) extends TermTree

while (cond) { body }

while (cond) { body }

final case
class WildcardPattern(tpe: Type)(span: Span) extends PatternTree

Wildcard pattern _.

Wildcard pattern _.

final case
class WildcardTypeBoundsTree(bounds: TypeBoundsTree)(span: Span) extends TypeTree

Types

type ParamsClause = Either[List[ValDef], List[TypeParam]]