treehugger.api.Trees

Tree

abstract class Tree extends Product

Tree is the basis for scala's abstract syntax. The nodes are implemented as case classes, and the parameters which initialize a given tree are immutable: however Trees have several mutable fields which are manipulated in the course of typechecking, including pos, symbol, and tpe.

Newly instantiated trees have tpe set to null (though it may be set immediately thereafter depending on how it is constructed.) When a tree is passed to the typer, typically via typer.typed(tree), under normal circumstances the tpe must be null or the typer will ignore it. Furthermore, the typer is not required to return the same tree it was passed.

Trees can be easily traversed with e.g. foreach on the root node; for a more nuanced traversal, subclass Traverser. Transformations can be considerably trickier: see the numerous subclasses of Transformer found around the compiler.

Copying Trees should be done with care depending on whether it need be done lazily or strictly (see LazyTreeCopier and StrictTreeCopier) and on whether the contents of the mutable fields should be copied. The tree copiers will copy the mutable attributes to the new tree; calling Tree#duplicate will copy symbol and tpe, but all the positions will be focused.

Trees can be coarsely divided into four mutually exclusive categories:

SymTrees include important nodes Ident and Select, which are used as both terms and types; they are distinguishable based on whether the Name is a TermName or TypeName. The correct way for to test for a type or a term (on any Tree) are the isTerm/isType methods on Tree.

"Others" are mostly syntactic or short-lived constructs. Examples include CaseDef, which wraps individual match cases: they are neither terms nor types, nor do they carry a symbol. Another example is Parens, which is eliminated during parsing.

Linear Supertypes
Product, Equals, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Tree
  2. Product
  3. Equals
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Tree()

Abstract Value Members

  1. abstract def canEqual(that: Any): Boolean

    Definition Classes
    Equals
  2. abstract def productArity: Int

    Definition Classes
    Product
  3. abstract def productElement(n: Int): Any

    Definition Classes
    Product

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def children: List[Universe.Tree]

    The direct child trees of this tree.

    The direct child trees of this tree. EmptyTrees are always omitted. Lists are flattened.

  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def defineType(tp: Universe.Type): Tree.this.type

    Like setType, but if this is a previously empty TypeTree that fact is remembered so that resetAllAttrs will snap back.

    Like setType, but if this is a previously empty TypeTree that fact is remembered so that resetAllAttrs will snap back.

    Attempting to elaborate on the above, I find: If defineType is called on a TypeTree whose type field is null or NoType, this is recorded as "wasEmpty = true". That value is used in ResetAttrsTraverser, which nulls out the type field of TypeTrees for which wasEmpty is true, leaving the others alone.

    resetAllAttrs is used in situations where some speculative typing of a tree takes place, fails, and the tree needs to be returned to its former state to try again. So according to me: using defineType instead of setType is how you communicate that the type being set does not depend on any previous state, and therefore should be abandoned if the current line of type inquiry doesn't work out.

  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(that: Any): Boolean

    Definition Classes
    Tree → Equals → AnyRef → Any
  12. def equalsStructure(that: Universe.Tree): Boolean

  13. def equalsStructure0(that: Universe.Tree)(f: (Universe.Tree, Universe.Tree) ⇒ Boolean): Boolean

  14. def exists(p: (Universe.Tree) ⇒ Boolean): Boolean

    Is there part of this tree which satisfies predicate p?

  15. def filter(f: (Universe.Tree) ⇒ Boolean): List[Universe.Tree]

    Find all subtrees matching predicate p

  16. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. def find(p: (Universe.Tree) ⇒ Boolean): Option[Universe.Tree]

    Returns optionally first tree (in a preorder traversal) which satisfies predicate p, or None if none exists.

  18. def foreach(f: (Universe.Tree) ⇒ Unit): Unit

    Apply f to each subtree

  19. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  20. def hasSymbol: Boolean

  21. def hasSymbolWhich(f: (Universe.Symbol) ⇒ Boolean): Boolean

  22. def hashCode(): Int

    Definition Classes
    Tree → AnyRef → Any
  23. val id: Int

  24. def isDef: Boolean

  25. def isEmpty: Boolean

  26. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  27. def isTerm: Boolean

    The canonical way to test if a Tree represents a term.

  28. def isType: Boolean

    The canonical way to test if a Tree represents a type.

  29. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  30. final def notify(): Unit

    Definition Classes
    AnyRef
  31. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  32. def pos: Position

  33. def pos_=(pos: Position): Unit

  34. def productIterator: Iterator[Any]

    Definition Classes
    Product
  35. def productPrefix: String

    Definition Classes
    Product
  36. def setPos(pos: Position): Tree.this.type

  37. def setSymbol(sym: Universe.Symbol): Tree.this.type

  38. def setType(tp: Universe.Type): Tree.this.type

    Set tpe to give tp and return this.

  39. def symbol: Universe.Symbol

    Note that symbol is fixed as null at this level.

    Note that symbol is fixed as null at this level. In SymTrees, it is overridden and implemented with a var, initialized to NoSymbol.

    Trees which are not SymTrees but which carry symbols do so by overriding def symbol to forward it elsewhere. Examples:

    Super(qual, _) // has qual's symbol Apply(fun, args) // has fun's symbol TypeApply(fun, args) // has fun's symbol AppliedTypeTree(tpt, args) // has tpt's symbol TypeTree(tpe) // has tpe's typeSymbol, if tpe != null

    Attempting to set the symbol of a Tree which does not support it will induce an exception.

  40. def symbol_=(sym: Universe.Symbol): Unit

  41. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  42. def toString(): String

    Definition Classes
    AnyRef → Any
  43. def tpe: Universe.Type

  44. def tpe_=(t: Universe.Type): Unit

  45. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  46. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped