Skip to content

Commit bf16cce

Browse files
committed
SI-8345 support both scalap 2.11.0-M8 and 2.11.0-RC1
Once scala/scala#3588 is merged, the ByteCode module will go back to scala.tools.scalap.scalax.rules.scalasig from its current (M8) package: scala.tools.scalap.scalasig
1 parent dc20dbb commit bf16cce

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/main/scala/scala/tools/partest/nest/Runner.scala

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import scala.tools.nsc.{ Settings, CompilerCommand, Global }
2121
import scala.tools.nsc.io.{ AbstractFile }
2222
import scala.tools.nsc.reporters.ConsoleReporter
2323
import scala.tools.nsc.util.{ Exceptional, stackTraceString }
24-
import scala.tools.scalap.Main.decompileScala
25-
import scala.tools.scalap.scalasig.ByteCode
2624
import scala.util.{ Try, Success, Failure }
2725
import ClassPath.{ join, split }
2826
import TestState.{ Pass, Fail, Crash, Uninitialized, Updated }
@@ -683,16 +681,36 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
683681
lastState
684682
}
685683

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+
686706
def runScalapTest() = runTestCommon {
687707
val isPackageObject = testFile.getName startsWith "package"
688708
val className = testFile.getName.stripSuffix(".scala").capitalize + (if (!isPackageObject) "" else ".package")
689709
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)
694711
diffIsOk
695712
}
713+
696714
def runScriptTest() = {
697715
import scala.sys.process._
698716
val (swr, wr) = newTestWriters()

0 commit comments

Comments
 (0)