Skip to content

Commit

Permalink
Merge pull request #851 from magnolia-k/replace_Manifest
Browse files Browse the repository at this point in the history
Replaced from Manifest to ClassTag
  • Loading branch information
takezoe committed Aug 8, 2018
2 parents c7720d0 + 43b27bb commit 9677cb5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/org/scalatra/Control.scala
Expand Up @@ -18,7 +18,7 @@ trait Control {
* @param body a result to render through the render pipeline as the body
* @param headers headers to add to the response
*/
def halt[T: Manifest](
def halt[T](
status: JInteger = null,
body: T = (),
headers: Map[String, String] = Map.empty): Nothing = {
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/scala/org/scalatra/servlet/AttributesMap.scala
Expand Up @@ -39,7 +39,7 @@ trait AttributesMap extends Map[String, Any] with MutableMapWithIndifferentAcces
* @return an option value containing the attributed associated with the key in the underlying servlet object,
* or None if none exists
*/
def getAs[T](key: String)(implicit mf: Manifest[T], converter: TypeConverter[Any, T]): Option[T] = {
def getAs[T](key: String)(implicit converter: TypeConverter[Any, T]): Option[T] = {
get(key) flatMap (converter(_))
}

Expand All @@ -51,7 +51,7 @@ trait AttributesMap extends Map[String, Any] with MutableMapWithIndifferentAcces
* @return an value for the attributed associated with the key in the underlying servlet object,
* or throw an exception if the key doesn't exist
*/
def as[T](key: String)(implicit mf: Manifest[T], converter: TypeConverter[Any, T]): T = {
def as[T](key: String)(implicit converter: TypeConverter[Any, T]): T = {
getAs[T](key) getOrElse (throw new ScalatraException("Key " + key + " not found"))
}

Expand All @@ -63,9 +63,7 @@ trait AttributesMap extends Map[String, Any] with MutableMapWithIndifferentAcces
* @return an value for the attributed associated with the key in the underlying servlet object,
* or throw an exception if the key doesn't exist
*/
def getAsOrElse[T](key: String, default: => T)(
implicit
mf: Manifest[T], converter: TypeConverter[Any, T]): T = {
def getAsOrElse[T](key: String, default: => T)(implicit converter: TypeConverter[Any, T]): T = {
getAs[T](key) getOrElse default
}

Expand Down
Expand Up @@ -7,6 +7,8 @@ import java.util.Date

import scala.util.control.Exception.allCatch

import scala.reflect.ClassTag

/**
* Support types and implicits for [[org.scalatra.util.conversion.TypeConverter]].
*/
Expand All @@ -27,8 +29,8 @@ trait TypeConverterSupport {
object TypeConverterSupport extends TypeConverterSupport

trait LowestPriorityImplicitConversions extends TypeConverterSupport {
implicit def lowestPriorityAny2T[T: Manifest]: TypeConverter[Any, T] = safe {
case a if manifest[T].runtimeClass.isAssignableFrom(a.getClass) => a.asInstanceOf[T]
implicit def lowestPriorityAny2T[T: ClassTag]: TypeConverter[Any, T] = safe {
case a if implicitly[ClassTag[T]].runtimeClass.isAssignableFrom(a.getClass) => a.asInstanceOf[T]
}
}

Expand Down Expand Up @@ -141,16 +143,16 @@ trait DefaultImplicitConversions extends LowPriorityImplicitConversions {

def stringToDateFormat(format: => DateFormat): TypeConverter[String, Date] = safe(format.parse(_))

implicit def defaultStringToSeq[T](implicit elementConverter: TypeConverter[String, T], mf: Manifest[T]): TypeConverter[String, Seq[T]] =
implicit def defaultStringToSeq[T: ClassTag](implicit elementConverter: TypeConverter[String, T]): TypeConverter[String, Seq[T]] =
stringToSeq[T](elementConverter)

def stringToSeq[T: Manifest](elementConverter: TypeConverter[String, T], separator: String = ","): TypeConverter[String, Seq[T]] =
def stringToSeq[T: ClassTag](elementConverter: TypeConverter[String, T], separator: String = ","): TypeConverter[String, Seq[T]] =
safe(s => s.split(separator).toSeq.flatMap(e => elementConverter(e.trim)))

implicit def seqHead[T](implicit elementConverter: TypeConverter[String, T], mf: Manifest[T]): TypeConverter[Seq[String], T] =
implicit def seqHead[T: ClassTag](implicit elementConverter: TypeConverter[String, T]): TypeConverter[Seq[String], T] =
safeOption(_.headOption.flatMap(elementConverter(_)))

implicit def seqToSeq[T](implicit elementConverter: TypeConverter[String, T], mf: Manifest[T]): TypeConverter[Seq[String], Seq[T]] =
implicit def seqToSeq[T: ClassTag](implicit elementConverter: TypeConverter[String, T]): TypeConverter[Seq[String], Seq[T]] =
safe(_.flatMap(elementConverter(_)))

}
Expand All @@ -167,9 +169,7 @@ object Conversions extends DefaultImplicitConversions {
}

implicit class SeqConversion(private val source: String) extends AnyVal {

def asSeq[T](separator: String)(implicit mf: Manifest[T], tc: TypeConverter[String, T]): Option[Seq[T]] =
def asSeq[T: ClassTag](separator: String)(implicit tc: TypeConverter[String, T]): Option[Seq[T]] =
stringToSeq[T](tc, separator).apply(source)

}
}
Expand Up @@ -6,6 +6,8 @@ import java.util.{ Calendar, Date }

import org.specs2.mutable.Specification

import scala.reflect.ClassTag

class ConversionsSpecs extends Specification {

"The TypeConverterSupport trait" should {
Expand Down Expand Up @@ -87,7 +89,7 @@ class ConversionsSpecs extends Specification {

import Impl._

def testConversion[T](args: (String, Seq[T]))(implicit mf: Manifest[T], t: TypeConverter[String, T]) = {
def testConversion[T: ClassTag](args: (String, Seq[T]))(implicit t: TypeConverter[String, T]) = {
val (source, expected) = args
Impl.stringToSeq(t).apply(source).get must containAllOf(expected).inOrder
}
Expand Down

0 comments on commit 9677cb5

Please sign in to comment.