diff options
author | Paul Phillips <paulp@improving.org> | 2013-03-25 11:03:25 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-03-25 11:03:25 -0700 |
commit | 98daf03a902e9af902870448f9de17ff140d9bca (patch) | |
tree | 34557b2cc0f7aba376a38e2ee5d76ddd4e55f2d9 /src/reflect | |
parent | 1187c9896c097e6e591e5655b35f52c06b3c900a (diff) | |
download | scala-98daf03a902e9af902870448f9de17ff140d9bca.tar.gz scala-98daf03a902e9af902870448f9de17ff140d9bca.tar.bz2 scala-98daf03a902e9af902870448f9de17ff140d9bca.zip |
Overhauled local/getter/setter name logic.
Sifted through extraneous methods trying to find consistency,
consolidating and deprecating as I went. The original motivation
for all this was the restoration of LOCAL_SUFFIX to originalName,
because:
It looks like in an attempt to make originalName print
consistently with decodedName, I went a little too far and
stripped invisible trailing spaces from originalName. This
meant outer fields would have an originalName of '$outer'
instead of '$outer ', which in turn could have caused them to
be mis-recognized as outer accessors, because the logic of
outerSource hinges upon "originalName == nme.OUTER".
I don't know if this affected anything - I noticed it by
inspection, improbably enough.
Deprecated originalName - original, compared to what? - in
favor of unexpandedName, which has a more obvious complement.
Introduced string_== for the many spots where people have
given up and are comparing string representations of names.
A light dusting of types is still better than nothing.
Editoral note: LOCAL_SUFFIX is the worst. Significant trailing
whitespace! It's a time bomb.
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/scala/reflect/internal/Names.scala | 50 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Printers.scala | 27 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/StdNames.scala | 119 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Symbols.scala | 66 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/TreeInfo.scala | 2 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Trees.scala | 3 | ||||
-rw-r--r-- | src/reflect/scala/reflect/runtime/JavaMirrors.scala | 20 |
7 files changed, 156 insertions, 131 deletions
diff --git a/src/reflect/scala/reflect/internal/Names.scala b/src/reflect/scala/reflect/internal/Names.scala index f8598dca7a..b8141d25f5 100644 --- a/src/reflect/scala/reflect/internal/Names.scala +++ b/src/reflect/scala/reflect/internal/Names.scala @@ -177,6 +177,12 @@ trait Names extends api.Names { /** @return the hash value of this name */ final override def hashCode(): Int = index + /** @return true if the string value of this name is equal + * to the string value of the given name or String. + */ + def string_==(that: Name): Boolean = (that ne null) && (toString == that.toString) + def string_==(that: String): Boolean = (that ne null) && (toString == that) + /**** * This has been quite useful to find places where people are comparing * a TermName and a TypeName, or a Name and a String. @@ -210,7 +216,7 @@ trait Names extends api.Names { /** @return the index of first occurrence of char c in this name, length if not found */ final def pos(c: Char): Int = pos(c, 0) - /** @return the index of first occurrence of char c in this name, length if not found */ + /** @return the index of first occurrence of s in this name, length if not found */ final def pos(s: String): Int = pos(s, 0) /** Returns the index of the first occurrence of character c in @@ -319,15 +325,18 @@ trait Names extends api.Names { final def endsWith(char: Char): Boolean = len > 0 && endChar == char final def endsWith(name: String): Boolean = endsWith(newTermName(name)) - def indexOf(ch: Char) = { - val idx = pos(ch) - if (idx == length) -1 else idx - } - def indexOf(ch: Char, fromIndex: Int) = { - val idx = pos(ch, fromIndex) - if (idx == length) -1 else idx - } - def lastIndexOf(ch: Char) = lastPos(ch) + /** Rewrite the confusing failure indication via result == length to + * the normal failure indication via result == -1. + */ + private def fixIndexOf(idx: Int): Int = if (idx == length) -1 else idx + + def indexOf(ch: Char) = fixIndexOf(pos(ch)) + def indexOf(ch: Char, fromIndex: Int) = fixIndexOf(pos(ch, fromIndex)) + def indexOf(s: String) = fixIndexOf(pos(s)) + + /** The lastPos methods already return -1 on failure. */ + def lastIndexOf(ch: Char): Int = lastPos(ch) + def lastIndexOf(s: String): Int = toString lastIndexOf s /** Replace all occurrences of `from` by `to` in * name; result is always a term name. @@ -392,9 +401,24 @@ trait Names extends api.Names { * reap the benefits because an (unused) $outer pointer so it is not single-field. */ final class NameOps[T <: Name](name: T) { - def stripSuffix(suffix: Name): T = if (name endsWith suffix) dropRight(suffix.length) else name - def dropRight(n: Int): T = name.subName(0, name.length - n).asInstanceOf[T] - def drop(n: Int): T = name.subName(n, name.length).asInstanceOf[T] + import NameTransformer._ + def stripSuffix(suffix: String): T = stripSuffix(suffix: TermName) + def stripSuffix(suffix: Name): T = if (name endsWith suffix) dropRight(suffix.length) else name + def take(n: Int): T = name.subName(0, n).asInstanceOf[T] + def drop(n: Int): T = name.subName(n, name.length).asInstanceOf[T] + def dropRight(n: Int): T = name.subName(0, name.length - n).asInstanceOf[T] + def dropLocal: TermName = name.toTermName stripSuffix LOCAL_SUFFIX_STRING + def dropSetter: TermName = name.toTermName stripSuffix SETTER_SUFFIX_STRING + def dropModule: T = this stripSuffix MODULE_SUFFIX_STRING + def localName: TermName = getterName append LOCAL_SUFFIX_STRING + def setterName: TermName = getterName append SETTER_SUFFIX_STRING + def getterName: TermName = dropTraitSetterSeparator.dropSetter.dropLocal + + private def dropTraitSetterSeparator: TermName = + name indexOf TRAIT_SETTER_SEPARATOR_STRING match { + case -1 => name.toTermName + case idx => name.toTermName drop idx drop TRAIT_SETTER_SEPARATOR_STRING.length + } } implicit val NameTag = ClassTag[Name](classOf[Name]) diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala index 28837c4ae8..e1ef6d6365 100644 --- a/src/reflect/scala/reflect/internal/Printers.scala +++ b/src/reflect/scala/reflect/internal/Printers.scala @@ -29,18 +29,19 @@ trait Printers extends api.Printers { self: SymbolTable => def quotedName(name: String): String = quotedName(newTermName(name), decode = false) private def symNameInternal(tree: Tree, name: Name, decoded: Boolean): String = { - val sym = tree.symbol - if (sym.name.toString == nme.ERROR.toString) { - "<" + quotedName(name, decoded) + ": error>" - } else if (sym != null && sym != NoSymbol) { - val prefix = if (sym.isMixinConstructor) "/*%s*/".format(quotedName(sym.owner.name, decoded)) else "" - var suffix = "" - if (settings.uniqid.value) suffix += ("#" + sym.id) - if (settings.Yshowsymkinds.value) suffix += ("#" + sym.abbreviatedKindString) - prefix + quotedName(tree.symbol.decodedName) + suffix - } else { - quotedName(name, decoded) - } + val sym = tree.symbol + def qname = quotedName(name.dropLocal, decoded) + def qowner = quotedName(sym.owner.name.dropLocal, decoded) + def qsymbol = quotedName(sym.nameString) + + if (sym.name.toTermName == nme.ERROR) + s"<$qname: error>" + else if (sym == null || sym == NoSymbol) + qname + else if (sym.isMixinConstructor) + s"/*$qowner*/$qsymbol" + else + qsymbol } def decodedSymName(tree: Tree, name: Name) = symNameInternal(tree, name, decoded = true) @@ -546,7 +547,7 @@ trait Printers extends api.Printers { self: SymbolTable => print("pendingSuperCall") case tree: Tree => val hasSymbolField = tree.hasSymbolField && tree.symbol != NoSymbol - val isError = hasSymbolField && tree.symbol.name.toString == nme.ERROR.toString + val isError = hasSymbolField && (tree.symbol.name string_== nme.ERROR) printProduct( tree, preamble = _ => { diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index a894bd649c..4fd86aa8b1 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -86,8 +86,12 @@ trait StdNames { def flattenedName(segments: Name*): NameType = compactify(segments mkString NAME_JOIN_STRING) - val MODULE_SUFFIX_STRING: String = NameTransformer.MODULE_SUFFIX_STRING - val NAME_JOIN_STRING: String = NameTransformer.NAME_JOIN_STRING + val NAME_JOIN_STRING: String = NameTransformer.NAME_JOIN_STRING + val MODULE_SUFFIX_STRING: String = NameTransformer.MODULE_SUFFIX_STRING + val SETTER_SUFFIX_STRING: String = NameTransformer.SETTER_SUFFIX_STRING + val LOCAL_SUFFIX_STRING: String = NameTransformer.LOCAL_SUFFIX_STRING + val TRAIT_SETTER_SEPARATOR_STRING: String = NameTransformer.TRAIT_SETTER_SEPARATOR_STRING + val SINGLETON_SUFFIX: String = ".type" val ANON_CLASS_NAME: NameType = "$anon" @@ -265,7 +269,7 @@ trait StdNames { val BITMAP_PREFIX = "bitmap$" val CHECK_IF_REFUTABLE_STRING = "check$ifrefutable$" val DEFAULT_GETTER_STRING = "$default$" - val DEFAULT_GETTER_INIT_STRING = "$lessinit$greater" // CONSTRUCTOR.encoded, less is more + val DEFAULT_GETTER_INIT_STRING = NameTransformer.encode("<init>") + DEFAULT_GETTER_STRING val DO_WHILE_PREFIX = "doWhile$" val EVIDENCE_PARAM_PREFIX = "evidence$" val EXCEPTION_RESULT_PREFIX = "exceptionResult" @@ -275,7 +279,6 @@ trait StdNames { val PROTECTED_PREFIX = "protected$" val PROTECTED_SET_PREFIX = PROTECTED_PREFIX + "set" val SUPER_PREFIX_STRING = "super$" - val TRAIT_SETTER_SEPARATOR_STRING = "$_setter_$" val WHILE_PREFIX = "while$" // Compiler internal names @@ -284,10 +287,8 @@ trait StdNames { val DEFAULT_CASE: NameType = "defaultCase$" val EQEQ_LOCAL_VAR: NameType = "eqEqTemp$" val FAKE_LOCAL_THIS: NameType = "this$" - val INITIALIZER: NameType = CONSTRUCTOR // Is this buying us something? val LAZY_LOCAL: NameType = "$lzy" val LAZY_SLOW_SUFFIX: NameType = "$lzycompute" - val LOCAL_SUFFIX_STRING = " " val UNIVERSE_BUILD_PREFIX: NameType = "$u.build." val UNIVERSE_PREFIX: NameType = "$u." val UNIVERSE_SHORT: NameType = "$u" @@ -301,21 +302,16 @@ trait StdNames { val MIXIN_CONSTRUCTOR: NameType = "$init$" val MODULE_INSTANCE_FIELD: NameType = NameTransformer.MODULE_INSTANCE_NAME // "MODULE$" val OUTER: NameType = "$outer" - val OUTER_LOCAL: NameType = OUTER + LOCAL_SUFFIX_STRING // "$outer ", note the space + val OUTER_LOCAL: NameType = OUTER.localName val OUTER_SYNTH: NameType = "<outer>" // emitted by virtual pattern matcher, replaced by outer accessor in explicitouter val ROOTPKG: NameType = "_root_" val SELECTOR_DUMMY: NameType = "<unapply-selector>" val SELF: NameType = "$this" - val SETTER_SUFFIX: NameType = encode("_=") + val SETTER_SUFFIX: NameType = NameTransformer.SETTER_SUFFIX_STRING val SPECIALIZED_INSTANCE: NameType = "specInstance$" val STAR: NameType = "*" val THIS: NameType = "_$this" - @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0") - def SPECIALIZED_SUFFIX_STRING = SPECIALIZED_SUFFIX.toString - @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0") - def SPECIALIZED_SUFFIX_NAME: TermName = SPECIALIZED_SUFFIX.toTermName - def isConstructorName(name: Name) = name == CONSTRUCTOR || name == MIXIN_CONSTRUCTOR def isExceptionResultName(name: Name) = name startsWith EXCEPTION_RESULT_PREFIX def isImplClassName(name: Name) = name endsWith IMPL_CLASS_SUFFIX @@ -345,31 +341,52 @@ trait StdNames { name.endChar == '=' && name.startChar != '=' && isOperatorPart(name.startChar) } - /** The expanded name of `name` relative to this class `base` with given `separator` - */ - def expandedName(name: TermName, base: Symbol, separator: String = EXPAND_SEPARATOR_STRING): TermName = + private def expandedNameInternal(name: TermName, base: Symbol, separator: String): TermName = newTermNameCached(base.fullName('$') + separator + name) + /** The expanded name of `name` relative to this class `base` + */ + def expandedName(name: TermName, base: Symbol) = expandedNameInternal(name, base, EXPAND_SEPARATOR_STRING) + /** The expanded setter name of `name` relative to this class `base` */ - def expandedSetterName(name: TermName, base: Symbol): TermName = - expandedName(name, base, separator = TRAIT_SETTER_SEPARATOR_STRING) + def expandedSetterName(name: TermName, base: Symbol) = expandedNameInternal(name, base, TRAIT_SETTER_SEPARATOR_STRING) - /** If `name` is an expandedName name, the original name. - * Otherwise `name` itself. - */ - def originalName(name: Name): Name = { - var i = name.length - while (i >= 2 && !(name.charAt(i - 1) == '$' && name.charAt(i - 2) == '$')) i -= 1 - if (i >= 2) { - while (i >= 3 && name.charAt(i - 3) == '$') i -= 1 - name.subName(i, name.length) - } else name + /** If `name` is an expandedName name, the original (unexpanded) name. + * Otherwise `name` itself. + * Look backward from the end of the string for "$$", and take the + * part of the string after that; but if the string is "$$$" or longer, + * be sure to retain the extra dollars. + */ + def unexpandedName(name: Name): Name = name lastIndexOf "$$" match { + case -1 => name + case idx0 => + // Sketchville - We've found $$ but if it's part of $$$ or $$$$ + // or something we need to keep the bonus dollars, so e.g. foo$$$outer + // has an original name of $outer. + var idx = idx0 + while (idx > 0 && name.charAt(idx - 1) == '$') + idx -= 1 + name drop idx + 2 } + @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0") + def SPECIALIZED_SUFFIX_STRING = SPECIALIZED_SUFFIX.toString + @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0") + def SPECIALIZED_SUFFIX_NAME: TermName = SPECIALIZED_SUFFIX.toTermName + + @deprecated("Use unexpandedName", "2.11.0") def originalName(name: Name): Name = unexpandedName(name) + @deprecated("Use Name#dropModule", "2.11.0") def stripModuleSuffix(name: Name): Name = name.dropModule + @deprecated("Use Name#dropLocal", "2.11.0") def localToGetter(name: TermName): TermName = name.dropLocal + @deprecated("Use Name#dropLocal", "2.11.0") def dropLocalSuffix(name: Name): TermName = name.dropLocal + @deprecated("Use Name#localName", "2.11.0") def getterToLocal(name: TermName): TermName = name.localName + @deprecated("Use Name#setterName", "2.11.0") def getterToSetter(name: TermName): TermName = name.setterName + @deprecated("Use Name#getterName", "2.11.0") def getterName(name: TermName): TermName = name.getterName + @deprecated("Use Name#getterName", "2.11.0") def setterToGetter(name: TermName): TermName = name.getterName + def unspecializedName(name: Name): Name = ( if (name endsWith SPECIALIZED_SUFFIX) - name.subName(0, name.lastIndexOf('m') - 1) + name.subName(0, name.lastIndexOf('m') - 1) else name ) @@ -394,39 +411,23 @@ trait StdNames { } else (name, "", "") - def getterName(name: TermName): TermName = if (isLocalName(name)) localToGetter(name) else name - def getterToLocal(name: TermName): TermName = name append LOCAL_SUFFIX_STRING - def getterToSetter(name: TermName): TermName = name append SETTER_SUFFIX - def localToGetter(name: TermName): TermName = name dropRight LOCAL_SUFFIX_STRING.length - - def dropLocalSuffix(name: Name): Name = if (name endsWith ' ') name dropRight 1 else name - - def setterToGetter(name: TermName): TermName = { - val p = name.pos(TRAIT_SETTER_SEPARATOR_STRING) - if (p < name.length) - setterToGetter(name drop (p + TRAIT_SETTER_SEPARATOR_STRING.length)) - else - name.subName(0, name.length - SETTER_SUFFIX.length) - } - // Nominally, name$default$N, encoded for <init> - def defaultGetterName(name: Name, pos: Int): TermName = { - val prefix = if (isConstructorName(name)) DEFAULT_GETTER_INIT_STRING else name - newTermName(prefix + DEFAULT_GETTER_STRING + pos) - } + def defaultGetterName(name: Name, pos: Int): TermName = ( + if (isConstructorName(name)) + DEFAULT_GETTER_INIT_STRING + pos + else + name + DEFAULT_GETTER_STRING + pos + ) // Nominally, name from name$default$N, CONSTRUCTOR for <init> - def defaultGetterToMethod(name: Name): TermName = { - val p = name.pos(DEFAULT_GETTER_STRING) - if (p < name.length) { - val q = name.toTermName.subName(0, p) - // i.e., if (q.decoded == CONSTRUCTOR.toString) CONSTRUCTOR else q - if (q.toString == DEFAULT_GETTER_INIT_STRING) CONSTRUCTOR else q - } else name.toTermName - } - - def stripModuleSuffix(name: Name): Name = ( - if (isModuleName(name)) name dropRight MODULE_SUFFIX_STRING.length else name + def defaultGetterToMethod(name: Name): TermName = ( + if (name startsWith DEFAULT_GETTER_INIT_STRING) + nme.CONSTRUCTOR + else name indexOf DEFAULT_GETTER_STRING match { + case -1 => name.toTermName + case idx => name.toTermName take idx + } ) + def localDummyName(clazz: Symbol): TermName = newTermName(LOCALDUMMY_PREFIX + clazz.name + ">") def superName(name: Name): TermName = newTermName(SUPER_PREFIX_STRING + name) diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index c881de7830..547fcdcfa7 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -761,16 +761,10 @@ trait Symbols extends api.Symbols { self: SymbolTable => def compileTimeOnlyMessage = getAnnotation(CompileTimeOnlyAttr) flatMap (_ stringArg 0) /** Is this symbol an accessor method for outer? */ - final def isOuterAccessor = { - hasFlag(STABLE | ARTIFACT) && - originalName == nme.OUTER - } + final def isOuterAccessor = hasFlag(STABLE | ARTIFACT) && (unexpandedName == nme.OUTER) /** Is this symbol an accessor method for outer? */ - final def isOuterField = { - hasFlag(ARTIFACT) && - originalName == nme.OUTER_LOCAL - } + final def isOuterField = isArtifact && (unexpandedName == nme.OUTER_LOCAL) /** Does this symbol denote a stable value? */ def isStable = false @@ -995,10 +989,12 @@ trait Symbols extends api.Symbols { self: SymbolTable => // ------ name attribute -------------------------------------------------------------- - /** If this symbol has an expanded name, its original name, otherwise its name itself. - * @see expandName + @deprecated("Use unexpandedName", "2.11.0") def originalName: Name = unexpandedName + + /** If this symbol has an expanded name, its original (unexpanded) name, + * otherwise the name itself. */ - def originalName: Name = nme.originalName(nme.dropLocalSuffix(name)) + def unexpandedName: Name = nme.unexpandedName(name) /** The name of the symbol before decoding, e.g. `\$eq\$eq` instead of `==`. */ @@ -1006,7 +1002,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** The decoded name of the symbol, e.g. `==` instead of `\$eq\$eq`. */ - def decodedName: String = nme.dropLocalSuffix(name).decode + def decodedName: String = name.decode private def addModuleSuffix(n: Name): Name = if (needsModuleSuffix) n append nme.MODULE_SUFFIX_STRING else n @@ -1025,7 +1021,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => ) /** These should be moved somewhere like JavaPlatform. */ - def javaSimpleName: Name = addModuleSuffix(nme.dropLocalSuffix(simpleName)) + def javaSimpleName: Name = addModuleSuffix(simpleName.dropLocal) def javaBinaryName: Name = addModuleSuffix(fullNameInternal('/')) def javaClassName: String = addModuleSuffix(fullNameInternal('.')).toString @@ -1046,7 +1042,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => else ((effectiveOwner.enclClass.fullNameAsName(separator) append separator): Name) append name ) - def fullNameAsName(separator: Char): Name = nme.dropLocalSuffix(fullNameInternal(separator)) + def fullNameAsName(separator: Char): Name = fullNameInternal(separator).dropLocal /** The encoded full path name of this symbol, where outer names and inner names * are separated by periods. @@ -1823,7 +1819,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => // // The slightly more principled approach of using the paramss of the // primary constructor leads to cycles in, for example, pos/t5084.scala. - val primaryNames = constrParamAccessors.map(acc => nme.dropLocalSuffix(acc.name)) + val primaryNames = constrParamAccessors map (_.name.dropLocal) caseFieldAccessorsUnsorted.sortBy { acc => primaryNames indexWhere { orig => (acc.name == orig) || (acc.name startsWith (orig append "$")) @@ -1842,7 +1838,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** The symbol accessed by this accessor function, but with given owner type. */ final def accessed(ownerTp: Type): Symbol = { assert(hasAccessorFlag, this) - ownerTp decl nme.getterToLocal(getterName.toTermName) + ownerTp decl localName } /** The module corresponding to this module class (note that this @@ -2199,22 +2195,23 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** The getter of this value or setter definition in class `base`, or NoSymbol if * none exists. */ - final def getter(base: Symbol): Symbol = base.info.decl(getterName) filter (_.hasAccessorFlag) + final def getter(base: Symbol): Symbol = + base.info decl getterName filter (_.hasAccessorFlag) - def getterName: TermName = ( - if (isSetter) nme.setterToGetter(name.toTermName) - else if (nme.isLocalName(name)) nme.localToGetter(name.toTermName) - else name.toTermName - ) + def getterName: TermName = name.getterName + def setterName: TermName = name.setterName + def localName: TermName = name.localName /** The setter of this value or getter definition, or NoSymbol if none exists */ - final def setter(base: Symbol): Symbol = setter(base, hasExpandedName = false) + final def setter(base: Symbol, hasExpandedName: Boolean = needsExpandedSetterName): Symbol = + base.info decl setterNameInBase(base, hasExpandedName) filter (_.hasAccessorFlag) - final def setter(base: Symbol, hasExpandedName: Boolean): Symbol = { - var sname = nme.getterToSetter(nme.getterName(name.toTermName)) - if (hasExpandedName) sname = nme.expandedSetterName(sname, base) - base.info.decl(sname) filter (_.hasAccessorFlag) - } + def needsExpandedSetterName = ( + if (isMethod) hasStableFlag && !isLazy + else hasNoFlags(LAZY | MUTABLE) + ) + def setterNameInBase(base: Symbol, expanded: Boolean): TermName = + if (expanded) nme.expandedSetterName(setterName, base) else setterName /** If this is a derived value class, return its unbox method * or NoSymbol if it does not exist. @@ -2391,12 +2388,13 @@ trait Symbols extends api.Symbols { self: SymbolTable => * If settings.uniqid, adds id. * If settings.Yshowsymkinds, adds abbreviated symbol kind. */ - def nameString: String = ( - if (!settings.uniqid.value && !settings.Yshowsymkinds.value) "" + originalName.decode - else if (settings.uniqid.value && !settings.Yshowsymkinds.value) originalName.decode + "#" + id - else if (!settings.uniqid.value && settings.Yshowsymkinds.value) originalName.decode + "#" + abbreviatedKindString - else originalName.decode + "#" + id + "#" + abbreviatedKindString - ) + def nameString: String = { + val name_s = if (settings.debug.value) "" + unexpandedName else unexpandedName.dropLocal.decode + val id_s = if (settings.uniqid.value) "#" + id else "" + val kind_s = if (settings.Yshowsymkinds.value) "#" + abbreviatedKindString else "" + + name_s + id_s + kind_s + } def fullNameString: String = { def recur(sym: Symbol): String = { diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala index e96fcc90df..b1f58814c7 100644 --- a/src/reflect/scala/reflect/internal/TreeInfo.scala +++ b/src/reflect/scala/reflect/internal/TreeInfo.scala @@ -188,7 +188,7 @@ abstract class TreeInfo { def isVariableOrGetter(tree: Tree) = { def sym = tree.symbol def isVar = sym.isVariable - def isGetter = mayBeVarGetter(sym) && sym.owner.info.member(nme.getterToSetter(sym.name.toTermName)) != NoSymbol + def isGetter = mayBeVarGetter(sym) && sym.owner.info.member(sym.setterName) != NoSymbol tree match { case Ident(_) => isVar diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index c00337e578..410bc738e2 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -242,6 +242,9 @@ trait Trees extends api.Trees { self: SymbolTable => trait NameTree extends Tree with NameTreeApi { def name: Name + def getterName: TermName = name.getterName + def setterName: TermName = name.setterName + def localName: TermName = name.localName } trait RefTree extends SymTree with NameTree with RefTreeApi { diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 2e38caaf5d..e58e89a4b1 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -242,10 +242,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni def reflectField(field: TermSymbol): FieldMirror = { checkMemberOf(field, symbol) if ((field.isMethod && !field.isAccessor) || field.isModule) ErrorNotField(field) - val name = - if (field.isGetter) nme.getterToLocal(field.name) - else if (field.isSetter) nme.getterToLocal(nme.setterToGetter(field.name)) - else field.name + val name = if (field.isAccessor) field.localName else field.name val field1 = (field.owner.info decl name).asTerm try fieldToJava(field1) catch { @@ -313,7 +310,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni // the "symbol == Any_getClass || symbol == Object_getClass" test doesn't cut it // because both AnyVal and its primitive descendants define their own getClass methods - private def isGetClass(meth: MethodSymbol) = meth.name.toString == "getClass" && meth.paramss.flatten.isEmpty + private def isGetClass(meth: MethodSymbol) = (meth.name string_== "getClass") && meth.paramss.flatten.isEmpty private def isStringConcat(meth: MethodSymbol) = meth == String_+ || (meth.owner.isPrimitiveValueClass && meth.returnType =:= StringClass.toType) lazy val bytecodelessMethodOwners = Set[Symbol](AnyClass, AnyValClass, AnyRefClass, ObjectClass, ArrayClass) ++ ScalaPrimitiveValueClasses lazy val bytecodefulObjectMethods = Set[Symbol](Object_clone, Object_equals, Object_finalize, Object_hashCode, Object_toString, @@ -844,9 +841,10 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni * that start with the given name are searched instead. */ private def lookup(clazz: Symbol, jname: String): Symbol = { - def approximateMatch(sym: Symbol, jstr: String): Boolean = - (sym.name.toString == jstr) || - sym.isPrivate && nme.expandedName(sym.name.toTermName, sym.owner).toString == jstr + def approximateMatch(sym: Symbol, jstr: String): Boolean = ( + (sym.name string_== jstr) + || sym.isPrivate && (nme.expandedName(sym.name.toTermName, sym.owner) string_== jstr) + ) clazz.info.decl(newTermName(jname)) orElse { (clazz.info.decls.iterator filter (approximateMatch(_, jname))).toList match { @@ -1008,7 +1006,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni private def typeParamToScala1(jparam: jTypeVariable[_ <: GenericDeclaration]): TypeSymbol = { val owner = genericDeclarationToScala(jparam.getGenericDeclaration) owner.info match { - case PolyType(tparams, _) => tparams.find(_.name.toString == jparam.getName).get.asType + case PolyType(tparams, _) => tparams.find(_.name string_== jparam.getName).get.asType } } @@ -1202,7 +1200,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni */ def fieldToJava(fld: TermSymbol): jField = fieldCache.toJava(fld) { val jclazz = classToJava(fld.owner.asClass) - val jname = nme.dropLocalSuffix(fld.name).toString + val jname = fld.name.dropLocal.toString try jclazz getDeclaredField jname catch { case ex: NoSuchFieldException => jclazz getDeclaredField expandedName(fld) @@ -1215,7 +1213,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni def methodToJava(meth: MethodSymbol): jMethod = methodCache.toJava(meth) { val jclazz = classToJava(meth.owner.asClass) val paramClasses = transformedType(meth).paramTypes map typeToJavaClass - val jname = nme.dropLocalSuffix(meth.name).toString + val jname = meth.name.dropLocal.toString try jclazz getDeclaredMethod (jname, paramClasses: _*) catch { case ex: NoSuchMethodException => |