Syntactic conveniences for additional internal APIs for trees, symbols and types
A creator for AnnotatedType
types.
This symbol cast to a free term symbol.
This symbol cast to a free term symbol.
ScalaReflectionException
if isFreeTerm
is false.
This symbol cast to a free type symbol.
This symbol cast to a free type symbol.
ScalaReflectionException
if isFreeType
is false.
A creator for BoundedWildcardType
types.
A factory method for ClassDef
nodes.
A creator for ClassInfoType
types.
A creator for ConstantType
types.
Creates an importer that moves reflection artifacts between universes.
Creates an importer that moves reflection artifacts between universes.
If this symbol is a skolem, its corresponding type parameter, otherwise the symbol itself.
If this symbol is a skolem, its corresponding type parameter, otherwise the symbol itself.
To quote Martin Odersky, skolems are synthetic type "constants" that are copies of existentially bound or universally bound type variables. E.g. if one is inside the right-hand side of a method:
def foo[T](x: T) = ... foo[List[T]]....
the skolem named T
refers to the unknown type instance of T
when foo
is called. It needs to be different
from the type parameter because in a recursive call as in the foo[List[T]]
above the type parameter gets
substituted with List[T]
, but the type skolem stays what it is.
The other form of skolem is an existential skolem. Say one has a function
def bar(xs: List[T] forSome { type T }) = xs.head
then each occurrence of xs
on the right will have type List[T']
where T'
is a fresh copy of T
.
A factory method for DefDef
nodes.
A factory method for DefDef
nodes.
A factory method for DefDef
nodes.
A factory method for DefDef
nodes.
A factory method for DefDef
nodes.
A creator for existential types.
A creator for existential types. This generates:
tpe1 where { tparams }
where tpe1
is the result of extrapolating tpe
with regard 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
.
A creator for ExistentialType
types.
Returns internal flags associated with the symbol.
Extracts free term symbols from a tree that is reified or contains reified subtrees.
Extracts free type symbols from a tree that is reified or contains reified subtrees.
Calls initialize on all the symbols that the scope consists of.
Calls initialize on all the value and type parameters of the type.
Calls initialize on the owner and all the value and type parameters of the symbol.
Forces all outstanding completers associated with this symbol.
Forces all outstanding completers associated with this symbol. After this call returns, the symbol becomes immutable and thread-safe.
A creator for intersection type where intersections of a single type are replaced by the type itself, and repeated parent classes are merged.
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?
A creator for intersection type where intersections of a single type are replaced by the type itself.
Does this symbol or its underlying type represent a typechecking error?
Does this symbol represent a free term captured by reification?
If yes, isTerm
is also guaranteed to be true.
Does this symbol represent a free type captured by reification?
If yes, isType
is also guaranteed to be true.
Does this symbol represent the definition of a skolem? Skolems are used during typechecking to represent type parameters viewed from inside their scopes.
A factory method for LabelDef
nodes.
A creator for MethodType
types.
A factory method for ModuleDef
nodes.
Create a new scope with the given initial elements.
A creator for NullaryMethodType
types.
A creator for type parameterizations that strips empty type parameter lists.
A creator for type parameterizations that strips empty type parameter lists. Use this factory method to indicate the type has kind * (it's a polymorphic value) until we start tracking explicit kinds equivalent to typeFun (except that the latter requires tparams nonEmpty).
A creator for RefinedType
types.
A creator for RefinedType
types.
A creator for RefinedType
types.
A creator for RefinedType
types.
A creator for RefinedType
types.
This is an internal implementation module.
A creator for SingleType
types.
Substitute symbols in to
for corresponding occurrences of references to
symbols from
in this type.
Substitute given tree to
for occurrences of nodes that represent
C.this
, where C
refers to the given class clazz
.
Substitute types in to
for corresponding occurrences of references to
symbols from
in this tree.
A creator for SuperType
types.
A creator for ThisType
types.
A creator for TypeBounds
types.
A factory method for TypeDef
nodes.
A factory method for TypeDef
nodes.
A creator for TypeRef
types.
A factory method for ValDef
nodes.
A factory method for ValDef
nodes.
Test two objects for inequality.
Test two objects for inequality.
true
if !(this == that), false otherwise.
Equivalent to x.hashCode
except for boxed numeric types and null
.
Equivalent to x.hashCode
except for boxed numeric types and null
.
For numerics, it returns a hash value which is consistent
with value equality: if two value type instances compare
as true, then ## will produce the same hash value for each
of them.
For null
returns a hashcode where null.hashCode
throws a
NullPointerException
.
a hash value consistent with ==
The expression x == that
is equivalent to if (x eq null) that eq null else x.equals(that)
.
The expression x == that
is equivalent to if (x eq null) that eq null else x.equals(that)
.
true
if the receiver object is equivalent to the argument; false
otherwise.
Cast the receiver object to be of type T0
.
Cast the receiver object to be of type T0
.
Note that the success of a cast at runtime is modulo Scala's erasure semantics.
Therefore the expression 1.asInstanceOf[String]
will throw a ClassCastException
at
runtime, while the expression List(1).asInstanceOf[List[String]]
will not.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the requested type.
the receiver object.
ClassCastException
if the receiver object is not an instance of the erasure of type T0
.
Create a copy of the receiver object.
Create a copy of the receiver object.
The default implementation of the clone
method is platform dependent.
a copy of the receiver object.
not specified by SLS as a member of AnyRef
Tests whether the argument (that
) is a reference to the receiver object (this
).
Tests whether the argument (that
) is a reference to the receiver object (this
).
The eq
method implements an equivalence relation on
non-null instances of AnyRef
, and has three additional properties:
x
and y
of type AnyRef
, multiple invocations of
x.eq(y)
consistently returns true
or consistently returns false
.x
of type AnyRef
, x.eq(null)
and null.eq(x)
returns false
.null.eq(null)
returns true
. When overriding the equals
or hashCode
methods, it is important to ensure that their behavior is
consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2
), they
should be equal to each other (o1 == o2
) and they should hash to the same value (o1.hashCode == o2.hashCode
).
true
if the argument is a reference to the receiver object; false
otherwise.
The equality method for reference types.
Called by the garbage collector on the receiver object when there are no more references to the object.
Called by the garbage collector on the receiver object when there are no more references to the object.
The details of when and if the finalize
method is invoked, as
well as the interaction between finalize
and non-local returns
and exceptions, are all platform dependent.
not specified by SLS as a member of AnyRef
A representation that corresponds to the dynamic class of the receiver object.
A representation that corresponds to the dynamic class of the receiver object.
The nature of the representation is platform dependent.
a representation that corresponds to the dynamic class of the receiver object.
not specified by SLS as a member of AnyRef
The hashCode method for reference types.
Test whether the dynamic type of the receiver object is T0
.
Test whether the dynamic type of the receiver object is T0
.
Note that the result of the test is modulo Scala's erasure semantics.
Therefore the expression 1.isInstanceOf[String]
will return false
, while the
expression List(1).isInstanceOf[List[String]]
will return true
.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the specified type.
true
if the receiver object is an instance of erasure of type T0
; false
otherwise.
Convert a scala.reflect.Manifest to a scala.reflect.api.TypeTags#TypeTag.
Convert a scala.reflect.Manifest to a scala.reflect.api.TypeTags#TypeTag.
Compiler usually generates these conversions automatically, when a manifest for a type T
is in scope,
and an implicit of type TypeTag[T]
is requested, but this method can also be called manually.
For example:
manifestToTypeTag(scala.reflect.runtime.currentMirror, implicitly[Manifest[String]])
Equivalent to !(this eq that)
.
Equivalent to !(this eq that)
.
true
if the argument is not a reference to the receiver object; false
otherwise.
Wakes up a single thread that is waiting on the receiver object's monitor.
Wakes up a single thread that is waiting on the receiver object's monitor.
not specified by SLS as a member of AnyRef
Wakes up all threads that are waiting on the receiver object's monitor.
Wakes up all threads that are waiting on the receiver object's monitor.
not specified by SLS as a member of AnyRef
Creates a String representation of this object.
Creates a String representation of this object. The default representation is platform dependent. On the java platform it is the concatenation of the class name, "@", and the object's hashcode in hexadecimal.
a String representation of the object.
Convert a scala.reflect.api.TypeTags#TypeTag to a scala.reflect.Manifest.
Convert a scala.reflect.api.TypeTags#TypeTag to a scala.reflect.Manifest.
Compiler usually generates these conversions automatically, when a type tag for a type T
is in scope,
and an implicit of type Manifest[T]
is requested, but this method can also be called manually.
For example:
typeTagToManifest(scala.reflect.runtime.currentMirror, implicitly[TypeTag[String]])
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) providesuniverse.compat: InternalApi
, whereas compile-time API endpoints (instances of scala.reflect.macros.Context) providec.compat: ContextInternalApi
, which extendsInternalApi
with additional universe-specific and context-specific functionality.