From a1206b99253d230684823c2f22fa42f648124672 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 9 Jul 2015 16:53:16 +0200 Subject: New name utility method: freshened Creates a fresh name by appending a $N suffix. Takes care of unwrapping/rewrapping module class suffixes. --- src/dotty/tools/dotc/core/NameOps.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/core/NameOps.scala') diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala index 4d6cca61d..dc90a8d3b 100644 --- a/src/dotty/tools/dotc/core/NameOps.scala +++ b/src/dotty/tools/dotc/core/NameOps.scala @@ -6,7 +6,7 @@ import scala.annotation.switch import scala.io.Codec import Names._, StdNames._, Contexts._, Symbols._, Flags._ import Decorators.StringDecorator -import dotty.tools.dotc.util.Chars +import util.{Chars, NameTransformer} import Chars.isOperatorPart object NameOps { @@ -59,7 +59,7 @@ object NameOps { implicit class NameDecorator[N <: Name](val name: N) extends AnyVal { import nme._ - def likeTyped(n: Name): N = + def likeTyped(n: PreName): N = (if (name.isTermName) n.toTermName else n.toTypeName).asInstanceOf[N] def isConstructorName = name == CONSTRUCTOR || name == TRAIT_CONSTRUCTOR @@ -184,6 +184,11 @@ object NameOps { def implClassName: N = likeTyped(name ++ tpnme.IMPL_CLASS_SUFFIX) + def freshened(implicit ctx: Context): N = + likeTyped( + if (name.isModuleClassName) name.stripModuleClassSuffix.freshened.moduleClassName + else likeTyped(ctx.freshName(name ++ NameTransformer.NAME_JOIN_STRING))) + /** Translate a name into a list of simple TypeNames and TermNames. * In all segments before the last, type/term is determined by whether * the following separator char is '.' or '#'. The last segment -- cgit v1.2.3