SymbolModule

scala.quoted.Quotes.reflectModule.SymbolModule

Methods of the module object val Symbol

Attributes

Source:
Quotes.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Concise view

Value members

Abstract methods

def classSymbol(fullName: String): Symbol

The class Symbol of a global class definition

The class Symbol of a global class definition

Attributes

Source:
Quotes.scala
def newBind(parent: Symbol, name: String, flags: Flags, tpe: TypeRepr): Symbol

Generates a pattern bind symbol with the given parent, name and type.

Generates a pattern bind symbol with the given parent, name and type.

This symbol starts without an accompanying definition. It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing this symbol to the BindDef constructor.

Attributes

flags

extra flags to with which the symbol should be constructed

name

The name of the binding

parent

The owner of the binding

tpe

The type of the binding

Note:

As a macro can only splice code into the point at which it is expanded, all generated symbols must be direct or indirect children of the reflection context's owner.

Source:
Quotes.scala
def newClass(parent: Symbol, name: String, parents: List[TypeRepr], decls: Symbol => List[Symbol], selfType: Option[TypeRepr]): Symbol

Generates a new class symbol for a class with a parameterless constructor.

Generates a new class symbol for a class with a parameterless constructor.

Example usage:

val name: String = "myClass"
val parents = List(TypeTree.of[Object], TypeTree.of[Foo])
def decls(cls: Symbol): List[Symbol] =
  List(Symbol.newMethod(cls, "foo", MethodType(Nil)(_ => Nil, _ => TypeRepr.of[Unit])))

val cls = Symbol.newClass(Symbol.spliceOwner, name, parents = parents.map(_.tpe), decls, selfType = None)
val fooSym = cls.declaredMethod("foo").head

val fooDef = DefDef(fooSym, argss => Some('{println(s"Calling foo")}.asTerm))
val clsDef = ClassDef(cls, parents, body = List(fooDef))
val newCls = Typed(Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), Nil), TypeTree.of[Foo])

Block(List(clsDef), newCls).asExprOf[Foo]

constructs the equivalent to

'{
  class myClass() extends Object with Foo {
    def foo(): Unit = println("Calling foo")
  }
  new myClass(): Foo
}

Attributes

decls

The member declarations of the class provided the symbol of this class

name

The name of the class

parent

The owner of the class

parents

The parent classes of the class. The first parent must not be a trait.

selfType

The self type of the class if it has one This symbol starts without an accompanying definition. It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing this symbol to the ClassDef constructor.

Note:

As a macro can only splice code into the point at which it is expanded, all generated symbols must be direct or indirect children of the reflection context's owner.

Source:
Quotes.scala
def newMethod(parent: Symbol, name: String, tpe: TypeRepr): Symbol

Generates a new method symbol with the given parent, name and type.

Generates a new method symbol with the given parent, name and type.

To define a member method of a class, use the newMethod within the decls function of newClass.

Attributes

name

The name of the method

parent

The owner of the method

tpe

The type of the method (MethodType, PolyType, ByNameType) This symbol starts without an accompanying definition. It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing this symbol to the DefDef constructor.

Note:

As a macro can only splice code into the point at which it is expanded, all generated symbols must be direct or indirect children of the reflection context's owner.

Source:
Quotes.scala
def newMethod(parent: Symbol, name: String, tpe: TypeRepr, flags: Flags, privateWithin: Symbol): Symbol

Works as the other newMethod, but with additional parameters.

Works as the other newMethod, but with additional parameters.

To define a member method of a class, use the newMethod within the decls function of newClass.

Attributes

flags

extra flags to with which the symbol should be constructed

name

The name of the method

parent

The owner of the method

privateWithin

the symbol within which this new method symbol should be private. May be noSymbol.

tpe

The type of the method (MethodType, PolyType, ByNameType)

Source:
Quotes.scala
def newVal(parent: Symbol, name: String, tpe: TypeRepr, flags: Flags, privateWithin: Symbol): Symbol

Generates a new val/var/lazy val symbol with the given parent, name and type.

Generates a new val/var/lazy val symbol with the given parent, name and type.

This symbol starts without an accompanying definition. It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing this symbol to the ValDef constructor.

Note: Also see reflect.let

Attributes

flags

extra flags to with which the symbol should be constructed

name

The name of the val/var/lazy val

parent

The owner of the val/var/lazy val

privateWithin

the symbol within which this new method symbol should be private. May be noSymbol.

tpe

The type of the val/var/lazy val

Note:

As a macro can only splice code into the point at which it is expanded, all generated symbols must be direct or indirect children of the reflection context's owner.

Source:
Quotes.scala

Definition not available

Definition not available

Attributes

Source:
Quotes.scala

Get class symbol if class is either defined in current compilation run or present on classpath.

Get class symbol if class is either defined in current compilation run or present on classpath.

Attributes

Source:
Quotes.scala

Get method symbol if method is either defined in current compilation run or present on classpath. Throws if the method has an overload.

Get method symbol if method is either defined in current compilation run or present on classpath. Throws if the method has an overload.

Attributes

Source:
Quotes.scala

Get module symbol if module is either defined in current compilation run or present on classpath.

Get module symbol if module is either defined in current compilation run or present on classpath.

Attributes

Source:
Quotes.scala

Get package symbol if package is either defined in current compilation run or present on classpath.

Get package symbol if package is either defined in current compilation run or present on classpath.

Attributes

Source:
Quotes.scala

Symbol of the definition that encloses the current splicing context.

Symbol of the definition that encloses the current splicing context.

For example, the following call to spliceOwner would return the symbol x.

val x = ${ ... Symbol.spliceOwner ... }

For a macro splice, it is the symbol of the definition where the macro expansion happens.

Attributes

Source:
Quotes.scala