~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to src/compiler/scala/tools/reflect/ToolBox.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package scala.tools
 
2
package reflect
 
3
 
 
4
trait ToolBox[U <: scala.reflect.api.Universe] {
 
5
 
 
6
  /** Underlying universe of a ToolBox
 
7
   */
 
8
  val u: U
 
9
 
 
10
  /** Underlying mirror of a ToolBox
 
11
   */
 
12
  val mirror: u.Mirror
 
13
 
 
14
  /** Front end of the toolbox.
 
15
   *
 
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.
 
18
   *
 
19
   *  [[scala.tools.reflect]] provides two predefined front ends that can be created using
 
20
   *  [[scala.tools.reflect.mkSilentFrontEnd]] and [[scala.tools.reflect.mkConsoleFrontEnd]].
 
21
   */
 
22
  def frontEnd: FrontEnd
 
23
 
 
24
  /** Typechecks a tree using this ToolBox.
 
25
   *  This populates symbols and types of the tree and possibly transforms it to reflect certain desugarings.
 
26
   *
 
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.
 
29
   *
 
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.
 
33
   *
 
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
 
37
   */
 
38
  def typeCheck(tree: u.Tree, pt: u.Type = u.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree
 
39
 
 
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.
 
42
   *
 
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.
 
46
   *
 
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.
 
51
   */
 
52
  def inferImplicitValue(pt: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree
 
53
 
 
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.
 
56
   *
 
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.
 
60
   *
 
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.
 
65
   */
 
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
 
67
 
 
68
  /** Recursively resets symbols and types in a given tree.
 
69
   *
 
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.
 
72
   */
 
73
  def resetAllAttrs(tree: u.Tree): u.Tree
 
74
 
 
75
  /** Recursively resets locally defined symbols and types in a given tree.
 
76
   *
 
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.
 
79
   */
 
80
  def resetLocalAttrs(tree: u.Tree): u.Tree
 
81
 
 
82
  /** .. */
 
83
  def parse(code: String): u.Tree
 
84
 
 
85
  /** Compiles a tree using this ToolBox.
 
86
   *
 
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.
 
89
   *
 
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.
 
93
   */
 
94
  def compile(tree: u.Tree): () => Any
 
95
 
 
96
  /** Compiles and runs a tree using this ToolBox.
 
97
   *  Is equivalent to `compile(tree)()`.
 
98
   */
 
99
  def eval(tree: u.Tree): Any
 
100
}
 
101
 
 
102
/** Represents an error during toolboxing
 
103
 */
 
104
case class ToolBoxError(val message: String, val cause: Throwable = null) extends Throwable(message, cause)