@@ -21,8 +21,6 @@ import scala.tools.nsc.{ Settings, CompilerCommand, Global }
21
21
import scala .tools .nsc .io .{ AbstractFile }
22
22
import scala .tools .nsc .reporters .ConsoleReporter
23
23
import scala .tools .nsc .util .{ Exceptional , stackTraceString }
24
- import scala .tools .scalap .Main .decompileScala
25
- import scala .tools .scalap .scalasig .ByteCode
26
24
import scala .util .{ Try , Success , Failure }
27
25
import ClassPath .{ join , split }
28
26
import TestState .{ Pass , Fail , Crash , Uninitialized , Updated }
@@ -683,16 +681,36 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
683
681
lastState
684
682
}
685
683
684
+ private def decompileClass (clazz : Class [_], isPackageObject : Boolean ): String = {
685
+ import scala .tools .scalap .Main
686
+
687
+ // TODO: remove use of reflection once Scala 2.11.0-RC1 is out
688
+ // have to use reflection to work on both 2.11.0-M8 and 2.11.0-RC1.
689
+ // Once we require only 2.11.0-RC1, replace the following definitions by:
690
+ // import scala.tools.scalap.scalax.rules.scalasig.ByteCode
691
+ type ByteCode = { def bytes : Array [Byte ] }
692
+ type ByteCodeModule = { def forClass (clazz : Class [_]): ByteCode }
693
+ val ByteCode = {
694
+ val ByteCodeModuleCls =
695
+ // RC1 package structure -- see: scala/scala#3588 and https://issues.scala-lang.org/browse/SI-8345
696
+ (util.Try { Class .forName(" scala.tools.scalap.scalax.rules.scalasig.ByteCode$" ) }
697
+ // M8 package structure
698
+ getOrElse Class .forName(" scala.tools.scalap.scalasig.ByteCode$" ))
699
+ ByteCodeModuleCls .getDeclaredFields()(0 ).get(null ).asInstanceOf [ByteCodeModule ]
700
+ }
701
+
702
+ val byteCode = ByteCode forClass clazz
703
+ Main .decompileScala(byteCode.bytes, isPackageObject)
704
+ }
705
+
686
706
def runScalapTest () = runTestCommon {
687
707
val isPackageObject = testFile.getName startsWith " package"
688
708
val className = testFile.getName.stripSuffix(" .scala" ).capitalize + (if (! isPackageObject) " " else " .package" )
689
709
val loader = ScalaClassLoader .fromURLs(List (outDir.toURI.toURL), this .getClass.getClassLoader)
690
- val byteCode = ByteCode forClass (loader loadClass className)
691
- val result = decompileScala(byteCode.bytes, isPackageObject)
692
-
693
- logFile writeAll result
710
+ logFile writeAll decompileClass(loader loadClass className)
694
711
diffIsOk
695
712
}
713
+
696
714
def runScriptTest () = {
697
715
import scala .sys .process ._
698
716
val (swr, wr) = newTestWriters()
0 commit comments