diff options
author | Paul Phillips <paulp@improving.org> | 2009-12-16 19:25:26 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-12-16 19:25:26 +0000 |
commit | 1a7200a1d20afb60bf5e1eb912e7e31c3156a851 (patch) | |
tree | ab31356647f8a357cfa998ccecbc6fe88f7a4dc9 /src/scalap | |
parent | eb46c9ab39c5b95724f17908225b2a3728e7b72d (diff) | |
download | scala-1a7200a1d20afb60bf5e1eb912e7e31c3156a851.tar.gz scala-1a7200a1d20afb60bf5e1eb912e7e31c3156a851.tar.bz2 scala-1a7200a1d20afb60bf5e1eb912e7e31c3156a851.zip |
REPL completion now understands type aliases de...
REPL completion now understands type aliases defined in package objects.
For instance try scala.List.<tab>. review by community.
Diffstat (limited to 'src/scalap')
-rw-r--r-- | src/scalap/scala/tools/scalap/Decode.scala | 39 | ||||
-rw-r--r-- | src/scalap/scala/tools/scalap/Main.scala | 3 |
2 files changed, 40 insertions, 2 deletions
diff --git a/src/scalap/scala/tools/scalap/Decode.scala b/src/scalap/scala/tools/scalap/Decode.scala new file mode 100644 index 0000000000..d859ac5766 --- /dev/null +++ b/src/scalap/scala/tools/scalap/Decode.scala @@ -0,0 +1,39 @@ +/* ___ ____ ___ __ ___ ___ +** / _// __// _ | / / / _ | / _ \ Scala classfile decoder +** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003-2010, LAMP/EPFL +** /____/\___/_/ |_/____/_/ |_/_/ http://scala-lang.org/ +** +*/ + +// $Id$ + +package scala.tools.scalap + +import scala.tools.scalap.scalax.rules.scalasig._ +import scala.tools.nsc.util.ScalaClassLoader.getSystemLoader + +/** Temporary decoder. This would be better off in the scala.tools.nsc + * but right now the compiler won't acknowledge scala.tools.scalap + * when it's bootstrapping, so the reference has to go from here to there. + */ +object Decode { + private def getAliasSymbol(t: Type): Symbol = t match { + case TypeRefType(_, s, _) => s + case PolyType(typeRef, _) => getAliasSymbol(typeRef) + case _ => NoSymbol + } + + /** Returns a map of Alias -> Type for the given package. + */ + def typeAliases(pkg: String) = { + for { + clazz <- getSystemLoader.tryToLoadClass[AnyRef](pkg + ".package") + ssig <- ScalaSigParser.parse(clazz) + } + yield { + val typeAliases = ssig.symbols partialMap { case x: AliasSymbol => x } + Map(typeAliases map (x => (x.name, getAliasSymbol(x.infoType).path)): _*) + } + } +} + diff --git a/src/scalap/scala/tools/scalap/Main.scala b/src/scalap/scala/tools/scalap/Main.scala index 2211945aab..59c77813dd 100644 --- a/src/scalap/scala/tools/scalap/Main.scala +++ b/src/scalap/scala/tools/scalap/Main.scala @@ -9,7 +9,6 @@ package scala.tools.scalap - import java.io.{File, PrintStream, OutputStreamWriter, ByteArrayOutputStream} import scalax.rules.scalasig._ import tools.nsc.io.AbstractFile @@ -46,7 +45,7 @@ object Main { def isScalaFile(bytes: Array[Byte]): Boolean = { val byteCode = ByteCode(bytes) val classFile = ClassFileParser.parse(byteCode) - classFile.attribute("ScalaSig") match {case Some(_) => true; case None => false} + classFile.attribute("ScalaSig").isDefined } /**Processes the given Java class file. |