The API of Annotation
instances. The main source of information about annotations is the scala.reflect.api.Annotations page.
An extractor class to create and pattern match with syntax Annotation(tpe, scalaArgs, javaArgs)
. Here, tpe
is the annotation type, scalaArgs
the payload of Scala annotations, and javaArgs
the payload of Java annotations.
An extractor class to create and pattern match with syntax Constant(value)
where value
is the Scala value of the constant.
Expr wraps an abstract syntax tree and tags it with its type. The main source of information about exprs is the scala.reflect.api.Exprs page.
The API of FlagSet
instances. The main source of information about flag sets is the scala.reflect.api.FlagSets page.
All possible values that can constitute flag sets. The main source of information about flag sets is the scala.reflect.api.FlagSets page.
The API of free term symbols. The main source of information about symbols is the Symbols page.
$SYMACCESSORS
The API of free type symbols. The main source of information about symbols is the Symbols page.
$SYMACCESSORS
This trait provides support for importers, a facility to migrate reflection artifacts between universes. Note: this trait should typically be used only rarely.
Reflection artifacts, such as Symbols and Types, are contained in Universes. Typically all processing happens within a single Universe
(e.g. a compile-time macro Universe
or a runtime reflection Universe
), but sometimes there is a need to migrate artifacts from one Universe
to another. For example, runtime compilation works by importing runtime reflection trees into a runtime compiler universe, compiling the importees and exporting the result back.
Reflection artifacts are firmly grounded in their Universe
s, which is reflected by the fact that types of artifacts from different universes are not compatible. By using Importer
s, however, they be imported from one universe into another. For example, to import foo.bar.Baz
from the source Universe
to the target Universe
, an importer will first check whether the entire owner chain exists in the target Universe
. If it does, then nothing else will be done. Otherwise, the importer will recreate the entire owner chain and will import the corresponding type signatures into the target Universe
.
Since importers match Symbol
tables of the source and the target Universe
s using plain string names, it is programmer's responsibility to make sure that imports don't distort semantics, e.g., that foo.bar.Baz
in the source Universe
means the same that foo.bar.Baz
does in the target Universe
.
Here's how one might implement a macro that performs compile-time evaluation of its argument by using a runtime compiler to compile and evaluate a tree that belongs to a compile-time compiler:
def staticEval[T](x: T) = macro staticEval[T] def staticEval[T](c: scala.reflect.macros.blackbox.Context)(x: c.Expr[T]) = { // creates a runtime reflection universe to host runtime compilation import scala.reflect.runtime.{universe => ru} val mirror = ru.runtimeMirror(c.libraryClassLoader) import scala.tools.reflect.ToolBox val toolBox = mirror.mkToolBox() // runtime reflection universe and compile-time macro universe are different // therefore an importer is needed to bridge them // currently mkImporter requires a cast to correctly assign the path-dependent types val importer0 = ru.internal.mkImporter(c.universe) val importer = importer0.asInstanceOf[ru.internal.Importer { val from: c.universe.type }] // the created importer is used to turn a compiler tree into a runtime compiler tree // both compilers use the same classpath, so semantics remains intact val imported = importer.importTree(tree) // after the tree is imported, it can be evaluated as usual val tree = toolBox.untypecheck(imported.duplicate) val valueOfX = toolBox.eval(imported).asInstanceOf[T] ... }
Reflection API exhibits a tension inherent to experimental things: on the one hand we want it to grow into a beautiful and robust API, but on the other hand we have to deal with immaturity of underlying mechanisms by providing not very pretty solutions to enable important use cases.
In Scala 2.10, which was our first stab at reflection API, we didn't have a systematic approach to dealing with this tension, sometimes exposing too much of internals (e.g. Symbol.deSkolemize) and sometimes exposing too little (e.g. there's still no facility to change owners, to do typing transformations, etc). This resulted in certain confusion with some internal APIs living among public ones, scaring the newcomers, and some internal APIs only available via casting, which requires intimate knowledge of the compiler and breaks compatibility guarantees.
This led to creation of the internal
API module for the reflection API, which provides advanced APIs necessary for macros that push boundaries of the state of the art, clearly demarcating them from the more or less straightforward rest and providing compatibility guarantees on par with the rest of the reflection API (full compatibility within minor releases, best effort towards backward compatibility within major releases, clear replacement path in case of rare incompatible changes in major releases).
The internal
module itself (the value that implements InternalApi) isn't defined here, in scala.reflect.api.Universe, but is provided on per-implementation basis. Runtime API endpoint (scala.reflect.runtime.universe) provides universe.compat: InternalApi
, whereas compile-time API endpoints (instances of scala.reflect.macros.Context) provide c.compat: ContextInternalApi
, which extends InternalApi
with additional universe-specific and context-specific functionality.
The API that all references support
An extractor class to create and pattern match with syntax ReferenceToBoxed(ident)
. This AST node does not have direct correspondence to Scala code, and is emitted by macros to reference capture vars directly without going through elem
.
For example:
var x = ... fun { x }
Will emit:
Ident(x)
Which gets transformed to:
Select(Ident(x), "elem")
If ReferenceToBoxed
were used instead of Ident, no transformation would be performed.
This is an internal implementation class.
A type class that defines a representation of T
as a Tree
.
http://docs.scala-lang.org/overviews/quasiquotes/lifting.html
A type class that defines a way to extract instance of T
from a Tree
.
http://docs.scala-lang.org/overviews/quasiquotes/unlifting.html
A mirror that reflects the instance parts of a runtime class. See the overview page for details on how to use runtime reflection.
A mirror that reflects a field. See the overview page for details on how to use runtime reflection.
A mirror that reflects a runtime value. See the overview page for details on how to use runtime reflection.
A mirror that reflects a method. See the overview page for details on how to use runtime reflection.
A mirror that reflects a Scala object definition or the static parts of a runtime class. See the overview page for details on how to use runtime reflection.
A mirror that reflects instances and static classes. See the overview page for details on how to use runtime reflection.
Has no special methods. Is here to provides erased identity for RuntimeClass
.
The API of a mirror for a reflective universe. See the overview page for details on how to use runtime reflection.
A mirror that reflects the instance or static parts of a runtime class. See the overview page for details on how to use runtime reflection.
The API of Name instances.
Has no special methods. Is here to provides erased identity for TermName
.
An extractor class to create and pattern match with syntax TermName(s)
.
Has no special methods. Is here to provides erased identity for TypeName
.
An extractor class to create and pattern match with syntax TypeName(s)
.
Implicit class that introduces q
, tq
, cq,
pq
and fq
string interpolators that are also known as quasiquotes. With their help you can easily manipulate Scala reflection ASTs.
The API that all member scopes support
The API that all scopes support
Defines standard symbols (and types via its base trait).
Defines standard types.
Defines standard names, common for term and type names: These can be accessed via the nme and tpnme members.
Defines standard term names that can be accessed via the nme member.
Defines standard type names that can be accessed via the tpnme member.
The API of class symbols. The main source of information about symbols is the Symbols page.
Class Symbol defines isXXX
test methods such as isPublic
or isFinal
, params
and returnType
methods for method symbols, baseClasses
for class symbols and so on. Some of these methods don't make sense for certain subclasses of Symbol
and return NoSymbol
, Nil
or other empty values.
The API of method symbols. The main source of information about symbols is the Symbols page.
Class Symbol defines isXXX
test methods such as isPublic
or isFinal
, params
and returnType
methods for method symbols, baseClasses
for class symbols and so on. Some of these methods don't make sense for certain subclasses of Symbol
and return NoSymbol
, Nil
or other empty values.
The API of module symbols. The main source of information about symbols is the Symbols page.
Class Symbol defines isXXX
test methods such as isPublic
or isFinal
, params
and returnType
methods for method symbols, baseClasses
for class symbols and so on. Some of these methods don't make sense for certain subclasses of Symbol
and return NoSymbol
, Nil
or other empty values.
The API of symbols. The main source of information about symbols is the Symbols page.
Class Symbol defines isXXX
test methods such as isPublic
or isFinal
, params
and returnType
methods for method symbols, baseClasses
for class symbols and so on. Some of these methods don't make sense for certain subclasses of Symbol
and return NoSymbol
, Nil
or other empty values.
The API of term symbols. The main source of information about symbols is the Symbols page.
Class Symbol defines isXXX
test methods such as isPublic
or isFinal
, params
and returnType
methods for method symbols, baseClasses
for class symbols and so on. Some of these methods don't make sense for certain subclasses of Symbol
and return NoSymbol
, Nil
or other empty values.
The API of type symbols. The main source of information about symbols is the Symbols page.
Class Symbol defines isXXX
test methods such as isPublic
or isFinal
, params
and returnType
methods for method symbols, baseClasses
for class symbols and so on. Some of these methods don't make sense for certain subclasses of Symbol
and return NoSymbol
, Nil
or other empty values.
The API that all alternatives support
An extractor class to create and pattern match with syntax Alternative(trees)
. This AST node corresponds to the following Scala code:
pat1 | ... | patn
The API that all annotateds support
An extractor class to create and pattern match with syntax Annotated(annot, arg)
. This AST node corresponds to the following Scala code:
arg @annot // for types arg: @annot // for exprs
The API that all applied type trees support
An extractor class to create and pattern match with syntax AppliedTypeTree(tpt, args)
. This AST node corresponds to the following Scala code:
tpt[args]
Should only be used with tpt
nodes which are types, i.e. which have isType
returning true
. Otherwise TypeApply
should be used instead.
List[Int] as in val x: List[Int] = ???
// represented as AppliedTypeTree(Ident(<List>), List(TypeTree(<Int>)))
def foo[T] = ??? foo[Int] // represented as TypeApply(Ident(<foo>), List(TypeTree(<Int>)))
The API that all applies support
An extractor class to create and pattern match with syntax Apply(fun, args)
. This AST node corresponds to the following Scala code:
fun(args)
For instance:
fun[targs](args)
Is expressed as:
Apply(TypeApply(fun, targs), args)
The API that all assigns support
An extractor class to create and pattern match with syntax Assign(lhs, rhs)
. This AST node corresponds to the following Scala code:
lhs = rhs
The API that all binds support
An extractor class to create and pattern match with syntax Bind(name, body)
. This AST node corresponds to the following Scala code:
pat*
The API that all blocks support
An extractor class to create and pattern match with syntax Block(stats, expr)
. This AST node corresponds to the following Scala code:
{ stats; expr }
If the block is empty, the expr
is set to Literal(Constant(()))
.
The API that all case defs support
An extractor class to create and pattern match with syntax CaseDef(pat, guard, body)
. This AST node corresponds to the following Scala code:
case
pat if
guard => body
If the guard is not present, the guard
is set to EmptyTree
. If the body is not specified, the body
is set to Literal(Constant(()))
The API that all class defs support
An extractor class to create and pattern match with syntax ClassDef(mods, name, tparams, impl)
. This AST node corresponds to the following Scala code:
mods class
name [tparams] impl
Where impl stands for:
extends
parents { defs }
The API that all compound type trees support
An extractor class to create and pattern match with syntax CompoundTypeTree(templ)
. This AST node corresponds to the following Scala code:
parent1 with ... with parentN { refinement }
The API that all def defs support
An extractor class to create and pattern match with syntax DefDef(mods, name, tparams, vparamss, tpt, rhs)
. This AST node corresponds to the following Scala code:
mods def
name[tparams](vparams_1)...(vparams_n): tpt = rhs
If the return type is not specified explicitly (i.e. is meant to be inferred), this is expressed by having tpt
set to TypeTree()
(but not to an EmptyTree
!).
The API that all def trees support
The API that all existential type trees support
An extractor class to create and pattern match with syntax ExistentialTypeTree(tpt, whereClauses)
. This AST node corresponds to the following Scala code:
tpt forSome { whereClauses }
The API that all functions support
An extractor class to create and pattern match with syntax Function(vparams, body)
. This AST node corresponds to the following Scala code:
vparams => body
The symbol of a Function is a synthetic TermSymbol. It is the owner of the function's parameters.
The API that all applies support
The API that all idents support
An extractor class to create and pattern match with syntax Ident(qual, name)
. This AST node corresponds to the following Scala code:
name
Type checker converts idents that refer to enclosing fields or methods to selects. For example, name ==> this.name
The API that all ifs support
An extractor class to create and pattern match with syntax If(cond, thenp, elsep)
. This AST node corresponds to the following Scala code:
if
(cond) thenp else
elsep
If the alternative is not present, the elsep
is set to Literal(Constant(()))
.
The API that all impl defs support
The API that all imports support
An extractor class to create and pattern match with syntax Import(expr, selectors)
. This AST node corresponds to the following Scala code:
import expr.{selectors}
Selectors are a list of ImportSelectors, which conceptually are pairs of names (from, to). The last (and maybe only name) may be a nme.WILDCARD. For instance:
import qual.{w => _, x, y => z, _}
Would be represented as:
Import(qual, List(("w", WILDCARD), ("x", "x"), ("y", "z"), (WILDCARD, null)))
The symbol of an Import
is an import symbol @see Symbol.newImport. It's used primarily as a marker to check that the import has been typechecked.
The API that all import selectors support
An extractor class to create and pattern match with syntax ImportSelector(name, namePos, rename, renamePos)
. This is not an AST node, it is used as a part of the Import
node.
The API that all label defs support
An extractor class to create and pattern match with syntax LabelDef(name, params, rhs)
.
This AST node does not have direct correspondence to Scala code. It is used for tailcalls and like. For example, while/do are desugared to label defs as follows:
while (cond) body ==> LabelDef($L, List(), if (cond) { body; L$() } else ())
do body while (cond) ==> LabelDef($L, List(), body; if (cond) L$() else ())
The API that all literals support
An extractor class to create and pattern match with syntax Literal(value)
. This AST node corresponds to the following Scala code:
value
The API that all matches support
An extractor class to create and pattern match with syntax Match(selector, cases)
. This AST node corresponds to the following Scala code:
selector match
{ cases }
Match
is also used in pattern matching assignments like val (foo, bar) = baz
.
The API that all member defs support
The API that all Modifiers support
An extractor class to create and pattern match with syntax Modifiers(flags, privateWithin, annotations)
. Modifiers encapsulate flags, visibility annotations and Scala annotations for member definitions.
The API that all module defs support
An extractor class to create and pattern match with syntax ModuleDef(mods, name, impl)
. This AST node corresponds to the following Scala code:
mods object
name impl
Where impl stands for:
extends
parents { defs }
The API that all name trees support
The API that all assigns support
An extractor class to create and pattern match with syntax NamedArg(lhs, rhs)
. This AST node corresponds to the following Scala code:
m.f(lhs = rhs)
@annotation(lhs = rhs)
The API that all news support
An extractor class to create and pattern match with syntax New(tpt)
. This AST node corresponds to the following Scala code:
new
T
This node always occurs in the following context:
(new
tpt).<init>[targs](args)
For example, an AST representation of:
new Example[Int](2)(3)
is the following code:
Apply( Apply( TypeApply( Select(New(TypeTree(typeOf[Example])), nme.CONSTRUCTOR) TypeTree(typeOf[Int])), List(Literal(Constant(2)))), List(Literal(Constant(3))))
The API that all package defs support
An extractor class to create and pattern match with syntax PackageDef(pid, stats)
. This AST node corresponds to the following Scala code:
package
pid { stats }
The API that all ref trees support
An extractor class to create and pattern match with syntax RefTree(qual, name)
. This AST node corresponds to either Ident, Select or SelectFromTypeTree.
The API that all returns support
An extractor class to create and pattern match with syntax Return(expr)
. This AST node corresponds to the following Scala code:
return
expr
The symbol of a Return node is the enclosing method.
The API that all selects support
An extractor class to create and pattern match with syntax Select(qual, name)
. This AST node corresponds to the following Scala code:
qualifier.selector
Should only be used with qualifier
nodes which are terms, i.e. which have isTerm
returning true
. Otherwise SelectFromTypeTree
should be used instead.
foo.Bar // represented as Select(Ident(<foo>), <Bar>) Foo#Bar // represented as SelectFromTypeTree(Ident(<Foo>), <Bar>)
The API that all selects from type trees support
An extractor class to create and pattern match with syntax SelectFromTypeTree(qualifier, name)
. This AST node corresponds to the following Scala code:
qualifier # selector
Note: a path-dependent type p.T is expressed as p.type # T
Should only be used with qualifier
nodes which are types, i.e. which have isType
returning true
. Otherwise Select
should be used instead.
Foo#Bar // represented as SelectFromTypeTree(Ident(<Foo>), <Bar>) foo.Bar // represented as Select(Ident(<foo>), <Bar>)
The API that all singleton type trees support
An extractor class to create and pattern match with syntax SingletonTypeTree(ref)
. This AST node corresponds to the following Scala code:
ref.type
The API that all stars support
An extractor class to create and pattern match with syntax Star(elem)
. This AST node corresponds to the following Scala code:
pat*
The API that all supers support
An extractor class to create and pattern match with syntax Super(qual, mix)
. This AST node corresponds to the following Scala code:
C.super[M]
Which is represented as:
Super(This(C), M)
If mix
is empty, it is tpnme.EMPTY.
The symbol of a Super is the class _from_ which the super reference is made. For instance in C.super(...), it would be C.
The API that all sym trees support
The API that all templates support
An extractor class to create and pattern match with syntax Template(parents, self, body)
. This AST node corresponds to the following Scala code:
extends
parents { self => body }
In case when the self-type annotation is missing, it is represented as an empty value definition with nme.WILDCARD as name and NoType as type.
The symbol of a template is a local dummy. @see Symbol.newLocalDummy The owner of the local dummy is the enclosing trait or class. The local dummy is itself the owner of any local blocks. For example:
class C { def foo { // owner is C def bar // owner is local dummy } }
The API that all term trees support
The API that all thises support
An extractor class to create and pattern match with syntax This(qual)
. This AST node corresponds to the following Scala code:
qual.this
The symbol of a This is the class to which the this refers. For instance in C.this, it would be C.
The API that all tries support
An extractor class to create and pattern match with syntax Throw(expr)
. This AST node corresponds to the following Scala code:
throw
expr
A class that implement a default tree transformation strategy: breadth-first component-wise cloning.
A class that implement a default tree traversal strategy: breadth-first component-wise.
The API that all trees support. The main source of information about trees is the scala.reflect.api.Trees page.
The API of a tree copier.
The API that all tries support
An extractor class to create and pattern match with syntax Try(block, catches, finalizer)
. This AST node corresponds to the following Scala code:
try
block catch
{ catches } finally
finalizer
If the finalizer is not present, the finalizer
is set to EmptyTree
.
The API that all typ trees support
The API that all type applies support
An extractor class to create and pattern match with syntax TypeApply(fun, args)
. This AST node corresponds to the following Scala code:
fun[args]
Should only be used with fun
nodes which are terms, i.e. which have isTerm
returning true
. Otherwise AppliedTypeTree
should be used instead.
def foo[T] = ??? foo[Int] // represented as TypeApply(Ident(<foo>), List(TypeTree(<Int>)))
List[Int] as in val x: List[Int] = ???
// represented as AppliedTypeTree(Ident(<List>), List(TypeTree(<Int>)))
The API that all type bound trees support
An extractor class to create and pattern match with syntax TypeBoundsTree(lo, hi)
. This AST node corresponds to the following Scala code:
>: lo <: hi
The API that all type defs support
An extractor class to create and pattern match with syntax TypeDef(mods, name, tparams, rhs)
. This AST node corresponds to the following Scala code:
mods type
name[tparams] = rhs
mods type
name[tparams] >: lo <: hi
First usage illustrates TypeDefs
representing type aliases and type parameters. Second usage illustrates TypeDefs
representing abstract types, where lo and hi are both TypeBoundsTrees
and Modifier.deferred
is set in mods.
The API that all type trees support
An extractor class to create and pattern match with syntax TypeTree()
. This AST node does not have direct correspondence to Scala code, and is emitted by everywhere when we want to wrap a Type
in a Tree
.
The API that all typeds support
An extractor class to create and pattern match with syntax Typed(expr, tpt)
. This AST node corresponds to the following Scala code:
expr: tpt
The API that all unapplies support
An extractor class to create and pattern match with syntax UnApply(fun, args)
. This AST node does not have direct correspondence to Scala code, and is introduced when typechecking pattern matches and try
blocks.
The API that all val defs support
An extractor class to create and pattern match with syntax ValDef(mods, name, tpt, rhs)
. This AST node corresponds to any of the following Scala code:
mods val
name: tpt = rhs
mods var
name: tpt = rhs
mods name: tpt = rhs // in signatures of function and method definitions
self: Bar => // self-types
If the type of a value is not specified explicitly (i.e. is meant to be inferred), this is expressed by having tpt
set to TypeTree()
(but not to an EmptyTree
!).
The API that all val defs and def defs support
A TypeTag
is a scala.reflect.api.TypeTags#WeakTypeTag with the additional static guarantee that all type references are concrete, i.e. it does not contain any references to unresolved type parameters or abstract types.
If an implicit value of type WeakTypeTag[T]
is required, the compiler will create one, and the reflective representation of T
can be accessed via the tpe
field. Components of T
can be references to type parameters or abstract types. Note that WeakTypeTag
makes an effort to be as concrete as possible, i.e. if TypeTag
s are available for the referenced type arguments or abstract types, they are used to embed the concrete types into the WeakTypeTag. Otherwise the WeakTypeTag will contain a reference to an abstract type. This behavior can be useful, when one expects T
to be perhaps be partially abstract, but requires special care to handle this case. However, if T
is expected to be fully known, use scala.reflect.api.TypeTags#TypeTag instead, which statically guarantees this property.
For more information about TypeTag
s, see the Reflection Guide: TypeTags
The API that all annotated types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax AnnotatedType(annotations, underlying)
. Here, annotations
are the annotations decorating the underlying type underlying
. selfSym
is a symbol representing the annotated type itself.
The API that all this types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax BoundedWildcardTypeExtractor(bounds)
with bounds
denoting the type bounds.
The API that all class info types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax ClassInfo(parents, decls, clazz)
Here, parents
is the list of parent types of the class, decls
is the scope containing all declarations in the class, and clazz
is the symbol of the class itself.
Has no special methods. Is here to provides erased identity for CompoundType
.
The API that all constant types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax ConstantType(constant)
Here, constant
is the constant value represented by the type.
The API that all existential types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax ExistentialType(quantified, underlying)
. Here, quantified
are the type variables bound by the existential type and underlying
is the type that's existentially quantified.
The API that all method types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax MethodType(params, restpe)
Here, params
is a potentially empty list of parameter symbols of the method, and restpe
is the result type of the method. If the method is curried, restpe
would be another MethodType
. Note: MethodType(Nil, Int)
would be the type of a method defined with an empty parameter list.
def f(): Int
If the method is completely parameterless, as in
def f: Int
its type is a NullaryMethodType
.
The API that all nullary method types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax NullaryMethodType(resultType)
. Here, resultType
is the result type of the parameterless method.
The API that all polymorphic types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax PolyType(typeParams, resultType)
. Here, typeParams
are the type parameters of the method and resultType
is the type signature following the type parameters.
The API that all refined types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax RefinedType(parents, decls)
Here, parents
is the list of parent types of the class, and decls
is the scope containing all declarations in the class.
The API that all single types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax SingleType(pre, sym)
Here, pre
is the prefix of the single-type, and sym
is the stable value symbol referred to by the single-type.
Has no special methods. Is here to provides erased identity for SingletonType
.
The API that all super types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax SuperType(thistpe, supertpe)
The API that all this types support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax ThisType(sym)
where sym
is the class prefix of the this type.
The API of types. The main source of information about types is the scala.reflect.api.Types page.
The API that all type bounds support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax TypeBound(lower, upper)
Here, lower
is the lower bound of the TypeBounds
pair, and upper
is the upper bound.
The API that all type refs support. The main source of information about types is the scala.reflect.api.Types page.
An extractor class to create and pattern match with syntax TypeRef(pre, sym, args)
Here, pre
is the prefix of the type reference, sym
is the symbol referred to by the type reference, and args
is a possible empty list of type arguments.
<invalid inheritdoc annotation>
Let's say you have a type definition
type T <: Number
and tsym is the symbol corresponding to T. Then
tsym is an instance of AbstractTypeSymbol tsym.info == TypeBounds(Nothing, Number) tsym.tpe == TypeRef(NoPrefix, T, List())
A type carrying some annotations. Created by the typechecker when eliminating Annotated trees (see typedAnnotated).
An additional checker for annotations on types. Typically these are registered by compiler plugins with the addAnnotationChecker method.
Typed information about an annotation. It can be attached to either a symbol or an annotated type.
Annotations are written to the classfile as Java annotations if atp
conforms to ClassfileAnnotation
(the classfile parser adds this interface to any Java annotation class).
Annotations are pickled (written to scala symtab attribute in the classfile) if atp
inherits form StaticAnnotation
.
args
stores arguments to Scala annotations, represented as typed trees. Note that these trees are not transformed by any phases following the type-checker.
assocs
stores arguments to classfile annotations as name-value pairs.
A class remembering a type instantiation for some a set of overloaded polymorphic symbols. Not used after phase typer
.
Precondition: params.length == typeArgs.length > 0
(enforced structurally).
Represents an array of classfile annotation arguments
An array of expressions. This AST node needs to be translated in backend. It is used to pass arguments to vararg arguments. Introduced by compiler phase uncurry.
This AST node does not have direct correspondence to Scala code, and is used to pass arguments to vararg arguments. For instance:
printf("%s%d", foo, 42)
Is translated to after compiler phase uncurry to:
Apply( Ident("printf"), Literal("%s%d"), ArrayValue(<Any>, List(Ident("foo"), Literal(42))))
A map to compute the asSeenFrom method.
Common code between reflect-internal Symbol and Tree related to Attachments.
Note: constructor is protected to force everyone to use the factory method newBaseTypeSeq instead. This is necessary because when run from reflection every base type sequence needs to have a SynchronizedBaseTypeSeq as mixin.
BoundedWildcardTypes, used only during type inference, are created in two places that I can find:
A class representing a class info
A class for class symbols
Arguments to constant annotations (Annotations defined in Java or extending ConstantAnnotation). Arguments are either:
TODO: rename to ConstantAnnotationArg
A map to implement the collect
method.
A common base class for intersection types and class types
Stores the trees that give rise to a refined type to be used in reification. Unfortunately typed CompoundTypeTree
is lacking essential info, and the reifier cannot use CompoundTypeTree.tpe
. Therefore we need this hack (see Reshape.toPreTyperTypeTree
for a detailed explanation).
A class representing a constant type. A constant type is either the inferred type of a constant value or an explicit or inferred literal type. Both may be constant folded at the type level, however literal types are not folded at the term level and do not elide effects.
A map to implement the contains
method.
An exception for cyclic references of symbol definitions
A temporary type representing the erasure of a user-defined value type. Created during phase erasure, eliminated again in posterasure.
scala/bug#6385 Erasure's creation of bridges considers method signatures exitingErasure
, which contain ErasedValueType
-s. In order to correctly consider the overriding and overridden signatures as equivalent in run/t6385.scala
, it is critical that this type contains the erasure of the wrapped type, rather than the unerased type of the value class itself, as was originally done.
The error scope.
Used by existentialAbstraction.
A map to implement the filter
method.
A map to implement the filter
method.
A marker trait representing an as-yet unevaluated type which doesn't assign flags to the underlying symbol.
A marker trait representing an as-yet unevaluated type which assigns flags to the underlying symbol.
A class representing the inferred type of a constant value. Constant types and their corresponding terms are constant-folded during type checking. To avoid constant folding, use the type returned by deconst
instead.
Precondition: !params.isEmpty. (args.nonEmpty enforced structurally.)
Attachment that knows how to import itself into another universe.
Note: This map is needed even for non-dependent method types, despite what the name might imply.
The API of a mirror for a reflective universe
This should be the first trait in the linearization.
The data structure describing the kind of a given type.
Proper types are represented using ProperTypeKind.
Type constructors are represented using TypeConKind.
Symbol annotations parsed in Namer
(typeCompleter of definitions) have to be lazy (#1782)
The type completer for packages.
A class representing an as-yet unevaluated type.
Represents a compile-time Constant (Boolean
, Byte
, Short
, Char
, Int
, Long
, Float
, Double
, String
, java.lang.Class
or an instance of a Java enumeration value).
A class representing an explicit or inferred literal type. Literal types may be be folded at at the type level during type checking, however they will not be folded at the term level and effects will not be elided.
A locator for trees with given positions. Given a position pos
, locator.apply returns the smallest tree that encloses pos
.
A throwable signalling a malformed type
A class for method symbols
A class representing a method type with parameters. Note that a parameterless method is represented by a NullaryMethodType:
def m(): Int MethodType(Nil, Int) def m: Int NullaryMethodType(Int)
In runtime reflection universes, mirrors are JavaMirrors
.
A class for module class symbols Note: Not all module classes are of this type; when unpickled, we get plain class symbols!
A class for module symbols
The name class. TODO - resolve schizophrenia regarding whether to treat Names as Strings or Strings as Names. Give names the key functions the absence of which make people want Strings all the time.
An ADT to represent the results of symbol name lookups.
FIXME: This is a good example of something which is pure "value class" but cannot reap the benefits because an (unused) $outer pointer so it is not single-field.
A class representing types with a name. When an application uses named arguments, the named argument types for calling isApplicable are represented as NamedType.
Represents a nested classfile annotation
An object representing a missing symbol
Lazily compute expected types for arguments to overloaded methods. Primarily to improve parameter type inference for higher-order overloaded methods.
Normally, overload resolution types the arguments to the alternatives without an expected type. However, typing function literals and eta-expansion are driven by the expected type:
Now that the collections are full of overloaded HO methods, we should try harder to type check them nicely.
(This paragraph is conceptually true, but not a spec.) To avoid breaking existing code, we only provide an expected type (for each argument position) when:
We allow polymorphic cases, taking account any instantiation by the AntiPolyType prefix. Constructors of polymorphic classes are not supported (type param occurrences use fresh symbols, hard to relate to class's type params).
In all other cases, the old behavior is maintained: Wildcard is expected.
A class containing the alternatives and type prefix of an overloaded symbol. Not used after phase typer
.
A period is an ordinal number for a phase in a run. Phases in later runs have higher periods than phases in earlier runs. Later phases have higher periods than earlier phases in the same run.
Attachment that doesn't contain any reflection artifacts and can be imported as-is.
A type function or the type of a polymorphic value (and thus of kind *).
Before the introduction of NullaryMethodType, a polymorphic nullary method (e.g, def isInstanceOf[T]: Boolean) used to be typed as PolyType(tps, restpe), and a monomorphic one as PolyType(Nil, restpe) This is now: PolyType(tps, NullaryMethodType(restpe)) and NullaryMethodType(restpe) by symmetry to MethodTypes: PolyType(tps, MethodType(params, restpe)) and MethodType(params, restpe)
Thus, a PolyType(tps, TypeRef(...)) unambiguously indicates a type function (which results from eta-expanding a type constructor alias). Similarly, PolyType(tps, ClassInfoType(...)) is a type constructor.
A polytype is of kind * iff its resultType is a (nullary) method type.
Defines a universe-specific notion of positions. The main documentation entry about positions is located at scala.reflect.api.Position.
An exception for cyclic references from which we can recover
A class representing intersection types with refinements of the form <parents_0> with ... with <parents_n> { decls }
Cannot be created directly; one should always use refinedType
for creation.
As with NamedType, used only when calling isApplicable. Records that the application has a wildcard star (aka _*) at the end of it.
A proxy for a type (identified by field underlying
) that forwards most operations to it. Every operation that is overridden for some kind of types is forwarded here. Some operations are rewrapped again.
An ordinal number for compiler runs. First run has number 1.
In runtime reflection universes, runtime representation of a class is java.lang.Class
.
Attached to a Function node during type checking when the expected type is a SAM type (and not a built-in FunctionN).
Ideally, we'd move to Dotty's Closure AST, which tracks the environment, the lifted method that has the implementation, and the target type. For backwards compatibility, an attachment is the best we can do right now.
2.12.0-M4
Note: constructor is protected to force everyone to use the factory methods newScope or newNestedScope instead. This is necessary because when run from reflection every scope needs to have a SynchronizedScope as mixin.
A proxy for a type (identified by field underlying
) that forwards most operations to it (for exceptions, see WrappingProxy, which forwards even more operations). every operation that is overridden for some kind of types should be forwarded.
A class for singleton types of the form <prefix>.<sym.name>.type
. Cannot be created directly; one should always use singleType
for creation.
A base class for types that represent a single value (single-types and this-types).
A base class for types that defer some operations to their immediate supertype.
Untyped list of subpatterns attached to selector dummy.
A base class to compute all substitutions
A map to implement the substSym
method.
A map to implement the substThis
method.
A map to implement the subst
method.
The class for all symbols
A class for term symbols
Substitute clazz.this with to
. to
must be an attributed tree.
A class for this-types of the form <sym>.this.type
The standard completer for top-level classes
The type of standard (lazy) tree copiers.
A transformer that replaces tree from
with tree to
in a given tree
Substitute symbols in from
with symbols in to
. Returns a new tree using the new symbols and whose Ident and Select nodes are name-consistent with the new symbols.
Note: This is currently a destructive operation on the original Tree. Trees currently assigned a symbol in from
will be assigned the new symbols without copying, and trees that define symbols with an info
that refer a symbol in from
will have a new type assigned.
The base class for all types
A class for the bounds of abstract types and type parameters
A class expressing upper and lower bounds constraints of type variables, as well as their instantiations.
A throwable signalling a type error
A prototype for mapping a function over all possible types
An attachment carrying information between uncurry and erasure
A class for named types of the form <prefix>.<sym.name>[args]
Cannot be created directly; one should always use typeRef
for creation. (@M: Otherwise hashing breaks)
A class for type parameters viewed from inside their scopes
A class of type symbols. Alias and abstract types are direct instances of this class. Classes are instances of a subclass.
A class representing a type variable: not used after phase typer
.
A higher-kinded TypeVar has params (Symbols) and typeArgs (Types). A TypeVar with nonEmpty typeArgs can only be instantiated by a higher-kinded type that can be applied to those args. A TypeVar is much like a TypeRef, except it has special logic for equality and subtyping.
Precondition for this class, enforced structurally: args.isEmpty && params.isEmpty.
A type that can be passed to unique(..) and be stored in the uniques map.
Used in Refchecks. TODO - eliminate duplication with varianceInType
Constructor/Extractor for Expr.
Can be useful, when having a tree and wanting to splice it in reify call, in which case the tree first needs to be wrapped in an expr.
The main source of information about exprs is the scala.reflect.api.Exprs page.
Companion to Liftable
type class that contains standard instances and provides a helper apply
method to simplify creation of new ones.
Companion to Unliftable
type class that contains standard instances and provides a helper apply
method to simplify creation of new ones.
Type tags corresponding to primitive types and constructor/extractor for WeakTypeTags.
Type tags corresponding to primitive types and constructor/extractor for WeakTypeTags.
A factory method for Apply
nodes.
0-1 argument list new, based on a type tree.
A factory method for Bind
nodes.
Block factory that flattens directly nested blocks.
casedef shorthand
A factory method for Ident
nodes.
A factory method for Ident
nodes.
The factory for Modifiers
instances.
The factory for Modifiers
instances.
0-1 argument list new, based on a symbol.
0-1 argument list new, based on a type.
Factory method for object creation new tpt(args_1)...(args_n)
A New(t, as)
is expanded to: (new t).<init>(as)
The empty set of flags
An empty Modifiers
object: no flags, empty visibility annotation and no Scala annotations.
A special "missing" position.
A special "missing" symbol. Commonly used in the API to denote a default or empty value.
A factory method for Select
nodes.
A factory method for Select
nodes. The string name
argument is assumed to represent a TermName
.
Adds the sm
String interpolator to a scala.StringContext.
A factory method for Super
nodes.
Creates a tree that selects a specific member sym
without having to qualify the super
. For example, given traits B <:< A
, a class C <:< B
needs to invoke A.$init$
. If A
is not a direct parent, a tree super[A].$init$
would not type check ("does not name a parent"). So we generate super.$init$
and pre-assign the correct symbol. A special-case in typedSelectInternal
assigns the correct type A
to the super
qualifier.
the template's symbol
trees that constitute the body of the template
the template
A factory method for This
nodes.
A factory method for Throw
nodes.
A factory method for Try
nodes.
A factory method for TypeTree
nodes.
AnnotationChecker.adaptBoundsToAnnotations
Register an annotation checker. Typically these are added by compiler plugins.
The API of FlagSet
instances.
Make symbol sym
a member of scope tp.decls
where thistp
is the narrowed owner type of the scope.
Creator for AnnotatedTypes. It returns the underlying type if annotations.isEmpty rather than walking into the assertion.
AnnotationChecker.annotationsConform
AnnotationChecker.annotationsGlb
AnnotationChecker.annotationsLub
Very convenient.
A creator for type applications
Convert array parameters denoting a repeated parameter of a Java method to JavaRepeatedParamClass
types.
Check that the executing thread is the compiler thread. No-op here, overridden in interactive.Global.
Position a tree. This means: Set position of a node and position all its unpositioned children.
Turns a path into a String, introducing backquotes as necessary.
Create a base type sequence consisting of a single type
Mark a variable as captured; i.e. force boxing in a *Ref type.
Convert type of a captured variable to *Ref type.
Convert type of a captured variable to *Ref type.
Check well-kindedness of type application (assumes arities are already checked) -- @M
This check is also performed when abstract type members become concrete (aka a "type alias") -- then tparams.length==1 (checked one type member at a time -- in that case, prefix is the name of the type alias)
Type application is just like value application: it's "contravariant" in the sense that the type parameters of the supplied type arguments must conform to the type parameters of the required type parameters:
e.g. class Iterable[t, m[+x <: t]] --> the application Iterable[Int, List] is okay, since List's type parameter is also covariant and its bounds are weaker than <: Int
Memory to store all names sequentially.
Convenience functions which derive symbols by cloning.
Clone symbols and apply the given function to each new symbol's info.
the prototypical symbols
the function to apply to the infos
the newly created, info-adjusted symbols
Return closest enclosing method, unless shadowed by an enclosing class.
The most deeply nested owner that contains all the symbols of thistype or prefixless typerefs/singletype occurrences in given list of types.
The most deeply nested owner that contains all the symbols of thistype or prefixless typerefs/singletype occurrences in given type.
Create the base type sequence of a compound type with given tp.parents
Create a new MethodType
True if all three arguments have the same number of elements and the function is true for all the triples.
Functions which perform the standard clone/substituting on the given symbols and type, then call the creator function with the new symbols and type as arguments.
The current period.
The current compiler run identifier.
Prints a stack trace if -Ydebug or equivalent was given, otherwise does nothing.
Override with final implementation for inlining.
Map a list of type parameter symbols to skolemized symbols, which can be deskolemized to the original type parameter. (A skolem is a representation of a bound variable when viewed inside its scope.) !!!Adriaan: this does not work for hk types.
Skolems will be created at level 0, rather than the current value of skolemizationLevel
. (See scala/bug#7782)
Derives a new list of symbols from the given list by mapping the given list across the given function. Then fixes the info of all the new symbols by substituting the new symbols for the original symbols.
the prototypical symbols
the function to create new symbols
the new list of info-adjusted symbols
Derives a new list of symbols from the given list by mapping the given list of syms
and as
across the given function. Then fixes the info of all the new symbols by substituting the new symbols for the original symbols.
the prototypical symbols
arguments to be passed to symFn together with symbols from syms (must be same length)
the function to create new symbols
the new list of info-adjusted symbols
Derives a new Type by first deriving new symbols as in deriveSymbols, then performing the same oldSyms => newSyms substitution on tpe
as is performed on the symbol infos in deriveSymbols.
the prototypical symbols
the function to create new symbols
the prototypical type
the new symbol-substituted type
Derives a new Type by first deriving new symbols as in deriveSymbols2, then performing the same oldSyms => newSyms substitution on tpe
as is performed on the symbol infos in deriveSymbols.
the prototypical symbols
arguments to be passed to symFn together with symbols from syms (must be same length)
the function to create new symbols based on as
the prototypical type
the new symbol-substituted type
Derives a new Type by instantiating the given list of symbols as WildcardTypes.
the symbols to replace
the new type with WildcardType replacing those syms
dev-warns if dev-warning is enabled and cond
is true; no-op otherwise
Ensure that given tree has no positions that overlap with any of the positions of others
. This is done by shortening the range, assigning TransparentPositions to some of the nodes in tree
or focusing on the position.
Perform given operation at given phase.
A creator for existential types. This generates:
tpe1 where { tparams }
where tpe1
is the result of extrapolating tpe
with respect to tparams
. Extrapolating means that type variables in tparams
occurring in covariant positions are replaced by upper bounds, (minus any SingletonClass markers), type variables in tparams
occurring in contravariant positions are replaced by upper bounds, provided the resulting type is legal with regard to stability, and does not contain any type variable in tparams
.
The abstraction drops all type parameters that are not directly or indirectly referenced by type tpe1
. If there are no remaining type parameters, simply returns result type tpe
.
Given a set rawSyms
of term- and type-symbols, and a type tp
, produce a set of fresh type parameters and a type so that it can be abstracted to an existential type. Every type symbol T
in rawSyms
is mapped to a clone. Every term symbol x
of type T
in rawSyms
is given an associated type symbol of the following form:
type x.type <: T with Singleton
The name of the type parameter is x.type
, to produce nice diagnostics. The Singleton parent ensures that the type parameter is still seen as a stable type. Type symbols in rawSyms are fully replaced by the new symbols. Term symbols are also replaced, except for term symbols of an Ident tree, where only the type of the Ident is changed.
Perform operation p
on arguments tp1
, arg2
and print trace of computation.
If option explaintypes
is set, print a subtype trace for op(found, required)
.
If option explaintypes
is set, print a subtype trace for found <:< required
.
The greatest lower bound of a list of types (as determined by <:<
).
The greatest lower bound of a list of types (as determined by <:<
), which have been normalized with regard to elimSuper
.
Again avoiding calling length, but the lengthCompare interface is clunky.
Members which can be imported into other scopes.
The set of all installed infotransformers.
Create a class and a companion object, enter in enclosing scope, and initialize with a lazy type completer.
The owner of the newly created class and object
The simple name of the newly created class
The completer to be used to set the info of the class and the module
A creator for intersection type where intersections of a single type are replaced by the type itself.
A creator for intersection type where intersections of a single type are replaced by the type itself, and repeated parent classes are merged.
!!! Repeated parent classes are not merged - is this a bug in the comment or in the code?
Are we later than given phase in compilation?
Declares that this is a runtime reflection universe.
This means that we can make certain assumptions to optimize the universe. For example, we may auto-initialize symbols on flag and annotation requests (see shouldTriggerCompleter
below for more details).
On the other hand, this also means that usage scenarios of the universe will differ from the conventional ones. For example, we have to do additional cleanup in order to prevent memory leaks: http://groups.google.com/group/scala-internals/browse_thread/thread/eabcf3d406dab8b2.
Does this type have a prefix that begins with a type variable, or is it a refinement type? For type prefixes that fulfil this condition, type selections with the same name of equal (as determined by =:=
) prefixes are considered equal in regard to =:=
.
def isNonValueType(tp: Type) = !isValueElseNonValue(tp)
Is intersection of given types populated? That is, for all types tp1, tp2 in intersection for all common base classes bc of tp1 and tp2 let bt1, bt2 be the base types of tp1, tp2 relative to class bc Then: bt1 and bt2 have the same prefix, and any corresponding non-variant type arguments of bt1 and bt2 are the same
Might the given symbol be important when calculating the prefix of a type? When tp.asSeenFrom(pre, clazz) is called on tp
, the result will be tp
unchanged if pre
is trivial and clazz
is a symbol such that isPossiblePrefix(clazz) == false.
Is type tp a raw type?
Do tp1
and tp2
denote equivalent types?
Are tps1
and tps2
lists of pairwise equivalent types?
This appears to be equivalent to tp.isInstanceof[SingletonType], except it excludes FoldableConstantTypes.
This method should be equivalent to tree.hasSymbolField, but that method doesn't do us any good when we're unpickling because we need to know based on the Int tag - the tree doesn't exist yet. Thus, this method is documentation only.
This is defined and named as it is because the goal is to exclude source level types which are not value types (e.g. MethodType) without excluding necessary internal types such as WildcardType. There are also non-value types which can be used as type arguments (e.g. type constructors.)
Do type arguments targs
conform to formal parameters tparams
?
Used by the GenBCode backend to lookup type names that are known to already exist. This method might be invoked in a multi-threaded setting. Invoking newTypeName instead might be unsafe.
can-multi-thread: names are added to the hash tables only after they are fully constructed.
The least upper bound wrt <:< of a list of types
The maximum allowable depth of lubs or glbs over types ts
.
Given a matrix tsBts
whose columns are basetype sequences (and the symbols tsParams
that should be interpreted as type parameters in this matrix), compute its least sorted upwards closed upper bound relative to the following ordering <= between lists of types:
xs <= ys iff forall y in ys exists x in xs such that x <: y
like map2, but returns list xs
itself - instead of a copy - if function f
maps all elements to themselves.
A version of List#map, specialized for List, and optimized to avoid allocation if as
is empty
A deep map on a symbol's paramss.
A function implementing tp1
matches tp2
.
Are syms1
and syms2
parameter lists with pairwise equivalent types?
The maximum number of recursions allowed in toString
Compute lub (if variance == Covariant
) or glb (if variance == Contravariant
) of given list of types tps
. All types in tps
are typerefs or singletypes with the same symbol. Return x
if the computation succeeds with result x
. Return NoType
if the computation fails.
All these mm methods are "deep map" style methods for mapping etc. on a list of lists while avoiding unnecessary intermediate structures like those created via flatten.
These are all written in terms of List because we're trying to wring all the performance we can and List is used almost exclusively in the compiler, but people are branching out in their collections so here's an overload.
Returns the mirror that loaded given symbol
1. If owner
is a package class (but not the empty package) and name
is a term name, make a new package <owner>.<name>, otherwise return NoSymbol. Exception: If owner is root and a java class with given name exists, create symbol in empty package instead 2. If owner
is the scala package and name
designates a phantom class, return the corresponding class symbol and enter it into this mirror's ScalaPackage.
A more persistent version of Type#memberType
which does not require that the symbol is a direct member of the prefix.
For instance:
class C[T] { sealed trait F[A] object X { object S1 extends F[T] } class S2 extends F[T] } object O extends C[Int] { def foo(f: F[Int]) = f match {...} // need to enumerate sealed subtypes of the scrutinee here. } class S3 extends O.F[String] nestedMemberType(<S1>, <O.type>, <C>) = O.X.S1.type nestedMemberType(<S2>, <O.type>, <C>) = O.S2.type nestedMemberType(<S3>, <O.type>, <C>) = S3.type
The symbol of the subtype
The prefix from which the symbol is seen
Hook to define what showCode(...)
means.
A creator for existential types which flattens nested existentials.
Create a new free term. Its owner is NoSymbol.
Create a new free type. Its owner is NoSymbol.
Creates a lazy tree copier.
Create a new scope nested in another one with which it shares its elements
Hook to define what showRaw(...)
means.
Create a new scope
Create a new scope with given initial elements
Creates a strict tree copier.
Create a term name from the UTF8 encoded bytes in bs[offset..offset+len-1].
Create a term name from string.
Create a term name from the characters in cs[offset..offset+len-1]. TODO - have a mode where name validation is performed at creation time (e.g. if a name has the string "$class" in it, then fail if that string is not at the very end.)
the length of the name. Negative lengths result in empty names.
Create a term name from the characters in cs[offset..offset+len-1].
Hook to define what show(...)
means.
Create a type name from the UTF8 encoded bytes in bs[offset..offset+len-1].
Create a type name from the characters in cs[offset..offset+len-1].
Create a type name from string.
Members of the given class, other than those inherited from Any or AnyRef.
if there's a package
member object in pkgClass
, enter its members into it.
The canonical creator for OverloadedTypes.
Compute an existential type from hidden symbols hidden
and type tp
.
The symbols that will be existentially abstracted
The original type
The owner for Java raw types.
The phase identifier of the given period.
The phase associated with given period.
The phase which has given index as identifier.
Local symbols only. The assessment of locality depends on convoluted conditions which depends in part on the root symbol being pickled, so it cannot be reproduced here. The pickler tags at stake are EXTMODCLASSref and EXTref. Those tags are never produced here - such symbols must be excluded prior to calling this method.
Adds backticks if the name is a scala keyword.
The raw to existential map converts a raw type to an existential type. It is necessary because we might have read a raw type of a parameterized Java class from a class file. At the time we read the type the corresponding class file might still not be read, so we do not know what the type parameters of the type are. Therefore the conversion of raw types to existential types might not have taken place in ClassFileParser.sigToType (where it is usually done).
Mark given identifier as a reference to a captured variable itself suppressing dereferencing with the elem
field.
The canonical creator for a refined type with an initially empty scope.
the canonical creator for a refined type with a given scope
Use reify
to produce the abstract syntax tree representing a given Scala expression.
For example:
val five = reify{ 5 } // Literal(Constant(5)) reify{ 5.toString } // Apply(Select(Literal(Constant(5)), TermName("toString")), List()) reify{ five.splice.toString } // Apply(Select(five, TermName("toString")), List())
The produced tree is path dependent on the Universe reify
was called from.
Use scala.reflect.api.Exprs#Expr.splice to embed an existing expression into a reify
call. Use Expr to turn a Tree into an expression that can be spliced.
Remove all annotation checkers
Repack existential types, otherwise they sometimes get unpacked in the wrong location (type inference comes up with an unexpected skolem)
The root mirror of this universe. This mirror contains standard Scala classes and types such as Any
, AnyRef
, AnyVal
, Nothing
, Null
, and all classes loaded from scala-library, which are shared across all mirrors within the enclosing universe.
The run identifier of the given period.
Creates a runtime reflection mirror from a JVM classloader.
For more information about Mirrors
s, see scala.reflect.api.Mirrors or the Reflection Guide: Mirrors
True if two lists have the same length. Since calling length on linear sequences is O(n), it is an inadvisable way to test length equality.
Does this set of types have the same weak lub as it does regular lub? This is exposed so lub callers can discover whether the trees they are typing will may require further adaptation. It may return false negatives, but it will not return false positives.
Renders a prettified representation of a position.
Renders a prettified representation of a flag set.
Renders a prettified representation of a name.
Renders a representation of a reflection artifact as desugared Scala code.
Renders the code of the passed tree, so that: 1) it can be later compiled by scalac retaining the same meaning, 2) it looks pretty. #1 is available for unattributed trees and attributed trees #2 is more or less okay indentation-wise, but at the moment there's a lot of desugaring left in place, and that's what we plan to improve in the future. printTypes, printIds, printPositions options have the same meaning as for TreePrinter printRootPkg option is available only for attributed trees.
Renders a string that represents a declaration of this symbol written in Scala.
Renders internal structure of a position.
Renders internal structure of a flag set.
Renders internal structure of a name.
Renders internal structure of a reflection artifact as the visualization of a Scala syntax tree.
The canonical creator for single-types
Solve constraint collected in types tvars
.
All type variables to be instantiated.
The type parameters corresponding to tvars
Function to extract variances of type parameters; we need to reverse solution direction for all contravariant variables.
When true
search for max solution else min.
A minimal type list which has a given list of types as its base type sequence
Does member symLo
of tpLo
have a stronger type than member symHi
of tpHi
?
Some statistics (normally disabled) set with -Ystatistics
Dump each symbol to stdout after shutdown.
The standard (lazy) tree copier.
By default trees are printed with show
The maximum depth of type tp
A creator for a type functions, assuming the type parameters tps already have the right owner.
Shortcut for implicitly[TypeTag[T]].tpe
The canonical creator for typerefs todo: see how we can clean this up a bit
Shortcut for implicitly[TypeTag[T]]
Delegate for a TypeTree symbol. This operation is unsafe because it may trigger type checking when forcing the type symbol of the underlying type.
A list of the typevars in a type.
Adds the @uncheckedBound annotation if the given tp
has type arguments
A marker object for a base type sequence that's no yet computed. used to catch inheritance cycles
Assert that packages have package scopes
Compute variance of type parameter tparam
in type tp
.
Compute variance of type parameter tparam
in all types tps
.
If the arguments are all numeric value types, the numeric lub according to the weak conformance spec. If any argument has type annotations, take the lub of the unannotated type and call the analyzerPlugin method annotationsLub so it can be further altered. Otherwise, the regular lub.
Shortcut for implicitly[WeakTypeTag[T]].tpe
Shortcut for implicitly[WeakTypeTag[T]]
Execute op
while printing a trace of the operations on types executed.
A position that wraps the non-empty set of trees. The point of the wrapping position is the point of the first trees' position. If some of the trees are non-synthetic, returns a range position enclosing the non-synthetic trees Otherwise returns a synthetic offset position to point.
A position that wraps a set of trees. The point of the wrapping position is the point of the default position. If some of the trees are ranges, returns a range position enclosing all ranges Otherwise returns default position that is either focused or not.
Hook for extensions
Provides an extension hook for the transformation strategy. Future-proofs against new node types.
The constructor/extractor for Alternative
instances.
The constructor/extractor for Annotated
instances.
The constructor/extractor for AnnotatedType
instances.
The constructor/extractor for Annotation
instances.
The constructor/extractor for AppliedTypeTree
instances.
The constructor/extractor for Apply
instances.
The constructor/extractor for Assign
instances.
When present, indicates that the host Ident
has been created from a backquoted identifier.
The constructor/extractor for Bind
instances.
The constructor/extractor for Block
instances.
The constructor/extractor for BoundedWildcardType
instances.
The constructor/extractor for CaseDef
instances.
The constructor/extractor for ClassDef
instances.
The constructor/extractor for ClassInfoType
instances.
The constructor/extractor for CompoundTypeTree
instances.
A writer that writes to the current Console and is sensitive to replacement of the Console's output stream.
The constructor/extractor for Constant
instances.
The constructor/extractor for ConstantType
instances.
The constructor/extractor for DefDef
instances.
The empty scope (immutable).
The empty tree
An object representing an erroneous type
The constructor/extractor for ExistentialType
instances.
The constructor/extractor for ExistentialTypeTree
instances.
A module that contains all possible values that can constitute flag sets.
Identifies trees are either result or intermediate value of for loop desugaring.
The constructor/extractor for Function
instances.
A creator and extractor for type parameterizations that strips empty type parameter lists. Use this factory method to indicate the type has kind * (it's a polymorphic value)
The constructor/extractor for Ident
instances.
The constructor/extractor for If
instances.
The constructor/extractor for Import
instances.
The constructor/extractor for ImportSelector
instances.
Attached to a class symbol to indicate that its children have been observed via knownDirectSubclasses. Children added subsequently will trigger an error to indicate that the earlier observation was incomplete.
The constructor/extractor for LabelDef
instances.
The constructor/extractor for Literal
instances.
The constructor/extractor for Match
instances.
The constructor/extractor for MethodType
instances.
The constructor/extractor for Modifiers
instances.
The constructor/extractor for ModuleDef
instances.
The constructor/extractor for NamedArg
instances.
The constructor/extractor for New
instances.
An object representing a non-existing prefix
An object representing a non-existing type
A pattern binding exempt from unused warning.
Its host Ident
has been created from a pattern2 binding, case x @ p
. In the absence of named parameters in patterns, allows nuanced warnings for unused variables. Hence, case X(x = _) =>
would not warn; for now, case X(x @ _) =>
is documentary if x is unused.
The constructor/extractor for NullaryMethodType
instances.
Attached to a local class that has its outer field elided. A null
constant may be passed in place of the outer parameter, can help callers to avoid capturing the outer instance.
The constructor/extractor for PackageDef
instances.
Indicates that a ValDef
was synthesized from a pattern definition, val P(x)
.
The constructor/extractor for PolyType
instances.
The constructor/extractor for RefTree
instances.
The constructor/extractor for RefinedType
instances.
The constructor/extractor for Return
instances.
The constructor/extractor for Select
instances.
The constructor/extractor for SelectFromTypeTree
instances.
The constructor/extractor for SingleType
instances.
The constructor/extractor for SingletonTypeTree
instances.
The constructor/extractor for Star
instances.
The constructor/extractor for Super
instances.
The constructor/extractor for SuperType
instances.
Identifies unit constants which were inserted by the compiler (e.g. gen.mkBlock)
The constructor/extractor for Template
instances.
The constructor/extractor for TermName
instances.
The constructor/extractor for This
instances.
The constructor/extractor for ThisType
instances.
The constructor/extractor for Throw
instances.
Extracts the type of the thrown exception from an AnnotationInfo.
Supports both “old-style” @throws(classOf[Exception])
as well as “new-style” @throws[Exception]("cause")
annotations.
The constructor/extractor for Try
instances.
The constructor/extractor for TypeApply
instances.
The constructor/extractor for TypeBounds
instances.
The constructor/extractor for TypeBoundsTree
instances.
The constructor/extractor for TypeDef
instances.
The constructor/extractor for TypeName
instances.
The constructor/extractor for TypeRef
instances.
The constructor/extractor for TypeTree
instances.
The constructor/extractor for Typed
instances.
The constructor/extractor for UnApply
instances.
The constructor/extractor for ValDef
instances.
An object representing an unknown type, used during type inference. If you see WildcardType outside of inference it is almost certainly a bug.
Type with all top-level occurrences of abstract types replaced by their bounds
Java binary names, like scala/runtime/Nothing$.
A value containing all standard definitions in DefinitionsApi
Turn any T* types into Seq[T] except when in method parameter position.
Remove any occurrence of type <singleton> from this type and its parents
For fully qualified type names.
Starting from a Symbol (sym) or a Type (tpe), infer the kind that classifies it (sym.tpeHK/tpe).
There's a whole lot of implementation detail which is nothing but noise when you are trying to see what's going on. This is my attempt to filter it out.
An empty deferred value definition corresponding to: val _: _ This is used as a placeholder in the self
parameter Template if there is no definition of a self value of self type.
Normalize any type aliases within this type (@see Type#normalize). Note that this depends very much on the call to "normalize", not "dealias", so it is no longer carries the too-stealthy name "deAlias".
An empty superclass constructor call corresponding to: super.<init>() This is used as a placeholder in the primary constructor body in class templates to denote the insertion point of a call to superclass constructor after the typechecker figures out the superclass of a given template.
Light color wrappers.
A map to convert each occurrence of a type variable to its origin.
Get rid of BoundedWildcardType where variance allows us to do so. Invariant: wildcardExtrapolation(tp) =:= tp
For example, the MethodType given by def bla(x: (_ >: String)): (_ <: Int)
is both a subtype and a supertype of def bla(x: String): Int
.
A map to convert every occurrence of a wildcard type to a fresh type variable
© 2002-2019 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://www.scala-lang.org/api/2.13.0/scala-reflect/scala/reflect/runtime/JavaUniverse.html
An implementation of scala.reflect.api.Universe for runtime reflection using JVM classloaders.
Should not be instantiated directly, use scala.reflect.runtime.universe instead.