Applications in Scala can have one of the following shapes:
Applications in Scala can have one of the following shapes:
1) naked core: Ident(_) or Select(_, _) or basically anything else 2) naked core with targs: TypeApply(core, targs) or AppliedTypeTree(core, targs) 3) apply or several applies wrapping a core: Apply(core, _), or Apply(Apply(core, _), _), etc
This class provides different ways to decompose applications and simplifies their analysis.
***Examples*** (TypeApply in the examples can be replaced with AppliedTypeTree)
Ident(foo): * callee = Ident(foo) * core = Ident(foo) * targs = Nil * argss = Nil
TypeApply(foo, List(targ1, targ2...)) * callee = TypeApply(foo, List(targ1, targ2...)) * core = foo * targs = List(targ1, targ2...) * argss = Nil
Apply(foo, List(arg1, arg2...)) * callee = foo * core = foo * targs = Nil * argss = List(List(arg1, arg2...))
Apply(Apply(foo, List(arg21, arg22, ...)), List(arg11, arg12...)) * callee = foo * core = foo * targs = Nil * argss = List(List(arg11, arg12...), List(arg21, arg22, ...))
Apply(Apply(TypeApply(foo, List(targs1, targs2, ...)), List(arg21, arg22, ...)), List(arg11, arg12...)) * callee = TypeApply(foo, List(targs1, targs2, ...)) * core = foo * targs = Nil * argss = List(List(arg11, arg12...), List(arg21, arg22, ...))
Some handy extractors for spotting trees through the the haze of irrelevant braces: i.e.
Some handy extractors for spotting trees through the the haze of irrelevant braces: i.e. Block(Nil, SomeTree) should not keep us from seeing SomeTree.
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.
Destructures applications into important subparts described in Applied
class,
namely into: core, targs and argss (in the specified order).
Destructures applications into important subparts described in Applied
class,
namely into: core, targs and argss (in the specified order).
Trees which are not applications are also accepted. Their callee and core will be equal to the input, while targs and argss will be Nil.
The provided extractors don't expose all the API of the Applied
class.
For advanced use, call dissectApplied
explicitly and use its methods instead of pattern matching.
Locates the synthetic Apply node corresponding to an extractor's call to unapply (unwrapping nested Applies) and returns the fun part of that Apply.
Locates the synthetic Apply node corresponding to an extractor's call to unapply (unwrapping nested Applies) and returns the fun part of that Apply.
Is tree
either a non-volatile type,
or a path that does not include any of:
Is tree
either a non-volatile type,
or a path that does not include any of:
Such a tree is a suitable target for type selection.
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
.
Translates an Assign(_, _) node to AssignOrNamedArg(_, _) if the lhs is a simple ident.
Translates an Assign(_, _) node to AssignOrNamedArg(_, _) if the lhs is a simple ident. Otherwise returns unchanged.
Does this CaseDef catch Throwable?
Does this CaseDef catch Throwable?
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
Returns a wrapper that knows how to destructure and analyze applications.
Returns a wrapper that knows how to destructure and analyze applications.
//------------------------ => effectivePatternArity(args) case Extractor(a) => 1 case Extractor(a, b) => 2 case Extractor((a, b)) => 2 case Extractor(a @ (b, c)) => 2
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
The first constructor definitions in stats
The first constructor definitions in stats
The arguments to the first constructor in stats
.
The arguments to the first constructor in stats
.
Does list of trees start with a definition of a class of module with given name (ignoring imports)
Does list of trees start with a definition of a class of module with given name (ignoring imports)
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
Is tree
's type volatile? (Ignored if its symbol has the @uncheckedStable annotation.)
Is tree
's type volatile? (Ignored if its symbol has the @uncheckedStable annotation.)
The hashCode method for reference types.
Is tpt a by-name parameter type of the form => T?
Is tpt a by-name parameter type of the form => T?
Is this pattern node a catch-all or type-test pattern?
Is this pattern node a catch-all or type-test pattern?
Is tree a declaration or type definition?
Is tree a declaration or type definition?
Is this pattern node a catch-all (wildcard or variable) pattern?
Is this pattern node a catch-all (wildcard or variable) pattern?
Is tree an expression which can be inlined without affecting program semantics?
Is tree an expression which can be inlined without affecting program semantics?
Note that this is not called "isExprPure" since purity (lack of side-effects) is not the litmus test. References to modules and lazy vals are side-effecting, both because side-effecting code may be executed and because the first reference takes a different code path than all to follow; but they are safe to inline because the expression result from evaluating them is always the same.
Is this case guarded?
Is this case guarded?
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.
Is tree legal as a member definition of an interface?
Is tree legal as a member definition of an interface?
Is name a left-associative operator?
Is name a left-associative operator?
Is tree
a path, defined as follows? (Spec: 3.1 Paths)
Is tree
a path, defined as follows? (Spec: 3.1 Paths)
- The empty path ε (which cannot be written explicitly in user programs). - C.this, where C references a class. - p.x where p is a path and x is a stable member of p. - C.super.x or C.super[M].x where C references a class and x references a stable member of the super class or designated parent class M of C.
NOTE: Trees with errors are (mostly) excluded.
Path ::= StableId | [id ‘.’] this
Is tree a pure (i.e.
Is tree a pure (i.e. non-side-effecting) definition?
As if the name of the method didn't give it away, this logic is designed around issuing helpful warnings and minimizing spurious ones.
As if the name of the method didn't give it away, this logic is designed around issuing helpful warnings and minimizing spurious ones. That means don't reuse it for important matters like inlining decisions.
Is tpt a vararg type of the form T* ?
Is tpt a vararg type of the form T* ?
Is tree a self constructor call this(...)? I.e.
Is tree a self constructor call this(...)? I.e. a call to a constructor of the same object?
Is tree a self or super constructor call?
Is tree a self or super constructor call?
Is this pattern node a sequence-valued pattern?
Is this pattern node a sequence-valued pattern?
Is tree
a stable identifier, a path which ends in an identifier?
Is tree
a stable identifier, a path which ends in an identifier?
StableId ::= id | Path ‘.’ id | [id ’.’] ‘super’ [‘[’ id ‘]’] ‘.’ id
Is tree
admissible as a stable identifier pattern (8.1.5 Stable Identifier Patterns)?
Is tree
admissible as a stable identifier pattern (8.1.5 Stable Identifier Patterns)?
We disregard volatility, as it's irrelevant in patterns (SI-6815)
Assuming sym
is a member of tree
, is it a "stable member"?
Assuming sym
is a member of tree
, is it a "stable member"?
Stable members are packages or members introduced by object definitions or by value definitions of non-volatile types (§3.6).
Is this tree a Star(_) after removing bindings?
Is this tree a Star(_) after removing bindings?
Is tree a super constructor call?
Is tree a super constructor call?
a Match(Typed(_, tpt), _) must be translated into a switch if isSwitchAnnotation(tpt.tpe)
a Match(Typed(_, tpt), _) must be translated into a switch if isSwitchAnnotation(tpt.tpe)
Is this CaseDef synthetically generated, e.g.
Is this CaseDef synthetically generated, e.g. by MatchTranslation.translateTry
?
Is this pattern node a synthetic catch-all case, added during PartialFunction synthesis before we know whether the user provided cases are exhaustive.
Is this pattern node a synthetic catch-all case, added during PartialFunction synthesis before we know whether the user provided cases are exhaustive.
Is tree a variable pattern?
Is tree a variable pattern?
Does this tree represent an irrefutable pattern match
in the position for { <tree> <- expr }
based only
on information at the parser
phase? To qualify, there
may be no subtree that will be interpreted as a
Stable Identifier Pattern, nor any type tests, even
on TupleN.
Does this tree represent an irrefutable pattern match
in the position for { <tree> <- expr }
based only
on information at the parser
phase? To qualify, there
may be no subtree that will be interpreted as a
Stable Identifier Pattern, nor any type tests, even
on TupleN. See SI-6968.
For instance:
(foo @ (bar @ _)) = 0
is a not a variable pattern; if only binds names.
The following are not variable patterns.
`bar` Bar (a, b) _: T
If the pattern is a simple identifier, it is always a variable pattern. For example, the following introduce new bindings:
for { X <- xs } yield X for { `backquoted` <- xs } yield `backquoted`
Note that this differs from a case clause:
object X scrut match { case X => // case _ if scrut == X }
Background: https://groups.google.com/d/msg/scala-internals/qwa_XOw_7Ks/IktkeTBYqg0J
Is tree a mutable variable, or the getter of a mutable field?
Is tree a mutable variable, or the getter of a mutable field?
Is the argument a wildcard argument of the form _
or x @ _
?
Is the argument a wildcard argument of the form _
or x @ _
?
Is this argument node of the form <expr> : _* ?
Is this argument node of the form <expr> : _* ?
Does this argument list end with an argument of the form <expr> : _* ?
Does this argument list end with an argument of the form <expr> : _* ?
Is the argument a wildcard star type of the form _*
?
Is the argument a wildcard star type of the form _*
?
can this type be a type pattern
can this type be a type pattern
Is symbol potentially a getter of a variable?
Is symbol potentially a getter of a variable?
Equivalent to !(this eq that)
.
Equivalent to !(this eq that)
.
true
if the argument is not a reference to the receiver object; false
otherwise.
Is this file the body of a compilation unit which should not have Predef imported?
Is this file the body of a compilation unit which should not have Predef imported?
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
The value definitions marked PRESUPER in this statement sequence
The value definitions marked PRESUPER in this statement sequence
Strips layers of .asInstanceOf[T]
/ _.$asInstanceOf[T]()
from an expression
Strips layers of .asInstanceOf[T]
/ _.$asInstanceOf[T]()
from an expression
Named arguments can transform a constructor call into a block, e.g.
Named arguments can transform a constructor call into a block, e.g. <init>(b = foo, a = bar) is transformed to { val x$1 = foo val x$2 = bar <init>(x$2, x$1) }
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.
If this tree has type parameters, those.
If this tree has type parameters, those. Otherwise Nil.
The underlying pattern ignoring any bindings
The underlying pattern ignoring any bindings