Tree

dotty.tools.dotc.ast.Trees.Tree
abstract class Tree[+T <: Untyped](implicit src: SourceFile) extends Positioned, SrcPos, Product, Container, Showable

Trees take a parameter indicating what the type of their tpe field is. Two choices: Type or Untyped. Untyped trees have type Tree[Untyped].

Tree typing uses a copy-on-write implementation:

  • You can never observe a tpe which is null (throws an exception)
  • So when creating a typed tree with withType we can re-use the existing tree transparently, assigning its tpe field.
  • It is impossible to embed untyped trees in typed ones.
  • Typed trees can be embedded in untyped ones provided they are rooted in a TypedSplice node.
  • Type checking an untyped tree should remove all embedded TypedSplice nodes.

Attributes

Graph
Supertypes
trait Showable
trait Container
trait LinkSource
class Positioned
trait Cloneable
trait Product
trait Equals
trait SrcPos
class Object
trait Matchable
class Any
Show all
Known subtypes
class Block[T]
class XMLBlock
class CaseDef[T]
class DenotingTree[T]
trait DefTree[T]
class NamedDefTree[T]
class Bind[T]
class MemberDef[T]
class TypeDef[T]
class ValOrDefDef[T]
class DefDef[T]
class ValDef[T]
class EmptyValDef[T]
trait ValOrTypeDef[T]
class ModuleDef
class Template[T]
class ImportOrExport[T]
class Export[T]
class Import[T]
class NameTree[T]
class Labeled[T]
class RefTree[T]
class Ident[T]
class Select[T]
class SelectWithSig[T]
class This[T]
class TypeTree[T]
class InferredTypeTree[T]
class TermRefTree
class TypeRefTree
class Hole[T]
class Inlined[T]
class Literal[T]
class NamedArg[T]
class New[T]
trait PatternTree[T]
class Alternative[T]
class QuotePattern[T]
class UnApply[T]
class ProxyTree[T]
class Annotated[T]
class AppliedTypeTree[T]
class GenericApply[T]
class Apply[T]
class TypeApply[T]
class PackageDef[T]
class RefinedTypeTree[T]
class Super[T]
class Typed[T]
class Parens
class TypedSplice
class SeqLiteral[T]
class JavaSeqLiteral[T]
trait TermTree[T]
class Assign[T]
class Closure[T]
class If[T]
class InlineIf[T]
class Match[T]
class InlineMatch[T]
class Quote[T]
class Return[T]
class Splice[T]
class SplicePattern[T]
class Try[T]
class WhileDo[T]
class Thicket[T]
class EmptyTree[T]
trait TypTree[T]
class ByNameTypeTree[T]
class LambdaTypeTree[T]
class MatchTypeTree[T]
class TypeBoundsTree[T]
trait WithoutTypeOrPos[T]
class ExtMethods
class Function
class GenAlias
class GenFrom
class Into
class MacroTree
class OpTree
class InfixOp
class PostfixOp
class PrefixOp
class PolyFunction
class Tuple
Show all

Members list

Type members

Types

type ThisTree[T <: Untyped] <: Tree[T]

The type constructor at the root of the tree

The type constructor at the root of the tree

Attributes

Value members

Concrete methods

def denot(using Context): Denotation

The denotation referred to by this tree. Defined for DenotingTrees and ProxyTrees, NoDenotation for other kinds of trees

The denotation referred to by this tree. Defined for DenotingTrees and ProxyTrees, NoDenotation for other kinds of trees

Attributes

