diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-07-11 14:46:01 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-07-17 15:25:07 +0200 |
commit | bab827a5426aeb654006573712eb7aabc047db36 (patch) | |
tree | b302480d37b362777f5f7fa2737df756c5d88fac /test/files/run/reflection-fieldmirror-accessorsareokay.scala | |
parent | 0cfd858a38ddf0ac83d9bbefe85110f88dc707c0 (diff) | |
download | scala-bab827a5426aeb654006573712eb7aabc047db36.tar.gz scala-bab827a5426aeb654006573712eb7aabc047db36.tar.bz2 scala-bab827a5426aeb654006573712eb7aabc047db36.zip |
SI-5895 fixes FieldMirrors
reflectField now accepts getters and setters along with the field symbols,
it also checks whether a field has a reasonable binary representation
(this is necessary, because ctor parameters that are unused outside of their
declaring constructors don't get compiled down to Java fields/methods).
Diffstat (limited to 'test/files/run/reflection-fieldmirror-accessorsareokay.scala')
-rw-r--r-- | test/files/run/reflection-fieldmirror-accessorsareokay.scala | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/files/run/reflection-fieldmirror-accessorsareokay.scala b/test/files/run/reflection-fieldmirror-accessorsareokay.scala new file mode 100644 index 0000000000..c586ce9bdd --- /dev/null +++ b/test/files/run/reflection-fieldmirror-accessorsareokay.scala @@ -0,0 +1,29 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +object Test extends App { + class A { + var x: Int = 42 + } + + val a = new A + + val im: InstanceMirror = cm.reflect(a) + val cs = im.symbol + + def test(f: Symbol) = { + try { + val fm: FieldMirror = im.reflectField(f.asTermSymbol) + println(fm.symbol.isVariable) + println(fm.get) + fm.set(2) + println(fm.get) + } catch { + case ex: Throwable => + println(ex.getMessage) + } + } + + test(cs.typeSignature.declaration(newTermName("x")).asTermSymbol) + test(cs.typeSignature.declaration(newTermName("x_$eq")).asTermSymbol) +} |