summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-10-12 13:22:29 -0700
committerPaul Phillips <paulp@improving.org>2013-10-12 13:22:29 -0700
commit1a1c37ce3aa75193ecf7ef3e4089cd2305728695 (patch)
tree99a8fe22ffe900cc59f0674421afe323d0e48b85 /src/reflect
parent392d1ddb1588d69c2e8ae10a2b3e902c7229b772 (diff)
downloadscala-1a1c37ce3aa75193ecf7ef3e4089cd2305728695.tar.gz
scala-1a1c37ce3aa75193ecf7ef3e4089cd2305728695.tar.bz2
scala-1a1c37ce3aa75193ecf7ef3e4089cd2305728695.zip
Convenience method findSymbol.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Scopes.scala4
-rw-r--r--src/reflect/scala/reflect/internal/SymbolTable.scala4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/reflect/scala/reflect/internal/Scopes.scala b/src/reflect/scala/reflect/internal/Scopes.scala
index 485d4d5ddd..1060b3a99c 100644
--- a/src/reflect/scala/reflect/internal/Scopes.scala
+++ b/src/reflect/scala/reflect/internal/Scopes.scala
@@ -221,8 +221,8 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
/** Lookup a module or a class, filtering out matching names in scope
* which do not match that requirement.
*/
- def lookupModule(name: Name): Symbol = lookupAll(name.toTermName) find (_.isModule) getOrElse NoSymbol
- def lookupClass(name: Name): Symbol = lookupAll(name.toTypeName) find (_.isClass) getOrElse NoSymbol
+ def lookupModule(name: Name): Symbol = findSymbol(lookupAll(name.toTermName))(_.isModule)
+ def lookupClass(name: Name): Symbol = findSymbol(lookupAll(name.toTypeName))(_.isClass)
/** True if the name exists in this scope, false otherwise. */
def containsName(name: Name) = lookupEntry(name) != null
diff --git a/src/reflect/scala/reflect/internal/SymbolTable.scala b/src/reflect/scala/reflect/internal/SymbolTable.scala
index a6f9dfc164..ff40c0108f 100644
--- a/src/reflect/scala/reflect/internal/SymbolTable.scala
+++ b/src/reflect/scala/reflect/internal/SymbolTable.scala
@@ -124,6 +124,10 @@ abstract class SymbolTable extends macros.Universe
result
}
+ @inline final def findSymbol(xs: TraversableOnce[Symbol])(p: Symbol => Boolean): Symbol = {
+ xs find p getOrElse NoSymbol
+ }
+
// For too long have we suffered in order to sort NAMES.
// I'm pretty sure there's a reasonable default for that.
// Notice challenge created by Ordering's invariance.