Symbol

oxygen.quoted.Symbol
See theSymbol companion object
final class Symbol extends Model

Attributes

Companion
object
Graph
Supertypes
trait Model
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def allOverriddenSymbols: Iterator[Symbol]

Returns all symbols overridden by this symbol.

Returns all symbols overridden by this symbol.

Attributes

def asQuotes: Quotes

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 q: Quotes): Expr[Unit] =
  import q.reflect.*
  '{ val y = ???; (y, y) }
def aValDef(using q: Quotes)(owner: q.reflect.Symbol) =
  import q.reflect.*
  val sym = Symbol.newVal(owner, "x", TypeRepr.of[Unit], Flags.EmptyFlags, Symbol.noSymbol)
  val rhs = rhsExpr(using sym.asQuotes).asTerm
  ValDef(sym, Some(rhs))
def inQuotes(using q: Quotes) = {
  import q.reflect.*
  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
}

Attributes

def asQuotesUsing[A](f: Quotes ?=> A): A
def caseFields: List[Symbol]

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

Attributes

def children: List[Symbol]

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.

Attributes

The symbol of the companion class

The symbol of the companion class

Attributes

The symbol of the companion module

The symbol of the companion module

Attributes

def declarations: List[Symbol]

All members directly declared in the class

All members directly declared in the class

Attributes

def declaredField(name: String): Symbol

Field with the given name directly declared in the class

Field with the given name directly declared in the class

Attributes

def declaredFields: List[Symbol]

Fields directly declared in the class

Fields directly declared in the class

Attributes

def declaredMethod(name: String): List[Symbol]

Get non-private named methods defined directly inside the class

Get non-private named methods defined directly inside the class

Attributes

def declaredMethods: List[Symbol]

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

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

Attributes

def declaredType(name: String): List[Symbol]

Get non-private named type defined directly inside the class

Get non-private named type defined directly inside the class

Attributes

def declaredTypes: List[Symbol]

Get all non-private types defined directly inside the class

Get all non-private types defined directly inside the class

Attributes

def docstring: Option[String]

The documentation for this symbol, if any

The documentation for this symbol, if any

Attributes

def exists: Boolean

Does this symbol represent a definition?

Does this symbol represent a definition?

Attributes

def fieldMember(name: String): Symbol

Get named non-private fields declared or inherited

Get named non-private fields declared or inherited

Attributes

def fieldMembers: List[Symbol]

Get all non-private fields declared or inherited

Get all non-private fields declared or inherited

Attributes

def flags: Flags

Flags of this symbol

Flags of this symbol

Attributes

def fullName: String

The full name of this symbol up to the root package

The full name of this symbol up to the root package

Attributes

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

Attributes

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?

Attributes

def isAbstractType: Boolean

Is this symbol an abstract type or a type parameter?

Is this symbol an abstract type or a type parameter?

Attributes

def isAliasType: Boolean

Is this symbol an alias type?

Is this symbol an alias type?

Attributes

def isAnonymousClass: Boolean

Is this symbol an anonymous class?

Is this symbol an anonymous class?

Attributes

def isAnonymousFunction: Boolean

Is this symbol an anonymous function?

Is this symbol an anonymous function?

Attributes

def isBind: Boolean

Is this the definition of a Bind pattern?

Is this the definition of a Bind pattern?

Attributes

def isClassConstructor: Boolean

Is this the constructor of a class?

Is this the constructor of a class?

Attributes

def isClassDef: Boolean

Is this the definition of a ClassDef tree?

Is this the definition of a ClassDef tree?

Attributes

def isDefDef: Boolean

Is this the definition of a DefDef tree?

Is this the definition of a DefDef tree?

Attributes

def isDefinedInCurrentRun: Boolean

Does this symbol come from a currently compiled source file?

Does this symbol come from a currently compiled source file?

Attributes

def isLocalDummy: Boolean

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.

Attributes

def isNoSymbol: Boolean

Does this symbol represent a no definition?

Does this symbol represent a no definition?

Attributes

def isPackageDef: Boolean

Is this the definition of a PackageDef tree?

Is this the definition of a PackageDef tree?

Attributes

def isRefinementClass: Boolean

Is this symbol a class representing a refinement?

Is this symbol a class representing a refinement?

Attributes

def isSuperAccessor: Boolean

Is this the super accessor?

Is this the super accessor?

Attributes

def isTerm: Boolean

Is this the definition of a term?

Is this the definition of a term?

Attributes

def isTupleClass: Boolean
def isType: Boolean

Is this the definition of a type?

Is this the definition of a type?

Attributes

def isTypeDef: Boolean

Is this the definition of a TypeDef tree

Is this the definition of a TypeDef tree

Attributes

def isTypeParam: Boolean

Is this the symbol of a type parameter

Is this the symbol of a type parameter

Attributes

def isValDef: Boolean

Is this the definition of a ValDef tree?

Is this the definition of a ValDef tree?

Attributes

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.

Attributes

override def maybePos: Option[Position]

Attributes

Definition Classes
def methodMember(name: String): List[Symbol]

Get named non-private methods declared or inherited

Get named non-private methods declared or inherited

Attributes

def methodMembers: List[Symbol]

Get all non-private methods declared or inherited

Get all non-private methods declared or inherited

Attributes

The class symbol of the companion module class

The class symbol of the companion module class

Attributes

def name: String

The name of this symbol

The name of this symbol

Attributes

def overridingSymbol(ofclazz: Symbol): Symbol

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

Attributes

def owner: Symbol

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.

Attributes

def paramSymss: List[List[Symbol]]

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.

Attributes

Variance flags for of this type parameter.

Variance flags for of this type parameter.

Variance flags can be one of Flags.{Covariant, Contravariant, EmptyFlags}. If this is not the symbol of a type parameter the result is Flags.EmptyFlags.

Attributes

def pos: Option[Position]

The position of this symbol

The position of this symbol

Attributes

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

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

Attributes

def privateWithin: Option[TypeRepr]

This symbol is private within the resulting type

This symbol is private within the resulting type

Attributes

def protectedWithin: Option[TypeRepr]

This symbol is protected within the resulting type

This symbol is protected within the resulting type

Attributes

Signature of this definition

Signature of this definition

Attributes

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

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

Attributes

def toTerm: Term
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

Attributes

def typeMember(name: String): Symbol

Type member with the given name declared or inherited in the class

Type member with the given name declared or inherited in the class

Attributes

def typeMembers: List[Symbol]

Type member directly declared or inherited in the class

Type member directly declared or inherited in the class

Attributes

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.

Attributes

See also

TypeReprMethods.select

def typeType: Option[TypeType]
def typeTypeCase: Option[Case]
def typeTypeCaseClass: Option[Class]
def typeTypeCaseObject: Option[Object]
def typeTypeSealed: Option[Sealed]
def unwrapWithin(using newQuotes: Quotes): newQuotes.reflect.Symbol

Inherited methods

final 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
Model -> Any
Inherited from:
Model
final 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
Model -> Any
Inherited from:
Model
final override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Model -> Any
Inherited from:
Model

Experimental methods

def info: TypeRepr

Type of the definition

Type of the definition

Attributes

Experimental
true

Concrete fields

val unwrap: quotes.reflect.Symbol

Givens

Givens

given quotes: Quotes