SymbolMethods

Extension methods of Symbol

Source:
Quotes.scala
class Object
trait Matchable
class Any

Extensions

Deprecated extensions

extension (self: Symbol)

Returns all symbols overridden by this symbol.

Returns all symbols overridden by this symbol.

Source:
Quotes.scala

Annotations attached to this symbol

Annotations attached to this symbol

Source:
Quotes.scala

Returns a nested quote with this symbol as splice owner (Symbol.spliceOwner).

Returns a nested quote with this symbol as splice owner (Symbol.spliceOwner).

Changes the owner under which the definition in a quote are created.

Usages:

def rhsExpr(using Quotes): Expr[Unit] = '{ val y = ???; (y, y) }
def aValDef(using Quotes)(owner: Symbol) =
  val sym = Symbol.newVal(owner, "x", TypeRepr.of[Unit], Flags.EmptyFlags, Symbol.noSymbol)
  val rhs = rhsExpr(using sym.asQuotes).asTerm
  ValDef(sym, Some(rhs))
new TreeMap:
  override def transformTerm(tree: Term)(owner: Symbol): Term =
    tree match
      case tree: Ident =>
        given Quotes = owner.asQuotes
        // Definitions contained in the quote will be owned by `owner`.
        // No need to use `changeOwner` in this case.
        '{ val x = ???; x }.asTerm
Source:
Quotes.scala

Fields of a case class type -- only the ones declared in primary constructor

Fields of a case class type -- only the ones declared in primary constructor

Source:
Quotes.scala

Case class or case object children of a sealed trait or cases of an enum.

Case class or case object children of a sealed trait or cases of an enum.

Source:
Quotes.scala

The symbol of the companion class

The symbol of the companion class

Source:
Quotes.scala

The symbol of the companion module

The symbol of the companion module

Source:
Quotes.scala

All members directly declared in the class

All members directly declared in the class

Source:
Quotes.scala

Field with the given name directly declared in the class

Field with the given name directly declared in the class

Source:
Quotes.scala

Fields directly declared in the class

Fields directly declared in the class

Source:
Quotes.scala

Get non-private named methods defined directly inside the class

Get non-private named methods defined directly inside the class

Source:
Quotes.scala

Get all non-private methods defined directly inside the class, excluding constructors

Get all non-private methods defined directly inside the class, excluding constructors

Source:
Quotes.scala

Get non-private named methods defined directly inside the class

Get non-private named methods defined directly inside the class

Source:
Quotes.scala

Get all non-private methods defined directly inside the class, excluding constructors

Get all non-private methods defined directly inside the class, excluding constructors

Source:
Quotes.scala

The documentation for this symbol, if any

The documentation for this symbol, if any

Source:
Quotes.scala

Does this symbol represent a definition?

Does this symbol represent a definition?

Source:
Quotes.scala

Get named non-private fields declared or inherited

Get named non-private fields declared or inherited

Source:
Quotes.scala

Get all non-private fields declared or inherited

Get all non-private fields declared or inherited

Source:
Quotes.scala

Flags of this symbol

Flags of this symbol

Source:
Quotes.scala

The full name of this symbol up to the root package

The full name of this symbol up to the root package

Source:
Quotes.scala
def getAnnotation(annotSym: Symbol): Option[Term]

Get the annotation defined with annotSym attached to this symbol

Get the annotation defined with annotSym attached to this symbol

Source:
Quotes.scala
def hasAnnotation(annotSym: Symbol): Boolean

Is the annotation defined with annotSym attached to this symbol?

Is the annotation defined with annotSym attached to this symbol?

Source:
Quotes.scala

Is this symbol an abstract type?

Is this symbol an abstract type?

Source:
Quotes.scala

Is this symbol an alias type?

Is this symbol an alias type?

Source:
Quotes.scala

Is this symbol an anonymous class?

Is this symbol an anonymous class?

Source:
Quotes.scala

Is this symbol an anonymous function?

Is this symbol an anonymous function?

Source:
Quotes.scala

Is this the definition of a Bind pattern?

Is this the definition of a Bind pattern?

Source:
Quotes.scala

Is this the constructor of a class?

Is this the constructor of a class?

Source:
Quotes.scala

Is this the definition of a ClassDef tree?

Is this the definition of a ClassDef tree?

Source:
Quotes.scala

Is this the definition of a DefDef tree?

Is this the definition of a DefDef tree?

Source:
Quotes.scala

Does this symbol come from a currently compiled source file?

Does this symbol come from a currently compiled source file?

Source:
Quotes.scala

Dummy val symbol that owns all statements within the initialization of the class. This may also contain local definitions such as classes defined in a locally block in the class.

