|
Scala example source code file (Enclosures.scala)
The Enclosures.scala Scala example source codepackage scala.reflect.macros package contexts import scala.reflect.{ClassTag, classTag} trait Enclosures { self: Context => import universe._ private lazy val site = callsiteTyper.context private lazy val enclTrees = site.enclosingContextChain map (_.tree) private lazy val enclPoses = enclosingMacros map (_.macroApplication.pos) filterNot (_ eq NoPosition) private def lenientEnclosure[T <: Tree : ClassTag]: Tree = enclTrees collectFirst { case x: T => x } getOrElse EmptyTree private def strictEnclosure[T <: Tree : ClassTag]: T = enclTrees collectFirst { case x: T => x } getOrElse (throw new EnclosureException(classTag[T].runtimeClass, enclTrees)) // vals are eager to simplify debugging // after all we wouldn't save that much time by making them lazy val macroApplication: Tree = expandee def enclosingPackage: PackageDef = strictEnclosure[PackageDef] val enclosingClass: Tree = lenientEnclosure[ImplDef] def enclosingImpl: ImplDef = strictEnclosure[ImplDef] def enclosingTemplate: Template = strictEnclosure[Template] val enclosingImplicits: List[ImplicitCandidate] = site.openImplicits.map(_.toImplicitCandidate) val enclosingMacros: List[Context] = this :: universe.analyzer.openMacros // include self val enclosingMethod: Tree = lenientEnclosure[DefDef] def enclosingDef: DefDef = strictEnclosure[DefDef] val enclosingPosition: Position = if (enclPoses.isEmpty) NoPosition else enclPoses.head.pos val enclosingUnit: CompilationUnit = universe.currentRun.currentUnit val enclosingRun: Run = universe.currentRun } Other Scala source code examplesHere is a short list of links related to this Scala Enclosures.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.