summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-07-30 22:35:36 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-08-02 15:36:57 +0200
commit7112c66d6951ac83ae3591426291ec2797824258 (patch)
treef8da05ea01df38b658c4b0cc75e96900c6dd4f32 /src
parent37d4bfe77c1d8443e522a951cd404459a409035b (diff)
downloadscala-7112c66d6951ac83ae3591426291ec2797824258.tar.gz
scala-7112c66d6951ac83ae3591426291ec2797824258.tar.bz2
scala-7112c66d6951ac83ae3591426291ec2797824258.zip
navigation between fields and accessors
This works around SI-5736 that's been deemed too risky to be fixed in 2.10.0. A reflection newbie will be unlikely to acquire a field symbol from its name, but the `accessed` method provides an easy way to navigate to it from a getter.
Diffstat (limited to 'src')
-rw-r--r--src/reflect/scala/reflect/api/Mirrors.scala2
-rw-r--r--src/reflect/scala/reflect/api/Symbols.scala12
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala2
3 files changed, 15 insertions, 1 deletions
diff --git a/src/reflect/scala/reflect/api/Mirrors.scala b/src/reflect/scala/reflect/api/Mirrors.scala
index 27176a2a2d..fe4348d568 100644
--- a/src/reflect/scala/reflect/api/Mirrors.scala
+++ b/src/reflect/scala/reflect/api/Mirrors.scala
@@ -34,7 +34,7 @@ trait Mirrors { self: Universe =>
* that can be used to get and, if appropriate, set the value of the field.
*
* To get a field symbol by the name of the field you would like to reflect,
- * use `<this mirror>.symbol.typeSignature.member(newTermName(<name of the field>)).asTermSymbol`.
+ * use `<this mirror>.symbol.typeSignature.member(newTermName(<name of the field>)).asTermSymbol.accessed`.
* For further information about member lookup refer to `Symbol.typeSignature`.
*
* The input symbol can be either private or non-private (Scala reflection transparently deals with visibility).
diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala
index 7a5db4a3f5..7ca1d9c7c6 100644
--- a/src/reflect/scala/reflect/api/Symbols.scala
+++ b/src/reflect/scala/reflect/api/Symbols.scala
@@ -185,6 +185,18 @@ trait Symbols extends base.Symbols { self: Universe =>
/** The overloaded alternatives of this symbol */
def alternatives: List[Symbol]
+
+ /** Backing field for an accessor method, NoSymbol for all other term symbols.
+ */
+ def accessed: Symbol
+
+ /** Getter method for a backing field of a val or a val, NoSymbol for all other term symbols.
+ */
+ def getter: Symbol
+
+ /** Setter method for a backing field of a val or a val, NoSymbol for all other term symbols.
+ */
+ def setter: Symbol
}
/** The API of type symbols */
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index 05ead8d1ac..8cf20ba062 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -84,6 +84,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def getAnnotations: List[AnnotationInfo] = { initialize; annotations }
def setAnnotations(annots: AnnotationInfo*): this.type = { setAnnotations(annots.toList); this }
+ def getter: Symbol = getter(owner)
+ def setter: Symbol = setter(owner)
}
/** The class for all symbols */