diff options
-rw-r--r-- | src/reflect/scala/reflect/api/Mirrors.scala | 2 | ||||
-rw-r--r-- | src/reflect/scala/reflect/api/Symbols.scala | 12 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Symbols.scala | 2 | ||||
-rw-r--r-- | test/files/run/reflection-fieldsymbol-navigation.check | 6 | ||||
-rw-r--r-- | test/files/run/reflection-fieldsymbol-navigation.scala | 15 |
5 files changed, 36 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 */ diff --git a/test/files/run/reflection-fieldsymbol-navigation.check b/test/files/run/reflection-fieldsymbol-navigation.check new file mode 100644 index 0000000000..79f0928ea5 --- /dev/null +++ b/test/files/run/reflection-fieldsymbol-navigation.check @@ -0,0 +1,6 @@ +method x
+false
+variable x
+true
+method x
+method x_=
diff --git a/test/files/run/reflection-fieldsymbol-navigation.scala b/test/files/run/reflection-fieldsymbol-navigation.scala new file mode 100644 index 0000000000..da4612a564 --- /dev/null +++ b/test/files/run/reflection-fieldsymbol-navigation.scala @@ -0,0 +1,15 @@ +import scala.reflect.runtime.universe._ + +class C { + var x = 2 +} + +object Test extends App { + val x = typeOf[C].member(newTermName("x")).asTerm + println(x) + println(x.isVariable) + println(x.accessed) + println(x.accessed.asTerm.isVariable) + println(x.getter) + println(x.setter) +}
\ No newline at end of file |