Skip to content

Commit 79e15e7

Browse files
authored
Upgrade to Scala 2.13.17 (#594)
1 parent df14c7c commit 79e15e7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import scala.language.postfixOps
22

3-
val currentScalaVersion = "2.13.16"
3+
val currentScalaVersion = "2.13.17"
44

55
inThisBuild(
66
Seq(

common/src/main/scala/org/mockito/ReflectionUtils.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ import org.scalactic.TripleEquals.*
66

77
import java.lang.reflect.Method
88
import scala.reflect.ClassTag
9-
import scala.reflect.internal.Symbols
109
import scala.util.Try as uTry
1110

1211
object ReflectionUtils {
1312
import scala.reflect.runtime.universe as ru
1413
import ru.*
1514

16-
implicit def symbolToMethodSymbol(sym: Symbol): Symbols#MethodSymbol = sym.asInstanceOf[Symbols#MethodSymbol]
17-
18-
private val mirror = runtimeMirror(getClass.getClassLoader)
19-
private val customMirror = mirror.asInstanceOf[{
20-
def methodToJava(sym: Symbols#MethodSymbol): Method
21-
}]
15+
private val mirror = runtimeMirror(getClass.getClassLoader)
16+
private val methodToJavaMethod: Method =
17+
mirror.getClass.getMethods.find(m => m.getName == "methodToJava" && m.getParameterCount == 1 && m.getParameterTypes.head.getName.endsWith("Symbol")).get
18+
private def asJavaMethod(sym: Symbol): Method = methodToJavaMethod.invoke(mirror, sym).asInstanceOf[Method]
2219

2320
private[mockito] def returnType(invocation: InvocationOnMock): Class[?] = {
2421
val javaReturnType = invocation.method.getReturnType
@@ -31,12 +28,15 @@ object ReflectionUtils {
3128
}
3229

3330
private[mockito] def returnsValueClass(invocation: InvocationOnMock): Boolean =
34-
findTypeSymbol(invocation).exists(_.returnType.typeSymbol.isDerivedValueClass)
31+
findTypeSymbol(invocation).exists { s =>
32+
val typeSymbol = s.asMethod.returnType.typeSymbol
33+
typeSymbol.isClass && typeSymbol.asClass.toType <:< typeOf[AnyVal]
34+
}
3535

3636
private def resolveWithScalaGenerics(invocation: InvocationOnMock): Option[Class[?]] =
3737
uTry {
3838
findTypeSymbol(invocation)
39-
.filter(_.returnType.typeSymbol.isClass)
39+
.filter(_.asMethod.returnType.typeSymbol.isClass)
4040
.map(_.asMethod.returnType.typeSymbol.asClass)
4141
.map(mirror.runtimeClass)
4242
}.toOption.flatten
@@ -48,7 +48,7 @@ object ReflectionUtils {
4848
.info
4949
.decls
5050
.collectFirst {
51-
case symbol if isNonConstructorMethod(symbol) && customMirror.methodToJava(symbol) === invocation.method => symbol
51+
case symbol if isNonConstructorMethod(symbol) && asJavaMethod(symbol) === invocation.method => symbol
5252
}
5353
}.toOption.flatten
5454

@@ -82,7 +82,7 @@ object ReflectionUtils {
8282
}.toSet
8383
}
8484
.collect {
85-
case (symbol, indices) if indices.nonEmpty => customMirror.methodToJava(symbol) -> indices
85+
case (symbol, indices) if indices.nonEmpty => asJavaMethod(symbol) -> indices
8686
}
8787
.toSeq
8888
}.toOption

0 commit comments

Comments
 (0)