Skip to content

Commit 1a1c37c

Browse files
committed
Convenience method findSymbol.
1 parent 392d1dd commit 1a1c37c

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ abstract class Pickler extends SubComponent {
8080
private var entries = new Array[AnyRef](256)
8181
private var ep = 0
8282
private val index = new LinkedHashMap[AnyRef, Int]
83-
private lazy val nonClassRoot = findOrElse(root.ownersIterator)(!_.isClass)(NoSymbol)
83+
private lazy val nonClassRoot = findSymbol(root.ownersIterator)(!_.isClass)
8484

8585
private def isRootSym(sym: Symbol) =
8686
sym.name.toTermName == rootName && sym.owner == rootOwner

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3418,7 +3418,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
34183418
val nvPairs = args map {
34193419
case arg @ AssignOrNamedArg(Ident(name), rhs) =>
34203420
val sym = if (isJava) annScope.lookup(name)
3421-
else typedFun.tpe.params.find(p => p.name == name).getOrElse(NoSymbol)
3421+
else findSymbol(typedFun.tpe.params)(_.name == name)
34223422
if (sym == NoSymbol) {
34233423
reportAnnotationError(UnknownAnnotationNameError(arg, name))
34243424
(nme.ERROR, None)

src/reflect/scala/reflect/internal/Scopes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
221221
/** Lookup a module or a class, filtering out matching names in scope
222222
* which do not match that requirement.
223223
*/
224-
def lookupModule(name: Name): Symbol = lookupAll(name.toTermName) find (_.isModule) getOrElse NoSymbol
225-
def lookupClass(name: Name): Symbol = lookupAll(name.toTypeName) find (_.isClass) getOrElse NoSymbol
224+
def lookupModule(name: Name): Symbol = findSymbol(lookupAll(name.toTermName))(_.isModule)
225+
def lookupClass(name: Name): Symbol = findSymbol(lookupAll(name.toTypeName))(_.isClass)
226226

227227
/** True if the name exists in this scope, false otherwise. */
228228
def containsName(name: Name) = lookupEntry(name) != null

src/reflect/scala/reflect/internal/SymbolTable.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ abstract class SymbolTable extends macros.Universe
124124
result
125125
}
126126

127+
@inline final def findSymbol(xs: TraversableOnce[Symbol])(p: Symbol => Boolean): Symbol = {
128+
xs find p getOrElse NoSymbol
129+
}
130+
127131
// For too long have we suffered in order to sort NAMES.
128132
// I'm pretty sure there's a reasonable default for that.
129133
// Notice challenge created by Ordering's invariance.

0 commit comments

Comments
 (0)