diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-27 20:49:07 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-14 13:24:47 +0100 |
commit | 9380a38351dd2e0932c0cbb9c6b176fc2820c32d (patch) | |
tree | fb0aec637ddc60cb440b7e19534226ceb7caa680 /src | |
parent | 7881137858960d5e59f133ef15730ad96feec5e2 (diff) | |
download | scala-9380a38351dd2e0932c0cbb9c6b176fc2820c32d.tar.gz scala-9380a38351dd2e0932c0cbb9c6b176fc2820c32d.tar.bz2 scala-9380a38351dd2e0932c0cbb9c6b176fc2820c32d.zip |
does away with implicits in StandardLiftables
Less magic - less opportunities for mystification.
Diffstat (limited to 'src')
-rw-r--r-- | src/reflect/scala/reflect/api/StandardLiftables.scala | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/reflect/scala/reflect/api/StandardLiftables.scala b/src/reflect/scala/reflect/api/StandardLiftables.scala index a1292d04ef..104215bb93 100644 --- a/src/reflect/scala/reflect/api/StandardLiftables.scala +++ b/src/reflect/scala/reflect/api/StandardLiftables.scala @@ -8,7 +8,7 @@ trait StandardLiftables { self: Universe => private def lift[T: Liftable](value: T): Tree = implicitly[Liftable[T]].apply(value) private def selectScala(names: Name*) = names.tail.foldLeft(ScalaDot(names.head)) { Select(_, _) } private def callScala(names: Name*)(args: List[Tree]) = Apply(selectScala(names: _*), args) - private def callCollection(name: Name)(args: List[Tree]) = callScala(nme.collection, nme.immutable, name)(args) + private def callCollection(name: Name)(args: List[Tree]) = callScala(stdnme.collection, stdnme.immutable, name)(args) private def liftAsLiteral[T]: Liftable[T] = Liftable { v => Literal(Constant(v)) } implicit def liftByte[T <: Byte]: Liftable[T] = liftAsLiteral[T] @@ -23,7 +23,7 @@ trait StandardLiftables { self: Universe => implicit def liftString[T <: String]: Liftable[T] = liftAsLiteral[T] implicit def liftScalaSymbol: Liftable[scala.Symbol] = Liftable { v => - callScala(nme.Symbol)(Literal(Constant(v.name)) :: Nil) + callScala(stdnme.Symbol)(Literal(Constant(v.name)) :: Nil) } implicit def liftName[T <: Name]: Liftable[T] = Liftable { name => Ident(name) } @@ -32,22 +32,22 @@ trait StandardLiftables { self: Universe => implicit def liftTypeTag[T <: WeakTypeTag[_]]: Liftable[T] = Liftable { ttag => TypeTree(ttag.tpe) } implicit def liftConstant[T <: Constant]: Liftable[T] = Liftable { const => Literal(const) } - implicit def liftArray[T: Liftable]: Liftable[Array[T]] = Liftable { arr => callScala(nme.Array)(arr.map(lift(_)).toList) } - implicit def liftVector[T: Liftable]: Liftable[Vector[T]] = Liftable { vect => callCollection(nme.Vector)(vect.map(lift(_)).toList) } - implicit def liftList[T: Liftable]: Liftable[List[T]] = Liftable { lst => callCollection(nme.List)(lst.map(lift(_))) } - implicit def liftNil: Liftable[Nil.type] = Liftable { _ => selectScala(nme.collection, nme.immutable, nme.Nil) } - implicit def liftMap[K: Liftable, V: Liftable]: Liftable[Map[K, V]] = Liftable { m => callCollection(nme.Map)(m.toList.map(lift(_))) } - implicit def liftSet[T: Liftable]: Liftable[Set[T]] = Liftable { s => callCollection(nme.Set)(s.toList.map(lift(_))) } + implicit def liftArray[T: Liftable]: Liftable[Array[T]] = Liftable { arr => callScala(stdnme.Array)(arr.map(lift(_)).toList) } + implicit def liftVector[T: Liftable]: Liftable[Vector[T]] = Liftable { vect => callCollection(stdnme.Vector)(vect.map(lift(_)).toList) } + implicit def liftList[T: Liftable]: Liftable[List[T]] = Liftable { lst => callCollection(stdnme.List)(lst.map(lift(_))) } + implicit def liftNil: Liftable[Nil.type] = Liftable { _ => selectScala(stdnme.collection, stdnme.immutable, stdnme.Nil) } + implicit def liftMap[K: Liftable, V: Liftable]: Liftable[Map[K, V]] = Liftable { m => callCollection(stdnme.Map)(m.toList.map(lift(_))) } + implicit def liftSet[T: Liftable]: Liftable[Set[T]] = Liftable { s => callCollection(stdnme.Set)(s.toList.map(lift(_))) } - implicit def liftSome[T: Liftable]: Liftable[Some[T]] = Liftable { case Some(v) => callScala(nme.Some)(lift(v) :: Nil) } - implicit def liftNone: Liftable[None.type] = Liftable { _ => selectScala(nme.None) } + implicit def liftSome[T: Liftable]: Liftable[Some[T]] = Liftable { case Some(v) => callScala(stdnme.Some)(lift(v) :: Nil) } + implicit def liftNone: Liftable[None.type] = Liftable { _ => selectScala(stdnme.None) } implicit def liftOption[T: Liftable]: Liftable[Option[T]] = Liftable { case some: Some[T] => lift(some) case none: None.type => lift(none) } - implicit def liftLeft[L: Liftable, R]: Liftable[Left[L, R]] = Liftable { case Left(v) => callScala(nme.util, nme.Left)(lift(v) :: Nil) } - implicit def liftRight[L, R: Liftable]: Liftable[Right[L, R]] = Liftable { case Right(v) => callScala(nme.util, nme.Right)(lift(v) :: Nil) } + implicit def liftLeft[L: Liftable, R]: Liftable[Left[L, R]] = Liftable { case Left(v) => callScala(stdnme.util, stdnme.Left)(lift(v) :: Nil) } + implicit def liftRight[L, R: Liftable]: Liftable[Right[L, R]] = Liftable { case Right(v) => callScala(stdnme.util, stdnme.Right)(lift(v) :: Nil) } implicit def liftEither[L: Liftable, R: Liftable]: Liftable[Either[L, R]] = Liftable { case left: Left[L, R] => lift(left) case right: Right[L, R] => lift(right) @@ -140,10 +140,10 @@ trait StandardLiftables { self: Universe => implicit def unliftString: Unliftable[String] = Unliftable { case Literal(Constant(s: String)) => s } implicit def unliftScalaSymbol: Unliftable[scala.Symbol] = Unliftable { - case Apply(ScalaDot(symbol), List(Literal(Constant(name: String)))) if symbol == nme.Symbol => scala.Symbol(name) + case Apply(ScalaDot(stdnme.Symbol), List(Literal(Constant(name: String)))) => scala.Symbol(name) } - implicit def unliftName[T <: Name : ClassTag]: Unliftable[T] = Unliftable[T] { case Ident(name: T) => name; case Bind(name: T, Ident(nme.WILDCARD)) => name } + implicit def unliftName[T <: Name : ClassTag]: Unliftable[T] = Unliftable[T] { case Ident(name: T) => name; case Bind(name: T, Ident(stdnme.WILDCARD)) => name } implicit def unliftType: Unliftable[Type] = Unliftable[Type] { case tt: TypeTree if tt.tpe != null => tt.tpe } implicit def unliftConstant: Unliftable[Constant] = Unliftable[Constant] { case Literal(const) => const } @@ -216,9 +216,10 @@ trait StandardLiftables { self: Universe => } // names used internally by implementations of standard liftables and unliftables - import scala.language.implicitConversions - private implicit def cachedNames(nme: self.nme.type): CachedNames.type = CachedNames - private object CachedNames { + // can't be `private object nme` because of https://groups.google.com/forum/#!topic/scala-internals/b-Full9WZeE + // can't be `private[this] object nme` because then STARR has problems prioritizing this.nme over self.nme + // therefore I'm essentially forced to give this object a non-standard name + private object stdnme { val Array = TermName("Array") val collection = TermName("collection") val immutable = TermName("immutable") @@ -231,7 +232,8 @@ trait StandardLiftables { self: Universe => val Set = TermName("Set") val Some = TermName("Some") val Symbol = TermName("Symbol") - val Vector = TermName("Vector") val util = TermName("util") + val Vector = TermName("Vector") + val WILDCARD = self.nme.WILDCARD } } |