blob: 48890a21c6203069b5a3423bab42209c94e0fafd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/* NSC -- new Scala compiler
* Copyright 2005-2013 LAMP/EPFL
* @author Paul Phillips
*/
package scala.tools.nsc
package interpreter
import java.lang.reflect
import util.ScalaClassLoader
import ScalaClassLoader.appLoader
import scala.reflect.NameTransformer._
object ByteCode {
/** Until I figure out why I can't get scalap onto the classpath such
* that the compiler will bootstrap, we have to use reflection.
*/
private lazy val DECODER: Option[AnyRef] =
for (clazz <- appLoader.tryToLoadClass[AnyRef]("scala.tools.scalap.Decode$")) yield
clazz.getField(MODULE_INSTANCE_NAME).get(null)
private def decoderMethod(name: String, args: JClass*): Option[reflect.Method] = {
for (decoder <- DECODER ; m <- Option(decoder.getClass.getMethod(name, args: _*))) yield m
}
private lazy val aliasMap = {
for (module <- DECODER ; method <- decoderMethod("typeAliases", classOf[String])) yield
method.invoke(module, _: String).asInstanceOf[Option[Map[String, String]]]
}
/** Scala sig bytes.
*/
def scalaSigBytesForPath(path: String) =
for {
module <- DECODER
method <- decoderMethod("scalaSigAnnotationBytes", classOf[String])
names <- method.invoke(module, path).asInstanceOf[Option[Array[Byte]]]
}
yield names
def aliasesForPackage(pkg: String) = aliasMap flatMap (_(pkg))
}
|