reflectModule
Low-level Typed AST metaprogramming API.
Provides all functionality related to AST-based metaprogramming.
Each type XYZ
in the API is defined as an abstract type type XYZ
. Methods on XYZ
are provided by a given XYZMethods
which implements extension methods on XYZ
in the trait XYZMethods
. The XYZ
module is defined by a val XYZ: XYZModule
which contains the methods defined in XYZModule
. Type tests (TypeTest
) are also given to perform subtype checks on these types.
Type hierarchy
+- Tree -+- PackageClause
|
+- Statement -+- Import
| +- Export
| +- Definition --+- ClassDef
| | +- TypeDef
| | +- DefDef
| | +- ValDef
| |
| +- Term --------+- Ref -+- Ident -+- Wildcard
| | +- Select
| |
| +- Literal
| +- This
| +- New
| +- NamedArg
| +- Apply
| +- TypeApply
| +- Super
| +- Assign
| +- Block
| +- Closure
| +- If
| +- Match
| +- SummonFrom
| +- Try
| +- Return
| +- Repeated
| +- Inlined
| +- SelectOuter
| +- While
| +---+- Typed
| /
+- TypedOrTest +----------------·
+- Bind
+- Unapply
+- Alternatives
|
+- CaseDef
+- TypeCaseDef
|
+- TypeTree ----+- Inferred
| +- TypeIdent
| +- TypeSelect
| +- TypeProjection
| +- Singleton
| +- Refined
| +- Applied
| +- Annotated
| +- MatchTypeTree
| +- ByName
| +- LambdaTypeTree
| +- TypeBind
| +- TypeBlock
|
+- TypeBoundsTree
+- WildcardTypeTree
+- ParamClause -+- TypeParamClause
+- TermParamClause
+- TypeRepr -+- NamedType -+- TermRef
| +- TypeRef
+- ConstantType
+- SuperType
+- Refinement
+- AppliedType
+- AnnotatedType
+- AndOrType -+- AndType
| +- OrType
+- MatchType
+- ByNameType
+- ParamRef
+- ThisType
+- RecursiveThis
+- RecursiveType
+- LambdaType -+- MethodOrPoly -+- MethodType
| | +- PolyType
| +- TypeLambda
+- MatchCase
+- TypeBounds
+- NoPrefix
+- Selector -+- SimpleSelector
+- RenameSelector
+- OmitSelector
+- GivenSelector
+- Signature
+- Position
+- SourceFile
+- Constant -+- BooleanConstant
+- ByteConstant
+- ShortConstant
+- IntConstant
+- LongConstant
+- FloatConstant
+- DoubleConstant
+- CharConstant
+- StringConstant
+- UnitConstant
+- NullConstant
+- ClassOfConstant
+- Symbol
+- Flags
Attributes
- Source
- Quotes.scala
- Graph
-
- Supertypes
- Self type
Members list
Type members
Classlikes
Extension methods of Alternatives
Methods of the module object val Alternatives
Extension methods of AndOrType
Methods of the module object val AndType
Extension methods of Annotated
Methods of the module object val Annotated
Extension methods of AnnotatedType
Methods of the module object val AnnotatedType
Extension methods of Applied
Methods of the module object val Applied
Extension methods of AppliedType
Methods of the module object val AppliedType
Extension methods of Apply
Methods of the module object val Apply
Extension methods of Assign
Methods of the module object val Assign
Extension methods of Bind
Methods of the module object val Bind
Extension methods of Block
Methods of the module object val Block
Methods of the module object val BooleanConstant
Methods of the module object val BooleanConstant
Attributes
- Source
- Quotes.scala
- Supertypes
- Self type
Extension methods of ByName
Methods of the module object val ByName
Extension methods of ByNameType
Methods of the module object val ByNameType
Methods of the module object val ByteConstant
Extension methods of CaseDef
Methods of the module object val CaseDef
Methods of the module object val CharConstant
Extension methods of ClassDef
Methods of the module object val ClassDef
Methods of the module object val ClassOf
Extension methods of Closure
Methods of the module object val Closure
Methods of the module object val CompilationInfo
Methods of the module object val CompilationInfo
Attributes
- Source
- Quotes.scala
- Supertypes
- Self type
Extension methods of Constant
Constant value represented as the constant itself
Constant value represented as the constant itself
Attributes
- Source
- Quotes.scala
- Supertypes
- Self type
Extension methods of ConstantType
Methods of the module object val Type
Extension methods of DefDef
Methods of the module object val DefDef
Extension methods of Definition
Methods of the module object val Definition
Methods of the module object val DoubleConstant
Extension methods of Export
Methods of the module object val Export
Extension methods of Flags
Methods of the module object val Flags
Methods of the module object val FloatConstant
Extension methods of GivenSelector
Methods of the module object val GivenSelector
Extension methods of Ident
Methods of the module object val Ident
Extension methods of If
Methods of the module object val If
Extension methods of ImplicitSearchFailure
Extension methods of ImplicitSearchSuccess
Methods of the module object val Implicits
Extension methods of Import
Methods of the module object val Import
Methods of the module object val Inferred
Extension methods of Inlined
Methods of the module object val Inlined
Methods of the module object val IntConstant
Methods of the module object val Lambda
Extension methods of LambdaType
Extension methods of LambdaTypeTree
Methods of the module object val LambdaTypeTree
Extension methods of Literal
Methods of the module object val Literal
Methods of the module object val LongConstant
Extension methods of MatchCase
Methods of the module object val MatchCase
Extension methods of Match
Methods of the module object val Match
Extension methods of MatchType
Methods of the module object val MatchType
Extension methods of MatchTypeTree
Methods of the module object val MatchTypeTree
Extension methods of MethodType
Methods of the module object val MethodType
Extension methods of NamedArg
Methods of the module object val NamedArg
Extension methods of NamedType
Extension methods of New
Methods of the module object val New
Methods of the module object val NoPrefix
Methods of the module object val NullConstant
Extension methods of OmitSelector
Methods of the module object val OmitSelector
Methods of the module object val OrType
Extension methods of PackageClause
Methods of the module object val PackageClause
Extension methods of ParamClause
Methods of the module object val ParamClause
Extension methods of ParamRef
Methods of the module object val ParamRef
Extension methods of PolyType
Methods of the module object val PolyType
Extension methods of Position
Methods of the module object val Position
Type class used in show
methods to provide customizable String
representations
Type class used in show
methods to provide customizable String
representations
Attributes
- Source
- Quotes.scala
- Supertypes
Methods of the module object val Printer
Extension methods of RecursiveThis
Methods of the module object val RecursiveThis
Extension methods of RecursiveType
Methods of the module object val RecursiveType
Methods of the module object val Ref
Extension methods of Refined
Methods of the module object val Refined
Extension methods of Refinement
Methods of the module object val Refinement
Extension methods of RenameSelector
Methods of the module object val RenameSelector
Extension methods of Repeated
Methods of the module object val Repeated
Extension methods of Return
Methods of the module object val Return
Extension methods of Select
Methods of the module object val Select
Extension methods of SelectOuter
Methods of the module object val SelectOuter
Methods of the module object val Selector
Methods of the module object val Short
Extension methods of Signature
Methods of the module object val Signature
Extension methods of SimpleSelector
Methods of the module object val SimpleSelector
Extension methods of Singleton
Methods of the module object val Singleton
Extension methods of SourceFile
Methods of the module object val SourceFile
Methods of the module object val StringConstant
Extension methods of SummonFrom
Methods of the module object val SummonFrom
Extension methods of Super
Methods of the module object val Super
Extension methods of SuperType
Methods of the module object val SuperType
Extension methods of Symbol
Methods of the module object val Symbol
Extension methods of Term
Methods of the module object val Term
Extension methods of TermParamClause
Methods of the module object val TermParamClause
Methods of the module object val TermParamClause
Attributes
- Source
- Quotes.scala
- Supertypes
- Self type
Methods of the module object val TermRef
Extension methods of This
Methods of the module object val This
Extension methods of ThisType
Methods of the module object val ThisType
Customizable Tree accumulator.
Customizable Tree accumulator.
Usage:
def inQuotes(using q: Quotes) = {
import q.reflect._
class MyTreeAccumulator[X] extends TreeAccumulator[X] {
def foldTree(x: X, tree: Tree)(owner: Symbol): X = ???
}
}
Attributes
- Source
- Quotes.scala
- Supertypes
- Known subtypes
-
trait TreeTraverser
Customizable tree mapper.
Customizable tree mapper.
Usage:
def inQuotes(using q: Quotes) = {
import q.reflect._
class MyTreeMap extends TreeMap {
override def transformTree(tree: Tree)(owner: Symbol): Tree = ???
}
}
Use Symbol.asQuotes
to create quotes with the correct owner within the TreeMap.
Attributes
- Source
- Quotes.scala
- Supertypes
Extension methods of Tree
Methods of the module object val Tree
Customizable tree traverser.
Customizable tree traverser.
Usage:
def inQuotes(using q: Quotes) = {
import q.reflect._
class MyTraverser extends TreeTraverser {
override def traverseTree(tree: Tree)(owner: Symbol): Unit = ???
}
}
Attributes
- Source
- Quotes.scala
- Supertypes
Extension methods of Try
Methods of the module object val Try
Extension methods of TypeApply
Methods of the module object val TypeApply
Extension methods of TypeBind
Methods of the module object val TypeBind
Extension methods of TypeBlock
Methods of the module object val TypeBlock
Extension methods of TypeBounds
Methods of the module object val TypeBounds
Extension methods of TypeBoundsTree
Methods of the module object val TypeBoundsTree
Extension methods of TypeCaseDef
Methods of the module object val TypeCaseDef
Extension methods of TypeDef
Methods of the module object val TypeDef
Extension methods of TypeIdent
Methods of the module object val TypeIdent
Extension methods of TypeLambda
Methods of the module object val TypeLambda
Extension methods of TypeParamClause
Methods of the module object val TypeParamClause
Methods of the module object val TypeParamClause
Attributes
- Source
- Quotes.scala
- Supertypes
- Self type
Extension methods of TypeProjection
Methods of the module object val TypeProjection
Extension methods of TypeRef
Methods of the module object val TypeRef
Extension methods of TypeRepr
Methods of the module object val TypeRepr
Extension methods of TypeSelect
Methods of the module object val TypeSelect
Extension methods of TypeTree
Methods of the module object val TypeTree
Extension methods of Typed
Methods of the module object val Typed
Extension methods of TypedOrTest
Methods of the module object val TypedOrTest
Extension methods of Unapply
Methods of the module object val Unapply
Methods of the module object val UnitConstant
Extension methods of ValDef
Methods of the module object val ValDef
Extension methods of While
Methods of the module object val While
Methods of the module object val Wildcard
Extension methods of WildcardTypeTree
Methods of the module object val WildcardTypeTree
Methods of the module object val WildcardTypeTree
Attributes
- Source
- Quotes.scala
- Supertypes
- Self type
Methods of the module object val defn
Methods of the module object val report
Types
Pattern representing X | Y | ...
alternatives.
Attributes
- Source
- Quotes.scala
Intersection type T & U
or an union type T | U
Intersection type T & U
Type tree representing an annotated type
A type with an annotation T @foo
Type tree representing a type application
A higher kinded type applied to some types T[U]
Tree representing an application of arguments. It represents a single list of arguments, multiple argument lists will have nested Apply
s
Tree representing an application of arguments. It represents a single list of arguments, multiple argument lists will have nested Apply
s
Attributes
- Source
- Quotes.scala
Tree representing an assignment x = y
in the source code
Pattern representing a _ @ _
binding.
Tree representing a block { ... }
in the source code
Constant Boolean value
Type tree representing a by name parameter
Type of a by-name definition of type =>T
.
Type of a by-name definition of type =>T
.
May represent by-name parameter such as thunk
in
type T
def log[T](thunk: => T): T = ???
May also represent a the return type of a parameterless method definition such as
def foo: Int = ???
Attributes
- Source
- Quotes.scala
Constant Byte value
Branch of a pattern match or catch clause
Constant Char value
Tree representing a class definition. This includes anonymous class definitions and the class of a module object
Tree representing a class definition. This includes anonymous class definitions and the class of a module object
Attributes
- Source
- Quotes.scala
Constant class value representing a classOf[T]
A lambda (...) => ...
in the source code is represented as a local method and a closure:
A lambda (...) => ...
in the source code is represented as a local method and a closure:
{ def m(...) = ... closure(m) }
Attributes
- Source
- Quotes.scala
Constant value represented as the constant itself
A singleton type representing a known constant value
Tree representing a method definition in the source code
Tree representing a definition in the source code. It can be ClassDef
, TypeDef
, DefDef
or ValDef
Tree representing a definition in the source code. It can be ClassDef
, TypeDef
, DefDef
or ValDef
Attributes
- Source
- Quotes.scala
Attributes
- Source
- Quotes.scala
Constant Double value
Tree representing an export clause in the source code. Export forwarders generated from this clause appear in the same scope.
Tree representing an export clause in the source code. Export forwarders generated from this clause appear in the same scope.
Attributes
- Source
- Quotes.scala
FlagSet of a Symbol
Constant Float value
given import/export selector: .given
/.{given T}
in import foo.given
/export foo.{given T}
given import/export selector: .given
/.{given T}
in import foo.given
/export foo.{given T}
Attributes
- Source
- Quotes.scala
Tree representing a reference to definition with a given name
Tree representing an if/then/else if (...) ... else ...
in the source code
Tree representing an if/then/else if (...) ... else ...
in the source code
Attributes
- Source
- Quotes.scala
Attributes
- Source
- Quotes.scala
Result of a given instance search
Attributes
- Source
- Quotes.scala
Tree representing an import in the source code.
Tree representing an import in the source code.
See also documentation on Selector
.
Attributes
- Source
- Quotes.scala
Type tree representing an inferred type
Tree representing the scope of an inlined tree
Constant Int value
Type of the definition of a method taking a single list of type or term parameters
Type of the definition of a method taking a single list of type or term parameters
Attributes
- Source
- Quotes.scala
Type tree representing a lambda abstraction type
Tree representing a literal value in the source code
Constant Long value
Tree representing a pattern match x match { ... }
in the source code
Case of a MatchType
containing pattern case P => R
.
Case of a MatchType
containing pattern case P => R
.
Note: cases with type bindings are represented nested in a TypeLambda
.
Attributes
- Source
- Quotes.scala
Type match T match { case U => ... }
Type tree representing a type match
Type of the definition of a method taking a single list of type or term parameters
Type of the definition of a method taking a single list of type or term parameters
Attributes
- Source
- Quotes.scala
Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType.
Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType.
Attributes
- Source
- Quotes.scala
Tree representing an argument passed with an explicit name. Such as arg1 = x
in foo(arg1 = x)
Tree representing an argument passed with an explicit name. Such as arg1 = x
in foo(arg1 = x)
Attributes
- Source
- Quotes.scala
Type of a reference to a type or term symbol
Tree representing new
in the source code
Attributes
- Source
- Quotes.scala
NoPrefix for a type selection
Constant null value
Omit import/export selector: .{bar => _}
in import foo.{bar => _}
Union type T | U
Tree representing a package clause in the source code
Tree representing a package clause in the source code
package foo {
// package stats
}
or
package foo.bar
// package stats
Attributes
- Source
- Quotes.scala
A parameter clause [X1, ..., Xn]
or (x1: X1, ..., xn: Xx)
A parameter clause [X1, ..., Xn]
or (x1: X1, ..., xn: Xx)
[X1, ..., Xn]
are represented with TypeParamClause
and (x1: X1, ..., xn: Xx)
are represented with TermParamClause
ParamClause
encodes the following enumeration
import scala.quoted._
def inQuotes(using Quotes) = {
val q: Quotes = summon[Quotes]
import q.reflect._
enum ParamClause:
case TypeParamClause(params: List[TypeDef])
case TermParamClause(params: List[ValDef])
}
Attributes
- Source
- Quotes.scala
Type of a parameter reference
Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType.
Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType.
Attributes
- Source
- Quotes.scala
Position in a source file
A type that is recursively defined this
A type that is recursively defined
Tree representing a reference to definition
Type tree representing a type refinement
A type with a type refinement T { type U }
Rename import/export selector: .{bar => baz}
in import foo.{bar => baz}
Rename import/export selector: .{bar => baz}
in import foo.{bar => baz}
Attributes
- Source
- Quotes.scala
Tree representing a variable argument list in the source code
Tree representing a return
in the source code
Tree representing a selection of definition with a given name on a given prefix
Tree representing a selection of definition with a given name on a given prefix
Attributes
- Source
- Quotes.scala
Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees
Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees
Attributes
- Source
- Quotes.scala
Import/Export selectors:
Import/Export selectors:
- SimpleSelector:
.bar
inimport foo.bar
- RenameSelector:
.{bar => baz}
inexport foo.{bar => baz}
- OmitSelector:
.{bar => _}
inimport foo.{bar => _}
- GivenSelector:
.given
/.{given T}
inexport foo.given
/import foo.{given T}
Attributes
- Source
- Quotes.scala
Constant Short value
The signature of a method
Simple import/export selector: .bar
in import foo.bar
Type tree representing a singleton type
Scala source file
Tree representing a statement in the source code
Constant String value
Tree representing a summoning match summonFrom { ... }
in the source code
Tree representing a summoning match summonFrom { ... }
in the source code
Attributes
- Source
- Quotes.scala
Tree representing super
in the source code
Type of a super
reference
Symbol of a definition. Symbols can be compared with ==
to know if two definitions are the same.
Symbol of a definition. Symbols can be compared with ==
to know if two definitions are the same.
Attributes
- Source
- Quotes.scala
Tree representing an expression in the source code
A term parameter clause (x1: X1, ..., xn: Xx)
Can also be (implicit X1, ..., Xn)
, (given X1, ..., Xn)
or (given x1: X1, ..., xn: Xn)
A term parameter clause (x1: X1, ..., xn: Xx)
Can also be (implicit X1, ..., Xn)
, (given X1, ..., Xn)
or (given x1: X1, ..., xn: Xn)
Attributes
- Source
- Quotes.scala
Type of a reference to a term symbol
Tree representing this
or C.this
in the source code
Type of this
Tree representing code written in the source
Tree representing a try catch try x catch { ... } finally { ... }
in the source code
Tree representing a try catch try x catch { ... } finally { ... }
in the source code
Attributes
- Source
- Quotes.scala
Tree representing an application of type arguments
Type tree representing a type binding
Type tree within a block with aliases { type U1 = ... ; T[U1, U2] }
Type bounds
Type tree representing a type bound written in the source
Branch of a type pattern match
Tree representing a type (parameter or member) definition in the source code
Tree representing a type (parameter or member) definition in the source code
Attributes
- Source
- Quotes.scala
Type tree representing a reference to definition with a given name
Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda.
Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda.
Attributes
- Source
- Quotes.scala
A type parameter clause [X1, ..., Xn]
Type tree representing a selection of definition with a given name on a given type prefix
Type tree representing a selection of definition with a given name on a given type prefix
Attributes
- Source
- Quotes.scala
Type of a reference to a type symbol
A type, type constructors, type bounds or NoPrefix
Type tree representing a selection of definition with a given name on a given term prefix
Type tree representing a selection of definition with a given name on a given term prefix
Attributes
- Source
- Quotes.scala
Type tree representing a type written in the source
Tree representing a type ascription x: T
in the source code.
Tree representing a type ascription x: T
in the source code.
Also represents a pattern that contains a term x
. Other : T
patterns use the more general TypedOrTest
.
Attributes
- Source
- Quotes.scala
Tree representing a type ascription or type test pattern x: T
in the source code.
Tree representing a type ascription or type test pattern x: T
in the source code.
Attributes
- Source
- Quotes.scala
Pattern representing a Xyz(...)
unapply.
Constant Unit value
Tree representing a value definition in the source code This includes val
, lazy val
, var
, object
and parameter definitions.
Tree representing a value definition in the source code This includes val
, lazy val
, var
, object
and parameter definitions.
Attributes
- Source
- Quotes.scala
Tree representing a while loop
Pattern representing a _
wildcard.
Type tree representing wildcard type bounds written in the source. The wildcard type _
(for example in in List[_]
) will be a type tree that represents a type but has TypeBounds
inside.
Type tree representing wildcard type bounds written in the source. The wildcard type _
(for example in in List[_]
) will be a type tree that represents a type but has TypeBounds
inside.
Attributes
- Source
- Quotes.scala
Value members
Abstract fields
Module object of type Alternatives
Module object of type AndType
Module object of type Annotated
Module object of type AnnotatedType
Module object of type Applied
Module object of type AppliedType
Module object of type Apply
Module object of type Assign
Module object of type Bind
Module object of type Block
Module object of type BooleanConstant
Module object of type ByName
Module object of type ByNameType
Module object of type ByteConstant
Module object of type CaseDef
Module object of type CharConstant
Module object of type ClassDef
Module object of type ClassOfConstant
Module object of type Closure
Module object of type CompilationInfo
Constant value represented as the constant itself
Module object of type ConstantType
Module object of type DefDef
Module object of type Definition
Module object of type DoubleConstant
Module object of type Export
Module object of type Flags
Module object of type FloatConstant
Module object of type GivenSelector
Module object of type Ident
Module object of type If
Module object of type Implicits
Module object of type Import
Module object of type Inferred
Module object of type Inlined
Module object of type IntConstant
A lambda (...) => ...
in the source code is represented as a local method and a closure:
A lambda (...) => ...
in the source code is represented as a local method and a closure:
{
def m(...) = ...
closure(m)
}
Attributes
- Note
-
Due to the encoding, in pattern matches the case for
Lambda
should come before the case forBlock
to avoid mishandling ofLambda
. - Source
- Quotes.scala
Module object of type LambdaTypeTree
Module object of type Literal
Module object of type LongConstant
Module object of type Match
Module object of type MatchCase
Module object of type MatchType
Module object of type MatchTypeTree
Module object of type MethodType
Module object of type NamedArg
Module object of type New
Module object of type NoPrefix
Module object of type NullConstant
Module object of type OmitSelector
Module object of type OrType