11package org .mockito .internal
22
33import org .mockito .internal .MacroDebug .debugResult
4+ import org .mockito .internal .ScalaVersion .{ V2_11 , V2_12 , V2_13 }
45
56import scala .reflect .macros .blackbox
6- import scala .util .Properties
77
88trait ValueClassExtractor [VC ] extends Serializable {
99 def isValueClass : Boolean = true
@@ -30,8 +30,6 @@ class ReflectionExtractor[VC] extends ValueClassExtractor[VC] {
3030object ValueClassExtractor {
3131 def apply [T : ValueClassExtractor ]: ValueClassExtractor [T ] = implicitly[ValueClassExtractor [T ]]
3232
33- private val ScalaVersion = Properties .scalaPropOrElse(" version.number" , " unknown" )
34-
3533 implicit def instance [VC ]: ValueClassExtractor [VC ] = macro materialise[VC ]
3634
3735 def materialise [VC : c.WeakTypeTag ](c : blackbox.Context ): c.Expr [ValueClassExtractor [VC ]] = {
@@ -41,24 +39,25 @@ object ValueClassExtractor {
4139 val isValueClass = typeSymbol.isClass && typeSymbol.asClass.isDerivedValueClass
4240
4341 val r =
44- if (isValueClass)
45- if (ScalaVersion .startsWith(" 2.12" ) || ScalaVersion .startsWith(" 2.13" ))
46- c.Expr [ValueClassExtractor [VC ]](q " new _root_.org.mockito.internal.ReflectionExtractor[ $tpe] " )
47- else if (ScalaVersion .startsWith(" 2.11" ))
48- c.Expr [ValueClassExtractor [VC ]] {
49- val companion = typeSymbol.companion
42+ if (isValueClass) {
43+ ScalaVersion .Current match {
44+ case V2_12 | V2_13 =>
45+ c.Expr [ValueClassExtractor [VC ]](q " new _root_.org.mockito.internal.ReflectionExtractor[ $tpe] " )
46+ case V2_11 =>
47+ c.Expr [ValueClassExtractor [VC ]] {
48+ val companion = typeSymbol.companion
5049
51- if (companion.info.decls.exists(_.name.toString == " unapply" ))
52- q """
53- new _root_.org.mockito.internal.ValueClassExtractor[ $tpe] {
54- override def extract(vc: $tpe): Any = $companion.unapply(vc).get
50+ if (companion.info.decls.exists(_.name.toString == " unapply" ))
51+ q """
52+ new _root_.org.mockito.internal.ValueClassExtractor[ $tpe] {
53+ override def extract(vc: $tpe): Any = $companion.unapply(vc).get
54+ }
55+ """
56+ else
57+ q " new _root_.org.mockito.internal.NormalClassExtractor[ $tpe] "
5558 }
56- """
57- else
58- q " new _root_.org.mockito.internal.NormalClassExtractor[ $tpe] "
59- }
60- else throw new Exception (s " Unsupported scala version $ScalaVersion" )
61- else
59+ }
60+ } else
6261 c.Expr [ValueClassExtractor [VC ]](q " new _root_.org.mockito.internal.NormalClassExtractor[ $tpe] " )
6362
6463 debugResult(c)(" mockito-print-extractor" )(r.tree)
0 commit comments