aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/target/jvm/type/reflection.lux
blob: b74a4ea30373025713479680e51674595a5abf2d (plain)
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
(.module:
  [lux (#- int char)
   [data
    [text
     ["%" format (#+ format)]]]]
  ["." //])

(template [<name> <reflection>]
  [(def: #export <name> <reflection>)]

  [void "void"]
  [boolean "boolean"]
  [byte "byte"]
  [short "short"]
  [int "int"]
  [long "long"]
  [float "float"]
  [double "double"]
  [char "char"]
  )

(def: #export (class type)
  (-> //.Type Text)
  (case type
    (#//.Primitive prim)
    (case prim
      #//.Boolean ..boolean
      #//.Byte    ..byte
      #//.Short   ..short
      #//.Int     ..int
      #//.Long    ..long
      #//.Float   ..float
      #//.Double  ..double
      #//.Char    ..char)

    (#//.Array sub)
    (|> sub class (format //.array-prefix))

    (#//.Generic generic)
    (case generic
      (#//.Class name params)
      name

      (^or (#//.Var name)
           (#//.Wildcard #.None)
           (#//.Wildcard (#.Some [#//.Lower bound])))
      //.object-class

      (#//.Wildcard (#.Some [#//.Upper bound]))
      (class (#//.Generic bound)))
    ))