diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/FreshNameCreator.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/util/FreshNameCreator.scala | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala b/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala new file mode 100644 index 0000000000..8215941256 --- /dev/null +++ b/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala @@ -0,0 +1,33 @@ +/* NSC -- new scala compiler + * Copyright 2005 LAMP/EPFL + * @author Martin Odersky + */ +// $Id$ +package scala.tools.nsc.util; + +import scala.collection.mutable.HashMap; + +class FreshNameCreator { + + protected var counter = 0; + protected val counters = new HashMap[String,int]; + + /** + * Create a fresh name with the given prefix. It is guaranteed + * 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 count = counters.get(prefix) match { + case Some(last) => last + 1 + case None => 0 + } + counters.update(prefix, count); + prefix + count + } + + def newName(): String = { + counter = counter + 1; + "$" + counter + "$" + } +} |