diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-29 14:20:21 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-29 15:01:57 -0700 |
commit | 29a59700b4cf1ade91abb6020ba4814be5ef88e7 (patch) | |
tree | 72e08ca9fed178bc4166ea00c1521b4d7b4a7975 /test/files | |
parent | 2e14b0771569b4fb6cd0273e1480f69c18743832 (diff) | |
download | scala-29a59700b4cf1ade91abb6020ba4814be5ef88e7.tar.gz scala-29a59700b4cf1ade91abb6020ba4814be5ef88e7.tar.bz2 scala-29a59700b4cf1ade91abb6020ba4814be5ef88e7.zip |
Added utility function shortClass.
Pretty sick of names like
scala> typeOf[List[Int]].getClass.getName
res0: String = scala.reflect.internal.Types$TypeRef$$anon$1
I wrote this so I can see what the class of some arbitrary
thing is in a way which my little brain can understand. For
the example above we get
scala> shortClassOfInstance(typeOf[List[Int]])
res0: String = ArgsTypeRef with AliasTypeRef
Let's pimp a "shortClassName" onto AnyRef and be happy.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/shortClass.check | 10 | ||||
-rw-r--r-- | test/files/run/shortClass.scala | 24 |
2 files changed, 34 insertions, 0 deletions
diff --git a/test/files/run/shortClass.check b/test/files/run/shortClass.check new file mode 100644 index 0000000000..fbdb725cca --- /dev/null +++ b/test/files/run/shortClass.check @@ -0,0 +1,10 @@ +bippity.bop.Foo +bippity.bop.Foo$Bar +bippity.bop.Foo$Bar$ +Test$$anon$1 +Test$$anon$2 +Foo +Bar +Bar$ +Foo with DingDongBippy +Bar with DingDongBippy diff --git a/test/files/run/shortClass.scala b/test/files/run/shortClass.scala new file mode 100644 index 0000000000..b7bb016896 --- /dev/null +++ b/test/files/run/shortClass.scala @@ -0,0 +1,24 @@ +import scala.reflect.internal.util._ + +package bippity { + trait DingDongBippy + + package bop { + class Foo { + class Bar + object Bar + } + } +} + +object Test { + import bippity._ + import bop._ + + def main(args: Array[String]): Unit = { + val f = new Foo + val instances = List(f, new f.Bar, f.Bar, new Foo with DingDongBippy, new f.Bar with DingDongBippy) + instances map (_.getClass.getName) foreach println + instances map shortClassOfInstance foreach println + } +} |