summaryrefslogtreecommitdiff
path: root/test/files/run/t6240-universe-code-gen.scala
blob: 80b60bab7e3c0818e59c2ef908d645f3ee8baecd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import scala.tools.partest.nest.FileManager._

object Test extends App {
  val cm = reflect.runtime.currentMirror
  val u = cm.universe
  import u._

  val JavaUniverseTpe = typeOf[reflect.runtime.JavaUniverse]
  val DefinitionsModule = JavaUniverseTpe.member(TermName("definitions"))

  def forceCode(prefix: String, tp: Type): String = {
    def isLazyAccessorOrObject(sym: Symbol) = (
          (sym.isMethod && sym.asMethod.isLazy)
       || sym.isModule
    )
    val forceables = tp.members.sorted.filter(isLazyAccessorOrObject)
    forceables.map {
      sym =>
        val path = s"$prefix.${sym.name}"
        "    " + (
          if (sym.isPrivate || sym.isProtected) s"// inaccessible: $path"
          else path
        )
    }.mkString("\n")
  }

  val code =
    s"""|// Generated Code, validated by run/t6240-universe-code-gen.scala
        |package scala.reflect
        |package runtime
        |
        |trait JavaUniverseForce { self: runtime.JavaUniverse  =>
        |  def force() {
        |    Literal(Constant(42)).duplicate
        |    nme.flattenedName()
        |    nme.raw
        |    WeakTypeTag
        |    TypeTag
        |    TypeTag.Byte.tpe
        |    TypeTag.Short.tpe
        |    TypeTag.Char.tpe
        |    TypeTag.Int.tpe
        |    TypeTag.Long.tpe
        |    TypeTag.Float.tpe
        |    TypeTag.Double.tpe
        |    TypeTag.Boolean.tpe
        |    TypeTag.Unit.tpe
        |    TypeTag.Any.tpe
        |    TypeTag.AnyVal.tpe
        |    TypeTag.AnyRef.tpe
        |    TypeTag.Object.tpe
        |    TypeTag.Nothing.tpe
        |    TypeTag.Null.tpe
        |
        |${forceCode("this", JavaUniverseTpe)}
        |${forceCode("definitions", DefinitionsModule.info)}
        |
        |${forceCode("uncurry", typeOf[scala.reflect.internal.transform.UnCurry])}
        |${forceCode("erasure", typeOf[scala.reflect.internal.transform.Erasure])}
        |  }
        |}""".stripMargin

  import java.io.File
  val testFile = new File(sys.props("partest.test-path"))
  val actualFile = new java.io.File(testFile.getParent + "/../../../src/reflect/scala/reflect/runtime/JavaUniverseForce.scala").getCanonicalFile
  val actual = scala.io.Source.fromFile(actualFile)
  val actualLines = actual.getLines.toList
  val generatedLines = code.lines.toList
  if (actualLines != generatedLines) {
    val msg = s"""|${actualFile} must be updated.
                  |===========================================================
                  | DIFF:
                  |===========================================================
                  |${compareContents(actualLines, generatedLines)}
                  |===========================================================
                  | NEW CONTENTS:
                  |===========================================================
                  |${code}""".stripMargin

    assert(false, msg)
  }
}