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
| | +- Select
| |
| +- Literal
| +- This
| +- New
| +- NamedArg
| +- Apply
| +- TypeApply
| +- Super
| +- Typed
| +- Assign
| +- Block
| +- Closure
| +- If
| +- Match
| +- SummonFrom
| +- Try
| +- Return
| +- Repeated
| +- Inlined
| +- SelectOuter
| +- While
|
|
+- TypeTree ----+- Inferred
| +- TypeIdent
| +- TypeSelect
| +- TypeProjection
| +- Singleton
| +- Refined
| +- Applied
| +- Annotated
| +- MatchTypeTree
| +- ByName
| +- LambdaTypeTree
| +- TypeBind
| +- TypeBlock
|
+- TypeBoundsTree
+- WildcardTypeTree
|
+- CaseDef
|
+- TypeCaseDef
+- Bind
+- Unapply
+- Alternatives
+- 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
Type members
Classlikes
Customizable Tree accumulator.
Usage:
import qctx.reflect._
class MyTreeAccumulator extends TreeAccumulator[X] {
def foldTree(x: X, tree: Tree)(owner: Symbol): X = ...
}
Customizable tree mapper.
Usage:
import quotes.reflect._
class MyTreeMap extends TreeMap {
override def transformTree(tree: Tree)(owner: Symbol): Tree = ...
}
Types
Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested Apply
s
Type of a by-name definition of type =>T
.
May represent by-name parameter such as thunk
in
scala
def log[T](thunk: =>T): T = ...
May also represent a the return type of a parameterless method definition such as
scala
def foo: Int = ...
Tree representing a class definition. This includes anonymous class definitions and the class of a module object
A lambda (...) => ...
in the source code is represented as
a local method and a closure:
{ def m(...) = ... closure(m) }
Tree representing an export clause in the source code. Export forwarders generated from this clause appear in the same scope.
Case of a MatchType
containing pattern case P => R
.
Note: cases with type bindings are represented nested in a TypeLambda
.
Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType.
Tree representing a pacakage clause in the source code
scala
package foo {
// package stats
}
or
scala
package foo.bar
// package stats
A parameter clause [X1, ..., Xn]
or (x1: X1, ..., xn: Xx)
[X1, ..., Xn]
are reresented with TypeParamClause
and (x1: X1, ..., xn: Xx)
are represented with TermParamClause
ParamClause
encodes the following enumeration
scala
enum ParamClause:
case TypeParamClause(params: List[TypeDef])
case TermParamClause(params: List[ValDef])
Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType.
Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees
Import/Export selectors:
- SimpleSelector: .bar
in import foo.bar
- RenameSelector: .{bar => baz}
in export foo.{bar => baz}
- OmitSelector: .{bar => _}
in import foo.{bar => _}
- GivenSelector: .given
/.{given T}
in export foo.given
/import foo.{given T}
A term parameter clause (x1: X1, ..., xn: Xx)
Can also be (implicit X1, ..., Xn)
, (given X1, ..., Xn)
or (given x1: X1, ..., xn: Xn)
Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda.
Tree representing a value definition in the source code This inclues val
, lazy val
, var
, object
and parameter defintions.
Value members
Abstract fields
A lambda (...) => ...
in the source code is represented as
a local method and a closure:
{ def m(...) = ... closure(m) }
- Note
Due to the encoding, in pattern matches the case for
Lambda
should come before the case forBlock
to avoid mishandling ofLambda
.
Givens
Givens
TypeTest
that allows testing at runtime in a pattern match if an ImplicitSearchResult
is an AmbiguousImplicits
TypeTest
that allows testing at runtime in a pattern match if an ImplicitSearchResult
is a DivergingImplicit
TypeTest
that allows testing at runtime in a pattern match if an ImplicitSearchResult
is an ImplicitSearchFailure
TypeTest
that allows testing at runtime in a pattern match if an ImplicitSearchResult
is an ImplicitSearchSuccess
TypeTest
that allows testing at runtime in a pattern match if an ImplicitSearchResult
is a NoMatchingImplicits