From 5e993b77ec12d139f43889a6f8194c8ff804a448 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 16 Feb 2010 16:31:29 +0000 Subject: Some minor bugfixing/refining to completion. --- .../scala/tools/nsc/interpreter/Completion.scala | 8 +++++++- .../tools/nsc/interpreter/PackageCompletion.scala | 8 ++++---- .../nsc/interpreter/ReflectionCompletion.scala | 22 ++++++++++++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/compiler/scala/tools/nsc/interpreter/Completion.scala b/src/compiler/scala/tools/nsc/interpreter/Completion.scala index 06f00c3d9d..65a6da7c07 100644 --- a/src/compiler/scala/tools/nsc/interpreter/Completion.scala +++ b/src/compiler/scala/tools/nsc/interpreter/Completion.scala @@ -26,6 +26,12 @@ import scala.tools.util.PathResolver import io.{ Path, Directory } object Completion { + // methods to leave out of completion + val excludeMethods = List("hashCode", "equals", "wait", "notify", "notifyAll") + + // strings to look for an exclude by default + val excludeStrings = List("$$super", "MODULE$") + def looksLikeInvocation(code: String) = ( (code != null) && (code startsWith ".") @@ -54,7 +60,7 @@ class Completion(repl: Interpreter) { // the top level packages we know about val pkgs = new PackageCompletion(classPath) // members of Predef - val predef = new StaticCompletion("scala.Predef") { + val predef = new StaticCompletion(classOf[scala.Predef$]) { override def filterNotFunction(s: String) = ( (s contains "2") || (s startsWith "wrap") || diff --git a/src/compiler/scala/tools/nsc/interpreter/PackageCompletion.scala b/src/compiler/scala/tools/nsc/interpreter/PackageCompletion.scala index ff5c4b3d8b..b75c0ca765 100644 --- a/src/compiler/scala/tools/nsc/interpreter/PackageCompletion.scala +++ b/src/compiler/scala/tools/nsc/interpreter/PackageCompletion.scala @@ -42,8 +42,8 @@ class PackageCompletion(classpath: List[URL]) extends CompletionAware { for (name <- ByteCode aliasForType path ; clazz <- classForName(name + "$")) yield new StaticCompletion(clazz) - lazy val pkgObject = classForName(root + ".package$") map (x => new InstanceCompletion(x)) - def pkgObjectMembers = pkgObject map (_.completions) getOrElse Nil + lazy val pkgObject = classForName(root + ".package$") map (x => new PackageObjectCompletion(x)) + def pkgObjectMembers = pkgObject map (_ completionsFor Parsed("")) getOrElse Nil private def infos = Option(dottedPaths get root) getOrElse Nil def completions() = { @@ -53,8 +53,8 @@ class PackageCompletion(classpath: List[URL]) extends CompletionAware { override def follow(segment: String): Option[CompletionAware] = { PackageCompletion.this.follow(root + "." + segment) orElse { - for (CompletionInfo(`segment`, className) <- infos) { - return Some(new StaticCompletion(className)) + for (CompletionInfo(`segment`, className) <- infos ; clazz <- classForName(className)) { + return Some(new StaticCompletion(clazz)) } aliasCompletor(root + "." + segment) diff --git a/src/compiler/scala/tools/nsc/interpreter/ReflectionCompletion.scala b/src/compiler/scala/tools/nsc/interpreter/ReflectionCompletion.scala index 1707edee00..89490119ff 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ReflectionCompletion.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ReflectionCompletion.scala @@ -12,6 +12,7 @@ import Modifier.{ isPrivate, isProtected, isStatic } import scala.reflect.NameTransformer import scala.collection.mutable.HashMap import ReflectionCompletion._ +import Completion.{ excludeMethods } trait ReflectionCompletion extends CompletionAware { def clazz: Class[_] @@ -38,18 +39,29 @@ trait ReflectionCompletion extends CompletionAware { lazy val (staticMethods, instanceMethods) = clazz.getMethods.toList partition (x => isStatic(x.getModifiers)) lazy val (staticFields, instanceFields) = clazz.getFields.toList partition (x => isStatic(x.getModifiers)) - def isScalaClazz(cl: Class[_]) = allInterfacesFor(cl) exists (_.getName == "scala.ScalaObject") + /** Oops, mirror classes don't descend from scalaobject. + */ + def isScalaClazz(cl: Class[_]) = { + (allInterfacesFor(cl) exists (_.getName == "scala.ScalaObject")) || + (classForName(cl.getName + "$").isDefined) + } def allInterfacesFor(cl: Class[_]): List[Class[_]] = allInterfacesFor(cl, Nil) - // methods to leave out of completion - val excludeMethods = List("hashCode", "equals", "wait", "notify", "notifyAll") - private def allInterfacesFor(cl: Class[_], acc: List[Class[_]]): List[Class[_]] = { if (cl == null) acc.distinct else allInterfacesFor(cl.getSuperclass, acc ::: cl.getInterfaces.toList) } } +/** An instance completion which hides a few useless members. + */ +class PackageObjectCompletion(clazz: Class[_]) extends InstanceCompletion(clazz) { + override lazy val completions = memberCompletions + override def filterNotFunction(s: String) = { + super.filterNotFunction(s) || (s == "getClass") || (s == "toString") + } +} + /** A completion aware object representing a single instance of some class. * It completes to instance fields and methods, and delegates to another * InstanceCompletion object if it can determine the result type of the element. @@ -71,8 +83,6 @@ class InstanceCompletion(val clazz: Class[_]) extends ReflectionCompletion { * java static members and scala companion object members. */ class StaticCompletion(val clazz: Class[_]) extends ReflectionCompletion { - def this(name: String) = this(classForName(name.replace('/', '.')).get) - protected def visibleMembers = whichMethods ::: whichFields lazy val completions = memberCompletions -- cgit v1.2.3