@@ -65,13 +65,12 @@ object Names {
6565 def isSimple : Boolean
6666 def asSimpleName : SimpleTermName
6767 def toSimpleName : SimpleTermName
68- def mapSimpleCore (f : SimpleTermName => Name ): ThisName
68+ def rewrite (f : PartialFunction [ Name , Name ] ): ThisName
6969
7070 /** A name of the same kind as this name and with same characters as given `name` */
7171 def likeKinded (name : Name ): ThisName
7272
7373 def derived (info : NameInfo ): ThisName
74- def select (name : SimpleTermName , sep : String ) = derived(NameInfo .Qualified (name, sep))
7574 def exclude (kind : NameInfo .Kind ): ThisName
7675 def is (kind : NameInfo .Kind ): Boolean
7776 def debugString : String
@@ -99,6 +98,8 @@ object Names {
9998 def startsWith (name : Name ): Boolean = startsWith(name.toString)
10099 def endsWith (str : String ): Boolean = lastPart.endsWith(str)
101100 def endsWith (name : Name ): Boolean = endsWith(name.toString)
101+ def lastIndexOfSlice (str : String ): Int = lastPart.toString.lastIndexOfSlice(str)
102+ def lastIndexOfSlice (name : Name ): Int = lastIndexOfSlice(name.toString)
102103
103104 override def equals (that : Any ) = this eq that.asInstanceOf [AnyRef ]
104105 }
@@ -231,7 +232,7 @@ object Names {
231232 def isSimple = true
232233 def asSimpleName = this
233234 def toSimpleName = this
234- def mapSimpleCore (f : SimpleTermName => Name ): TermName = likeKinded(f(this ))
235+ def rewrite (f : PartialFunction [ Name , Name ] ): ThisName = likeKinded(f(this ))
235236
236237 def encode : SimpleTermName =
237238 if (dontEncode(toTermName)) this else NameTransformer .encode(this )
@@ -272,7 +273,7 @@ object Names {
272273 def isSimple = toTermName.isSimple
273274 def asSimpleName = toTermName.asSimpleName
274275 def toSimpleName = toTermName.toSimpleName
275- def mapSimpleCore (f : SimpleTermName => Name ): TypeName = toTermName.mapSimpleCore (f).toTypeName
276+ def rewrite (f : PartialFunction [ Name , Name ] ): ThisName = toTermName.rewrite (f).toTypeName
276277
277278 def likeKinded (name : Name ): TypeName = name.toTypeName
278279
@@ -292,16 +293,13 @@ object Names {
292293 def isEmpty = false
293294 def encode : Name = underlying.encode.derived(info.map(_.encode))
294295 def decode : Name = underlying.decode.derived(info.map(_.decode))
295- def firstPart = info match {
296- case NameInfo .Qualified (name, _) => name
297- case _ => underlying.firstPart
298- }
296+ def firstPart = underlying.firstPart
299297 def lastPart = info match {
300- case NameInfo .Qualified (name, _) => name
298+ case qual : NameInfo .Qualified => qual. name
301299 case _ => underlying.lastPart
302300 }
303301 def ++ (other : String ): ThisName = info match {
304- case NameInfo .Qualified (name, sep) => underlying.select(name ++ other, sep )
302+ case qual : NameInfo .Qualified => underlying.derived(qual.map(_ ++ other) )
305303 case _ => (underlying ++ other).derived(info)
306304 }
307305 override def toString = info.mkString(underlying)
@@ -310,7 +308,13 @@ object Names {
310308 def isSimple = false
311309 def asSimpleName = throw new UnsupportedOperationException (s " $debugString is not a simple name " )
312310 def toSimpleName = termName(toString)
313- def mapSimpleCore (f : SimpleTermName => Name ) = underlying.mapSimpleCore(f).derived(info)
311+
312+ def rewrite (f : PartialFunction [Name , Name ]): ThisName =
313+ if (f.isDefinedAt(this )) likeKinded(f(this ))
314+ else info match {
315+ case qual : NameInfo .Qualified => this
316+ case _ => underlying.rewrite(f).derived(info)
317+ }
314318 }
315319
316320 // Nametable
@@ -470,7 +474,6 @@ object Names {
470474 def seq : WrappedString = new WrappedString (name.toString)
471475 override protected [this ] def thisCollection : WrappedString = seq
472476 def indexOfSlice (name : Name ): Int = indexOfSlice(name.toString)
473- def lastIndexOfSlice (name : Name ): Int = lastIndexOfSlice(name.toString)
474477 def containsSlice (name : Name ): Boolean = containsSlice(name.toString)
475478 }
476479
0 commit comments