override def equals(that: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Equals -> Any
def foreachInThicket(op: (Tree[T]) => Unit): Unit

If this is a thicket, perform op on each of its trees otherwise, perform op ion tree itself.

If this is a thicket, perform op on each of its trees otherwise, perform op ion tree itself.

Attributes

final def hasType: Boolean

Does the tree have its type field set? Note: this operation is not referentially transparent, because it can observe the withType modifications. Should be used only in special circumstances (we need it for printing trees with optional type info).

Does the tree have its type field set? Note: this operation is not referentially transparent, because it can observe the withType modifications. Should be used only in special circumstances (we need it for printing trees with optional type info).

Attributes

override def hashCode(): Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
Any
def isDef: Boolean

Does this tree define a new symbol that is not defined elsewhere?

Does this tree define a new symbol that is not defined elsewhere?

Attributes

Is this tree either the empty tree or the empty ValDef or an empty type ident?

Is this tree either the empty tree or the empty ValDef or an empty type ident?

Attributes

Is this a legal part of a pattern which is not at the same time a term?

Is this a legal part of a pattern which is not at the same time a term?

Attributes

Does this tree represent a term?

Does this tree represent a term?

Attributes

Does this tree represent a type?

Does this tree represent a type?

Attributes

inline def orElse[U >: T <: Untyped](inline that: Tree[U]): Tree[U]

if this tree is the empty tree, the alternative, else this tree

if this tree is the empty tree, the alternative, else this tree

Attributes

def sameTree(that: Tree[_]): Boolean
final def symbol(using Context): Symbol

Shorthand for denot.symbol.

Shorthand for denot.symbol.

Attributes

def toList: List[Tree[T]]

Convert tree to a list. Gives a singleton list, except for thickets which return their element trees.

Convert tree to a list. Gives a singleton list, except for thickets which return their element trees.

Attributes

override def toText(printer: Printer): Text

The text representation of this showable element. This normally dispatches to a pattern matching method in Printers.

The text representation of this showable element. This normally dispatches to a pattern matching method in Printers.

Attributes

Definition Classes
final def tpe: T

The type of the tree. In case of an untyped tree, an UnAssignedTypeException is thrown. (Overridden by empty trees)

The type of the tree. In case of an untyped tree, an UnAssignedTypeException is thrown. (Overridden by empty trees)

Attributes

def treeSize: Int

The number of nodes in this tree

The number of nodes in this tree

Attributes

final def typeOpt: Type
def withType(tpe: Type)(using Context): ThisTree[Type]

Return a typed tree that's isomorphic to this tree, but has given type. (Overridden by empty trees)

Return a typed tree that's isomorphic to this tree, but has given type. (Overridden by empty trees)

Attributes

Inherited methods

final def allAttachments: List[(Key[_], Any)]

The list of all keys and values attached to this container.

The list of all keys and values attached to this container.

Attributes

Inherited from:
LinkSource
final def attachment[V](key: Key[V]): V

The attachment corresponding to key.

The attachment corresponding to key.

Attributes

Throws
NoSuchElementException

if no attachment with key exists

Inherited from:
LinkSource
final def attachmentOrElse[V](key: Key[V], default: V): V

The attachment corresponding to key, or default if no attachment with key exists.

The attachment corresponding to key, or default if no attachment with key exists.

Attributes

Inherited from:
LinkSource
def canEqual(that: Any): Boolean

Attributes

Inherited from:
Equals
def checkPos(nonOverlapping: Boolean)(using Context): Unit

Check that all positioned items in this tree satisfy the following conditions:

Check that all positioned items in this tree satisfy the following conditions:

  • Parent spans contain child spans
  • If item is a non-empty tree, it has a position

Attributes

Inherited from:
Positioned
def cloneIn(src: SourceFile): Positioned.this.type

Clone this node but assign it a fresh id which marks it as a node in file.

Clone this node but assign it a fresh id which marks it as a node in file.

Attributes

Inherited from:
Positioned

Attributes

Inherited from:
Positioned
def endPos(using ctx: Context): SourcePosition

Attributes

Inherited from:
SrcPos
def envelope(src: SourceFile, startSpan: Span): Span

The union of startSpan and the spans of all positioned children that have the same source as this node, except that Inlined nodes only consider their call child.

The union of startSpan and the spans of all positioned children that have the same source as this node, except that Inlined nodes only consider their call child.

Side effect: Any descendants without spans have but with the same source as this node have their span set to the end position of the envelope of all children to the left, or, if that one does not exist, to the start position of the envelope of all children to the right.

Attributes

Inherited from:
Positioned
def fallbackToText(printer: Printer): Text

A fallback text representation, if the pattern matching in Printers does not have a case for this showable element

A fallback text representation, if the pattern matching in Printers does not have a case for this showable element

Attributes

Inherited from:
Showable
def focus(using ctx: Context): SourcePosition

Attributes

Inherited from:
SrcPos
final def getAttachment[V](key: Key[V]): Option[V]

Optionally get attachment corresponding to key

Optionally get attachment corresponding to key

Attributes

Inherited from:
LinkSource
final def hasAttachment[V](key: Key[V]): Boolean

Does an attachment corresponding to key exist?

Does an attachment corresponding to key exist?

Attributes

Inherited from:
LinkSource
def line(using ctx: Context): Int

Attributes

Inherited from:
SrcPos

Attributes

Inherited from:
Product
def productElement(n: Int): Any

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product
final def pushAttachment[V](key: Key[V], value: V)(using ctx: Context): Unit

Attributes

Inherited from:
Container
final def putAttachment[V](key: Key[V], value: V): Option[V]

Add attachment with given key and value.

Add attachment with given key and value.

Attributes

Returns

Optionally, the old attachment with given key if one existed before. The new attachment is added at the position of the old one, or at the end if no attachment with same key existed.

Inherited from:
LinkSource
final def removeAllAttachments(): Unit

Attributes

Inherited from:
Container
final def removeAttachment[V](key: Key[V]): Option[V]

Remove attachment with given key, if it exists.

Remove attachment with given key, if it exists.

Attributes

Returns

Optionally, the removed attachment with given key if one existed before.

Inherited from:
LinkSource
def show(using Context): String

The string representation of this showable element.

The string representation of this showable element.

Attributes

Inherited from:
Showable
def showIndented(margin: Int)(using Context): String

The string representation with each line after the first one indented by the given given margin (in spaces).

The string representation with each line after the first one indented by the given given margin (in spaces).

Attributes

Inherited from:
Showable
def showSummary(depth: Int)(using Context): String

The summarized string representation of this showable element. Recursion depth is limited to some smallish value. Default is Config.summarizeDepth.

The summarized string representation of this showable element. Recursion depth is limited to some smallish value. Default is Config.summarizeDepth.

Attributes

Inherited from:
Showable

Attributes

Inherited from:
Positioned

Attributes

Inherited from:
Positioned
def span: Span

The span part of the item's position

The span part of the item's position

Attributes

Inherited from:
Positioned
def span_=(span: Span): Unit

Attributes

Inherited from:
Positioned
final def srcPos: SrcPos

This positioned item, widened to SrcPos. Used to make clear we only need the position, typically for error reporting.

This positioned item, widened to SrcPos. Used to make clear we only need the position, typically for error reporting.

Attributes

Inherited from:
Positioned
def startPos(using ctx: Context): SourcePosition

Attributes

Inherited from:
SrcPos
def uniqueId: Int

A unique identifier in case -Yshow-tree-ids, or -Ydebug-tree-with-id is set, -1 otherwise.

A unique identifier in case -Yshow-tree-ids, or -Ydebug-tree-with-id is set, -1 otherwise.

Attributes

Inherited from:
Positioned
def withAttachment[V](key: Key[V], value: V): Container.this.type

Attributes

Inherited from:
Container
final def withAttachmentsFrom(container: Container): Container.this.type

Copy the sticky attachments from container to this container.

Copy the sticky attachments from container to this container.

Attributes

Inherited from:
Container
def withSpan(span: Span): Positioned.this.type

A positioned item like this one with given span. If the positioned item is source-derived, a clone is returned. If the positioned item is synthetic, the position is updated destructively and the item itself is returned.

A positioned item like this one with given span. If the positioned item is source-derived, a clone is returned. If the positioned item is synthetic, the position is updated destructively and the item itself is returned.

Attributes

Inherited from:
Positioned

Concrete fields

protected var myTpe: T