Packages

  • package root
    Definition Classes
    root
  • package scala
    Definition Classes
    root
  • package reflect
    Definition Classes
    scala
  • package macros

    EXPERIMENTAL

    EXPERIMENTAL

    The base package for Scala macros.

    Macros are functions that are called by the compiler during compilation. Within these functions the programmer has access to compiler APIs. For example, it is possible to generate, analyze and typecheck code.

    See the Macros Guide on how to get started with Scala macros.

    Definition Classes
    reflect
  • package whitebox
    Definition Classes
    macros
  • Context

trait Context extends blackbox.Context

EXPERIMENTAL

The whitebox Scala macros context.

See the overview page for a description of how macros work. This documentation entry provides information on the API available to macro writers.

A macro context wraps a compiler universe exposed in universe and having type scala.reflect.macros.Universe. This type is a refinement over the generic reflection API provided in scala.reflect.api.Universe. The extended Universe provides mutability for reflection artifacts (e.g. macros can change types of compiler trees, add annotation to symbols representing definitions, etc) and exposes some internal compiler functionality such as Symbol.deSkolemize or Tree.attachments.

Another fundamental part of a macro context is macroApplication, which provides access to the tree undergoing macro expansion. Parts of this tree can be found in arguments of the corresponding macro implementations and in prefix, but macroApplication gives the full picture.

Other than that, macro contexts provide facilities for typechecking, exploring the compiler's symbol table and enclosing trees and compilation units, evaluating trees, logging warnings/errors and much more. Refer to the documentation of top-level traits in this package to learn the details.

If a macro def refers to a macro impl that uses whitebox.Context, then this macro def becomes a whitebox macro, gaining the ability to refine the type of its expansion beyond its official return type, which enables a number of important use cases. Blackbox macros, i.e. the ones defined with blackbox.Context, can't do that, so they are less powerful. However blackbox macros are also going to enjoy better support than whitebox macros, so choose wisely. See the Macros Guide for more information.

Source
Context.scala
See also

scala.reflect.macros.blackbox.Context

Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Context
  2. Context
  3. Internals
  4. ExprUtils
  5. Evals
  6. Parsers
  7. Typers
  8. Infrastructure
  9. FrontEnds
  10. Reifiers
  11. Names
  12. Enclosures
  13. Aliases
  14. AnyRef
  15. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. trait ContextInternalApi extends MacroInternalApi

    Definition Classes
    Internals
    See also

    scala.reflect.api.Internals

  2. type Expr[+T] = Universe.Expr[T]

    Expr wraps an abstract syntax tree and tags it with its type.

    Expr wraps an abstract syntax tree and tags it with its type.

    Definition Classes
    Aliases
  3. case class ImplicitCandidate(pre: Context.Type, sym: Context.Symbol, pt: Context.Type, tree: Context.Tree) extends Product with Serializable

    Information about one of the currently considered implicit candidates.

    Information about one of the currently considered implicit candidates. Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, hence implicit searches can recursively trigger other implicit searches.

    pre and sym provide information about the candidate itself. pt and tree store the parameters of the implicit search the candidate is participating in.

  4. type Modifiers = Universe.Modifiers

    The type of tree modifiers.

    The type of tree modifiers.

    Definition Classes
    Aliases
  5. type Name = Universe.Name

    The abstract type of names.

    The abstract type of names.

    Definition Classes
    Aliases
  6. type Position = Universe.Position

    Defines a universe-specific notion of positions.

    Defines a universe-specific notion of positions.

    Definition Classes
    Aliases
  7. abstract type PrefixType

    The type of the prefix tree from which the macro is selected.

    The type of the prefix tree from which the macro is selected. See the documentation entry for prefix for an example.

    Definition Classes
    Context
  8. type Scope = Universe.Scope

    The base type of all scopes.

    The base type of all scopes.

    Definition Classes
    Aliases
  9. type Symbol = Universe.Symbol

    The type of symbols representing declarations.

    The type of symbols representing declarations.

    Definition Classes
    Aliases
  10. type TermName = Universe.TermName

    The abstract type of names representing terms.

    The abstract type of names representing terms.

    Definition Classes
    Aliases
  11. type Tree = Universe.Tree

    The type of Scala abstract syntax trees.

    The type of Scala abstract syntax trees.

    Definition Classes
    Aliases
  12. type Type = Universe.Type

    The type of Scala types, and also Scala type signatures.

    The type of Scala types, and also Scala type signatures. (No difference is internally made between the two).

    Definition Classes
    Aliases
  13. type TypeName = Universe.TypeName

    The abstract type of names representing types.

    The abstract type of names representing types.

    Definition Classes
    Aliases
  14. type TypeTag[T] = Universe.TypeTag[T]

    The type of type tags.

    The type of type tags.

    Definition Classes
    Aliases
  15. type TypecheckException = macros.TypecheckException

    Definition Classes
    Typers
    See also

    scala.reflect.macros.TypecheckException

  16. abstract type TypecheckMode

    Represents mode of operations of the typechecker underlying c.typecheck calls.

    Represents mode of operations of the typechecker underlying c.typecheck calls. Is necessary since the shape of the typechecked tree alone is not enough to guess how it should be typechecked. Can be TERMmode (typecheck as a term), TYPEmode (typecheck as a type) or PATTERNmode (typecheck as a pattern).

    Definition Classes
    Typers
  17. type WeakTypeTag[T] = Universe.WeakTypeTag[T]

    The type of weak type tags.

    The type of weak type tags.

    Definition Classes
    Aliases

