|
| 1 | +import scala.tasty.Reflection |
| 2 | +import scala.tasty.inspector._ |
| 3 | + |
| 4 | +package tests { |
| 5 | + |
| 6 | +class A { |
| 7 | + /** This is a method. */ |
| 8 | + def method(s: String): String = s |
| 9 | + |
| 10 | + class AA |
| 11 | + |
| 12 | + object AA |
| 13 | +} |
| 14 | + |
| 15 | +/** Companion object to test linking */ |
| 16 | +object A |
| 17 | + |
| 18 | +class B extends A { |
| 19 | + /** This is a method. */ |
| 20 | + def otherMethod(s: String): String = s |
| 21 | + |
| 22 | + class BB |
| 23 | +} |
| 24 | + |
| 25 | +object B { |
| 26 | + type Z = Int |
| 27 | + val Z: Int = 0 |
| 28 | +} |
| 29 | + |
| 30 | +class C |
| 31 | +class D[T] |
| 32 | +class E[T] extends D[T] |
| 33 | + |
| 34 | +class Constructors(a: String): |
| 35 | + def this() = this("Ala") |
| 36 | + def this(a: A)(b: A) = this("Ala") |
| 37 | + |
| 38 | +/** Some methods to tests */ |
| 39 | +class Methods: |
| 40 | + def nobraces: A = ??? |
| 41 | + /** Class doc test. |
| 42 | + * @throws [[Error]] Throws errors. |
| 43 | + */ |
| 44 | + def simple(): B = ??? |
| 45 | + def oneParam(a: A): B = ??? |
| 46 | + def multipleParams(a: A, b: B): C = ??? |
| 47 | + def vararg(a: A*): C = ??? |
| 48 | + def multipleList(a: A)(b: B): C = ??? |
| 49 | + |
| 50 | + def generic[T](a: D[T]): D[T] = ??? |
| 51 | + def generic2[T, V](a: D[T], b: E[V]): D[T] = ??? |
| 52 | + |
| 53 | + def primitives(a: Int, b: Double, c: Short): Byte = 0 |
| 54 | + def strings(a: String): String = "" |
| 55 | + def arrays(a: Array[String], b: Array[Int]): Array[Double] = ??? |
| 56 | +} |
| 57 | + |
| 58 | +object Test { |
| 59 | + def main(args: Array[String]): Unit = { |
| 60 | + new TestInspector().inspect("", List("tests.A")) |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +class TestInspector() extends TastyInspector: |
| 65 | + |
| 66 | + protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit = |
| 67 | + import reflect._ |
| 68 | + inspectClass(reflect)(root) |
| 69 | + |
| 70 | + private def inspectClass(reflect: Reflection)(tree: reflect.Tree): Unit = |
| 71 | + import reflect.{given _, _} |
| 72 | + tree match { |
| 73 | + case t: reflect.PackageClause => |
| 74 | + def hackMembersOf(using r: Reflection)(rsym: r.Symbol) = { |
| 75 | + import dotty.tools.dotc |
| 76 | + given dotc.core.Contexts.Context = r.rootContext.asInstanceOf |
| 77 | + val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol] |
| 78 | + val members = sym.info.decls.iterator |
| 79 | + // println(s"members of ${sym.show} : ${members.map(_.show).mkString(", ")}") |
| 80 | + members.asInstanceOf[Iterator[r.Symbol]] |
| 81 | + } |
| 82 | + |
| 83 | + hackMembersOf(using reflect)(t.symbol).foreach { s => |
| 84 | + println(s">>> ${s.show}") |
| 85 | + println(s">>> ${s.pos}") |
| 86 | + println(s">>> [${s.flags.show}]") |
| 87 | + } |
| 88 | + t.stats.map( m => inspectClass(reflect)(m) ) |
| 89 | + case x => |
| 90 | + } |
0 commit comments