From 1935b66102808cc72262cffca3546f4bb5b7baac Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 21 Mar 2010 23:00:14 +0000 Subject: Some support code related to partest changes. --- src/scalap/scala/tools/scalap/Decode.scala | 8 +++++--- src/scalap/scala/tools/scalap/Main.scala | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/scalap') diff --git a/src/scalap/scala/tools/scalap/Decode.scala b/src/scalap/scala/tools/scalap/Decode.scala index 6e55558249..4b319da13a 100644 --- a/src/scalap/scala/tools/scalap/Decode.scala +++ b/src/scalap/scala/tools/scalap/Decode.scala @@ -10,7 +10,8 @@ package scala.tools.scalap import scala.tools.scalap.scalax.rules.scalasig._ -import scala.tools.nsc.util.ScalaClassLoader.{ getSystemLoader, findBytesForClassName } +import scala.tools.nsc.util.ScalaClassLoader +import scala.tools.nsc.util.ScalaClassLoader.getSystemLoader import Main.SCALA_SIG /** Temporary decoder. This would be better off in the scala.tools.nsc @@ -26,8 +27,9 @@ object Decode { /** Return the classfile bytes representing the scala sig attribute. */ - def scalaSigBytes(name: String): Option[Array[Byte]] = { - val bytes = findBytesForClassName(name) + def scalaSigBytes(name: String): Option[Array[Byte]] = scalaSigBytes(name, getSystemLoader()) + def scalaSigBytes(name: String, classLoader: ScalaClassLoader): Option[Array[Byte]] = { + val bytes = classLoader.findBytesForClassName(name) val reader = new ByteArrayReader(bytes) val cf = new Classfile(reader) cf.scalaSigAttribute map (_.data) diff --git a/src/scalap/scala/tools/scalap/Main.scala b/src/scalap/scala/tools/scalap/Main.scala index eee689c189..d386e7a08f 100644 --- a/src/scalap/scala/tools/scalap/Main.scala +++ b/src/scalap/scala/tools/scalap/Main.scala @@ -97,16 +97,16 @@ object Main { baos.toString } - - def decompileScala(bytes: Array[Byte], isPackageObject: Boolean) = { + def getDecompiledScala(bytes: Array[Byte], isPackageObject: Boolean) = { val byteCode = ByteCode(bytes) val classFile = ClassFileParser.parse(byteCode) - classFile.attribute(SCALA_SIG).map(_.byteCode).map(ScalaSigAttributeParsers.parse) match { - case Some(scalaSig) => Console.println(parseScalaSignature(scalaSig, isPackageObject)) - case None => //Do nothing - } + val sig = classFile.attribute(SCALA_SIG).map(_.byteCode).map(ScalaSigAttributeParsers.parse) + + sig map (x => parseScalaSignature(x, isPackageObject)) } + def decompileScala(bytes: Array[Byte], isPackageObject: Boolean) = + getDecompiledScala(bytes, isPackageObject) foreach (Console println _) /**Executes scalap with the given arguments and classpath for the * class denoted by classname. -- cgit v1.2.3