aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala17
1 files changed, 10 insertions, 7 deletions
diff --git a/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala b/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala
index 8892a570e..529e30f05 100644
--- a/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala
+++ b/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala
@@ -3,9 +3,12 @@ package dotc
package util
import scala.collection.mutable
+import core.Names.TermName
+import core.NameExtractors.UniqueNameExtractor
+import core.StdNames.str
-trait FreshNameCreator {
- def newName(prefix: String = ""): String
+abstract class FreshNameCreator {
+ def newName(prefix: TermName, unique: UniqueNameExtractor): TermName
}
object FreshNameCreator {
@@ -18,11 +21,11 @@ object FreshNameCreator {
* that the returned name has never been returned by a previous
* call to this function (provided the prefix does not end in a digit).
*/
- def newName(prefix: String): String = {
- val safePrefix = prefix.replaceAll("""[<>]""", """\$""")
- counters(safePrefix) += 1
- val counter = counters(safePrefix)
- if (prefix.isEmpty) "$" + counter + "$" else safePrefix + counter
+ def newName(prefix: TermName, unique: UniqueNameExtractor): TermName = {
+ val key = str.sanitize(prefix.toString + unique.separator)
+ counters(key) += 1
+ val counter = counters(key)
+ prefix.derived(unique.NumberedInfo(counter))
}
}
}