summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/internal/Symbols.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-09-30 02:05:39 +0000
committerPaul Phillips <paulp@improving.org>2011-09-30 02:05:39 +0000
commit6663d12daa44d2ca8240ed796b8f2900379844f1 (patch)
tree5e980c0be0526e9643da63d17cf81a69edf70560 /src/compiler/scala/reflect/internal/Symbols.scala
parent6116b8db81b46b0f179a1ea277a7323595e6dd68 (diff)
downloadscala-6663d12daa44d2ca8240ed796b8f2900379844f1.tar.gz
scala-6663d12daa44d2ca8240ed796b8f2900379844f1.tar.bz2
scala-6663d12daa44d2ca8240ed796b8f2900379844f1.zip
Massively simplified caseFieldAccessors.
It's nice when you can delete such absurd complication by figuring out how to avoid it in the first place. Also includes some Namer cleanup as I tried to follow the logic involved to fix a protected[this] accessor bug. No review.
Diffstat (limited to 'src/compiler/scala/reflect/internal/Symbols.scala')
-rw-r--r--src/compiler/scala/reflect/internal/Symbols.scala43
1 files changed, 10 insertions, 33 deletions
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala
index fb6d512243..82706d7265 100644
--- a/src/compiler/scala/reflect/internal/Symbols.scala
+++ b/src/compiler/scala/reflect/internal/Symbols.scala
@@ -487,6 +487,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def isLiftedMethod = isMethod && hasFlag(LIFTED)
def isCaseClass = isClass && isCase
+ // unfortunately having the CASEACCESSOR flag does not actually mean you
+ // are a case accessor (you can also be a field.)
+ def isCaseAccessorMethod = isMethod && isCaseAccessor
+
/** Does this symbol denote the primary constructor of its enclosing class? */
final def isPrimaryConstructor =
isConstructor && owner.primaryConstructor == this
@@ -1275,39 +1279,12 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
def thisType: Type = NoPrefix
- /** Return every accessor of a primary constructor parameter in this case class.
- * The scope declarations may be out of order because fields with less than private
- * access are first given a regular getter, then a new renamed getter which comes
- * later in the declaration list. For this reason we have to pinpoint the
- * right accessors by starting with the original fields (which will be in the right
- * order) and looking for getters with applicable names. The getters may have the
- * standard name "foo" or may have been renamed to "foo$\d+" in SyntheticMethods.
- * See ticket #1373.
- */
- final def caseFieldAccessors: List[Symbol] = {
- val allWithFlag = info.decls.toList filter (_.isCaseAccessor)
- val (accessors, fields) = allWithFlag partition (_.isMethod)
-
- def findAccessor(field: Symbol): Symbol = {
- // There is another renaming the field may have undergone, for instance as in
- // ticket #2175: case class Property[T](private var t: T), t becomes Property$$t.
- // So we use the original name everywhere.
- val getterName = nme.getterName(field.originalName)
-
- // Note this is done in two passes intentionally, to ensure we pick up the original
- // getter if present before looking for the renamed getter.
- def origGetter = accessors find (_.originalName == getterName)
- def renamedGetter = accessors find (_.originalName startsWith (getterName + "$"))
- val accessorName = origGetter orElse renamedGetter
-
- // This fails more gracefully rather than throw an Error as it used to because
- // as seen in #2625, we can reach this point with an already erroneous tree.
- accessorName getOrElse NoSymbol
- // throw new Error("Could not find case accessor for %s in %s".format(field, this))
- }
-
- fields map findAccessor
- }
+ /** For a case class, the symbols of the accessor methods, one for each
+ * argument in the first parameter list of the primary constructor.
+ * The empty list for all other classes.
+ */
+ final def caseFieldAccessors: List[Symbol] =
+ info.decls filter (_.isCaseAccessorMethod) toList
final def constrParamAccessors: List[Symbol] =
info.decls.toList filter (sym => !sym.isMethod && sym.isParamAccessor)