Deprecated Type Members

  1. case class EnclosureException(expected: Class[_], enclosingTrees: List[blackbox.Context.Tree]) extends Exception with Product with Serializable

    Indicates than one of the enclosure methods failed to find a tree of required type among enclosing trees.

    Indicates than one of the enclosure methods failed to find a tree of required type among enclosing trees.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  2. type CompilationUnit = Universe.CompilationUnit

    The type of compilation units.

    The type of compilation units.

    Definition Classes
    Aliases
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  3. type Run = Universe.Run

    The type of compilation runs.

    The type of compilation runs.

    Definition Classes
    Aliases
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

Abstract Value Members

  1. abstract def Expr[T](tree: Tree)(implicit arg0: WeakTypeTag[T]): Expr[T]

    A shorthand to create an expr.

    A shorthand to create an expr.

    Unlike the conventional expr factory, which requires a scala.reflect.api.TreeCreator, this one accepts a regular tree, but the resulting exprs are unable of being migrated to other universes/mirrors (the functionality normally not needed for macros, since there is only one compile-time universe and only one compile-time mirror).

    Definition Classes
    Aliases
  2. abstract val PATTERNmode: TypecheckMode

    Indicates that an argument to c.typecheck should be typechecked as a pattern.

    Indicates that an argument to c.typecheck should be typechecked as a pattern.

    Definition Classes
    Typers
  3. abstract val TERMmode: TypecheckMode

    Indicates that an argument to c.typecheck should be typechecked as a term.

    Indicates that an argument to c.typecheck should be typechecked as a term. This is the default typechecking mode in Scala 2.11 and the only one supported in Scala 2.10.

    Definition Classes
    Typers
  4. abstract val TYPEmode: TypecheckMode

    Indicates that an argument to c.typecheck should be typechecked as a type.

    Indicates that an argument to c.typecheck should be typechecked as a type.

    Definition Classes
    Typers
  5. abstract def TypeTag[T](tpe: Type): TypeTag[T]

    A shorthand to create a type tag.

    A shorthand to create a type tag.

    Unlike the conventional type tag factory, which requires a scala.reflect.api.TypeCreator, this one accepts a regular type, but the resulting type tags are unable of being migrated to other universes/mirrors (the functionality normally not needed for macros, since there is only one compile-time universe and only one compile-time mirror).

    Definition Classes
    Aliases
  6. abstract def WeakTypeTag[T](tpe: Type): WeakTypeTag[T]

    A shorthand to create a weak type tag.

    A shorthand to create a weak type tag.

    Unlike the conventional type tag factory, which requires a scala.reflect.api.TypeCreator, this one accepts a regular type, but the resulting type tags are unable of being migrated to other universes/mirrors (the functionality normally not needed for macros, since there is only one compile-time universe and only one compile-time mirror).

    Definition Classes
    Aliases
  7. abstract def abort(pos: Position, msg: String): Nothing

    Abruptly terminates current macro expansion leaving a note about what happened.

    Abruptly terminates current macro expansion leaving a note about what happened. Use enclosingPosition if you're in doubt what position to pass to pos.

    Definition Classes
    FrontEnds
  8. abstract def classPath: List[URL]

    Exposes current classpath.

    Exposes current classpath.

    Definition Classes
    Infrastructure
  9. abstract def compilerSettings: List[String]

    Exposes current compiler settings as a list of options.

    Exposes current compiler settings as a list of options. Use scalac -help, scalac -X and scalac -Y to learn about currently supported options.

    Definition Classes
    Infrastructure
  10. abstract def echo(pos: Position, msg: String): Unit

    For sending a message which should not be labelled as a warning/error, but also shouldn't require -verbose to be visible.

    For sending a message which should not be labelled as a warning/error, but also shouldn't require -verbose to be visible. Use enclosingPosition if you're in doubt what position to pass to pos.

    Definition Classes
    FrontEnds
  11. abstract def enclosingImplicits: List[ImplicitCandidate]

    Information about one of the currently considered implicit candidates.

    Information about one of the currently considered implicit candidates. Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, hence implicit searches can recursively trigger other implicit searches.

    Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. If we're in an implicit macro being expanded, it's included in this list.

    Unlike openImplicits, this is a val, which means that it gets initialized when the context is created and always stays the same regardless of whatever happens during macro expansion.

  12. abstract def enclosingMacros: List[Context]

    Contexts that represent macros in-flight, including the current one.

    Contexts that represent macros in-flight, including the current one. Very much like a stack trace, but for macros only. Can be useful for interoperating with other macros and for imposing compiler-friendly limits on macro expansion.

    Is also priceless for emitting sane error messages for macros that are called by other macros on synthetic (i.e. position-less) trees. In that dire case navigate the enclosingMacros stack, and it will most likely contain at least one macro with a position-ful macro application. See enclosingPosition for a default implementation of this logic.

    Unlike openMacros, this is a val, which means that it gets initialized when the context is created and always stays the same regardless of whatever happens during macro expansion.

    Definition Classes
    ContextEnclosures
  13. abstract def enclosingPosition: Position

    Tries to guess a position for the enclosing application.

    Tries to guess a position for the enclosing application. But that is simple, right? Just dereference pos of macroApplication? Not really. If we're in a synthetic macro expansion (no positions), we must do our best to infer the position of something that triggered this expansion. Surprisingly, quite often we can do this by navigation the enclosingMacros stack.

    Definition Classes
    Enclosures
  14. abstract def error(pos: Position, msg: String): Unit

    Emits a compilation error.

    Emits a compilation error. Use enclosingPosition if you're in doubt what position to pass to pos.

    Definition Classes
    FrontEnds
  15. abstract def eval[T](expr: Expr[T]): T

    Takes a typed wrapper for a tree of type T and evaluates it to a value of type T.

    Takes a typed wrapper for a tree of type T and evaluates it to a value of type T.

    Can be used to perform compile-time computations on macro arguments to the extent permitted by the shape of the arguments.

    Known issues: because of https://github.com/scala/bug/issues/5748 trees being evaluated first need to undergo untypecheck. Resetting symbols and types mutates the tree in place, therefore the conventional approach is to duplicate the tree first.

    scala> def impl(c: Context)(x: c.Expr[String]) = {
         | val x1 = c.Expr[String](c.untypecheck(x.tree.duplicate))
         | println(s"compile-time value is: ${c.eval(x1)}")
         | x
         | }
    impl: (c: Context)(x: c.Expr[String])c.Expr[String]
    
    scala> def test(x: String) = macro impl
    test: (x: String)String
    
    scala> test("x")
    compile-time value is: x
    res0: String = x
    
    scala> test("x" + "y")
    compile-time value is: xy
    res1: String = xy
    
    scala> val x = "x"
    x: String = x
    
    scala> test(x + "y")
    compile-time value is: xy
    res2: String = xy
    
    scala> { val x = "x"; test(x + "y") }
    error: exception during macro expansion:
    scala.tools.reflect.ToolBoxError: reflective compilation failed

    Note that in the last case evaluation has failed, because the argument of a macro refers to a runtime value x, which is unknown at compile time.

    Definition Classes
    Evals
  16. abstract def freshName[NameType <: Name](name: NameType): NameType

    Creates a more or less unique name having a given name as a prefix and having the same flavor (term name or type name) as the given name.

    Creates a more or less unique name having a given name as a prefix and having the same flavor (term name or type name) as the given name. Consult scala.reflect.macros.Names for more information on uniqueness of such names.

    Definition Classes
    Names
  17. abstract def freshName(name: String): String

    Creates a string that represents a more or less unique name having a given prefix.

    Creates a string that represents a more or less unique name having a given prefix. Consult scala.reflect.macros.Names for more information on uniqueness of such names.

    Definition Classes
    Names
  18. abstract def freshName(): String

    Creates a string that represents a more or less unique name.

    Creates a string that represents a more or less unique name. Consult scala.reflect.macros.Names for more information on uniqueness of such names.

    Definition Classes
    Names
  19. abstract def hasErrors: Boolean

    Does the compilation session have any errors?

    Does the compilation session have any errors?

    Definition Classes
    FrontEnds
  20. abstract def hasWarnings: Boolean

    Does the compilation session have any warnings?

    Does the compilation session have any warnings?

    Definition Classes
    FrontEnds
  21. abstract def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree

    Infers an implicit value of the expected type pt in the macro callsite context.

    Infers an implicit value of the expected type pt in the macro callsite context. Optional pos parameter provides a position that will be associated with the implicit search.

    If silent is false, TypecheckException will be thrown in case of an inference error. If silent is true, the typecheck is silent and will return EmptyTree if an error occurs. Such errors don't vanish and can be inspected by turning on -Vimplicits. Unlike in typecheck, silent is true by default.

    Definition Classes
    Typers
    Exceptions thrown
  22. abstract def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree

    Infers an implicit view from the provided tree tree of the type from to the type to in the macro callsite context.

    Infers an implicit view from the provided tree tree of the type from to the type to in the macro callsite context. Optional pos parameter provides a position that will be associated with the implicit search.

    If silent is false, TypecheckException will be thrown in case of an inference error. If silent is true, the typecheck is silent and will return EmptyTree if an error occurs. Such errors don't vanish and can be inspected by turning on -Vimplicits. Unlike in typecheck, silent is true by default.

    Definition Classes
    Typers
    Exceptions thrown
  23. abstract def info(pos: Position, msg: String, force: Boolean): Unit

    Emits an informational message, suppressed unless -verbose or force=true.

    Emits an informational message, suppressed unless -verbose or force=true. Use enclosingPosition if you're in doubt what position to pass to pos.

    Definition Classes
    FrontEnds
  24. abstract val internal: ContextInternalApi

    Definition Classes
    Internals
    See also

    scala.reflect.api.Internals

  25. abstract def macroApplication: Tree

    The tree that undergoes macro expansion.

    The tree that undergoes macro expansion. Can be useful to get an offset or a range position of the entire tree being processed.

    Definition Classes
    Enclosures
  26. abstract val mirror: Universe.Mirror

    The mirror of the compile-time universe.

    The mirror of the compile-time universe.

    Definition Classes
    Context
  27. abstract def openImplicits: List[ImplicitCandidate]

    Information about one of the currently considered implicit candidates.

    Information about one of the currently considered implicit candidates. Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, hence implicit searches can recursively trigger other implicit searches.

    Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. If we're in an implicit macro being expanded, it's included in this list.

    Unlike enclosingImplicits, this is a def, which means that it gets recalculated on every invocation, so it might change depending on what is going on during macro expansion.

  28. abstract def openMacros: List[Context]

    Contexts that represent macros in-flight, including the current one.

    Contexts that represent macros in-flight, including the current one. Very much like a stack trace, but for macros only. Can be useful for interoperating with other macros and for imposing compiler-friendly limits on macro expansion.

    Is also priceless for emitting sane error messages for macros that are called by other macros on synthetic (i.e. position-less) trees. In that dire case navigate the openMacros stack, and it will most likely contain at least one macro with a position-ful macro application. See enclosingPosition for a default implementation of this logic.

    Unlike enclosingMacros, this is a def, which means that it gets recalculated on every invocation, so it might change depending on what is going on during macro expansion.

    Definition Classes
    ContextTypers
  29. abstract def parse(code: String): Tree

    Parses a string with a Scala expression into an abstract syntax tree.

    Parses a string with a Scala expression into an abstract syntax tree. Only works for expressions, i.e. parsing a package declaration will fail.

    Definition Classes
    Parsers
    Exceptions thrown
  30. abstract val prefix: Expr[PrefixType]

    The prefix tree from which the macro is selected.

    The prefix tree from which the macro is selected.

    For example, for a macro filter defined as an instance method on a collection Coll, prefix represents an equivalent of this for normal instance methods:

    scala> class Coll[T] {
         | def filter(p: T => Boolean): Coll[T] = macro M.filter[T]
         | }; object M {
         | def filter[T](c: Context { type PrefixType = Coll[T] })
         |              (p: c.Expr[T => Boolean]): c.Expr[Coll[T]] =
         |   {
         |     println(c.prefix.tree)
         |     c.prefix
         |   }
         | }
    defined class Coll
    defined module Macros
    
    scala> new Coll[Int]().filter(_ % 2 == 0)
    new Coll[Int]()
    res0: Coll[Int] = ...
    
    scala> val x = new Coll[String]()
    x: Coll[String] = ...
    
    scala> x.filter(_ != "")
    $line11.$read.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.x
    res1 @ 35563b4b: x.type = ...

    Note how the value of prefix changes depending on the qualifier of the macro call (i.e. the expression that is at the left-hand side of the dot).

    Another noteworthy thing about the snippet above is the Context { type PrefixType = Coll[T] } type that is used to stress that the macro implementation works with prefixes of type Coll[T].

    Definition Classes
    Context
  31. abstract def reifyEnclosingRuntimeClass: Tree

    Given a type, generate a tree that when compiled and executed produces the runtime class of the enclosing class or module.

    Given a type, generate a tree that when compiled and executed produces the runtime class of the enclosing class or module. Returns EmptyTree if there does not exist an enclosing class or module.

    Definition Classes
    Reifiers
  32. abstract def reifyRuntimeClass(tpe: Type, concrete: Boolean = true): Tree

    Given a type, generate a tree that when compiled and executed produces the runtime class of the original type.

    Given a type, generate a tree that when compiled and executed produces the runtime class of the original type. If concrete is true, then this function will bail on types, who refer to abstract types (like ClassTag does).

    Definition Classes
    Reifiers
  33. abstract def reifyTree(universe: Tree, mirror: Tree, tree: Tree): Tree

    Given a tree, generate a tree that when compiled and executed produces the original tree.

    Given a tree, generate a tree that when compiled and executed produces the original tree. For more information and examples see the documentation for Universe.reify.

    The produced tree will be bound to the specified universe and mirror. Possible values for universe include universe.internal.gen.mkRuntimeUniverseRef. Possible values for mirror include EmptyTree (in that case the reifier will automatically pick an appropriate mirror).

    This function is deeply connected to Universe.reify, a macro that reifies arbitrary expressions into runtime trees. They do very similar things (Universe.reify calls Context.reifyTree to implement itself), but they operate on different metalevels (see below).

    Let's study the differences between Context.reifyTree and Universe.reify on an example of using them inside a fooMacro macro:

    * Since reify itself is a macro, it will be executed when fooMacro is being compiled (metalevel -1) and will produce a tree that when evaluated during macro expansion of fooMacro (metalevel 0) will recreate the input tree.

    This provides a facility analogous to quasi-quoting. Writing "reify{ expr }" will generate an AST that represents expr. Afterwards this AST (or its parts) can be used to construct the return value of fooMacro.

    * reifyTree is evaluated during macro expansion (metalevel 0) and will produce a tree that when evaluated during the runtime of the program (metalevel 1) will recreate the input tree.

    This provides a way to retain certain trees from macro expansion time to be inspected later, in the runtime. For example, DSL authors may find it useful to capture DSL snippets into ASTs that are then processed at runtime in a domain-specific way.

    Also note the difference between universes of the runtime trees produced by two reifies:

    * The result of compiling and running the result of reify will be bound to the Universe that called reify. This is possible because it's a macro, so it can generate whatever code it wishes.

    * The result of compiling and running the result of reifyTree will be the prefix that needs to be passed explicitly. This happens because the Universe of the evaluated result is from a different metalevel than the Context the called reify.

    Typical usage of this function is to retain some of the trees received/created by a macro into the form that can be inspected (via pattern matching) or compiled/run (by a reflective ToolBox) during the runtime.

    Definition Classes
    Reifiers
  34. abstract def reifyType(universe: Tree, mirror: Tree, tpe: Type, concrete: Boolean = false): Tree

    Given a type, generate a tree that when compiled and executed produces the original type.

    Given a type, generate a tree that when compiled and executed produces the original type. The produced tree will be bound to the specified universe and mirror. For more information and examples see the documentation for Context.reifyTree and Universe.reify.

    Definition Classes
    Reifiers
  35. abstract def settings: List[String]

    Exposes macro-specific settings as a list of strings.

    Exposes macro-specific settings as a list of strings. These settings are passed to the compiler via the "-Xmacro-settings:setting1,setting2...,settingN" command-line option.

    Definition Classes
    Infrastructure
  36. abstract def typecheck(tree: Tree, mode: TypecheckMode = TERMmode, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree

    Typechecks the provided tree against the expected type pt in the macro callsite context under typechecking mode specified in mode with TERMmode being default.

    Typechecks the provided tree against the expected type pt in the macro callsite context under typechecking mode specified in mode with TERMmode being default. This populates symbols and types of the tree and possibly transforms it to reflect certain desugarings.

    If silent is false, TypecheckException will be thrown in case of a typecheck error. If silent is true, the typecheck is silent and will return EmptyTree if an error occurs. Such errors don't vanish and can be inspected by turning on -Ymacro-debug-verbose. Unlike in inferImplicitValue and inferImplicitView, silent is false by default.

    Typechecking can be steered with the following optional parameters: withImplicitViewsDisabled recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false withMacrosDisabled recursively prohibits macro expansions and macro-based implicits, default value is false

    Definition Classes
    Typers
    Exceptions thrown
  37. abstract val universe: Universe

    The compile-time universe.

    The compile-time universe.

    Definition Classes
    Context
  38. abstract def unreifyTree(tree: Tree): Tree

    Undoes reification of a tree.

    Undoes reification of a tree.

    This reversion doesn't simply restore the original tree (that would lose the context of reification), but does something more involved that conforms to the following laws:

    1) unreifyTree(reifyTree(tree)) != tree // unreified tree is tree + saved context // in current implementation, the result of unreify is opaque // i.e. there's no possibility to inspect underlying tree/context

    2) reifyTree(unreifyTree(reifyTree(tree))) == reifyTree(tree) // the result of reifying a tree in its original context equals to // the result of reifying a tree along with its saved context

    3) compileAndEval(unreifyTree(reifyTree(tree))) ~ compileAndEval(tree) // at runtime original and unreified trees are behaviorally equivalent

    Definition Classes
    Reifiers
  39. abstract def untypecheck(tree: Tree): Tree

    In the current implementation of Scala's reflection API, untyped trees (also known as parser trees or unattributed trees) are observationally different from typed trees (also known as typer trees, typechecked trees or attributed trees),

    In the current implementation of Scala's reflection API, untyped trees (also known as parser trees or unattributed trees) are observationally different from typed trees (also known as typer trees, typechecked trees or attributed trees),

    Usually, if some compiler API takes a tree, then both untyped and typed trees will do. However in some cases, only untyped or only typed trees are appropriate. For example, Evals.eval only accepts untyped trees and one can only splice typed trees inside typed trees. Therefore in the current reflection API, there is a need in functions that go back and forth between untyped and typed trees. For this we have typecheck and untypecheck.

    Note that untypecheck is currently afflicted by https://github.com/scala/bug/issues/5464, which makes it sometimes corrupt trees so that they don't make sense anymore. Unfortunately, there's no workaround for that. We plan to fix this issue soon, but for now please keep it in mind.

    Definition Classes
    Typers
    See also

    https://stackoverflow.com/questions/20936509/scala-macros-what-is-the-difference-between-typed-aka-typechecked-an-untyped

  40. abstract def warning(pos: Position, msg: String): Unit

    Emits a warning.

    Emits a warning. Use enclosingPosition if you're in doubt what position to pass to pos.

    Definition Classes
    FrontEnds
  41. abstract def enclosingClass: Tree

    Tree that corresponds to the enclosing class, or EmptyTree if not applicable.

    Tree that corresponds to the enclosing class, or EmptyTree if not applicable.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  42. abstract def enclosingDef: Universe.DefDef

    Tree that corresponds to the enclosing DefDef tree.

    Tree that corresponds to the enclosing DefDef tree. Throws EnclosureException if there's no such enclosing tree.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  43. abstract def enclosingImpl: Universe.ImplDef

    Tree that corresponds to the enclosing ImplDef tree (i.e.

    Tree that corresponds to the enclosing ImplDef tree (i.e. either ClassDef or ModuleDef). Throws EnclosureException if there's no such enclosing tree.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  44. abstract def enclosingMethod: Tree

    Tree that corresponds to the enclosing method, or EmptyTree if not applicable.

    Tree that corresponds to the enclosing method, or EmptyTree if not applicable.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  45. abstract def enclosingPackage: Universe.PackageDef

    Tree that corresponds to the enclosing PackageDef tree.

    Tree that corresponds to the enclosing PackageDef tree. Throws EnclosureException if there's no such enclosing tree.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  46. abstract def enclosingRun: Run

    Compilation run that contains this macro application.

    Compilation run that contains this macro application.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  47. abstract def enclosingTemplate: Universe.Template

    Tree that corresponds to the enclosing Template tree.

    Tree that corresponds to the enclosing Template tree. Throws EnclosureException if there's no such enclosing tree.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  48. abstract def enclosingUnit: CompilationUnit

    Compilation unit that contains this macro application.

    Compilation unit that contains this macro application.

    Definition Classes
    Enclosures
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information

    See also

    scala.reflect.macros.Enclosures

  49. abstract def fresh[NameType <: Name](name: NameType): NameType

    Creates a more or less unique name having a given name as a prefix and having the same flavor (term name or type name) as the given name.

    Creates a more or less unique name having a given name as a prefix and having the same flavor (term name or type name) as the given name. Consult scala.reflect.macros.Names for more information on uniqueness of such names.

    Definition Classes
    Names
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use freshName instead

  50. abstract def fresh(name: String): String

    Creates a string that represents a more or less unique name having a given prefix.

    Creates a string that represents a more or less unique name having a given prefix. Consult scala.reflect.macros.Names for more information on uniqueness of such names.

    Definition Classes
    Names
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use freshName instead

  51. abstract def fresh(): String

    Creates a string that represents a more or less unique name.

    Creates a string that represents a more or less unique name. Consult scala.reflect.macros.Names for more information on uniqueness of such names.

    Definition Classes
    Names
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use freshName instead

  52. abstract def literal(x: Char): Expr[Char]

    Shorthand for Literal(Constant(x: Char)) in the underlying universe.

    Shorthand for Literal(Constant(x: Char)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  53. abstract def literal(x: String): Expr[String]

    Shorthand for Literal(Constant(x: String)) in the underlying universe.

    Shorthand for Literal(Constant(x: String)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  54. abstract def literal(x: Double): Expr[Double]

    Shorthand for Literal(Constant(x: Double)) in the underlying universe.

    Shorthand for Literal(Constant(x: Double)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  55. abstract def literal(x: Float): Expr[Float]

    Shorthand for Literal(Constant(x: Float)) in the underlying universe.

    Shorthand for Literal(Constant(x: Float)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  56. abstract def literal(x: Long): Expr[Long]

    Shorthand for Literal(Constant(x: Long)) in the underlying universe.

    Shorthand for Literal(Constant(x: Long)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  57. abstract def literal(x: Int): Expr[Int]

    Shorthand for Literal(Constant(x: Int)) in the underlying universe.

    Shorthand for Literal(Constant(x: Int)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  58. abstract def literal(x: Short): Expr[Short]

    Shorthand for Literal(Constant(x: Short)) in the underlying universe.

    Shorthand for Literal(Constant(x: Short)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  59. abstract def literal(x: Byte): Expr[Byte]

    Shorthand for Literal(Constant(x: Byte)) in the underlying universe.

    Shorthand for Literal(Constant(x: Byte)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  60. abstract def literal(x: Boolean): Expr[Boolean]

    Shorthand for Literal(Constant(x: Boolean)) in the underlying universe.

    Shorthand for Literal(Constant(x: Boolean)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  61. abstract def literalFalse: Expr[Boolean]

    Shorthand for Literal(Constant(false)) in the underlying universe.

    Shorthand for Literal(Constant(false)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  62. abstract def literalNull: Expr[Null]

    Shorthand for Literal(Constant(null)) in the underlying universe.

    Shorthand for Literal(Constant(null)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  63. abstract def literalTrue: Expr[Boolean]

    Shorthand for Literal(Constant(true)) in the underlying universe.

    Shorthand for Literal(Constant(true)) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  64. abstract def literalUnit: Expr[Unit]

    Shorthand for Literal(Constant(())) in the underlying universe.

    Shorthand for Literal(Constant(())) in the underlying universe.

    Definition Classes
    ExprUtils
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use quasiquotes instead

  65. abstract def resetLocalAttrs(tree: Tree): Tree

    Recursively resets locally defined symbols and types in a given tree.

    Recursively resets locally defined symbols and types in a given tree. WARNING: Don't use this API, go for untypecheck instead.

    Definition Classes
    Typers
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use c.untypecheck instead

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from Context toany2stringadd[Context] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Context, B)
    Implicit
    This member is added by an implicit conversion from Context toArrowAssoc[Context] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. val Expr: Universe.Expr.type

    Constructor/Extractor for Expr.

    Constructor/Extractor for Expr.

    Definition Classes
    Aliases
  7. val TypeTag: Universe.TypeTag.type

    Constructor/Extractor for TypeTag.

    Constructor/Extractor for TypeTag.

    Definition Classes
    Aliases
  8. val TypecheckException: macros.TypecheckException.type

    Definition Classes
    Typers
    See also

    scala.reflect.macros.TypecheckException

  9. val WeakTypeTag: Universe.WeakTypeTag.type

    Constructor/Extractor for WeakTypeTag.

    Constructor/Extractor for WeakTypeTag.

    Definition Classes
    Aliases
  10. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  11. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  12. def ensuring(cond: (Context) => Boolean, msg: => Any): Context
    Implicit
    This member is added by an implicit conversion from Context toEnsuring[Context] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: (Context) => Boolean): Context
    Implicit
    This member is added by an implicit conversion from Context toEnsuring[Context] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean, msg: => Any): Context
    Implicit
    This member is added by an implicit conversion from Context toEnsuring[Context] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: Boolean): Context
    Implicit
    This member is added by an implicit conversion from Context toEnsuring[Context] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  18. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  19. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  20. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  21. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  24. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  25. def symbolOf[T](implicit arg0: WeakTypeTag[T]): Universe.TypeSymbol

    Type symbol of x as derived from a type tag.

    Type symbol of x as derived from a type tag.

    Definition Classes
    Aliases
  26. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  27. def toString(): String
    Definition Classes
    AnyRef → Any
  28. def typeOf[T](implicit ttag: TypeTag[T]): Type

    Shortcut for implicitly[TypeTag[T]].tpe

    Shortcut for implicitly[TypeTag[T]].tpe

    Definition Classes
    Aliases
  29. def typeTag[T](implicit ttag: TypeTag[T]): TypeTag[T]

    Shortcut for implicitly[TypeTag[T]]

    Shortcut for implicitly[TypeTag[T]]

    Definition Classes
    Aliases
  30. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  32. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  33. def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type

    Shortcut for implicitly[WeakTypeTag[T]].tpe

    Shortcut for implicitly[WeakTypeTag[T]].tpe

    Definition Classes
    Aliases
  34. def weakTypeTag[T](implicit attag: WeakTypeTag[T]): WeakTypeTag[T]

    Shortcut for implicitly[WeakTypeTag[T]]

    Shortcut for implicitly[WeakTypeTag[T]]

    Definition Classes
    Aliases

Deprecated Value Members

  1. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from Context toStringFormat[Context] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @deprecated @inline()
    Deprecated

    (Since version 2.12.16) Use formatString.format(value) instead of value.formatted(formatString), or use the f"" string interpolator. In Java 15 and later, formatted resolves to the new method in String which has reversed parameters.

  2. def typeCheck(tree: Tree, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree

    Definition Classes
    Typers
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) use c.typecheck instead

    See also

    Typers.typecheck

  3. def [B](y: B): (Context, B)
    Implicit
    This member is added by an implicit conversion from Context toArrowAssoc[Context] 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.

Inherited from blackbox.Context

Inherited from Internals

Inherited from ExprUtils

Inherited from Evals

Inherited from Parsers

Inherited from Typers

Inherited from Infrastructure

Inherited from FrontEnds

Inherited from Reifiers

Inherited from Names

Inherited from Enclosures

Inherited from Aliases

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd fromContext to any2stringadd[Context]

Inherited by implicit conversion StringFormat fromContext to StringFormat[Context]

Inherited by implicit conversion Ensuring fromContext to Ensuring[Context]

Inherited by implicit conversion ArrowAssoc fromContext to ArrowAssoc[Context]

Ungrouped