Dummy val symbol that owns all statements within the initialization of the class. This may also contain local definitions such as classes defined in a locally block in the class.

Source:
Quotes.scala

Does this symbol represent a no definition?

Does this symbol represent a no definition?

Source:
Quotes.scala

Is this the definition of a PackageDef tree?

Is this the definition of a PackageDef tree?

Source:
Quotes.scala

Is this symbol a class representing a refinement?

Is this symbol a class representing a refinement?

Source:
Quotes.scala

Is this the definition of a term?

Is this the definition of a term?

Source:
Quotes.scala

Is this the definition of a type?

Is this the definition of a type?

Source:
Quotes.scala

Is this the definition of a TypeDef tree

Is this the definition of a TypeDef tree

Source:
Quotes.scala

Is this the definition of a ValDef tree?

Is this the definition of a ValDef tree?

Source:
Quotes.scala

Owner of this symbol. The owner is the symbol in which this symbol is defined. Returns NoSymbol if this symbol does not have an owner.

Owner of this symbol. The owner is the symbol in which this symbol is defined. Returns NoSymbol if this symbol does not have an owner.

Source:
Quotes.scala

Get named non-private fields declared or inherited

Get named non-private fields declared or inherited

Deprecated
Source:
Quotes.scala

Get all non-private fields declared or inherited

Get all non-private fields declared or inherited

Deprecated
Source:
Quotes.scala

Get named non-private methods declared or inherited

Get named non-private methods declared or inherited

Deprecated
Source:
Quotes.scala

Get all non-private methods declared or inherited

Get all non-private methods declared or inherited

Deprecated
Source:
Quotes.scala

Type member with the given name directly declared in the class

Type member with the given name directly declared in the class

Deprecated
Source:
Quotes.scala

Type member directly declared in the class

Type member directly declared in the class

Deprecated
Source:
Quotes.scala

Get named non-private methods declared or inherited

Get named non-private methods declared or inherited

Source:
Quotes.scala

Get all non-private methods declared or inherited

Get all non-private methods declared or inherited

Source:
Quotes.scala

The class symbol of the companion module class

The class symbol of the companion module class

Source:
Quotes.scala

The name of this symbol

The name of this symbol

Source:
Quotes.scala

The symbol overriding this symbol in given subclass ofclazz.

The symbol overriding this symbol in given subclass ofclazz.

Value parameters:
ofclazz

is a subclass of this symbol's owner

Source:
Quotes.scala

Owner of this symbol. The owner is the symbol in which this symbol is defined. Throws if this symbol does not have an owner.

Owner of this symbol. The owner is the symbol in which this symbol is defined. Throws if this symbol does not have an owner.

Source:
Quotes.scala

The symbols of each type parameter list and value parameter list of this method, or Nil if this isn't a method.

The symbols of each type parameter list and value parameter list of this method, or Nil if this isn't a method.

Source:
Quotes.scala

The position of this symbol

The position of this symbol

Source:
Quotes.scala

The primary constructor of a class or trait, noSymbol if not applicable.

The primary constructor of a class or trait, noSymbol if not applicable.

Source:
Quotes.scala

This symbol is private within the resulting type

This symbol is private within the resulting type

Source:
Quotes.scala

This symbol is protected within the resulting type

This symbol is protected within the resulting type

Source:
Quotes.scala

Signature of this definition

Signature of this definition

Source:
Quotes.scala

Term reference to the symbol usable in the scope of its owner.

Term reference to the symbol usable in the scope of its owner.

Source:
Quotes.scala
def tree: Tree

Tree of this definition

Tree of this definition

If this symbol isClassDef it will return aClassDef, if this symbolisTypeDefit will returna TypeDef, if this symbol isValDef it will return aValDef, if this symbolisDefDefit will returna DefDef if this symbol isBind it will return aBind`, else will throw

Warning: avoid using this method in macros.

Caveat: The tree is not guaranteed to exist unless the compiler option -Yretain-trees is enabled.

Anti-pattern: The following code is an anti-pattern:

symbol.tree.tpe

It should be replaced by one of the following:

tp.memberType(symbol)
symbol.typeRef
symbol.termRef
Source:
Quotes.scala

Type member with the given name directly declared in the class

Type member with the given name directly declared in the class

Source:
Quotes.scala

Type member directly declared in the class

Type member directly declared in the class

Source:
Quotes.scala

Type reference to the symbol usable in the scope of its owner.

Type reference to the symbol usable in the scope of its owner.

To get a reference to a symbol from a specific prefix tp, use tp.select(symbol) instead.

See also:

TypeReprMethods.select

Source:
Quotes.scala