4
trait ToolBox[U <: scala.reflect.api.Universe] {
6
/** Underlying universe of a ToolBox
10
/** Underlying mirror of a ToolBox
14
/** Front end of the toolbox.
16
* Accumulates and displays warnings and errors, can drop to interactive mode (if supported).
17
* The latter can be useful to study the typechecker or to debug complex macros.
19
* [[scala.tools.reflect]] provides two predefined front ends that can be created using
20
* [[scala.tools.reflect.mkSilentFrontEnd]] and [[scala.tools.reflect.mkConsoleFrontEnd]].
22
def frontEnd: FrontEnd
24
/** Typechecks a tree using this ToolBox.
25
* This populates symbols and types of the tree and possibly transforms it to reflect certain desugarings.
27
* If the tree has unresolved type variables (represented as instances of `FreeTypeSymbol` symbols),
28
* then they all have to be resolved first using `Tree.substituteTypes`, or an error occurs.
30
* If `silent` is false, `TypeError` will be thrown in case of a typecheck error.
31
* If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs.
32
* Such errors don't vanish and can be inspected by turning on -Ydebug.
34
* Typechecking can be steered with the following optional parameters:
35
* `withImplicitViewsDisabled` recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false
36
* `withMacrosDisabled` recursively prohibits macro expansions and macro-based implicits, default value is false
38
def typeCheck(tree: u.Tree, pt: u.Type = u.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree
40
/** Infers an implicit value of the expected type `pt` in top-level context.
41
* Optional `pos` parameter provides a position that will be associated with the implicit search.
43
* As mentioned in https://groups.google.com/forum/#!topic/scala-internals/ta-vbUT6JE8
44
* this API won't take into account the lexical context of the callsite, because
45
* currently it's impossible to reify it.
47
* If `silent` is false, `TypeError` will be thrown in case of an inference error.
48
* If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs.
49
* Such errors don't vanish and can be inspected by turning on -Xlog-implicits.
50
* Unlike in `typeCheck`, `silent` is true by default.
52
def inferImplicitValue(pt: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree
54
/** Infers an implicit view from the provided tree `tree` from the type `from` to the type `to` in the toplevel context.
55
* Optional `pos` parameter provides a position that will be associated with the implicit search.
57
* As mentioned in https://groups.google.com/forum/#!topic/scala-internals/ta-vbUT6JE8
58
* this API won't take into account the lexical context of the callsite, because
59
* currently it's impossible to reify it.
61
* If `silent` is false, `TypeError` will be thrown in case of an inference error.
62
* If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs.
63
* Such errors don't vanish and can be inspected by turning on -Xlog-implicits.
64
* Unlike in `typeCheck`, `silent` is true by default.
66
def inferImplicitView(tree: u.Tree, from: u.Type, to: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree
68
/** Recursively resets symbols and types in a given tree.
70
* Note that this does not revert the tree to its pre-typer shape.
71
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
73
def resetAllAttrs(tree: u.Tree): u.Tree
75
/** Recursively resets locally defined symbols and types in a given tree.
77
* Note that this does not revert the tree to its pre-typer shape.
78
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
80
def resetLocalAttrs(tree: u.Tree): u.Tree
83
def parse(code: String): u.Tree
85
/** Compiles a tree using this ToolBox.
87
* If the tree has unresolved type variables (represented as instances of `FreeTypeSymbol` symbols),
88
* then they all have to be resolved first using `Tree.substituteTypes`, or an error occurs.
90
* This spawns the compiler at the Namer phase, and pipelines the tree through that compiler.
91
* Currently `compile` does not accept trees that already typechecked, because typechecking isn't idempotent.
92
* For more info, take a look at https://issues.scala-lang.org/browse/SI-5464.
94
def compile(tree: u.Tree): () => Any
96
/** Compiles and runs a tree using this ToolBox.
97
* Is equivalent to `compile(tree)()`.
99
def eval(tree: u.Tree): Any
102
/** Represents an error during toolboxing
104
case class ToolBoxError(val message: String, val cause: Throwable = null) extends Throwable(message, cause)