@@ -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,40 @@ 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
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 block by:
690
+ // import scalap.scalax.rules.scalasig.ByteCode
691
+ // ByteCode forClass clazz bytes
692
+ val bytes = {
693
+ import scala .language .{reflectiveCalls , existentials }
694
+ type ByteCode = { def bytes : Array [Byte ] }
695
+ type ByteCodeModule = { def forClass (clazz : Class [_]): ByteCode }
696
+ val ByteCode = {
697
+ val ByteCodeModuleCls =
698
+ // RC1 package structure -- see: scala/scala#3588 and https://issues.scala-lang.org/browse/SI-8345
699
+ (util.Try { Class .forName(" scala.tools.scalap.scalax.rules.scalasig.ByteCode$" ) }
700
+ // M8 package structure
701
+ getOrElse Class .forName(" scala.tools.scalap.scalasig.ByteCode$" ))
702
+ ByteCodeModuleCls .getDeclaredFields()(0 ).get(null ).asInstanceOf [ByteCodeModule ]
703
+ }
704
+ ByteCode forClass clazz bytes
705
+ }
706
+
707
+ scalap.Main .decompileScala(bytes, isPackageObject)
708
+ }
709
+
686
710
def runScalapTest () = runTestCommon {
687
711
val isPackageObject = testFile.getName startsWith " package"
688
712
val className = testFile.getName.stripSuffix(" .scala" ).capitalize + (if (! isPackageObject) " " else " .package" )
689
713
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
714
+ logFile writeAll decompileClass(loader loadClass className, isPackageObject)
694
715
diffIsOk
695
716
}
717
+
696
718
def runScriptTest () = {
697
719
import scala .sys .process ._
698
720
val (swr, wr) = newTestWriters()
0 commit comments