dimanche 14 août 2016

Scala Reflection why NoPosition on reify tree?

The scala.reflect.api.Position and the documentation Annotations, Names, Scopes, and More don't give enough explanation about why trees or symbols could have a position as NoPosition.

In the code below, what is the reason the symbols, terms, constant all have NoPosition?

import scala.reflect.runtime.universe._

def movieTree = reify {
  final class Movie {
    val year = 1998
    def name = "You've Got Mail"
  }
}.tree

showRaw(movieTree, printPositions = true)

// res0: String = [NoPosition]Block(
// List([NoPosition]ClassDef(Modifiers(FINAL), TypeName("Movie"), List(),
// [NoPosition]Template(List([NoPosition]Ident(TypeName("AnyRef"))), noSelfType,
// List([NoPosition]DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()),
// [NoPosition]TypeTree(), 
// [NoPosition]Block(List([NoPosition]Apply([NoPosition]Select([NoPosition]Super([NoPosition]This(typeNames.EMPTY), typeNames.EMPTY), 
// termNames.CONSTRUCTOR), List())), [NoPosition]Literal(Constant(())))), 
// [NoPosition]ValDef(Modifiers(), TermName("year"), [NoPosition]TypeTree(), [NoPosition]Literal(Constant(1998))),
// [NoPosition]DefDef(Modifiers(), TermName("name"), List(), List(), [NoPosition]TypeTree(),
// [NoPosition]Literal(Constant("You've Got Mail"))))))),
// [NoPosition]Literal(Constant(())))





Aucun commentaire:

Enregistrer un commentaire