Skip to content

Commit 5ce951f

Browse files
committed
Add NameOps methods testing for anonymous classes and functions
1 parent 7cf15bc commit 5ce951f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ object NameOps {
6969
def isSetterName: Boolean = name endsWith str.SETTER_SUFFIX
7070
def isScala2LocalSuffix: Boolean = testSimple(_.endsWith(" "))
7171
def isSelectorName: Boolean = testSimple(n => n.startsWith("_") && n.drop(1).forall(_.isDigit))
72+
def isAnonymousClassName: Boolean = name.startsWith(str.ANON_CLASS)
73+
def isAnonymousFunctionName: Boolean = name.startsWith(str.ANON_FUN)
7274

7375
/** Is name a variable name? */
7476
def isVariableName: Boolean = testSimple { n =>

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,13 @@ object SymDenotations {
484484

485485
/** Is this symbol an anonymous class? */
486486
final def isAnonymousClass(implicit ctx: Context): Boolean =
487-
isClass && (initial.name startsWith str.ANON_CLASS)
487+
isClass && initial.name.isAnonymousClassName
488488

489489
final def isAnonymousFunction(implicit ctx: Context): Boolean =
490-
this.symbol.is(Method) && (initial.name startsWith str.ANON_FUN)
490+
this.symbol.is(Method) && initial.name.isAnonymousFunctionName
491491

492492
final def isAnonymousModuleVal(implicit ctx: Context): Boolean =
493-
this.symbol.is(ModuleVal) && (initial.name startsWith str.ANON_CLASS)
493+
this.symbol.is(ModuleVal) && initial.name.isAnonymousClassName
494494

495495
/** Is this a synthetic method that represents conversions between representations of a value class
496496
* These methods are generated in ExtensionMethods

0 commit comments

Comments
 (0)