aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/target/jvm/type/reflection.lux
blob: f4df7e88b2983704be94626dbd24373268ea3188 (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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(.using
  [library
   [lux {"-" Primitive int char}
    [abstract
     [equivalence {"+" Equivalence}]]
    [data
     ["[0]" text ("[1]#[0]" equivalence)
      ["%" format {"+" format}]]]
    [type
     abstract]]]
  ["[0]" // "_"
   [category {"+" Void Value Return Method Primitive Object Class Array Var Parameter Declaration}]
   ["[1][0]" descriptor]
   [//
    [encoding
     ["[1][0]" name {"+" External}]]]])

(abstract: .public (Reflection category)
  Text

  (def: .public reflection
    (-> (Reflection Any) Text)
    (|>> :representation))

  (implementation: .public equivalence
    (All (_ category) (Equivalence (Reflection category)))
    
    (def: (= parameter subject)
      (text#= (:representation parameter) (:representation subject))))

  (template [<category> <name> <reflection>]
    [(def: .public <name>
       (Reflection <category>)
       (:abstraction <reflection>))]

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

  (def: .public class
    (-> External (Reflection Class))
    (|>> :abstraction))

  (def: .public (declaration name)
    (-> External (Reflection Declaration))
    (:transmutation (..class name)))

  (def: .public as_class
    (-> (Reflection Declaration) (Reflection Class))
    (|>> :transmutation))

  (def: .public (array element)
    (-> (Reflection Value) (Reflection Array))
    (let [element' (:representation element)
          elementR (`` (cond (text.starts_with? //descriptor.array_prefix element')
                             element'
                             
                             (~~ (template [<primitive> <descriptor>]
                                   [(# ..equivalence = <primitive> element)
                                    (//descriptor.descriptor <descriptor>)]

                                   [..boolean //descriptor.boolean]
                                   [..byte //descriptor.byte]
                                   [..short //descriptor.short]
                                   [..int //descriptor.int]
                                   [..long //descriptor.long]
                                   [..float //descriptor.float]
                                   [..double //descriptor.double]
                                   [..char //descriptor.char]))

                             (|> element'
                                 //descriptor.class
                                 //descriptor.descriptor
                                 (text.replaced //name.internal_separator
                                                //name.external_separator))))]
      (|> elementR
          (format //descriptor.array_prefix)
          :abstraction)))

  (template [<name> <category>]
    [(def: .public <name>
       (Reflection <category>)
       (:transmutation
        (..class "java.lang.Object")))]

    [var Var]
    [wildcard Parameter]
    )

  (def: .public (lower reflection)
    (-> (Reflection Parameter) (Reflection Parameter))
    ..wildcard)

  (def: .public upper
    (-> (Reflection Parameter) (Reflection Parameter))
    (|>> :transmutation))
  )