trait Trees extends AnyRef
EXPERIMENTAL
This trait defines the node types used in Scala abstract syntax trees (AST) and operations on them.
Trees are the basis for Scala's abstract syntax that is used to represent programs. They are also called abstract syntax trees and commonly abbreviated as ASTs.
In Scala reflection, APIs that produce or use Tree
s are:
- Annotations which use trees to represent their arguments, exposed in Annotation.scalaArgs.
- reify, a special method on scala.reflect.api.Universe that takes an expression and returns an AST which represents the expression.
- Macros and runtime compilation with toolboxes which both use trees as their program representation medium.
Trees are immutable, except for three fields pos, symbol, and tpe, which are assigned when a tree is typechecked to attribute it with the information gathered by the typechecker.
Examples
The following creates an AST representing a literal 5 in Scala source code:
Literal(Constant(5))
The following creates an AST representing print("Hello World")
:
Apply(Select(Select(This(TypeName("scala")), TermName("Predef")), TermName("print")), List(Literal(Constant("Hello World"))))
The following creates an AST from a literal 5, and then uses showRaw
to print it in a readable format.
import scala.reflect.runtime.universe.{ reify, showRaw } print( showRaw( reify{5}.tree ) )` // prints Literal(Constant(5))
For more information about Tree
s, see the Reflection Guide: Symbols, Trees, Types.
- Self Type
- Universe
- Source
- Trees.scala
- Grouped
- Alphabetic
- By Inheritance
- Trees
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- Protected
Type Members
- abstract type Alternative >: Null <: Universe.AlternativeApi with Universe.TermTree
Alternatives of patterns.
Alternatives of patterns.
Eliminated by compiler phases Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher), except for occurrences in encoded Switch stmt (i.e. remaining Match(CaseDef(...)))
- trait AlternativeApi extends Universe.TermTreeApi
The API that all alternatives support
- abstract class AlternativeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Alternative(trees)
.An extractor class to create and pattern match with syntax
Alternative(trees)
. This AST node corresponds to the following Scala code:pat1 | ... | patn
- abstract type Annotated >: Null <: Universe.AnnotatedApi with Universe.Tree
A tree that has an annotation attached to it.
A tree that has an annotation attached to it. Only used for annotated types and annotation ascriptions, annotations on definitions are stored in the Modifiers. Eliminated by typechecker (typedAnnotated), the annotations are then stored in an AnnotatedType.
- trait AnnotatedApi extends Universe.TreeApi
The API that all annotateds support
- abstract class AnnotatedExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Annotated(annot, arg)
.An extractor class to create and pattern match with syntax
Annotated(annot, arg)
. This AST node corresponds to the following Scala code:arg @annot // for types arg: @annot // for exprs
- abstract type AppliedTypeTree >: Null <: Universe.AppliedTypeTreeApi with Universe.TypTree
Applied type <tpt> [ <args> ], eliminated by RefCheck
- trait AppliedTypeTreeApi extends Universe.TypTreeApi
The API that all applied type trees support
- abstract class AppliedTypeTreeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
AppliedTypeTree(tpt, args)
.An extractor class to create and pattern match with syntax
AppliedTypeTree(tpt, args)
. This AST node corresponds to the following Scala code:tpt[args]
Should only be used with
tpt
nodes which are types, i.e. which haveisType
returningtrue
. OtherwiseTypeApply
should be used instead.List[Int] as in
val x: List[Int] = ???
// represented as AppliedTypeTree(Ident(<List>), List(TypeTree(<Int>)))def foo[T] = ??? foo[Int] // represented as TypeApply(Ident(<foo>), List(TypeTree(<Int>)))
- abstract type Apply >: Null <: Universe.ApplyApi with Universe.GenericApply
Value application
- trait ApplyApi extends Universe.GenericApplyApi
The API that all applies support
- abstract class ApplyExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Apply(fun, args)
.An extractor class to create and pattern match with syntax
Apply(fun, args)
. This AST node corresponds to the following Scala code:fun(args)
For instance:
fun[targs](args)
Is expressed as:
Apply(TypeApply(fun, targs), args)
- abstract type Assign >: Null <: Universe.AssignApi with Universe.TermTree
Assignment
- trait AssignApi extends Universe.TermTreeApi
The API that all assigns support
- abstract class AssignExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Assign(lhs, rhs)
.An extractor class to create and pattern match with syntax
Assign(lhs, rhs)
. This AST node corresponds to the following Scala code:lhs = rhs
- abstract type Bind >: Null <: Universe.BindApi with Universe.DefTree
Bind a variable to a rhs pattern.
Bind a variable to a rhs pattern.
Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher).
- trait BindApi extends Universe.DefTreeApi
The API that all binds support
- abstract class BindExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Bind(name, body)
.An extractor class to create and pattern match with syntax
Bind(name, body)
. This AST node corresponds to the following Scala code:pat*
- abstract type Block >: Null <: Universe.BlockApi with Universe.TermTree
Block of expressions (semicolon separated expressions)
- trait BlockApi extends Universe.TermTreeApi
The API that all blocks support
- abstract class BlockExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Block(stats, expr)
.An extractor class to create and pattern match with syntax
Block(stats, expr)
. This AST node corresponds to the following Scala code:{ stats; expr }
If the block is empty, the
expr
is set toLiteral(Constant(()))
. - abstract type CaseDef >: Null <: Universe.CaseDefApi with Universe.Tree
Case clause in a pattern match.
Case clause in a pattern match. (except for occurrences in switch statements). Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher)
- trait CaseDefApi extends Universe.TreeApi
The API that all case defs support
- abstract class CaseDefExtractor extends AnyRef
An extractor class to create and pattern match with syntax
CaseDef(pat, guard, body)
.An extractor class to create and pattern match with syntax
CaseDef(pat, guard, body)
. This AST node corresponds to the following Scala code:case
patif
guard => bodyIf the guard is not present, the
guard
is set toEmptyTree
. If the body is not specified, thebody
is set toLiteral(Constant(()))
- abstract type ClassDef >: Null <: Universe.ClassDefApi with Universe.ImplDef
A class definition.
- trait ClassDefApi extends Universe.ImplDefApi
The API that all class defs support
- abstract class ClassDefExtractor extends AnyRef
An extractor class to create and pattern match with syntax
ClassDef(mods, name, tparams, impl)
.An extractor class to create and pattern match with syntax
ClassDef(mods, name, tparams, impl)
. This AST node corresponds to the following Scala code:mods
class
name [tparams] implWhere impl stands for:
extends
parents { defs } - abstract type CompoundTypeTree >: Null <: Universe.CompoundTypeTreeApi with Universe.TypTree
Intersection type <parent1> with ...
Intersection type <parent1> with ... with <parentN> { <decls> }, eliminated by RefCheck
- trait CompoundTypeTreeApi extends Universe.TypTreeApi
The API that all compound type trees support
- abstract class CompoundTypeTreeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
CompoundTypeTree(templ)
.An extractor class to create and pattern match with syntax
CompoundTypeTree(templ)
. This AST node corresponds to the following Scala code:parent1 with ... with parentN { refinement }
- abstract type DefDef >: Null <: Universe.DefDefApi with Universe.ValOrDefDef
A method or macro definition.
- trait DefDefApi extends Universe.ValOrDefDefApi
The API that all def defs support
- abstract class DefDefExtractor extends AnyRef
An extractor class to create and pattern match with syntax
DefDef(mods, name, tparams, vparamss, tpt, rhs)
.An extractor class to create and pattern match with syntax
DefDef(mods, name, tparams, vparamss, tpt, rhs)
. This AST node corresponds to the following Scala code:mods
def
name[tparams](vparams_1)...(vparams_n): tpt = rhsIf the return type is not specified explicitly (i.e. is meant to be inferred), this is expressed by having
tpt
set toTypeTree()
(but not to anEmptyTree
!). - abstract type DefTree >: Null <: Universe.DefTreeApi with Universe.SymTree with Universe.NameTree
A tree representing a symbol-defining entity: 1) A declaration or a definition (type, class, object, package, val, var, or def) 2)
Bind
that is used to represent binding occurrences in pattern matches 3)LabelDef
that is used internally to represent while loops - trait DefTreeApi extends Universe.SymTreeApi with Universe.NameTreeApi
The API that all def trees support
- abstract type ExistentialTypeTree >: Null <: Universe.ExistentialTypeTreeApi with Universe.TypTree
Existential type tree node
- trait ExistentialTypeTreeApi extends Universe.TypTreeApi
The API that all existential type trees support
- abstract class ExistentialTypeTreeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
ExistentialTypeTree(tpt, whereClauses)
.An extractor class to create and pattern match with syntax
ExistentialTypeTree(tpt, whereClauses)
. This AST node corresponds to the following Scala code:tpt forSome { whereClauses }
- abstract type Function >: Null <: Universe.FunctionApi with Universe.TermTree with Universe.SymTree
Anonymous function, eliminated by compiler phase lambdalift
- trait FunctionApi extends Universe.TermTreeApi with Universe.SymTreeApi
The API that all functions support
- abstract class FunctionExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Function(vparams, body)
.An extractor class to create and pattern match with syntax
Function(vparams, body)
. This AST node corresponds to the following Scala code:vparams => body
The symbol of a Function is a synthetic TermSymbol. It is the owner of the function's parameters.
- abstract type GenericApply >: Null <: Universe.GenericApplyApi with Universe.TermTree
Common base class for Apply and TypeApply.
- trait GenericApplyApi extends Universe.TermTreeApi
The API that all applies support
- abstract type Ident >: Null <: Universe.IdentApi with Universe.RefTree
A reference to identifier
name
. - trait IdentApi extends Universe.RefTreeApi
The API that all idents support
- abstract class IdentExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Ident(qual, name)
.An extractor class to create and pattern match with syntax
Ident(qual, name)
. This AST node corresponds to the following Scala code:name
Type checker converts idents that refer to enclosing fields or methods to selects. For example, name ==> this.name
- abstract type If >: Null <: Universe.IfApi with Universe.TermTree
Conditional expression
- trait IfApi extends Universe.TermTreeApi
The API that all ifs support
- abstract class IfExtractor extends AnyRef
An extractor class to create and pattern match with syntax
If(cond, thenp, elsep)
.An extractor class to create and pattern match with syntax
If(cond, thenp, elsep)
. This AST node corresponds to the following Scala code:if
(cond) thenpelse
elsepIf the alternative is not present, the
elsep
is set toLiteral(Constant(()))
. - abstract type ImplDef >: Null <: Universe.ImplDefApi with Universe.MemberDef
A common base class for class and object definitions.
- trait ImplDefApi extends Universe.MemberDefApi
The API that all impl defs support
- abstract type Import >: Null <: Universe.ImportApi with Universe.SymTree
Import clause
- trait ImportApi extends Universe.SymTreeApi
The API that all imports support
- abstract class ImportExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Import(expr, selectors)
.An extractor class to create and pattern match with syntax
Import(expr, selectors)
. This AST node corresponds to the following Scala code:import expr.{selectors}
Selectors are a list of ImportSelectors, which conceptually are pairs of names (from, to). The last (and maybe only name) may be a nme.WILDCARD. For instance:
import qual.{w => _, x, y => z, _}
Would be represented as:
Import(qual, List(("w", WILDCARD), ("x", "x"), ("y", "z"), (WILDCARD, null)))
The symbol of an
Import
is an import symbol @see Symbol.newImport. It's used primarily as a marker to check that the import has been typechecked. - abstract type ImportSelector >: Null <: Universe.ImportSelectorApi
Import selector (not a tree, but a component of the
Import
tree)Import selector (not a tree, but a component of the
Import
tree)Representation of an imported name its optional rename and their optional positions
Eliminated by typecheck.
- trait ImportSelectorApi extends AnyRef
The API that all import selectors support
- abstract class ImportSelectorExtractor extends AnyRef
An extractor class to create and pattern match with syntax
ImportSelector(name, namePos, rename, renamePos)
.An extractor class to create and pattern match with syntax
ImportSelector(name, namePos, rename, renamePos)
. This is not an AST node, it is used as a part of theImport
node. - abstract type LabelDef >: Null <: Universe.LabelDefApi with Universe.DefTree with Universe.TermTree
A labelled expression.
A labelled expression. Not expressible in language syntax, but generated by the compiler to simulate while/do-while loops, and also by the pattern matcher.
The label acts much like a nested function, where
params
represents the incoming parameters. The symbol given to the LabelDef should have a MethodType, as if it were a nested function.Jumps are apply nodes attributed with a label's symbol. The arguments from the apply node will be passed to the label and assigned to the Idents.
Forward jumps within a block are allowed.
- trait LabelDefApi extends Universe.DefTreeApi with Universe.TermTreeApi
The API that all label defs support
- abstract class LabelDefExtractor extends AnyRef
An extractor class to create and pattern match with syntax
LabelDef(name, params, rhs)
.An extractor class to create and pattern match with syntax
LabelDef(name, params, rhs)
.This AST node does not have direct correspondence to Scala code. It is used for tailcalls and like. For example, while/do are desugared to label defs as follows:
while (cond) body ==> LabelDef($L, List(), if (cond) { body; L$() } else ())
do body while (cond) ==> LabelDef($L, List(), body; if (cond) L$() else ())
- abstract type Literal >: Null <: Universe.LiteralApi with Universe.TermTree
Literal
- trait LiteralApi extends Universe.TermTreeApi
The API that all literals support
- abstract class LiteralExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Literal(value)
.An extractor class to create and pattern match with syntax
Literal(value)
. This AST node corresponds to the following Scala code:value
- abstract type Match >: Null <: Universe.MatchApi with Universe.TermTree
- Pattern matching expression (before compiler phase explicitouter before 2.10 / patmat from 2.10)
- Pattern matching expression (before compiler phase explicitouter before 2.10 / patmat from 2.10)
- Switch statements (after compiler phase explicitouter before 2.10 / patmat from 2.10)
After compiler phase explicitouter before 2.10 / patmat from 2.10, cases will satisfy the following constraints:
- all guards are
EmptyTree
, - all patterns will be either
Literal(Constant(x:Int))
orAlternative(lit|...|lit)
- except for an "otherwise" branch, which has pattern
Ident(nme.WILDCARD)
- trait MatchApi extends Universe.TermTreeApi
The API that all matches support
- abstract class MatchExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Match(selector, cases)
.An extractor class to create and pattern match with syntax
Match(selector, cases)
. This AST node corresponds to the following Scala code:selector
match
{ cases }Match
is also used in pattern matching assignments likeval (foo, bar) = baz
. - abstract type MemberDef >: Null <: Universe.MemberDefApi with Universe.DefTree
Common base class for all member definitions: types, classes, objects, packages, vals and vars, defs.
- trait MemberDefApi extends Universe.DefTreeApi
The API that all member defs support
- abstract type Modifiers >: Null <: Universe.ModifiersApi
The type of tree modifiers (not a tree, but rather part of DefTrees).
- abstract class ModifiersApi extends AnyRef
The API that all Modifiers support
- abstract class ModifiersExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Modifiers(flags, privateWithin, annotations)
.An extractor class to create and pattern match with syntax
Modifiers(flags, privateWithin, annotations)
. Modifiers encapsulate flags, visibility annotations and Scala annotations for member definitions. - abstract type ModuleDef >: Null <: Universe.ModuleDefApi with Universe.ImplDef
An object definition, e.g.
An object definition, e.g.
object Foo
. Internally, objects are quite frequently called modules to reduce ambiguity. Eliminated by compiler phase refcheck. - trait ModuleDefApi extends Universe.ImplDefApi
The API that all module defs support
- abstract class ModuleDefExtractor extends AnyRef
An extractor class to create and pattern match with syntax
ModuleDef(mods, name, impl)
.An extractor class to create and pattern match with syntax
ModuleDef(mods, name, impl)
. This AST node corresponds to the following Scala code:mods
object
name implWhere impl stands for:
extends
parents { defs } - abstract type NameTree >: Null <: Universe.NameTreeApi with Universe.Tree
A tree that carries a name, e.g.
A tree that carries a name, e.g. by defining it (
DefTree
) or by referring to it (RefTree
). - trait NameTreeApi extends Universe.TreeApi
The API that all name trees support
- abstract type NamedArg >: Null <: Universe.NamedArgApi with Universe.TermTree
Either an assignment or a named argument.
Either an assignment or a named argument. Only appears in argument lists, eliminated by compiler phase typecheck (doTypedApply), resurrected by reifier.
- trait NamedArgApi extends Universe.TermTreeApi
The API that all assigns support
- abstract class NamedArgExtractor extends AnyRef
An extractor class to create and pattern match with syntax
NamedArg(lhs, rhs)
.An extractor class to create and pattern match with syntax
NamedArg(lhs, rhs)
. This AST node corresponds to the following Scala code:m.f(lhs = rhs)
@annotation(lhs = rhs)
- abstract type New >: Null <: Universe.NewApi with Universe.TermTree
Object instantiation
- trait NewApi extends Universe.TermTreeApi
The API that all news support
- abstract class NewExtractor extends AnyRef
An extractor class to create and pattern match with syntax
New(tpt)
.An extractor class to create and pattern match with syntax
New(tpt)
. This AST node corresponds to the following Scala code:new
TThis node always occurs in the following context:
(
new
tpt).<init>[targs](args)For example, an AST representation of:
new Example[Int](2)(3)
is the following code:
Apply( Apply( TypeApply( Select(New(TypeTree(typeOf[Example])), nme.CONSTRUCTOR) TypeTree(typeOf[Int])), List(Literal(Constant(2)))), List(Literal(Constant(3))))
- abstract type PackageDef >: Null <: Universe.PackageDefApi with Universe.MemberDef
A packaging, such as
package pid { stats }
- trait PackageDefApi extends Universe.MemberDefApi
The API that all package defs support
- abstract class PackageDefExtractor extends AnyRef
An extractor class to create and pattern match with syntax
PackageDef(pid, stats)
.An extractor class to create and pattern match with syntax
PackageDef(pid, stats)
. This AST node corresponds to the following Scala code:package
pid { stats } - abstract type RefTree >: Null <: Universe.RefTreeApi with Universe.SymTree with Universe.NameTree
A tree which references a symbol-carrying entity.
A tree which references a symbol-carrying entity. References one, as opposed to defining one; definitions are in DefTrees.
- trait RefTreeApi extends Universe.SymTreeApi with Universe.NameTreeApi
The API that all ref trees support
- abstract class RefTreeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
RefTree(qual, name)
.An extractor class to create and pattern match with syntax
RefTree(qual, name)
. This AST node corresponds to either Ident, Select or SelectFromTypeTree. - abstract type Return >: Null <: Universe.ReturnApi with Universe.SymTree with Universe.TermTree
Return expression
- trait ReturnApi extends Universe.TermTreeApi
The API that all returns support
- abstract class ReturnExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Return(expr)
.An extractor class to create and pattern match with syntax
Return(expr)
. This AST node corresponds to the following Scala code:return
exprThe symbol of a Return node is the enclosing method.
- abstract type Select >: Null <: Universe.SelectApi with Universe.RefTree
A member selection <qualifier> .
A member selection <qualifier> . <name>
- trait SelectApi extends Universe.RefTreeApi
The API that all selects support
- abstract class SelectExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Select(qual, name)
.An extractor class to create and pattern match with syntax
Select(qual, name)
. This AST node corresponds to the following Scala code:qualifier.selector
Should only be used with
qualifier
nodes which are terms, i.e. which haveisTerm
returningtrue
. OtherwiseSelectFromTypeTree
should be used instead.foo.Bar // represented as Select(Ident(<foo>), <Bar>) Foo#Bar // represented as SelectFromTypeTree(Ident(<Foo>), <Bar>)
- abstract type SelectFromTypeTree >: Null <: Universe.SelectFromTypeTreeApi with Universe.TypTree with Universe.RefTree
Type selection <qualifier> # <name>, eliminated by RefCheck
- trait SelectFromTypeTreeApi extends Universe.TypTreeApi with Universe.RefTreeApi
The API that all selects from type trees support
- abstract class SelectFromTypeTreeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
SelectFromTypeTree(qualifier, name)
.An extractor class to create and pattern match with syntax
SelectFromTypeTree(qualifier, name)
. This AST node corresponds to the following Scala code:qualifier # selector
Note: a path-dependent type p.T is expressed as p.type # T
Should only be used with
qualifier
nodes which are types, i.e. which haveisType
returningtrue
. OtherwiseSelect
should be used instead.Foo#Bar // represented as SelectFromTypeTree(Ident(<Foo>), <Bar>) foo.Bar // represented as Select(Ident(<foo>), <Bar>)
- abstract type SingletonTypeTree >: Null <: Universe.SingletonTypeTreeApi with Universe.TypTree
Singleton type, eliminated by RefCheck
- trait SingletonTypeTreeApi extends Universe.TypTreeApi
The API that all singleton type trees support
- abstract class SingletonTypeTreeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
SingletonTypeTree(ref)
.An extractor class to create and pattern match with syntax
SingletonTypeTree(ref)
. This AST node corresponds to the following Scala code:ref.type
- abstract type Star >: Null <: Universe.StarApi with Universe.TermTree
Repetition of pattern.
Repetition of pattern.
Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher).
- trait StarApi extends Universe.TermTreeApi
The API that all stars support
- abstract class StarExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Star(elem)
.An extractor class to create and pattern match with syntax
Star(elem)
. This AST node corresponds to the following Scala code:pat*
- abstract type Super >: Null <: Universe.SuperApi with Universe.TermTree
Super reference, where
qual
is the correspondingthis
reference.Super reference, where
qual
is the correspondingthis
reference. A super referenceC.super[M]
is represented asSuper(This(C), M)
. - trait SuperApi extends Universe.TermTreeApi
The API that all supers support
- abstract class SuperExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Super(qual, mix)
.An extractor class to create and pattern match with syntax
Super(qual, mix)
. This AST node corresponds to the following Scala code:C.super[M]
Which is represented as:
Super(This(C), M)
If
mix
is empty, it is tpnme.EMPTY.The symbol of a Super is the class _from_ which the super reference is made. For instance in C.super(...), it would be C.
- abstract type SymTree >: Null <: Universe.SymTreeApi with Universe.Tree
A tree that carries a symbol, e.g.
A tree that carries a symbol, e.g. by defining it (
DefTree
) or by referring to it (RefTree
). Such trees start their life naked, returningNoSymbol
, but after being typechecked without errors they hold non-empty symbols. - trait SymTreeApi extends Universe.TreeApi
The API that all sym trees support
- abstract type Template >: Null <: Universe.TemplateApi with Universe.SymTree
Instantiation template of a class or trait
- trait TemplateApi extends Universe.SymTreeApi
The API that all templates support
- abstract class TemplateExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Template(parents, self, body)
.An extractor class to create and pattern match with syntax
Template(parents, self, body)
. This AST node corresponds to the following Scala code:extends
parents { self => body }In case when the self-type annotation is missing, it is represented as an empty value definition with nme.WILDCARD as name and NoType as type.
The symbol of a template is a local dummy. @see Symbol.newLocalDummy The owner of the local dummy is the enclosing trait or class. The local dummy is itself the owner of any local blocks. For example:
class C { def foo { // owner is C def bar // owner is local dummy } }
- abstract type TermTree >: Null <: Universe.TermTreeApi with Universe.Tree
A tree for a term.
A tree for a term. Not all trees representing terms are TermTrees; use isTerm to reliably identify terms.
- trait TermTreeApi extends Universe.TreeApi
The API that all term trees support
- abstract type This >: Null <: Universe.ThisApi with Universe.TermTree with Universe.SymTree
Self reference
- trait ThisApi extends Universe.TermTreeApi with Universe.SymTreeApi
The API that all thises support
- abstract class ThisExtractor extends AnyRef
An extractor class to create and pattern match with syntax
This(qual)
.An extractor class to create and pattern match with syntax
This(qual)
. This AST node corresponds to the following Scala code:qual.this
The symbol of a This is the class to which the this refers. For instance in C.this, it would be C.
- abstract type Throw >: Null <: Universe.ThrowApi with Universe.TermTree
Throw expression
- trait ThrowApi extends Universe.TermTreeApi
The API that all tries support
- abstract class ThrowExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Throw(expr)
.An extractor class to create and pattern match with syntax
Throw(expr)
. This AST node corresponds to the following Scala code:throw
expr - abstract class Transformer extends AnyRef
A class that implement a default tree transformation strategy: breadth-first component-wise cloning.
- class Traverser extends AnyRef
A class that implement a default tree traversal strategy: breadth-first component-wise.
- abstract type Tree >: Null <: Universe.TreeApi
The type of Scala abstract syntax trees.
- trait TreeApi extends Product
The API that all trees support.
The API that all trees support. The main source of information about trees is the scala.reflect.api.Trees page.
- abstract type TreeCopier >: Null <: Universe.TreeCopierOps
The type of standard (lazy) tree copiers.
- abstract class TreeCopierOps extends AnyRef
The API of a tree copier.
- abstract type Try >: Null <: Universe.TryApi with Universe.TermTree
Try catch node
- trait TryApi extends Universe.TermTreeApi
The API that all tries support
- abstract class TryExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Try(block, catches, finalizer)
.An extractor class to create and pattern match with syntax
Try(block, catches, finalizer)
. This AST node corresponds to the following Scala code:try
blockcatch
{ catches }finally
finalizerIf the finalizer is not present, the
finalizer
is set toEmptyTree
. - abstract type TypTree >: Null <: Universe.TypTreeApi with Universe.Tree
A tree for a type.
A tree for a type. Not all trees representing types are TypTrees; use isType to reliably identify types.
- trait TypTreeApi extends Universe.TreeApi
The API that all typ trees support
- abstract type TypeApply >: Null <: Universe.TypeApplyApi with Universe.GenericApply
Explicit type application.
- trait TypeApplyApi extends Universe.GenericApplyApi
The API that all type applies support
- abstract class TypeApplyExtractor extends AnyRef
An extractor class to create and pattern match with syntax
TypeApply(fun, args)
.An extractor class to create and pattern match with syntax
TypeApply(fun, args)
. This AST node corresponds to the following Scala code:fun[args]
Should only be used with
fun
nodes which are terms, i.e. which haveisTerm
returningtrue
. OtherwiseAppliedTypeTree
should be used instead.def foo[T] = ??? foo[Int] // represented as TypeApply(Ident(<foo>), List(TypeTree(<Int>)))
List[Int] as in
val x: List[Int] = ???
// represented as AppliedTypeTree(Ident(<List>), List(TypeTree(<Int>))) - abstract type TypeBoundsTree >: Null <: Universe.TypeBoundsTreeApi with Universe.TypTree
Type bounds tree node
- trait TypeBoundsTreeApi extends Universe.TypTreeApi
The API that all type bound trees support
- abstract class TypeBoundsTreeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
TypeBoundsTree(lo, hi)
.An extractor class to create and pattern match with syntax
TypeBoundsTree(lo, hi)
. This AST node corresponds to the following Scala code:>: lo <: hi
- abstract type TypeDef >: Null <: Universe.TypeDefApi with Universe.MemberDef
An abstract type, a type parameter, or a type alias.
An abstract type, a type parameter, or a type alias. Eliminated by erasure.
- trait TypeDefApi extends Universe.MemberDefApi
The API that all type defs support
- abstract class TypeDefExtractor extends AnyRef
An extractor class to create and pattern match with syntax
TypeDef(mods, name, tparams, rhs)
.An extractor class to create and pattern match with syntax
TypeDef(mods, name, tparams, rhs)
. This AST node corresponds to the following Scala code:mods
type
name[tparams] = rhsmods
type
name[tparams] >: lo <: hiFirst usage illustrates
TypeDefs
representing type aliases and type parameters. Second usage illustratesTypeDefs
representing abstract types, where lo and hi are bothTypeBoundsTrees
andModifier.deferred
is set in mods. - abstract type TypeTree >: Null <: Universe.TypeTreeApi with Universe.TypTree
A synthetic tree holding an arbitrary type.
A synthetic tree holding an arbitrary type. Not to be confused with with TypTree, the trait for trees that are only used for type trees. TypeTree's are inserted in several places, but most notably in
RefCheck
, where the arbitrary type trees are all replaced by TypeTree's. - trait TypeTreeApi extends Universe.TypTreeApi
The API that all type trees support
- abstract class TypeTreeExtractor extends AnyRef
An extractor class to create and pattern match with syntax
TypeTree()
.An extractor class to create and pattern match with syntax
TypeTree()
. This AST node does not have direct correspondence to Scala code, and is emitted by everywhere when we want to wrap aType
in aTree
. - abstract type Typed >: Null <: Universe.TypedApi with Universe.TermTree
Type annotation, eliminated by compiler phase cleanup
- trait TypedApi extends Universe.TermTreeApi
The API that all typeds support
- abstract class TypedExtractor extends AnyRef
An extractor class to create and pattern match with syntax
Typed(expr, tpt)
.An extractor class to create and pattern match with syntax
Typed(expr, tpt)
. This AST node corresponds to the following Scala code:expr: tpt
- abstract type UnApply >: Null <: Universe.UnApplyApi with Universe.TermTree
Used to represent
unapply
methods in pattern matching.Used to represent
unapply
methods in pattern matching.For example:
2 match { case Foo(x) => x }
Is represented as:
Match( Literal(Constant(2)), List( CaseDef( UnApply( // a dummy node that carries the type of unapplication to patmat // the <unapply-selector> here doesn't have an underlying symbol // it only has a type assigned, therefore after `untypecheck` this tree is no longer typeable Apply(Select(Ident(Foo), TermName("unapply")), List(Ident(TermName("<unapply-selector>")))), // arguments of the unapply => nothing synthetic here List(Bind(TermName("x"), Ident(nme.WILDCARD)))), EmptyTree, Ident(TermName("x")))))
Introduced by typer. Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher).
- trait UnApplyApi extends Universe.TermTreeApi
The API that all unapplies support
- abstract class UnApplyExtractor extends AnyRef
An extractor class to create and pattern match with syntax
UnApply(fun, args)
.An extractor class to create and pattern match with syntax
UnApply(fun, args)
. This AST node does not have direct correspondence to Scala code, and is introduced when typechecking pattern matches andtry
blocks. - abstract type ValDef >: Null <: Universe.ValDefApi with Universe.ValOrDefDef
Broadly speaking, a value definition.
Broadly speaking, a value definition. All these are encoded as ValDefs:
- immutable values, e.g. "val x"
- mutable values, e.g. "var x" - the MUTABLE flag set in mods
- lazy values, e.g. "lazy val x" - the LAZY flag set in mods
- method parameters, see vparamss in scala.reflect.api.Trees#DefDef - the PARAM flag is set in mods
- explicit self-types, e.g. class A { self: Bar => }
- trait ValDefApi extends Universe.ValOrDefDefApi
The API that all val defs support
- abstract class ValDefExtractor extends AnyRef
An extractor class to create and pattern match with syntax
ValDef(mods, name, tpt, rhs)
.An extractor class to create and pattern match with syntax
ValDef(mods, name, tpt, rhs)
. This AST node corresponds to any of the following Scala code:mods
val
name: tpt = rhsmods
var
name: tpt = rhsmods name: tpt = rhs // in signatures of function and method definitions
self: Bar => // self-types
If the type of a value is not specified explicitly (i.e. is meant to be inferred), this is expressed by having
tpt
set toTypeTree()
(but not to anEmptyTree
!). - abstract type ValOrDefDef >: Null <: Universe.ValOrDefDefApi with Universe.MemberDef
A common base class for ValDefs and DefDefs.
- trait ValOrDefDefApi extends Universe.MemberDefApi
The API that all val defs and def defs support
Deprecated Type Members
- type ModifiersCreator = Universe.ModifiersExtractor
- Annotations
- @deprecated
- Deprecated
(Since version 2.11.0) use ModifiersExtractor instead
Abstract Value Members
- abstract val Alternative: Universe.AlternativeExtractor
The constructor/extractor for
Alternative
instances. - abstract val Annotated: Universe.AnnotatedExtractor
The constructor/extractor for
Annotated
instances. - abstract val AppliedTypeTree: Universe.AppliedTypeTreeExtractor
The constructor/extractor for
AppliedTypeTree
instances. - abstract val Apply: Universe.ApplyExtractor
The constructor/extractor for
Apply
instances. - abstract val Assign: Universe.AssignExtractor
The constructor/extractor for
Assign
instances. - abstract val Bind: Universe.BindExtractor
The constructor/extractor for
Bind
instances. - abstract val Block: Universe.BlockExtractor
The constructor/extractor for
Block
instances. - abstract val CaseDef: Universe.CaseDefExtractor
The constructor/extractor for
CaseDef
instances. - abstract val ClassDef: Universe.ClassDefExtractor
The constructor/extractor for
ClassDef
instances. - abstract val CompoundTypeTree: Universe.CompoundTypeTreeExtractor
The constructor/extractor for
CompoundTypeTree
instances. - abstract val DefDef: Universe.DefDefExtractor
The constructor/extractor for
DefDef
instances. - abstract val EmptyTree: Universe.Tree
The empty tree
- abstract val ExistentialTypeTree: Universe.ExistentialTypeTreeExtractor
The constructor/extractor for
ExistentialTypeTree
instances. - abstract val Function: Universe.FunctionExtractor
The constructor/extractor for
Function
instances. - abstract def Ident(sym: Universe.Symbol): Universe.Ident
A factory method for
Ident
nodes. - abstract val Ident: Universe.IdentExtractor
The constructor/extractor for
Ident
instances. - abstract val If: Universe.IfExtractor
The constructor/extractor for
If
instances. - abstract val Import: Universe.ImportExtractor
The constructor/extractor for
Import
instances. - abstract val ImportSelector: Universe.ImportSelectorExtractor
The constructor/extractor for
ImportSelector
instances. - abstract val LabelDef: Universe.LabelDefExtractor
The constructor/extractor for
LabelDef
instances. - abstract val Literal: Universe.LiteralExtractor
The constructor/extractor for
Literal
instances. - abstract val Match: Universe.MatchExtractor
The constructor/extractor for
Match
instances. - abstract val Modifiers: Universe.ModifiersExtractor
The constructor/extractor for
Modifiers
instances. - abstract val ModuleDef: Universe.ModuleDefExtractor
The constructor/extractor for
ModuleDef
instances. - abstract val NamedArg: Universe.NamedArgExtractor
The constructor/extractor for
NamedArg
instances. - abstract val New: Universe.NewExtractor
The constructor/extractor for
New
instances. - abstract val PackageDef: Universe.PackageDefExtractor
The constructor/extractor for
PackageDef
instances. - abstract val RefTree: Universe.RefTreeExtractor
The constructor/extractor for
RefTree
instances. - abstract val Return: Universe.ReturnExtractor
The constructor/extractor for
Return
instances. - abstract def Select(qualifier: Universe.Tree, sym: Universe.Symbol): Universe.Select
A factory method for
Select
nodes. - abstract val Select: Universe.SelectExtractor
The constructor/extractor for
Select
instances. - abstract val SelectFromTypeTree: Universe.SelectFromTypeTreeExtractor
The constructor/extractor for
SelectFromTypeTree
instances. - abstract val SingletonTypeTree: Universe.SingletonTypeTreeExtractor
The constructor/extractor for
SingletonTypeTree
instances. - abstract val Star: Universe.StarExtractor
The constructor/extractor for
Star
instances. - abstract val Super: Universe.SuperExtractor
The constructor/extractor for
Super
instances. - abstract val Template: Universe.TemplateExtractor
The constructor/extractor for
Template
instances. - abstract def This(sym: Universe.Symbol): Universe.Tree
A factory method for
This
nodes. - abstract val This: Universe.ThisExtractor
The constructor/extractor for
This
instances. - abstract val Throw: Universe.ThrowExtractor
The constructor/extractor for
Throw
instances. - abstract val Try: Universe.TryExtractor
The constructor/extractor for
Try
instances. - abstract val TypeApply: Universe.TypeApplyExtractor
The constructor/extractor for
TypeApply
instances. - abstract val TypeBoundsTree: Universe.TypeBoundsTreeExtractor
The constructor/extractor for
TypeBoundsTree
instances. - abstract val TypeDef: Universe.TypeDefExtractor
The constructor/extractor for
TypeDef
instances. - abstract def TypeTree(tp: Universe.Type): Universe.TypeTree
A factory method for
TypeTree
nodes. - abstract val TypeTree: Universe.TypeTreeExtractor
The constructor/extractor for
TypeTree
instances. - abstract val Typed: Universe.TypedExtractor
The constructor/extractor for
Typed
instances. - abstract val UnApply: Universe.UnApplyExtractor
The constructor/extractor for
UnApply
instances. - abstract val ValDef: Universe.ValDefExtractor
The constructor/extractor for
ValDef
instances. - abstract def newLazyTreeCopier: Universe.TreeCopier
Creates a lazy tree copier.
- abstract def newStrictTreeCopier: Universe.TreeCopier
Creates a strict tree copier.
- abstract val noSelfType: Universe.ValDef
An empty deferred value definition corresponding to: val _: _ This is used as a placeholder in the
self
parameter Template if there is no definition of a self value of self type. - abstract val pendingSuperCall: Universe.Apply
An empty superclass constructor call corresponding to: super.<init>() This is used as a placeholder in the primary constructor body in class templates to denote the insertion point of a call to superclass constructor after the typechecker figures out the superclass of a given template.
- abstract def treeToString(tree: Universe.Tree): String
Obtains string representation of a tree
Obtains string representation of a tree
- Attributes
- protected
- abstract def Apply(sym: Universe.Symbol, args: Universe.Tree*): Universe.Tree
A factory method for
Apply
nodes.A factory method for
Apply
nodes.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use q"$sym(..$args)" instead
- abstract def ApplyConstructor(tpt: Universe.Tree, args: List[Universe.Tree]): Universe.Tree
0-1 argument list new, based on a type tree.
0-1 argument list new, based on a type tree.
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use q"new $tpt(..$args)" instead
- abstract def Bind(sym: Universe.Symbol, body: Universe.Tree): Universe.Bind
A factory method for
Bind
nodes.A factory method for
Bind
nodes.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use the canonical Bind constructor to create a bind and then initialize its symbol manually
- abstract def Block(stats: Universe.Tree*): Universe.Block
A factory method for
Block
nodes.A factory method for
Block
nodes. Flattens directly nested blocks.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use q"{..$stats}" instead. Flatten directly nested blocks manually if needed
- abstract def CaseDef(pat: Universe.Tree, body: Universe.Tree): Universe.CaseDef
A factory method for
CaseDef
nodes.A factory method for
CaseDef
nodes.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use cq"$pat => $body" instead
- abstract def Ident(name: String): Universe.Ident
A factory method for
Ident
nodes.A factory method for
Ident
nodes.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use Ident(TermName(name)) instead
- abstract def New(sym: Universe.Symbol, args: Universe.Tree*): Universe.Tree
0-1 argument list new, based on a symbol.
0-1 argument list new, based on a symbol.
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1)
- abstract def New(tpe: Universe.Type, args: Universe.Tree*): Universe.Tree
0-1 argument list new, based on a type.
0-1 argument list new, based on a type.
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use q"new $tpe(..$args)" instead
- abstract def New(tpt: Universe.Tree, argss: List[List[Universe.Tree]]): Universe.Tree
Factory method for object creation
new tpt(args_1)...(args_n)
ANew(t, as)
is expanded to:(new t).<init>(as)
Factory method for object creation
new tpt(args_1)...(args_n)
ANew(t, as)
is expanded to:(new t).<init>(as)
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use q"new $tpt(...$argss)" instead
- abstract def Select(qualifier: Universe.Tree, name: String): Universe.Select
A factory method for
Select
nodes.A factory method for
Select
nodes. The stringname
argument is assumed to represent aTermName
.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use Select(tree, TermName(name)) instead
- abstract def Super(sym: Universe.Symbol, mix: Universe.TypeName): Universe.Tree
A factory method for
Super
nodes.A factory method for
Super
nodes.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use q"$sym.super[$mix].x".qualifier instead
- abstract def Throw(tpe: Universe.Type, args: Universe.Tree*): Universe.Throw
A factory method for
Throw
nodes.A factory method for
Throw
nodes.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) use q"throw new $tpe(..$args)" instead
- abstract def Try(body: Universe.Tree, cases: (Universe.Tree, Universe.Tree)*): Universe.Try
A factory method for
Try
nodes.A factory method for
Try
nodes.- Annotations
- @deprecated
- Deprecated
(Since version 2.10.1) convert cases into casedefs and use q"try $body catch { case ..$newcases }" instead
- abstract val emptyValDef: Universe.ValDef
- Annotations
- @deprecated
- Deprecated
(Since version 2.11.0) use
noSelfType
instead
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- def ->[B](y: B): (Trees, B)
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def Modifiers(flags: Universe.FlagSet): Universe.Modifiers
The factory for
Modifiers
instances. - def Modifiers(flags: Universe.FlagSet, privateWithin: Universe.Name): Universe.Modifiers
The factory for
Modifiers
instances. - lazy val NoMods: Universe.Modifiers
An empty
Modifiers
object: no flags, empty visibility annotation and no Scala annotations. - final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def ensuring(cond: (Trees) => Boolean, msg: => Any): Trees
- def ensuring(cond: (Trees) => Boolean): Trees
- def ensuring(cond: Boolean, msg: => Any): Trees
- def ensuring(cond: Boolean): Trees
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def formatted(fmtstr: String): String
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def itransform(transformer: Universe.Transformer, tree: Universe.Tree): Universe.Tree
Delegates the transformation strategy to
scala.reflect.internal.Trees
, because pattern matching on abstract types we have here degrades performance.Delegates the transformation strategy to
scala.reflect.internal.Trees
, because pattern matching on abstract types we have here degrades performance.- Attributes
- protected
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- val treeCopy: Universe.TreeCopier
The standard (lazy) tree copier.
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def xtransform(transformer: Universe.Transformer, tree: Universe.Tree): Universe.Tree
Provides an extension hook for the transformation strategy.
Provides an extension hook for the transformation strategy. Future-proofs against new node types.
- Attributes
- protected
Deprecated Value Members
- def itraverse(traverser: Universe.Traverser, tree: Universe.Tree): Unit
Delegates the traversal strategy to
scala.reflect.internal.Trees
, because pattern matching on abstract types we have here degrades performance.Delegates the traversal strategy to
scala.reflect.internal.Trees
, because pattern matching on abstract types we have here degrades performance.- Attributes
- protected
- Annotations
- @deprecated
- Deprecated
(Since version 2.12.3) Use Tree#traverse instead
- def xtraverse(traverser: Universe.Traverser, tree: Universe.Tree): Unit
Provides an extension hook for the traversal strategy.
Provides an extension hook for the traversal strategy. Future-proofs against new node types.
- Attributes
- protected
- Annotations
- @deprecated
- Deprecated
(Since version 2.12.3) Use Tree#traverse instead
- def →[B](y: B): (Trees, B)
- Implicit
- This member is added by an implicit conversion from Trees toArrowAssoc[Trees] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use
->
instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.
Trees
Tree Copying
Factories
Tree Traversal and Transformation
API
The methods available for each reflection entity, without the implementation. Since the reflection entities are later overridden by runtime reflection and macros, their API counterparts guarantee a minimum set of methods that are implemented.
Extractors
Extractors provide the machinery necessary to allow pattern matching and construction of reflection entities that is similar to case classes, although the entities are only abstract types that are later overridden.