@ts-for-gir/lib 4.0.0-beta.25 → 4.0.0-beta.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (567) hide show
  1. package/package.json +12 -26
  2. package/src/constants.ts +154 -0
  3. package/src/dependency-manager.ts +427 -0
  4. package/src/formatters/default.ts +7 -0
  5. package/src/formatters/formatter.ts +3 -0
  6. package/src/formatters/index.ts +3 -0
  7. package/src/formatters/json.ts +7 -0
  8. package/src/generators/generator.ts +65 -0
  9. package/src/generators/index.ts +2 -0
  10. package/src/generics/clutter.ts +71 -0
  11. package/src/generics/generify.ts +74 -0
  12. package/src/generics/gio.ts +91 -0
  13. package/src/generics/glib.ts +31 -0
  14. package/src/generics/gtk.ts +99 -0
  15. package/src/generics/meta.ts +41 -0
  16. package/src/generics/st.ts +197 -0
  17. package/src/generics/visitor.ts +484 -0
  18. package/src/gir/alias.ts +73 -0
  19. package/src/gir/callback.ts +79 -0
  20. package/src/gir/const.ts +73 -0
  21. package/src/gir/constructor.ts +91 -0
  22. package/src/gir/data.ts +12 -0
  23. package/src/gir/dependency-resolver.ts +81 -0
  24. package/src/gir/direct-allocation-constructor.ts +65 -0
  25. package/src/gir/enum-member.ts +51 -0
  26. package/src/gir/enum.ts +126 -0
  27. package/src/gir/error.ts +82 -0
  28. package/src/gir/function.ts +296 -0
  29. package/src/gir/generics.ts +66 -0
  30. package/src/gir/gir-complex-record.ts +7 -0
  31. package/src/gir/index.ts +25 -0
  32. package/src/gir/introspected-base.ts +104 -0
  33. package/src/gir/introspected-class-member.ts +15 -0
  34. package/src/gir/introspected-classes.ts +1517 -0
  35. package/src/gir/introspected-namespace-member.ts +24 -0
  36. package/src/gir/namespace.ts +76 -0
  37. package/src/gir/parameter.ts +199 -0
  38. package/src/gir/promisify.ts +209 -0
  39. package/src/gir/property.ts +203 -0
  40. package/src/gir/record.ts +477 -0
  41. package/src/gir/registry.ts +184 -0
  42. package/src/gir/signal.ts +246 -0
  43. package/src/gir-module.ts +703 -0
  44. package/src/gir.ts +892 -0
  45. package/src/index.ts +16 -0
  46. package/src/injections/gee08.ts +89 -0
  47. package/src/injections/gee1.ts +35 -0
  48. package/src/injections/gio.ts +707 -0
  49. package/src/injections/glib.ts +275 -0
  50. package/src/injections/gobject.ts +901 -0
  51. package/src/injections/gtk4.ts +23 -0
  52. package/src/injections/inject.ts +43 -0
  53. package/src/injections/shell.ts +45 -0
  54. package/src/injections/tracker1.ts +42 -0
  55. package/src/library-version.ts +50 -0
  56. package/src/logger.ts +104 -0
  57. package/src/messages.ts +57 -0
  58. package/src/templates/index.ts +1 -0
  59. package/src/templates/template-engine.ts +178 -0
  60. package/src/types/answer-version.ts +4 -0
  61. package/src/types/any-introspected-type.ts +3 -0
  62. package/src/types/class-function-types.ts +49 -0
  63. package/src/types/class-member.ts +5 -0
  64. package/src/types/class-parent.ts +14 -0
  65. package/src/types/class.ts +45 -0
  66. package/src/types/config-flags.ts +5 -0
  67. package/src/types/construct-name.ts +13 -0
  68. package/src/types/dependency-map.ts +4 -0
  69. package/{lib/types/dependency.d.ts → src/types/dependency.ts} +17 -15
  70. package/{lib/types/file-info.d.ts → src/types/file-info.ts} +3 -3
  71. package/src/types/format.ts +1 -0
  72. package/src/types/generator-constructor.ts +7 -0
  73. package/src/types/generics-config.ts +90 -0
  74. package/src/types/gir-any-element.ts +35 -0
  75. package/src/types/gir-module-interface.ts +22 -0
  76. package/src/types/gir-module-resolved.ts +32 -0
  77. package/src/types/gir-type-name.ts +20 -0
  78. package/src/types/index.ts +94 -0
  79. package/{lib/types/inheritance-table.d.ts → src/types/inheritance-table.ts} +1 -1
  80. package/src/types/introspected.ts +18 -0
  81. package/src/types/local-name-check.ts +5 -0
  82. package/src/types/local-name-type.ts +1 -0
  83. package/src/types/local-name.ts +8 -0
  84. package/src/types/local-names.ts +5 -0
  85. package/src/types/metadata.ts +6 -0
  86. package/src/types/ns-loader.ts +7 -0
  87. package/src/types/options-base.ts +8 -0
  88. package/{lib/types/options-generation.d.ts → src/types/options-generation.ts} +22 -13
  89. package/src/types/options-load.ts +6 -0
  90. package/src/types/options-transform.ts +5 -0
  91. package/src/types/output-format.ts +1 -0
  92. package/{lib/types/package-data-parsed.d.ts → src/types/package-data-parsed.ts} +13 -13
  93. package/{lib/types/package-data.d.ts → src/types/package-data.ts} +12 -11
  94. package/src/types/package-section-parsed.ts +9 -0
  95. package/src/types/parsed-gir.ts +5 -0
  96. package/src/types/parsed-package-data.ts +7 -0
  97. package/src/types/property-case.ts +1 -0
  98. package/src/types/resolve-type.ts +4 -0
  99. package/src/types/template-data.ts +8 -0
  100. package/src/types/template-options.ts +33 -0
  101. package/src/types/transformation-case.ts +9 -0
  102. package/src/types/transformations.ts +5 -0
  103. package/{lib/types/ts-doc-tag.d.ts → src/types/ts-doc-tag.ts} +5 -3
  104. package/{lib/types/ts-doc.d.ts → src/types/ts-doc.ts} +5 -3
  105. package/{lib/types/type-gir-alias.d.ts → src/types/type-gir-alias.ts} +1 -1
  106. package/{lib/types/type-gir-class.d.ts → src/types/type-gir-class.ts} +1 -1
  107. package/src/types/type-gir-element.ts +25 -0
  108. package/{lib/types/type-gir-enumeration-member.d.ts → src/types/type-gir-enumeration-member.ts} +1 -1
  109. package/{lib/types/type-ts-enumeration-member.d.ts → src/types/type-gir-enumeration.ts} +1 -1
  110. package/src/types/type-gir-function.ts +8 -0
  111. package/{lib/types/type-gir-interface.d.ts → src/types/type-gir-interface.ts} +1 -1
  112. package/{lib/types/type-gir-method.d.ts → src/types/type-gir-method.ts} +1 -1
  113. package/src/types/type-gir-parameter.ts +1 -0
  114. package/{lib/types/type-gir-property.d.ts → src/types/type-gir-property.ts} +1 -1
  115. package/src/types/type-gir-variable.ts +1 -0
  116. package/src/types/type-ts-element.ts +13 -0
  117. package/{lib/types/type-gir-enumeration.d.ts → src/types/type-ts-enumeration-member.ts} +1 -1
  118. package/{lib/types/type-ts-function.d.ts → src/types/type-ts-function.ts} +1 -1
  119. package/{lib/types/type-ts-property.d.ts → src/types/type-ts-property.ts} +1 -1
  120. package/src/types/user-config-load-result.ts +6 -0
  121. package/{lib/types/user-config.d.ts → src/types/user-config.ts} +25 -17
  122. package/src/util.ts +84 -0
  123. package/src/utils/conflicts/conflict-resolver.ts +122 -0
  124. package/src/utils/conflicts/function-conflict-detector.ts +139 -0
  125. package/src/utils/conflicts/index.ts +2 -0
  126. package/src/utils/conflicts.ts +490 -0
  127. package/{lib/utils/documentation.js → src/utils/documentation.ts} +25 -22
  128. package/src/utils/files.ts +71 -0
  129. package/src/utils/function-type-guards.ts +61 -0
  130. package/src/utils/generation.ts +69 -0
  131. package/src/utils/gir-parsing.ts +243 -0
  132. package/src/utils/girs.ts +113 -0
  133. package/src/utils/index.ts +14 -0
  134. package/src/utils/naming.ts +188 -0
  135. package/{lib/utils/numbers.d.ts → src/utils/numbers.ts} +3 -1
  136. package/{lib/utils/objects.js → src/utils/objects.ts} +15 -7
  137. package/src/utils/path.ts +7 -0
  138. package/src/utils/registry.ts +5 -0
  139. package/src/utils/strings.ts +134 -0
  140. package/src/utils/type-resolution.ts +116 -0
  141. package/src/utils/types.ts +247 -0
  142. package/src/validators/class.ts +324 -0
  143. package/src/validators/function-parameters.ts +52 -0
  144. package/src/validators/interface.ts +20 -0
  145. package/src/visitor.ts +58 -0
  146. package/lib/constants.d.ts +0 -25
  147. package/lib/constants.js +0 -93
  148. package/lib/constants.js.map +0 -1
  149. package/lib/dependency-manager.d.ts +0 -151
  150. package/lib/dependency-manager.js +0 -340
  151. package/lib/dependency-manager.js.map +0 -1
  152. package/lib/formatters/default.d.ts +0 -4
  153. package/lib/formatters/default.js +0 -7
  154. package/lib/formatters/default.js.map +0 -1
  155. package/lib/formatters/formatter.d.ts +0 -3
  156. package/lib/formatters/formatter.js +0 -3
  157. package/lib/formatters/formatter.js.map +0 -1
  158. package/lib/formatters/json.d.ts +0 -4
  159. package/lib/formatters/json.js +0 -7
  160. package/lib/formatters/json.js.map +0 -1
  161. package/lib/generators/dts/glib.d.ts +0 -2
  162. package/lib/generators/dts/glib.js +0 -514
  163. package/lib/generators/dts/glib.js.map +0 -1
  164. package/lib/generators/dts/gobject.d.ts +0 -2
  165. package/lib/generators/dts/gobject.js +0 -117
  166. package/lib/generators/dts/gobject.js.map +0 -1
  167. package/lib/generators/dts-inline.d.ts +0 -10
  168. package/lib/generators/dts-inline.js +0 -57
  169. package/lib/generators/dts-inline.js.map +0 -1
  170. package/lib/generators/dts-modules.d.ts +0 -10
  171. package/lib/generators/dts-modules.js +0 -98
  172. package/lib/generators/dts-modules.js.map +0 -1
  173. package/lib/generators/dts.d.ts +0 -45
  174. package/lib/generators/dts.js +0 -683
  175. package/lib/generators/dts.js.map +0 -1
  176. package/lib/generators/generator.d.ts +0 -45
  177. package/lib/generators/generator.js +0 -9
  178. package/lib/generators/generator.js.map +0 -1
  179. package/lib/generators/index.d.ts +0 -5
  180. package/lib/generators/index.js +0 -6
  181. package/lib/generators/index.js.map +0 -1
  182. package/lib/generators/json.d.ts +0 -257
  183. package/lib/generators/json.js +0 -866
  184. package/lib/generators/json.js.map +0 -1
  185. package/lib/generics/clutter.d.ts +0 -41
  186. package/lib/generics/clutter.js +0 -52
  187. package/lib/generics/clutter.js.map +0 -1
  188. package/lib/generics/generify.d.ts +0 -2
  189. package/lib/generics/generify.js +0 -47
  190. package/lib/generics/generify.js.map +0 -1
  191. package/lib/generics/gio.d.ts +0 -7
  192. package/lib/generics/gio.js +0 -51
  193. package/lib/generics/gio.js.map +0 -1
  194. package/lib/generics/glib.d.ts +0 -7
  195. package/lib/generics/glib.js +0 -18
  196. package/lib/generics/glib.js.map +0 -1
  197. package/lib/generics/gtk.d.ts +0 -7
  198. package/lib/generics/gtk.js +0 -56
  199. package/lib/generics/gtk.js.map +0 -1
  200. package/lib/generics/meta.d.ts +0 -36
  201. package/lib/generics/meta.js +0 -29
  202. package/lib/generics/meta.js.map +0 -1
  203. package/lib/generics/st.d.ts +0 -31
  204. package/lib/generics/st.js +0 -98
  205. package/lib/generics/st.js.map +0 -1
  206. package/lib/generics/visitor.d.ts +0 -20
  207. package/lib/generics/visitor.js +0 -255
  208. package/lib/generics/visitor.js.map +0 -1
  209. package/lib/gir/alias.d.ts +0 -24
  210. package/lib/gir/alias.js +0 -43
  211. package/lib/gir/alias.js.map +0 -1
  212. package/lib/gir/base.d.ts +0 -62
  213. package/lib/gir/base.js +0 -83
  214. package/lib/gir/base.js.map +0 -1
  215. package/lib/gir/class.d.ts +0 -228
  216. package/lib/gir/class.js +0 -1151
  217. package/lib/gir/class.js.map +0 -1
  218. package/lib/gir/const.d.ts +0 -25
  219. package/lib/gir/const.js +0 -43
  220. package/lib/gir/const.js.map +0 -1
  221. package/lib/gir/enum.d.ts +0 -45
  222. package/lib/gir/enum.js +0 -164
  223. package/lib/gir/enum.js.map +0 -1
  224. package/lib/gir/function.d.ts +0 -200
  225. package/lib/gir/function.js +0 -683
  226. package/lib/gir/function.js.map +0 -1
  227. package/lib/gir/generics.d.ts +0 -5
  228. package/lib/gir/generics.js +0 -57
  229. package/lib/gir/generics.js.map +0 -1
  230. package/lib/gir/index.d.ts +0 -14
  231. package/lib/gir/index.js +0 -15
  232. package/lib/gir/index.js.map +0 -1
  233. package/lib/gir/namespace.d.ts +0 -21
  234. package/lib/gir/namespace.js +0 -57
  235. package/lib/gir/namespace.js.map +0 -1
  236. package/lib/gir/nodes.d.ts +0 -11
  237. package/lib/gir/nodes.js +0 -12
  238. package/lib/gir/nodes.js.map +0 -1
  239. package/lib/gir/promisify.d.ts +0 -5
  240. package/lib/gir/promisify.js +0 -158
  241. package/lib/gir/promisify.js.map +0 -1
  242. package/lib/gir/property.d.ts +0 -60
  243. package/lib/gir/property.js +0 -128
  244. package/lib/gir/property.js.map +0 -1
  245. package/lib/gir/registry.d.ts +0 -51
  246. package/lib/gir/registry.js +0 -147
  247. package/lib/gir/registry.js.map +0 -1
  248. package/lib/gir/signal.d.ts +0 -36
  249. package/lib/gir/signal.js +0 -169
  250. package/lib/gir/signal.js.map +0 -1
  251. package/lib/gir/util.d.ts +0 -49
  252. package/lib/gir/util.js +0 -561
  253. package/lib/gir/util.js.map +0 -1
  254. package/lib/gir-module.d.ts +0 -104
  255. package/lib/gir-module.js +0 -584
  256. package/lib/gir-module.js.map +0 -1
  257. package/lib/gir.d.ts +0 -254
  258. package/lib/gir.js +0 -639
  259. package/lib/gir.js.map +0 -1
  260. package/lib/index.d.ts +0 -13
  261. package/lib/index.js +0 -16
  262. package/lib/index.js.map +0 -1
  263. package/lib/injections/gee08.d.ts +0 -7
  264. package/lib/injections/gee08.js +0 -68
  265. package/lib/injections/gee08.js.map +0 -1
  266. package/lib/injections/gee1.d.ts +0 -7
  267. package/lib/injections/gee1.js +0 -28
  268. package/lib/injections/gee1.js.map +0 -1
  269. package/lib/injections/gio.d.ts +0 -7
  270. package/lib/injections/gio.js +0 -563
  271. package/lib/injections/gio.js.map +0 -1
  272. package/lib/injections/glib.d.ts +0 -7
  273. package/lib/injections/glib.js +0 -210
  274. package/lib/injections/glib.js.map +0 -1
  275. package/lib/injections/gobject.d.ts +0 -7
  276. package/lib/injections/gobject.js +0 -594
  277. package/lib/injections/gobject.js.map +0 -1
  278. package/lib/injections/gtk4.d.ts +0 -7
  279. package/lib/injections/gtk4.js +0 -19
  280. package/lib/injections/gtk4.js.map +0 -1
  281. package/lib/injections/inject.d.ts +0 -4
  282. package/lib/injections/inject.js +0 -33
  283. package/lib/injections/inject.js.map +0 -1
  284. package/lib/injections/shell.d.ts +0 -20
  285. package/lib/injections/shell.js +0 -34
  286. package/lib/injections/shell.js.map +0 -1
  287. package/lib/injections/tracker1.d.ts +0 -7
  288. package/lib/injections/tracker1.js +0 -30
  289. package/lib/injections/tracker1.js.map +0 -1
  290. package/lib/library-version.d.ts +0 -10
  291. package/lib/library-version.js +0 -45
  292. package/lib/library-version.js.map +0 -1
  293. package/lib/logger.d.ts +0 -36
  294. package/lib/logger.js +0 -134
  295. package/lib/logger.js.map +0 -1
  296. package/lib/messages.d.ts +0 -23
  297. package/lib/messages.js +0 -39
  298. package/lib/messages.js.map +0 -1
  299. package/lib/registry.d.ts +0 -8
  300. package/lib/registry.js +0 -12
  301. package/lib/registry.js.map +0 -1
  302. package/lib/transformation.d.ts +0 -169
  303. package/lib/transformation.js +0 -393
  304. package/lib/transformation.js.map +0 -1
  305. package/lib/types/answer-version.d.ts +0 -4
  306. package/lib/types/answer-version.js +0 -2
  307. package/lib/types/answer-version.js.map +0 -1
  308. package/lib/types/class-parent.d.ts +0 -13
  309. package/lib/types/class-parent.js +0 -2
  310. package/lib/types/class-parent.js.map +0 -1
  311. package/lib/types/config-flags.d.ts +0 -4
  312. package/lib/types/config-flags.js +0 -2
  313. package/lib/types/config-flags.js.map +0 -1
  314. package/lib/types/construct-name.d.ts +0 -1
  315. package/lib/types/construct-name.js +0 -2
  316. package/lib/types/construct-name.js.map +0 -1
  317. package/lib/types/dependency-map.d.ts +0 -4
  318. package/lib/types/dependency-map.js +0 -2
  319. package/lib/types/dependency-map.js.map +0 -1
  320. package/lib/types/dependency.js +0 -2
  321. package/lib/types/dependency.js.map +0 -1
  322. package/lib/types/file-info.js +0 -2
  323. package/lib/types/file-info.js.map +0 -1
  324. package/lib/types/format.d.ts +0 -1
  325. package/lib/types/format.js +0 -2
  326. package/lib/types/format.js.map +0 -1
  327. package/lib/types/gir-alias-element.d.ts +0 -4
  328. package/lib/types/gir-alias-element.js +0 -2
  329. package/lib/types/gir-alias-element.js.map +0 -1
  330. package/lib/types/gir-annotation.d.ts +0 -9
  331. package/lib/types/gir-annotation.js +0 -2
  332. package/lib/types/gir-annotation.js.map +0 -1
  333. package/lib/types/gir-any-element.d.ts +0 -2
  334. package/lib/types/gir-any-element.js +0 -2
  335. package/lib/types/gir-any-element.js.map +0 -1
  336. package/lib/types/gir-bitfield-element.d.ts +0 -6
  337. package/lib/types/gir-bitfield-element.js +0 -2
  338. package/lib/types/gir-bitfield-element.js.map +0 -1
  339. package/lib/types/gir-callable-param-element.d.ts +0 -4
  340. package/lib/types/gir-callable-param-element.js +0 -2
  341. package/lib/types/gir-callable-param-element.js.map +0 -1
  342. package/lib/types/gir-callable-params.d.ts +0 -7
  343. package/lib/types/gir-callable-params.js +0 -2
  344. package/lib/types/gir-callable-params.js.map +0 -1
  345. package/lib/types/gir-callable-return.d.ts +0 -5
  346. package/lib/types/gir-callable-return.js +0 -2
  347. package/lib/types/gir-callable-return.js.map +0 -1
  348. package/lib/types/gir-callback-element.d.ts +0 -6
  349. package/lib/types/gir-callback-element.js +0 -2
  350. package/lib/types/gir-callback-element.js.map +0 -1
  351. package/lib/types/gir-class-element.d.ts +0 -17
  352. package/lib/types/gir-class-element.js +0 -2
  353. package/lib/types/gir-class-element.js.map +0 -1
  354. package/lib/types/gir-constant-element.d.ts +0 -4
  355. package/lib/types/gir-constant-element.js +0 -2
  356. package/lib/types/gir-constant-element.js.map +0 -1
  357. package/lib/types/gir-constructor-element.d.ts +0 -6
  358. package/lib/types/gir-constructor-element.js +0 -2
  359. package/lib/types/gir-constructor-element.js.map +0 -1
  360. package/lib/types/gir-enum-element.d.ts +0 -6
  361. package/lib/types/gir-enum-element.js +0 -2
  362. package/lib/types/gir-enum-element.js.map +0 -1
  363. package/lib/types/gir-field-element.d.ts +0 -5
  364. package/lib/types/gir-field-element.js +0 -2
  365. package/lib/types/gir-field-element.js.map +0 -1
  366. package/lib/types/gir-function-element.d.ts +0 -6
  367. package/lib/types/gir-function-element.js +0 -2
  368. package/lib/types/gir-function-element.js.map +0 -1
  369. package/lib/types/gir-instance-parameter.d.ts +0 -7
  370. package/lib/types/gir-instance-parameter.js +0 -2
  371. package/lib/types/gir-instance-parameter.js.map +0 -1
  372. package/lib/types/gir-interface-element.d.ts +0 -16
  373. package/lib/types/gir-interface-element.js +0 -2
  374. package/lib/types/gir-interface-element.js.map +0 -1
  375. package/lib/types/gir-member-element.d.ts +0 -5
  376. package/lib/types/gir-member-element.js +0 -2
  377. package/lib/types/gir-member-element.js.map +0 -1
  378. package/lib/types/gir-method-element.d.ts +0 -7
  379. package/lib/types/gir-method-element.js +0 -2
  380. package/lib/types/gir-method-element.js.map +0 -1
  381. package/lib/types/gir-module-resolved-by.d.ts +0 -15
  382. package/lib/types/gir-module-resolved-by.js +0 -2
  383. package/lib/types/gir-module-resolved-by.js.map +0 -1
  384. package/lib/types/gir-modules-grouped-map.d.ts +0 -4
  385. package/lib/types/gir-modules-grouped-map.js +0 -2
  386. package/lib/types/gir-modules-grouped-map.js.map +0 -1
  387. package/lib/types/gir-modules-grouped.d.ts +0 -12
  388. package/lib/types/gir-modules-grouped.js +0 -2
  389. package/lib/types/gir-modules-grouped.js.map +0 -1
  390. package/lib/types/gir-namespace.d.ts +0 -27
  391. package/lib/types/gir-namespace.js +0 -2
  392. package/lib/types/gir-namespace.js.map +0 -1
  393. package/lib/types/gir-property-element.d.ts +0 -4
  394. package/lib/types/gir-property-element.js +0 -2
  395. package/lib/types/gir-property-element.js.map +0 -1
  396. package/lib/types/gir-record-element.d.ts +0 -10
  397. package/lib/types/gir-record-element.js +0 -2
  398. package/lib/types/gir-record-element.js.map +0 -1
  399. package/lib/types/gir-repository.d.ts +0 -5
  400. package/lib/types/gir-repository.js +0 -2
  401. package/lib/types/gir-repository.js.map +0 -1
  402. package/lib/types/gir-signal.d.ts +0 -10
  403. package/lib/types/gir-signal.js +0 -2
  404. package/lib/types/gir-signal.js.map +0 -1
  405. package/lib/types/gir-type-name.d.ts +0 -2
  406. package/lib/types/gir-type-name.js +0 -2
  407. package/lib/types/gir-type-name.js.map +0 -1
  408. package/lib/types/gir-union-element.d.ts +0 -9
  409. package/lib/types/gir-union-element.js +0 -2
  410. package/lib/types/gir-union-element.js.map +0 -1
  411. package/lib/types/gir-unparsed-number.d.ts +0 -2
  412. package/lib/types/gir-unparsed-number.js +0 -2
  413. package/lib/types/gir-unparsed-number.js.map +0 -1
  414. package/lib/types/gir-virtual-method.d.ts +0 -6
  415. package/lib/types/gir-virtual-method.js +0 -2
  416. package/lib/types/gir-virtual-method.js.map +0 -1
  417. package/lib/types/index.d.ts +0 -79
  418. package/lib/types/index.js +0 -80
  419. package/lib/types/index.js.map +0 -1
  420. package/lib/types/inheritance-table.js +0 -2
  421. package/lib/types/inheritance-table.js.map +0 -1
  422. package/lib/types/local-name-check.d.ts +0 -4
  423. package/lib/types/local-name-check.js +0 -2
  424. package/lib/types/local-name-check.js.map +0 -1
  425. package/lib/types/local-name-type.d.ts +0 -1
  426. package/lib/types/local-name-type.js +0 -2
  427. package/lib/types/local-name-type.js.map +0 -1
  428. package/lib/types/local-name.d.ts +0 -7
  429. package/lib/types/local-name.js +0 -2
  430. package/lib/types/local-name.js.map +0 -1
  431. package/lib/types/local-names.d.ts +0 -4
  432. package/lib/types/local-names.js +0 -2
  433. package/lib/types/local-names.js.map +0 -1
  434. package/lib/types/metadata.d.ts +0 -8
  435. package/lib/types/metadata.js +0 -2
  436. package/lib/types/metadata.js.map +0 -1
  437. package/lib/types/options-base.d.ts +0 -4
  438. package/lib/types/options-base.js +0 -2
  439. package/lib/types/options-base.js.map +0 -1
  440. package/lib/types/options-generation.js +0 -2
  441. package/lib/types/options-generation.js.map +0 -1
  442. package/lib/types/options-load.d.ts +0 -5
  443. package/lib/types/options-load.js +0 -2
  444. package/lib/types/options-load.js.map +0 -1
  445. package/lib/types/options-transform.d.ts +0 -4
  446. package/lib/types/options-transform.js +0 -2
  447. package/lib/types/options-transform.js.map +0 -1
  448. package/lib/types/output-format.d.ts +0 -1
  449. package/lib/types/output-format.js +0 -2
  450. package/lib/types/output-format.js.map +0 -1
  451. package/lib/types/package-data-parsed.js +0 -2
  452. package/lib/types/package-data-parsed.js.map +0 -1
  453. package/lib/types/package-data.js +0 -2
  454. package/lib/types/package-data.js.map +0 -1
  455. package/lib/types/package-section-parsed.d.ts +0 -8
  456. package/lib/types/package-section-parsed.js +0 -2
  457. package/lib/types/package-section-parsed.js.map +0 -1
  458. package/lib/types/parsed-gir.d.ts +0 -5
  459. package/lib/types/parsed-gir.js +0 -2
  460. package/lib/types/parsed-gir.js.map +0 -1
  461. package/lib/types/parsed-package-data.d.ts +0 -6
  462. package/lib/types/parsed-package-data.js +0 -2
  463. package/lib/types/parsed-package-data.js.map +0 -1
  464. package/lib/types/part-of-class.d.ts +0 -7
  465. package/lib/types/part-of-class.js +0 -2
  466. package/lib/types/part-of-class.js.map +0 -1
  467. package/lib/types/part-of-module.d.ts +0 -6
  468. package/lib/types/part-of-module.js +0 -2
  469. package/lib/types/part-of-module.js.map +0 -1
  470. package/lib/types/property-case.d.ts +0 -1
  471. package/lib/types/property-case.js +0 -2
  472. package/lib/types/property-case.js.map +0 -1
  473. package/lib/types/resolve-type.d.ts +0 -4
  474. package/lib/types/resolve-type.js +0 -6
  475. package/lib/types/resolve-type.js.map +0 -1
  476. package/lib/types/template-data.d.ts +0 -7
  477. package/lib/types/template-data.js +0 -2
  478. package/lib/types/template-data.js.map +0 -1
  479. package/lib/types/transformation-case.d.ts +0 -1
  480. package/lib/types/transformation-case.js +0 -2
  481. package/lib/types/transformation-case.js.map +0 -1
  482. package/lib/types/transformations.d.ts +0 -4
  483. package/lib/types/transformations.js +0 -2
  484. package/lib/types/transformations.js.map +0 -1
  485. package/lib/types/ts-doc-tag.js +0 -2
  486. package/lib/types/ts-doc-tag.js.map +0 -1
  487. package/lib/types/ts-doc.js +0 -2
  488. package/lib/types/ts-doc.js.map +0 -1
  489. package/lib/types/type-gir-alias.js +0 -2
  490. package/lib/types/type-gir-alias.js.map +0 -1
  491. package/lib/types/type-gir-class.js +0 -2
  492. package/lib/types/type-gir-class.js.map +0 -1
  493. package/lib/types/type-gir-element.d.ts +0 -3
  494. package/lib/types/type-gir-element.js +0 -2
  495. package/lib/types/type-gir-element.js.map +0 -1
  496. package/lib/types/type-gir-enumeration-member.js +0 -2
  497. package/lib/types/type-gir-enumeration-member.js.map +0 -1
  498. package/lib/types/type-gir-enumeration.js +0 -2
  499. package/lib/types/type-gir-enumeration.js.map +0 -1
  500. package/lib/types/type-gir-function.d.ts +0 -1
  501. package/lib/types/type-gir-function.js +0 -2
  502. package/lib/types/type-gir-function.js.map +0 -1
  503. package/lib/types/type-gir-interface.js +0 -2
  504. package/lib/types/type-gir-interface.js.map +0 -1
  505. package/lib/types/type-gir-method.js +0 -2
  506. package/lib/types/type-gir-method.js.map +0 -1
  507. package/lib/types/type-gir-parameter.d.ts +0 -1
  508. package/lib/types/type-gir-parameter.js +0 -2
  509. package/lib/types/type-gir-parameter.js.map +0 -1
  510. package/lib/types/type-gir-property.js +0 -2
  511. package/lib/types/type-gir-property.js.map +0 -1
  512. package/lib/types/type-gir-variable.d.ts +0 -1
  513. package/lib/types/type-gir-variable.js +0 -2
  514. package/lib/types/type-gir-variable.js.map +0 -1
  515. package/lib/types/type-ts-element.d.ts +0 -3
  516. package/lib/types/type-ts-element.js +0 -2
  517. package/lib/types/type-ts-element.js.map +0 -1
  518. package/lib/types/type-ts-enumeration-member.js +0 -2
  519. package/lib/types/type-ts-enumeration-member.js.map +0 -1
  520. package/lib/types/type-ts-function.js +0 -2
  521. package/lib/types/type-ts-function.js.map +0 -1
  522. package/lib/types/type-ts-property.js +0 -2
  523. package/lib/types/type-ts-property.js.map +0 -1
  524. package/lib/types/user-config-load-result.d.ts +0 -6
  525. package/lib/types/user-config-load-result.js +0 -2
  526. package/lib/types/user-config-load-result.js.map +0 -1
  527. package/lib/types/user-config.js +0 -2
  528. package/lib/types/user-config.js.map +0 -1
  529. package/lib/util.d.ts +0 -20
  530. package/lib/util.js +0 -67
  531. package/lib/util.js.map +0 -1
  532. package/lib/utils/documentation.d.ts +0 -13
  533. package/lib/utils/documentation.js.map +0 -1
  534. package/lib/utils/files.d.ts +0 -21
  535. package/lib/utils/files.js +0 -62
  536. package/lib/utils/files.js.map +0 -1
  537. package/lib/utils/girs.d.ts +0 -45
  538. package/lib/utils/girs.js +0 -101
  539. package/lib/utils/girs.js.map +0 -1
  540. package/lib/utils/index.d.ts +0 -8
  541. package/lib/utils/index.js +0 -9
  542. package/lib/utils/index.js.map +0 -1
  543. package/lib/utils/naming.d.ts +0 -13
  544. package/lib/utils/naming.js +0 -40
  545. package/lib/utils/naming.js.map +0 -1
  546. package/lib/utils/numbers.js +0 -9
  547. package/lib/utils/numbers.js.map +0 -1
  548. package/lib/utils/objects.d.ts +0 -136
  549. package/lib/utils/objects.js.map +0 -1
  550. package/lib/utils/path.d.ts +0 -1
  551. package/lib/utils/path.js +0 -7
  552. package/lib/utils/path.js.map +0 -1
  553. package/lib/utils/strings.d.ts +0 -74
  554. package/lib/utils/strings.js +0 -121
  555. package/lib/utils/strings.js.map +0 -1
  556. package/lib/validators/class.d.ts +0 -7
  557. package/lib/validators/class.js +0 -217
  558. package/lib/validators/class.js.map +0 -1
  559. package/lib/validators/function-parameters.d.ts +0 -14
  560. package/lib/validators/function-parameters.js +0 -31
  561. package/lib/validators/function-parameters.js.map +0 -1
  562. package/lib/validators/interface.d.ts +0 -5
  563. package/lib/validators/interface.js +0 -16
  564. package/lib/validators/interface.js.map +0 -1
  565. package/lib/visitor.d.ts +0 -35
  566. package/lib/visitor.js +0 -29
  567. package/lib/visitor.js.map +0 -1
@@ -0,0 +1,1517 @@
1
+ import { ConsoleReporter } from "@ts-for-gir/reporter";
2
+ import type { FormatGenerator } from "../generators/generator.ts";
3
+ import {
4
+ FunctionType,
5
+ Generic,
6
+ GenericType,
7
+ GenerifiedTypeIdentifier,
8
+ type TypeExpression,
9
+ TypeIdentifier,
10
+ UnknownType,
11
+ } from "../gir.ts";
12
+ import type {
13
+ GirCallbackElement,
14
+ GirClassElement,
15
+ GirFunctionElement,
16
+ GirInterfaceElement,
17
+ GirMethodElement,
18
+ GirRecordElement,
19
+ GirVirtualMethodElement,
20
+ } from "../index.ts";
21
+ import type {
22
+ ClassDefinition,
23
+ ClassMember,
24
+ ClassResolution,
25
+ InterfaceResolution,
26
+ IntrospectedOptions,
27
+ OptionsLoad,
28
+ RecordResolution,
29
+ } from "../types/index.ts";
30
+ import { findMap } from "../util.ts";
31
+ import { parseDoc, parseMetadata } from "../utils/gir-parsing.ts";
32
+ import { sanitizeIdentifierName } from "../utils/naming.ts";
33
+ import { resolveTypeIdentifier } from "../utils/type-resolution.ts";
34
+ import { parseTypeIdentifier } from "../utils/types.ts";
35
+ import type { GirVisitor } from "../visitor.ts";
36
+ import { IntrospectedConstructor } from "./constructor.ts";
37
+ import type { IntrospectedDirectAllocationConstructor } from "./direct-allocation-constructor.ts";
38
+ import type { IntrospectedEnum } from "./enum.ts";
39
+ import { IntrospectedFunction } from "./function.ts";
40
+ import { createGenericNameGenerator, createGenericNameGeneratorAt } from "./generics.ts";
41
+ import { IntrospectedBase } from "./introspected-base.ts";
42
+ import { IntrospectedNamespaceMember } from "./introspected-namespace-member.ts";
43
+ import type { IntrospectedNamespace } from "./namespace.ts";
44
+ import type { IntrospectedFunctionParameter } from "./parameter.ts";
45
+ import { IntrospectedField, IntrospectedProperty } from "./property.ts";
46
+ import { IntrospectedSignal } from "./signal.ts";
47
+
48
+ const log = new ConsoleReporter(true, "gir/introspected-classes", true);
49
+
50
+ /**
51
+ * Represents a signal with metadata
52
+ */
53
+ export interface SignalDescriptor {
54
+ name: string;
55
+ signal?: IntrospectedSignal;
56
+ isNotifySignal?: boolean;
57
+ isDetailSignal?: boolean;
58
+ parameterTypes?: string[];
59
+ returnType?: string;
60
+ }
61
+
62
+ /**
63
+ * Base class for all class functions
64
+ */
65
+ export class IntrospectedClassFunction<
66
+ Parent extends IntrospectedBaseClass | IntrospectedEnum = IntrospectedBaseClass | IntrospectedEnum,
67
+ > extends IntrospectedBase<Parent> {
68
+ readonly parameters: IntrospectedFunctionParameter[];
69
+ protected readonly return_type: TypeExpression;
70
+ readonly output_parameters: IntrospectedFunctionParameter[];
71
+ protected _anyify: boolean = false;
72
+ protected _generify: boolean = false;
73
+ interfaceParent: IntrospectedBaseClass | IntrospectedEnum | null = null;
74
+ returnTypeDoc?: string | null;
75
+
76
+ generics: Generic[] = [];
77
+
78
+ constructor({
79
+ name,
80
+ parameters = [],
81
+ output_parameters = [],
82
+ return_type = UnknownType,
83
+ parent,
84
+ doc,
85
+ ...args
86
+ }: IntrospectedOptions<{
87
+ name: string;
88
+ parameters?: IntrospectedFunctionParameter[];
89
+ output_parameters?: IntrospectedFunctionParameter[];
90
+ return_type?: TypeExpression;
91
+ parent: Parent;
92
+ originalParent?: Parent | null;
93
+ doc?: string | null;
94
+ }>) {
95
+ super(name, parent, { ...args });
96
+
97
+ this.parameters = parameters.map((p) => p.copy({ parent: this }));
98
+ this.output_parameters = output_parameters.map((p) => p.copy({ parent: this }));
99
+ this.return_type = return_type;
100
+ this.doc = doc;
101
+ }
102
+
103
+ get namespace() {
104
+ return this.parent.namespace;
105
+ }
106
+
107
+ getCallbackParameters() {
108
+ const { name, parent, output_parameters, parameters, return_type } = this;
109
+ return {
110
+ name,
111
+ parent,
112
+ output_parameters,
113
+ parameters,
114
+ return_type,
115
+ };
116
+ }
117
+
118
+ copy({
119
+ parent = this.parent,
120
+ name,
121
+ interfaceParent,
122
+ parameters,
123
+ outputParameters,
124
+ returnType,
125
+ }: {
126
+ parent?: Parent;
127
+ name?: string;
128
+ interfaceParent?: IntrospectedBaseClass | IntrospectedEnum;
129
+ parameters?: IntrospectedFunctionParameter[];
130
+ outputParameters?: IntrospectedFunctionParameter[];
131
+ returnType?: TypeExpression;
132
+ } = {}): IntrospectedClassFunction<Parent> {
133
+ const fn = new IntrospectedClassFunction<Parent>({
134
+ name: name ?? this.name,
135
+ parent,
136
+ output_parameters: outputParameters ?? this.output_parameters,
137
+ parameters: parameters ?? this.parameters,
138
+ return_type: returnType ?? this.return_type,
139
+ });
140
+
141
+ fn.generics = [...this.generics];
142
+ fn.returnTypeDoc = this.returnTypeDoc;
143
+
144
+ if (interfaceParent) {
145
+ fn.interfaceParent = interfaceParent;
146
+ }
147
+
148
+ return fn._copyBaseProperties(this);
149
+ }
150
+
151
+ accept(visitor: GirVisitor): IntrospectedClassFunction<Parent> {
152
+ const node = this.copy({
153
+ parameters: this.parameters.map((p) => {
154
+ return p.accept(visitor);
155
+ }),
156
+ outputParameters: this.output_parameters.map((p) => {
157
+ return p.accept(visitor);
158
+ }),
159
+ returnType: visitor.visitType?.(this.return_type),
160
+ });
161
+
162
+ const fn = visitor.visitClassFunction?.(node);
163
+
164
+ return fn ?? node;
165
+ }
166
+
167
+ static fromXML(
168
+ element: GirFunctionElement | GirMethodElement,
169
+ parent: IntrospectedBaseClass | IntrospectedEnum,
170
+ options: OptionsLoad,
171
+ ): IntrospectedClassFunction {
172
+ const fn = IntrospectedFunction.fromXML(element, parent.namespace, options);
173
+
174
+ // Convert the function to a class function
175
+ const { raw_name: name, output_parameters, parameters, return_type, doc, isIntrospectable } = fn;
176
+
177
+ const classFn = new IntrospectedClassFunction({
178
+ parent,
179
+ name,
180
+ output_parameters,
181
+ parameters,
182
+ return_type,
183
+ doc,
184
+ isIntrospectable,
185
+ });
186
+
187
+ classFn.returnTypeDoc = fn.returnTypeDoc;
188
+ classFn.generics = [...fn.generics];
189
+
190
+ return classFn;
191
+ }
192
+
193
+ anyify(): this {
194
+ this._anyify = true;
195
+
196
+ return this;
197
+ }
198
+
199
+ shouldAnyify() {
200
+ return this._anyify;
201
+ }
202
+
203
+ return(): TypeExpression {
204
+ return this.return_type;
205
+ }
206
+
207
+ asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateClassFunction"]> {
208
+ return generator.generateClassFunction(this) as ReturnType<T["generateClassFunction"]>;
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Virtual class function
214
+ */
215
+ export class IntrospectedVirtualClassFunction extends IntrospectedClassFunction<IntrospectedBaseClass> {
216
+ constructor({
217
+ name,
218
+ parameters = [],
219
+ output_parameters = [],
220
+ return_type = UnknownType,
221
+ parent,
222
+ doc,
223
+ ...args
224
+ }: IntrospectedOptions<{
225
+ name: string;
226
+ parameters: IntrospectedFunctionParameter[];
227
+ output_parameters?: IntrospectedFunctionParameter[];
228
+ return_type?: TypeExpression;
229
+ parent: IntrospectedBaseClass;
230
+ doc?: string | null;
231
+ }>) {
232
+ super({
233
+ parent,
234
+ name: name.startsWith("vfunc_") ? name : `vfunc_${name}`,
235
+ parameters,
236
+ output_parameters,
237
+ return_type,
238
+ doc,
239
+ ...args,
240
+ });
241
+ }
242
+
243
+ copy({
244
+ parent = this.parent,
245
+ interfaceParent,
246
+ parameters,
247
+ outputParameters,
248
+ returnType,
249
+ }: {
250
+ parent?: IntrospectedBaseClass;
251
+ interfaceParent?: IntrospectedBaseClass | IntrospectedEnum | undefined;
252
+ parameters?: IntrospectedFunctionParameter[] | undefined;
253
+ outputParameters?: IntrospectedFunctionParameter[] | undefined;
254
+ returnType?: TypeExpression | undefined;
255
+ }): IntrospectedVirtualClassFunction {
256
+ const fn = new IntrospectedVirtualClassFunction({
257
+ name: this.name,
258
+ parent,
259
+ output_parameters: outputParameters ?? this.output_parameters,
260
+ parameters: parameters ?? this.parameters,
261
+ return_type: returnType ?? this.return_type,
262
+ });
263
+
264
+ fn.generics = [...this.generics];
265
+ fn.returnTypeDoc = this.returnTypeDoc;
266
+
267
+ if (interfaceParent) {
268
+ fn.interfaceParent = interfaceParent;
269
+ }
270
+
271
+ return fn._copyBaseProperties(this);
272
+ }
273
+
274
+ accept(visitor: GirVisitor): IntrospectedVirtualClassFunction {
275
+ const node = this.copy({
276
+ parameters: this.parameters.map((p) => {
277
+ return p.accept(visitor);
278
+ }),
279
+ outputParameters: this.output_parameters.map((p) => {
280
+ return p.accept(visitor);
281
+ }),
282
+ returnType: visitor.visitType?.(this.return_type),
283
+ });
284
+ return visitor.visitVirtualClassFunction?.(node) ?? node;
285
+ }
286
+
287
+ static fromXML(
288
+ m: GirVirtualMethodElement,
289
+ parent: IntrospectedBaseClass,
290
+ options: OptionsLoad,
291
+ ): IntrospectedVirtualClassFunction {
292
+ const fn = IntrospectedFunction.fromXML(m, parent.namespace, options);
293
+
294
+ // Convert the function to a virtual class function
295
+ const { raw_name: name, output_parameters, parameters, return_type, doc, isIntrospectable } = fn;
296
+
297
+ return new IntrospectedVirtualClassFunction({
298
+ parent,
299
+ name,
300
+ output_parameters,
301
+ parameters,
302
+ return_type,
303
+ doc,
304
+ isIntrospectable,
305
+ });
306
+ }
307
+
308
+ asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateVirtualClassFunction"]> {
309
+ return generator.generateVirtualClassFunction(this) as ReturnType<T["generateVirtualClassFunction"]>;
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Static class function
315
+ */
316
+ export class IntrospectedStaticClassFunction extends IntrospectedClassFunction {
317
+ asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateStaticClassFunction"]> {
318
+ return generator.generateStaticClassFunction(this) as ReturnType<T["generateStaticClassFunction"]>;
319
+ }
320
+
321
+ copy({
322
+ parent = this.parent,
323
+ interfaceParent,
324
+ parameters,
325
+ outputParameters,
326
+ returnType,
327
+ }: {
328
+ parent?: IntrospectedBaseClass | IntrospectedEnum;
329
+ interfaceParent?: IntrospectedBaseClass | IntrospectedEnum | undefined;
330
+ parameters?: IntrospectedFunctionParameter[] | undefined;
331
+ outputParameters?: IntrospectedFunctionParameter[] | undefined;
332
+ returnType?: TypeExpression | undefined;
333
+ } = {}): IntrospectedStaticClassFunction {
334
+ const fn = new IntrospectedStaticClassFunction({
335
+ name: this.name,
336
+ parent,
337
+ output_parameters: outputParameters ?? this.output_parameters,
338
+ parameters: parameters ?? this.parameters,
339
+ return_type: returnType ?? this.return_type,
340
+ });
341
+
342
+ fn.generics = [...this.generics];
343
+ fn.returnTypeDoc = this.returnTypeDoc;
344
+
345
+ if (interfaceParent) {
346
+ fn.interfaceParent = interfaceParent;
347
+ }
348
+
349
+ return fn._copyBaseProperties(this);
350
+ }
351
+
352
+ accept(visitor: GirVisitor): IntrospectedStaticClassFunction {
353
+ const node = this.copy({
354
+ parent: this.parent,
355
+ parameters: this.parameters.map((p) => {
356
+ return p.accept(visitor);
357
+ }),
358
+ outputParameters: this.output_parameters.map((p) => {
359
+ return p.accept(visitor);
360
+ }),
361
+ returnType: visitor.visitType?.(this.return_type),
362
+ });
363
+
364
+ return visitor.visitStaticClassFunction?.(node) ?? node;
365
+ }
366
+
367
+ asClassFunction(parent: IntrospectedBaseClass): IntrospectedClassFunction {
368
+ const { name, output_parameters, parameters, return_type, doc, isIntrospectable } = this;
369
+
370
+ const fn = new IntrospectedClassFunction({
371
+ parent,
372
+ name,
373
+ output_parameters,
374
+ parameters,
375
+ return_type,
376
+ doc,
377
+ isIntrospectable,
378
+ });
379
+
380
+ fn.returnTypeDoc = this.returnTypeDoc;
381
+ fn.generics = [...this.generics];
382
+
383
+ return fn;
384
+ }
385
+
386
+ static fromXML(
387
+ m: GirFunctionElement,
388
+ parent: IntrospectedBaseClass | IntrospectedEnum,
389
+ options: OptionsLoad,
390
+ ): IntrospectedStaticClassFunction {
391
+ const fn = IntrospectedFunction.fromXML(m, parent.namespace, options);
392
+
393
+ // Convert the function to a static class function
394
+ const { raw_name: name, output_parameters, parameters, return_type, doc, isIntrospectable } = fn;
395
+
396
+ return new IntrospectedStaticClassFunction({
397
+ parent,
398
+ name,
399
+ output_parameters,
400
+ parameters,
401
+ return_type,
402
+ doc,
403
+ isIntrospectable,
404
+ });
405
+ }
406
+ }
407
+
408
+ /**
409
+ * Class callback function
410
+ */
411
+ export class IntrospectedClassCallback extends IntrospectedClassFunction {
412
+ asFunctionType(): FunctionType {
413
+ return new FunctionType(
414
+ Object.fromEntries(this.parameters.map((p) => [p.name, p.type] as const)),
415
+ this.return_type,
416
+ );
417
+ }
418
+
419
+ copy({
420
+ parameters,
421
+ returnType,
422
+ outputParameters,
423
+ parent,
424
+ }: {
425
+ parent?: IntrospectedBaseClass;
426
+ parameters?: IntrospectedFunctionParameter[];
427
+ outputParameters?: IntrospectedFunctionParameter[];
428
+ returnType?: TypeExpression;
429
+ } = {}): IntrospectedClassCallback {
430
+ const cb = new IntrospectedClassCallback({
431
+ name: this.name,
432
+ return_type: returnType ?? this.return_type,
433
+ parameters: parameters ?? this.parameters,
434
+ output_parameters: outputParameters ?? this.output_parameters,
435
+ parent: parent ?? this.parent,
436
+ })._copyBaseProperties(this);
437
+
438
+ cb.generics = [...this.generics];
439
+
440
+ return cb;
441
+ }
442
+
443
+ accept(visitor: GirVisitor): IntrospectedClassCallback {
444
+ const node = this.copy({
445
+ parameters: this.parameters.map((p) => {
446
+ return p.accept(visitor);
447
+ }),
448
+ outputParameters: this.output_parameters.map((p) => {
449
+ return p.accept(visitor);
450
+ }),
451
+ returnType: visitor.visitType?.(this.return_type),
452
+ });
453
+
454
+ return visitor.visitClassCallback?.(node) ?? node;
455
+ }
456
+
457
+ static fromXML(
458
+ element: GirCallbackElement,
459
+ parent: IntrospectedBaseClass,
460
+ options: OptionsLoad,
461
+ ): IntrospectedClassCallback {
462
+ const ns = parent.namespace;
463
+ const cb = new IntrospectedClassCallback(
464
+ IntrospectedClassFunction.fromXML(element, parent, options).getCallbackParameters(),
465
+ );
466
+
467
+ const glibTypeName = element.$["glib:type-name"];
468
+ if (typeof glibTypeName === "string" && element.$["glib:type-name"]) {
469
+ cb.resolve_names.push(glibTypeName);
470
+
471
+ ns.registerResolveName(glibTypeName, ns.namespace, cb.name);
472
+ }
473
+
474
+ if (element.$["c:type"]) {
475
+ cb.resolve_names.push(element.$["c:type"]);
476
+
477
+ ns.registerResolveName(element.$["c:type"], ns.namespace, cb.name);
478
+ }
479
+
480
+ return cb;
481
+ }
482
+
483
+ asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateClassCallback"]> {
484
+ return generator.generateClassCallback(this) as ReturnType<T["generateClassCallback"]>;
485
+ }
486
+ }
487
+
488
+ /**
489
+ * Abstract base class for classes and interfaces
490
+ */
491
+ export abstract class IntrospectedBaseClass extends IntrospectedNamespaceMember {
492
+ /**
493
+ * Used to add a TypeScript index signature to a class
494
+ *
495
+ * NOTE: This should probably be migrated into the TypeScript generator itself.
496
+ */
497
+ __ts__indexSignature?: string;
498
+ superType: TypeIdentifier | null;
499
+
500
+ mainConstructor: null | IntrospectedConstructor | IntrospectedDirectAllocationConstructor;
501
+ constructors: IntrospectedConstructor[];
502
+ members: IntrospectedClassFunction[];
503
+ props: IntrospectedProperty[];
504
+ fields: IntrospectedField[];
505
+ callbacks: IntrospectedClassCallback[];
506
+
507
+ // Generics support
508
+ generics: Generic[] = [];
509
+
510
+ constructor(
511
+ options: IntrospectedOptions<{
512
+ name: string;
513
+ namespace: IntrospectedNamespace;
514
+ }> &
515
+ Partial<ClassDefinition>,
516
+ ) {
517
+ const {
518
+ name,
519
+ namespace,
520
+ superType = null,
521
+ mainConstructor = null,
522
+ constructors = [],
523
+ members = [],
524
+ props = [],
525
+ fields = [],
526
+ callbacks = [],
527
+ ...args
528
+ } = options;
529
+
530
+ super(name, namespace, { ...args });
531
+
532
+ this.superType = superType;
533
+
534
+ this.mainConstructor = mainConstructor?.copy({ parent: this }) ?? null;
535
+ this.constructors = [...constructors.map((c) => c.copy({ parent: this }))];
536
+ this.members = [...members.map((m) => m.copy({ parent: this }))];
537
+ this.props = [...props.map((p) => p.copy({ parent: this }))];
538
+ this.fields = [...fields.map((f) => f.copy({ parent: this }))];
539
+ this.callbacks = [...callbacks.map((c) => c.copy({ parent: this }))];
540
+ }
541
+
542
+ abstract accept(visitor: GirVisitor): IntrospectedBaseClass;
543
+
544
+ abstract copy(options?: {
545
+ parent?: undefined;
546
+ constructors?: IntrospectedConstructor[];
547
+ members?: IntrospectedClassFunction[];
548
+ props?: IntrospectedProperty[];
549
+ fields?: IntrospectedField[];
550
+ callbacks?: IntrospectedClassCallback[];
551
+ }): IntrospectedBaseClass;
552
+
553
+ getGenericName = createGenericNameGenerator();
554
+
555
+ abstract resolveParents(): RecordResolution | InterfaceResolution | ClassResolution;
556
+ abstract someParent(predicate: (b: IntrospectedBaseClass) => boolean): boolean;
557
+ abstract findParent(predicate: (b: IntrospectedBaseClass) => boolean): IntrospectedBaseClass | undefined;
558
+ abstract findParentMap<K>(predicate: (b: IntrospectedBaseClass) => K | undefined): K | undefined;
559
+
560
+ addGeneric(definition: {
561
+ deriveFrom?: TypeIdentifier;
562
+ default?: TypeExpression;
563
+ constraint?: TypeExpression;
564
+ propagate?: boolean;
565
+ }) {
566
+ const param = new Generic(
567
+ new GenericType(this.getGenericName(), definition.constraint),
568
+ definition.default,
569
+ definition.deriveFrom,
570
+ definition.constraint,
571
+ definition.propagate,
572
+ );
573
+
574
+ this.generics.push(param);
575
+ }
576
+
577
+ getType(): TypeIdentifier {
578
+ return new TypeIdentifier(this.name, this.namespace.namespace);
579
+ }
580
+
581
+ static fromXML(
582
+ _element: GirClassElement | GirInterfaceElement | GirRecordElement,
583
+ _ns: IntrospectedNamespace,
584
+ _options: OptionsLoad,
585
+ ): IntrospectedBaseClass {
586
+ throw new Error("fromXML is not implemented on GirBaseClass");
587
+ }
588
+
589
+ abstract asString<T = string>(generator: FormatGenerator<T>): T;
590
+ }
591
+
592
+ /**
593
+ * Represents a GIR class
594
+ */
595
+ export class IntrospectedClass extends IntrospectedBaseClass {
596
+ signals: IntrospectedSignal[] = [];
597
+ interfaces: TypeIdentifier[] = [];
598
+ isAbstract: boolean = false;
599
+ mainConstructor: null | IntrospectedConstructor = null;
600
+ private _staticDefinition: string | null = null;
601
+
602
+ constructor(name: string, namespace: IntrospectedNamespace) {
603
+ super({ name, namespace });
604
+ }
605
+
606
+ getAllSignals(): SignalDescriptor[] {
607
+ const allSignals = this.getBaseSignals();
608
+
609
+ if (this.hasGObjectSupport()) {
610
+ this.addNotifySignals(allSignals);
611
+ this.addDetailedSignals(allSignals);
612
+ }
613
+
614
+ return allSignals;
615
+ }
616
+
617
+ private getBaseSignals() {
618
+ return this.signals.map((signal) => ({
619
+ name: signal.name,
620
+ signal: signal,
621
+ isNotifySignal: false,
622
+ isDetailSignal: false,
623
+ }));
624
+ }
625
+
626
+ private hasGObjectSupport(): boolean {
627
+ const isGObjectObject = this.isGObjectObject();
628
+ const hasNotifySignal = this.hasExplicitNotifySignal();
629
+ const hasGObjectParent = this.hasGObjectParent();
630
+
631
+ return isGObjectObject || hasNotifySignal || hasGObjectParent;
632
+ }
633
+
634
+ private isGObjectObject(): boolean {
635
+ return this.name === "Object" && this.namespace.namespace === "GObject";
636
+ }
637
+
638
+ private hasExplicitNotifySignal(): boolean {
639
+ return this.signals.some((signal) => signal.name === "notify");
640
+ }
641
+
642
+ private hasGObjectParent(): boolean {
643
+ return this.someParent(
644
+ (p: IntrospectedClass | IntrospectedInterface) => p.namespace.namespace === "GObject" && p.name === "Object",
645
+ );
646
+ }
647
+
648
+ private addNotifySignals(allSignals: SignalDescriptor[]): void {
649
+ const propertyNames = this.getUniquePropertyNames();
650
+
651
+ propertyNames.forEach((propertyName) => {
652
+ allSignals.push({
653
+ name: `notify::${propertyName}`,
654
+ isNotifySignal: true,
655
+ isDetailSignal: false,
656
+ parameterTypes: ["GObject.ParamSpec"],
657
+ returnType: "void",
658
+ });
659
+ });
660
+ }
661
+
662
+ private addDetailedSignals(allSignals: SignalDescriptor[]): void {
663
+ const propertyNames = this.getUniquePropertyNames();
664
+
665
+ this.signals.forEach((signal) => {
666
+ if (signal.detailed) {
667
+ propertyNames.forEach((propertyName) => {
668
+ allSignals.push({
669
+ name: `${signal.name}::${propertyName}`,
670
+ signal: signal,
671
+ isNotifySignal: false,
672
+ isDetailSignal: true,
673
+ parameterTypes: signal.parameters.map((p) => this.getPropertyTypeString(p.type)),
674
+ returnType: this.getPropertyTypeString(signal.return_type),
675
+ });
676
+ });
677
+ }
678
+ });
679
+ }
680
+
681
+ private getUniquePropertyNames(): Set<string> {
682
+ const allProperties = this.getAllProperties();
683
+ return new Set(
684
+ allProperties.map((prop) =>
685
+ prop.name
686
+ .replace(/_/g, "-")
687
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
688
+ .toLowerCase(),
689
+ ),
690
+ );
691
+ }
692
+
693
+ private getPropertyTypeString(type: TypeExpression): string {
694
+ // Simple type conversion - this might need to be adjusted based on actual type structure
695
+ if (typeof type === "string") return type;
696
+ if (type?.toString) return type.toString();
697
+ return "any";
698
+ }
699
+
700
+ private getAllProperties(): IntrospectedProperty[] {
701
+ const allProperties = [...this.props];
702
+ let currentClass = this as IntrospectedClass;
703
+ while (currentClass) {
704
+ const parentResolution = currentClass.resolveParents().extends();
705
+ if (parentResolution && parentResolution.node instanceof IntrospectedClass) {
706
+ const parentClass = parentResolution.node as IntrospectedClass;
707
+ allProperties.push(...parentClass.props);
708
+ currentClass = parentClass;
709
+ } else {
710
+ break;
711
+ }
712
+ }
713
+ const implementedProps = this.implementedProperties();
714
+ allProperties.push(...implementedProps);
715
+ return allProperties;
716
+ }
717
+
718
+ accept(visitor: GirVisitor): IntrospectedClass {
719
+ const node = this.copy({
720
+ signals: this.signals.map((s) => s.accept(visitor)),
721
+ constructors: this.constructors.map((c) => c.accept(visitor)),
722
+ members: this.members.map((m) => m.accept(visitor)),
723
+ props: this.props.map((p) => p.accept(visitor)),
724
+ fields: this.fields.map((f) => f.accept(visitor)),
725
+ callbacks: this.callbacks.map((c) => c.accept(visitor)),
726
+ });
727
+ return visitor.visitClass?.(node) ?? node;
728
+ }
729
+
730
+ hasInstanceSymbol<S extends { name: string }>(s: S): boolean {
731
+ return (
732
+ this.members.some((p) => s.name === p.name && !(p instanceof IntrospectedStaticClassFunction)) ||
733
+ this.props.some((p) => s.name === p.name) ||
734
+ this.fields.some((p) => s.name === p.name)
735
+ );
736
+ }
737
+
738
+ someParent(predicate: (p: IntrospectedClass | IntrospectedInterface) => boolean): boolean {
739
+ const resolution = this.resolveParents();
740
+ const parent = resolution.extends();
741
+
742
+ if (parent) {
743
+ if (predicate(parent.node as IntrospectedClass | IntrospectedInterface)) return true;
744
+ const some = parent.node.someParent(predicate);
745
+ if (some) return some;
746
+ }
747
+
748
+ return resolution
749
+ .implements()
750
+ .map((i) => i.node)
751
+ .some(
752
+ (i) =>
753
+ predicate(i) ||
754
+ i.someParent(
755
+ (p: IntrospectedBaseClass) =>
756
+ (p instanceof IntrospectedClass || p instanceof IntrospectedInterface) && predicate(p),
757
+ ),
758
+ );
759
+ }
760
+
761
+ findParent(
762
+ predicate: (p: IntrospectedClass | IntrospectedInterface) => boolean,
763
+ ): IntrospectedClass | IntrospectedInterface | undefined {
764
+ return this.findParentMap((parent) => {
765
+ if (predicate(parent)) {
766
+ return parent;
767
+ }
768
+ return undefined;
769
+ });
770
+ }
771
+
772
+ findParentMap<K>(predicate: (p: IntrospectedClass | IntrospectedInterface) => K | undefined): K | undefined {
773
+ const resolution = this.resolveParents();
774
+ const parent = resolution.extends();
775
+
776
+ if (parent) {
777
+ const value = predicate(parent.node as IntrospectedClass | IntrospectedInterface);
778
+ if (value) return value;
779
+ const parentMap = parent.node.findParentMap(predicate);
780
+ if (parentMap) return parentMap;
781
+ }
782
+
783
+ return findMap(
784
+ resolution.implements().map((i) => i.node),
785
+ (i) =>
786
+ predicate(i) ||
787
+ i.findParentMap((p: IntrospectedBaseClass) =>
788
+ p instanceof IntrospectedClass || p instanceof IntrospectedInterface ? predicate(p) : undefined,
789
+ ),
790
+ );
791
+ }
792
+
793
+ implementedProperties(potentialConflicts: IntrospectedBase<never>[] = []) {
794
+ const resolution = this.resolveParents();
795
+ const implementedOnParent = [...(resolution.extends() ?? [])].flatMap((r) => r.implements());
796
+ const properties = new Map<string, IntrospectedProperty>();
797
+
798
+ const validateProp = (prop: IntrospectedProperty) =>
799
+ !this.hasInstanceSymbol(prop) &&
800
+ !properties.has(prop.name) &&
801
+ potentialConflicts.every((p) => prop.name !== p.name);
802
+
803
+ for (const implemented of resolution.implements()) {
804
+ if (implemented.node instanceof IntrospectedClass) continue;
805
+
806
+ if (implementedOnParent.find((p) => p.identifier.equals(implemented.identifier))?.node?.generics?.length === 0)
807
+ continue;
808
+ for (const prop of implemented.node.props) {
809
+ if (!validateProp(prop)) continue;
810
+ properties.set(prop.name, prop);
811
+ }
812
+ }
813
+
814
+ for (const implemented of resolution.implements()) {
815
+ [...implemented].forEach((e) => {
816
+ if (e.node instanceof IntrospectedClass) return;
817
+
818
+ if (implementedOnParent.find((p) => p.identifier.equals(e.identifier))?.node.generics.length === 0) return;
819
+ for (const prop of e.node.props) {
820
+ if (!validateProp(prop)) continue;
821
+
822
+ properties.set(prop.name, prop);
823
+ }
824
+ });
825
+ }
826
+
827
+ // If an interface inherits from a class (such as Gtk.Widget)
828
+ // we need to pull in every property from that class...
829
+ for (const implemented of resolution.implements()) {
830
+ const extended = implemented.extends();
831
+
832
+ if (extended?.node instanceof IntrospectedClass) {
833
+ for (const prop of extended.node.props) {
834
+ if (!validateProp(prop)) continue;
835
+
836
+ properties.set(prop.name, prop);
837
+ }
838
+ }
839
+ }
840
+
841
+ return [...properties.values()];
842
+ }
843
+
844
+ implementedMethods(potentialConflicts: ClassMember[] = []) {
845
+ const resolution = this.resolveParents();
846
+ const implementedOnParent = [...(resolution.extends() ?? [])].flatMap((r) => r.implements());
847
+ const methods = new Map<string, IntrospectedClassFunction>();
848
+
849
+ const validateMethod = (method: IntrospectedClassFunction) =>
850
+ !(method instanceof IntrospectedStaticClassFunction) &&
851
+ !this.hasInstanceSymbol(method) &&
852
+ !methods.has(method.name) &&
853
+ potentialConflicts.every((m) => method.name !== m.name);
854
+
855
+ for (const implemented of resolution.implements()) {
856
+ if (implemented.node instanceof IntrospectedClass) continue;
857
+
858
+ if (implementedOnParent.find((p) => p.identifier.equals(implemented.identifier))?.node?.generics?.length === 0)
859
+ continue;
860
+ for (const member of implemented.node.members) {
861
+ if (!validateMethod(member)) continue;
862
+ methods.set(member.name, member);
863
+ }
864
+ }
865
+
866
+ for (const implemented of resolution.implements()) {
867
+ [...implemented].forEach((e) => {
868
+ if (e.node instanceof IntrospectedClass) return;
869
+
870
+ if (implementedOnParent.find((p) => p.identifier.equals(e.identifier))?.node.generics.length === 0) return;
871
+ for (const member of e.node.members) {
872
+ if (!validateMethod(member)) continue;
873
+
874
+ methods.set(member.name, member);
875
+ }
876
+ });
877
+ }
878
+
879
+ // If an interface inherits from a class (such as Gtk.Widget)
880
+ // we need to pull in every method from that class...
881
+ for (const implemented of resolution.implements()) {
882
+ const extended = implemented.extends();
883
+
884
+ if (extended?.node instanceof IntrospectedClass) {
885
+ for (const member of extended.node.members) {
886
+ if (!validateMethod(member)) continue;
887
+
888
+ methods.set(member.name, member);
889
+ }
890
+ }
891
+ }
892
+
893
+ return [...methods.values()].map((f) => {
894
+ const mapping = new Map<string, TypeExpression>();
895
+ if (f.parent instanceof IntrospectedBaseClass) {
896
+ const inter = this.interfaces.find((i) => i.equals(f.parent.getType()));
897
+
898
+ if (inter instanceof GenerifiedTypeIdentifier) {
899
+ f.parent.generics.forEach((g, i) => {
900
+ if (inter.generics.length > i) {
901
+ mapping.set(g.type.identifier, inter.generics[i]);
902
+ }
903
+ });
904
+ }
905
+ }
906
+
907
+ const unwrapped = f.return().deepUnwrap();
908
+ let modifiedReturn = f.return();
909
+
910
+ if (unwrapped instanceof GenericType && mapping.has(unwrapped.identifier)) {
911
+ const mapped = mapping.get(unwrapped.identifier);
912
+
913
+ if (mapped) {
914
+ modifiedReturn = f.return().rewrap(mapped);
915
+ }
916
+ // Handles the case where a class implements an interface and thus copies its virtual methods.
917
+ } else if (unwrapped.equals(this.getType())) {
918
+ modifiedReturn = f.return().rewrap(this.getType());
919
+ }
920
+
921
+ return f.copy({
922
+ parent: this,
923
+ interfaceParent: f.parent,
924
+ parameters: f.parameters.map((p) => {
925
+ const t = p.type.deepUnwrap();
926
+ if (t instanceof GenericType && mapping.has(t.identifier)) {
927
+ const iden = mapping.get(t.identifier);
928
+
929
+ if (iden) {
930
+ return p.copy({ type: p.type.rewrap(iden) });
931
+ }
932
+ }
933
+
934
+ return p;
935
+ }),
936
+ outputParameters: f.output_parameters.map((p) => {
937
+ const t = p.type.deepUnwrap();
938
+ if (t instanceof GenericType && mapping.has(t.identifier)) {
939
+ const iden = mapping.get(t.identifier);
940
+
941
+ if (iden) {
942
+ return p.copy({ type: p.type.rewrap(iden) });
943
+ }
944
+ }
945
+
946
+ return p;
947
+ }),
948
+ returnType: modifiedReturn,
949
+ });
950
+ });
951
+ }
952
+
953
+ resolveParents(): ClassResolution {
954
+ const self = this;
955
+ return {
956
+ *[Symbol.iterator]() {
957
+ let current = this.extends();
958
+ while (current !== undefined) {
959
+ yield current;
960
+ current = current.extends();
961
+ }
962
+ },
963
+ extends(): ClassResolution | undefined {
964
+ const resolved_parent = self.superType ? resolveTypeIdentifier(self.namespace, self.superType) : undefined;
965
+ if (resolved_parent instanceof IntrospectedClass) {
966
+ return resolved_parent.resolveParents();
967
+ }
968
+ return undefined;
969
+ },
970
+ implements(): InterfaceResolution[] {
971
+ return self.interfaces
972
+ .map((iface) => {
973
+ const resolved = resolveTypeIdentifier(self.namespace, iface);
974
+ if (resolved instanceof IntrospectedInterface) {
975
+ return resolved.resolveParents();
976
+ }
977
+ throw new Error(`Interface ${iface.name} not found`);
978
+ })
979
+ .filter((res): res is InterfaceResolution => res !== undefined);
980
+ },
981
+ node: self,
982
+ identifier: self.getType(),
983
+ };
984
+ }
985
+
986
+ copy(
987
+ options: {
988
+ parent?: undefined;
989
+ signals?: IntrospectedSignal[];
990
+ constructors?: IntrospectedConstructor[];
991
+ members?: IntrospectedClassFunction[];
992
+ props?: IntrospectedProperty[];
993
+ fields?: IntrospectedField[];
994
+ callbacks?: IntrospectedClassCallback[];
995
+ } = {},
996
+ ): IntrospectedClass {
997
+ const klass = new IntrospectedClass(this.name, this.namespace);
998
+ klass.interfaces = [...this.interfaces];
999
+ klass.superType = this.superType;
1000
+ klass.isAbstract = this.isAbstract;
1001
+ klass.doc = this.doc;
1002
+ klass.generics = [...this.generics];
1003
+ klass._staticDefinition = this._staticDefinition;
1004
+
1005
+ const {
1006
+ signals = this.signals,
1007
+ constructors = this.constructors,
1008
+ members = this.members,
1009
+ props = this.props,
1010
+ fields = this.fields,
1011
+ callbacks = this.callbacks,
1012
+ } = options;
1013
+
1014
+ klass.signals = [...signals.map((s) => s.copy({ parent: klass }))];
1015
+ klass.constructors = [...constructors.map((c) => c.copy({ parent: klass }))];
1016
+ klass.members = [...members.map((m) => m.copy({ parent: klass }))];
1017
+ klass.props = [...props.map((p) => p.copy({ parent: klass }))];
1018
+ klass.fields = [...fields.map((f) => f.copy({ parent: klass }))];
1019
+ klass.callbacks = [...callbacks.map((c) => c.copy({ parent: klass }))];
1020
+
1021
+ if (this.mainConstructor) {
1022
+ klass.mainConstructor = this.mainConstructor.copy({ parent: klass });
1023
+ }
1024
+
1025
+ klass.getGenericName = createGenericNameGeneratorAt(this.getGenericName());
1026
+ return klass._copyBaseProperties(this);
1027
+ }
1028
+
1029
+ get staticDefinition() {
1030
+ return this._staticDefinition;
1031
+ }
1032
+
1033
+ static fromXML(element: GirClassElement, ns: IntrospectedNamespace, options: OptionsLoad): IntrospectedClass {
1034
+ const name = sanitizeIdentifierName(ns.namespace, element.$.name);
1035
+ if (options.verbose) {
1036
+ log.debug(` >> GirClass: Parsing definition ${element.$.name} (${name})...`);
1037
+ }
1038
+
1039
+ const clazz = new IntrospectedClass(name, ns);
1040
+
1041
+ IntrospectedClass.parseBasicProperties(element, clazz, ns, options);
1042
+ IntrospectedClass.parseResolveNames(element, clazz, ns, name);
1043
+ IntrospectedClass.parseInheritanceAndMembers(element, clazz, ns, options);
1044
+
1045
+ return clazz;
1046
+ }
1047
+
1048
+ private static parseBasicProperties(
1049
+ element: GirClassElement,
1050
+ clazz: IntrospectedClass,
1051
+ ns: IntrospectedNamespace,
1052
+ options: OptionsLoad,
1053
+ ): void {
1054
+ if (options.loadDocs) {
1055
+ clazz.doc = parseDoc(element);
1056
+ clazz.metadata = parseMetadata(element);
1057
+ }
1058
+
1059
+ if (element.$.parent) {
1060
+ clazz.superType = parseTypeIdentifier(ns.namespace, element.$.parent);
1061
+ }
1062
+
1063
+ if (element.$.abstract) {
1064
+ clazz.isAbstract = true;
1065
+ }
1066
+ }
1067
+
1068
+ private static parseResolveNames(
1069
+ element: GirClassElement,
1070
+ clazz: IntrospectedClass,
1071
+ ns: IntrospectedNamespace,
1072
+ name: string,
1073
+ ): void {
1074
+ if (element.$["glib:type-name"]) {
1075
+ clazz.resolve_names.push(element.$["glib:type-name"]);
1076
+ ns.registerResolveName(element.$["glib:type-name"], ns.namespace, name);
1077
+ }
1078
+
1079
+ if (element.$["c:type"]) {
1080
+ clazz.resolve_names.push(element.$["c:type"]);
1081
+ ns.registerResolveName(element.$["c:type"], ns.namespace, name);
1082
+ }
1083
+
1084
+ const typeStruct = element.$["glib:type-struct"];
1085
+ if (typeStruct) {
1086
+ clazz.registerStaticDefinition(typeStruct);
1087
+ clazz.resolve_names.push(typeStruct);
1088
+ ns.registerResolveName(typeStruct, ns.namespace, name);
1089
+ }
1090
+ }
1091
+
1092
+ private static parseInheritanceAndMembers(
1093
+ element: GirClassElement,
1094
+ clazz: IntrospectedClass,
1095
+ ns: IntrospectedNamespace,
1096
+ options: OptionsLoad,
1097
+ ): void {
1098
+ try {
1099
+ IntrospectedClass.parseConstructors(element, clazz, options);
1100
+ IntrospectedClass.parseSignals(element, clazz, options);
1101
+ IntrospectedClass.parseProperties(element, clazz, options);
1102
+ IntrospectedClass.parseMethods(element, clazz, options);
1103
+ IntrospectedClass.parseFields(element, clazz);
1104
+ IntrospectedClass.parseInterfaces(element, clazz, ns);
1105
+ IntrospectedClass.parseCallbacks(element, clazz, ns, options);
1106
+ IntrospectedClass.parseVirtualMethods(element, clazz, options);
1107
+ IntrospectedClass.parseStaticFunctions(element, clazz, options);
1108
+ } catch (e) {
1109
+ log.reportParsingFailure(clazz.name, "class", ns.namespace, e as Error);
1110
+ }
1111
+ }
1112
+
1113
+ private static parseConstructors(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
1114
+ if (Array.isArray(element.constructor)) {
1115
+ clazz.constructors.push(
1116
+ ...element.constructor.map((constructorElement) =>
1117
+ IntrospectedConstructor.fromXML(constructorElement, clazz, options),
1118
+ ),
1119
+ );
1120
+ }
1121
+ }
1122
+
1123
+ private static parseSignals(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
1124
+ if (element["glib:signal"]) {
1125
+ clazz.signals.push(...element["glib:signal"].map((signal) => IntrospectedSignal.fromXML(signal, clazz, options)));
1126
+ }
1127
+ }
1128
+
1129
+ private static parseProperties(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
1130
+ if (!element.property) return;
1131
+
1132
+ element.property.forEach((prop) => {
1133
+ const property = IntrospectedProperty.fromXML(prop, clazz, options);
1134
+ switch (options.propertyCase) {
1135
+ case "both": {
1136
+ clazz.props.push(property);
1137
+ const camelCase = property.toCamelCase();
1138
+ if (property.name !== camelCase.name) {
1139
+ clazz.props.push(camelCase);
1140
+ }
1141
+ break;
1142
+ }
1143
+ case "camel":
1144
+ clazz.props.push(property.toCamelCase());
1145
+ break;
1146
+ case "underscore":
1147
+ clazz.props.push(property);
1148
+ break;
1149
+ }
1150
+ });
1151
+ }
1152
+
1153
+ private static parseMethods(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
1154
+ if (element.method) {
1155
+ clazz.members.push(...element.method.map((method) => IntrospectedClassFunction.fromXML(method, clazz, options)));
1156
+ }
1157
+ }
1158
+
1159
+ private static parseFields(element: GirClassElement, clazz: IntrospectedClass): void {
1160
+ if (element.field) {
1161
+ element.field
1162
+ .filter((field) => !("callback" in field))
1163
+ .forEach((field) => {
1164
+ const f = IntrospectedField.fromXML(field, clazz);
1165
+ clazz.fields.push(f);
1166
+ });
1167
+ }
1168
+ }
1169
+
1170
+ private static parseInterfaces(element: GirClassElement, clazz: IntrospectedClass, ns: IntrospectedNamespace): void {
1171
+ if (element.implements) {
1172
+ element.implements.forEach((implementee) => {
1173
+ const name = implementee.$.name;
1174
+ const type = parseTypeIdentifier(ns.namespace, name);
1175
+ if (type) {
1176
+ clazz.interfaces.push(type);
1177
+ }
1178
+ });
1179
+ }
1180
+ }
1181
+
1182
+ private static parseCallbacks(
1183
+ element: GirClassElement,
1184
+ clazz: IntrospectedClass,
1185
+ ns: IntrospectedNamespace,
1186
+ options: OptionsLoad,
1187
+ ): void {
1188
+ if (element.callback) {
1189
+ if (options.verbose) {
1190
+ element.callback.forEach((callback) => {
1191
+ log.debug(`Adding callback ${callback.$.name} for ${ns.namespace}`);
1192
+ });
1193
+ }
1194
+ clazz.callbacks.push(
1195
+ ...element.callback.map((callback) => IntrospectedClassCallback.fromXML(callback, clazz, options)),
1196
+ );
1197
+ }
1198
+ }
1199
+
1200
+ private static parseVirtualMethods(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
1201
+ if (element["virtual-method"]) {
1202
+ clazz.members.push(
1203
+ ...element["virtual-method"].map((method) => IntrospectedVirtualClassFunction.fromXML(method, clazz, options)),
1204
+ );
1205
+ }
1206
+ }
1207
+
1208
+ private static parseStaticFunctions(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
1209
+ if (element.function) {
1210
+ clazz.members.push(
1211
+ ...element.function.map((func) => IntrospectedStaticClassFunction.fromXML(func, clazz, options)),
1212
+ );
1213
+ }
1214
+ }
1215
+
1216
+ registerStaticDefinition(typeStruct: string) {
1217
+ this._staticDefinition = typeStruct;
1218
+ }
1219
+
1220
+ asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateClass"]> {
1221
+ return generator.generateClass(this) as ReturnType<T["generateClass"]>;
1222
+ }
1223
+ }
1224
+
1225
+ /**
1226
+ * Represents a GIR interface
1227
+ */
1228
+ export class IntrospectedInterface extends IntrospectedBaseClass {
1229
+ interfaces: TypeIdentifier[] = [];
1230
+ noParent: boolean = false;
1231
+
1232
+ accept(visitor: GirVisitor): IntrospectedInterface {
1233
+ const node = this.copy({
1234
+ constructors: this.constructors.map((c) => c.accept(visitor)),
1235
+ members: this.members.map((m) => m.accept(visitor)),
1236
+ props: this.props.map((p) => p.accept(visitor)),
1237
+ fields: this.fields.map((f) => f.accept(visitor)),
1238
+ callbacks: this.callbacks.map((c) => c.accept(visitor)),
1239
+ });
1240
+ return visitor.visitInterface?.(node) ?? node;
1241
+ }
1242
+
1243
+ someParent(predicate: (b: IntrospectedBaseClass) => boolean): boolean {
1244
+ const resolution = this.resolveParents();
1245
+ const parent = resolution.extends();
1246
+ return !!parent && (predicate(parent.node) || parent.node.someParent(predicate));
1247
+ }
1248
+
1249
+ findParent(predicate: (b: IntrospectedBaseClass) => boolean): IntrospectedBaseClass | undefined {
1250
+ return this.findParentMap((parent) => {
1251
+ if (predicate(parent)) {
1252
+ return parent;
1253
+ }
1254
+ return undefined;
1255
+ });
1256
+ }
1257
+
1258
+ findParentMap<K>(predicate: (b: IntrospectedBaseClass) => K | undefined): K | undefined {
1259
+ const resolution = this.resolveParents();
1260
+ const parent = resolution.extends();
1261
+
1262
+ if (parent) {
1263
+ const result = predicate(parent.node);
1264
+ if (result !== undefined) return result;
1265
+ return parent.node.findParentMap(predicate);
1266
+ }
1267
+
1268
+ return undefined;
1269
+ }
1270
+
1271
+ resolveParents(): InterfaceResolution {
1272
+ const self = this;
1273
+ return {
1274
+ *[Symbol.iterator]() {
1275
+ const parentResolution = this.extends();
1276
+ if (parentResolution) {
1277
+ yield parentResolution;
1278
+ yield* parentResolution;
1279
+ }
1280
+ },
1281
+ extends(): InterfaceResolution | ClassResolution | undefined {
1282
+ // For interfaces, superType would be the prerequisite
1283
+ const resolved_parent = self.superType ? resolveTypeIdentifier(self.namespace, self.superType) : undefined;
1284
+ if (resolved_parent instanceof IntrospectedInterface) {
1285
+ return resolved_parent.resolveParents();
1286
+ }
1287
+ if (resolved_parent instanceof IntrospectedClass) {
1288
+ return resolved_parent.resolveParents();
1289
+ }
1290
+ return undefined;
1291
+ },
1292
+ node: self,
1293
+ identifier: self.getType(),
1294
+ };
1295
+ }
1296
+
1297
+ copy(
1298
+ options: {
1299
+ parent?: undefined;
1300
+ constructors?: IntrospectedConstructor[];
1301
+ members?: IntrospectedClassFunction[];
1302
+ props?: IntrospectedProperty[];
1303
+ fields?: IntrospectedField[];
1304
+ callbacks?: IntrospectedClassCallback[];
1305
+ } = {},
1306
+ ): IntrospectedInterface {
1307
+ const iface = new IntrospectedInterface({ name: this.name, namespace: this.namespace });
1308
+
1309
+ iface.interfaces = [...this.interfaces];
1310
+ iface.superType = this.superType;
1311
+ iface.doc = this.doc;
1312
+ iface.generics = [...this.generics];
1313
+
1314
+ const {
1315
+ constructors = this.constructors,
1316
+ members = this.members,
1317
+ props = this.props,
1318
+ fields = this.fields,
1319
+ callbacks = this.callbacks,
1320
+ } = options;
1321
+
1322
+ iface.constructors = [...constructors.map((c) => c.copy({ parent: iface }))];
1323
+ iface.members = [...members.map((m) => m.copy({ parent: iface }))];
1324
+ iface.props = [...props.map((p) => p.copy({ parent: iface }))];
1325
+ iface.fields = [...fields.map((f) => f.copy({ parent: iface }))];
1326
+ iface.callbacks = [...callbacks.map((c) => c.copy({ parent: iface }))];
1327
+
1328
+ if (this.mainConstructor) {
1329
+ iface.mainConstructor = this.mainConstructor.copy({ parent: iface });
1330
+ }
1331
+
1332
+ return iface._copyBaseProperties(this);
1333
+ }
1334
+
1335
+ static fromXML(
1336
+ element: GirInterfaceElement,
1337
+ namespace: IntrospectedNamespace,
1338
+ options: OptionsLoad,
1339
+ ): IntrospectedInterface {
1340
+ const name = sanitizeIdentifierName(namespace.namespace, element.$.name);
1341
+ if (options.verbose) {
1342
+ log.debug(` >> GirInterface: Parsing definition ${element.$.name} (${name})...`);
1343
+ }
1344
+
1345
+ const iface = new IntrospectedInterface({ name, namespace });
1346
+
1347
+ IntrospectedInterface.parseInterfaceBasicProperties(element, iface, namespace, options);
1348
+ IntrospectedInterface.parseInterfaceResolveNames(element, iface, namespace, name);
1349
+ IntrospectedInterface.parseInterfaceMembers(element, iface, namespace, options);
1350
+
1351
+ return iface;
1352
+ }
1353
+
1354
+ private static parseInterfaceBasicProperties(
1355
+ element: GirInterfaceElement,
1356
+ iface: IntrospectedInterface,
1357
+ namespace: IntrospectedNamespace,
1358
+ options: OptionsLoad,
1359
+ ): void {
1360
+ if (options.loadDocs) {
1361
+ iface.doc = parseDoc(element);
1362
+ iface.metadata = parseMetadata(element);
1363
+ }
1364
+
1365
+ if (element.prerequisite?.[0]) {
1366
+ const [prerequisite] = element.prerequisite;
1367
+ if (prerequisite.$.name) {
1368
+ iface.superType = parseTypeIdentifier(namespace.namespace, prerequisite.$.name);
1369
+ }
1370
+ }
1371
+ }
1372
+
1373
+ private static parseInterfaceResolveNames(
1374
+ element: GirInterfaceElement,
1375
+ iface: IntrospectedInterface,
1376
+ namespace: IntrospectedNamespace,
1377
+ name: string,
1378
+ ): void {
1379
+ if (element.$["glib:type-name"]) {
1380
+ iface.resolve_names.push(element.$["glib:type-name"]);
1381
+ namespace.registerResolveName(element.$["glib:type-name"], namespace.namespace, name);
1382
+ }
1383
+
1384
+ if (element.$["c:type"]) {
1385
+ iface.resolve_names.push(element.$["c:type"]);
1386
+ namespace.registerResolveName(element.$["c:type"], namespace.namespace, name);
1387
+ }
1388
+ }
1389
+
1390
+ private static parseInterfaceMembers(
1391
+ element: GirInterfaceElement,
1392
+ iface: IntrospectedInterface,
1393
+ namespace: IntrospectedNamespace,
1394
+ options: OptionsLoad,
1395
+ ): void {
1396
+ try {
1397
+ IntrospectedInterface.parseInterfaceConstructors(element, iface, options);
1398
+ IntrospectedInterface.parseInterfaceProperties(element, iface, options);
1399
+ IntrospectedInterface.parseInterfaceMethods(element, iface, options);
1400
+ IntrospectedInterface.parseInterfaceFields(element, iface);
1401
+ IntrospectedInterface.parseInterfaceCallbacks(element, iface, namespace, options);
1402
+ IntrospectedInterface.parseInterfaceVirtualMethods(element, iface, options);
1403
+ IntrospectedInterface.parseInterfaceStaticFunctions(element, iface, options);
1404
+ } catch (e) {
1405
+ log.reportParsingFailure(iface.name, "interface", namespace.namespace, e as Error);
1406
+ }
1407
+ }
1408
+
1409
+ private static parseInterfaceConstructors(
1410
+ element: GirInterfaceElement,
1411
+ iface: IntrospectedInterface,
1412
+ options: OptionsLoad,
1413
+ ): void {
1414
+ if (Array.isArray(element.constructor)) {
1415
+ iface.constructors.push(
1416
+ ...element.constructor.map((constructorElement) =>
1417
+ IntrospectedConstructor.fromXML(constructorElement, iface, options),
1418
+ ),
1419
+ );
1420
+ }
1421
+ }
1422
+
1423
+ private static parseInterfaceProperties(
1424
+ element: GirInterfaceElement,
1425
+ iface: IntrospectedInterface,
1426
+ options: OptionsLoad,
1427
+ ): void {
1428
+ if (!element.property) return;
1429
+
1430
+ element.property.forEach((prop) => {
1431
+ const property = IntrospectedProperty.fromXML(prop, iface, options);
1432
+ switch (options.propertyCase) {
1433
+ case "both": {
1434
+ iface.props.push(property);
1435
+ const camelCase = property.toCamelCase();
1436
+ if (property.name !== camelCase.name) {
1437
+ iface.props.push(camelCase);
1438
+ }
1439
+ break;
1440
+ }
1441
+ case "camel":
1442
+ iface.props.push(property.toCamelCase());
1443
+ break;
1444
+ case "underscore":
1445
+ iface.props.push(property);
1446
+ break;
1447
+ }
1448
+ });
1449
+ }
1450
+
1451
+ private static parseInterfaceMethods(
1452
+ element: GirInterfaceElement,
1453
+ iface: IntrospectedInterface,
1454
+ options: OptionsLoad,
1455
+ ): void {
1456
+ if (element.method) {
1457
+ iface.members.push(...element.method.map((method) => IntrospectedClassFunction.fromXML(method, iface, options)));
1458
+ }
1459
+ }
1460
+
1461
+ private static parseInterfaceFields(element: GirInterfaceElement, iface: IntrospectedInterface): void {
1462
+ if (element.field) {
1463
+ element.field
1464
+ .filter((field) => !("callback" in field))
1465
+ .forEach((field) => {
1466
+ const f = IntrospectedField.fromXML(field, iface);
1467
+ iface.fields.push(f);
1468
+ });
1469
+ }
1470
+ }
1471
+
1472
+ private static parseInterfaceCallbacks(
1473
+ element: GirInterfaceElement,
1474
+ iface: IntrospectedInterface,
1475
+ namespace: IntrospectedNamespace,
1476
+ options: OptionsLoad,
1477
+ ): void {
1478
+ if (element.callback) {
1479
+ if (options.verbose) {
1480
+ element.callback.forEach((callback) => {
1481
+ log.debug(`Adding callback ${callback.$.name} for ${namespace.namespace}`);
1482
+ });
1483
+ }
1484
+ iface.callbacks.push(
1485
+ ...element.callback.map((callback) => IntrospectedClassCallback.fromXML(callback, iface, options)),
1486
+ );
1487
+ }
1488
+ }
1489
+
1490
+ private static parseInterfaceVirtualMethods(
1491
+ element: GirInterfaceElement,
1492
+ iface: IntrospectedInterface,
1493
+ options: OptionsLoad,
1494
+ ): void {
1495
+ if (element["virtual-method"]) {
1496
+ iface.members.push(
1497
+ ...element["virtual-method"].map((method) => IntrospectedVirtualClassFunction.fromXML(method, iface, options)),
1498
+ );
1499
+ }
1500
+ }
1501
+
1502
+ private static parseInterfaceStaticFunctions(
1503
+ element: GirInterfaceElement,
1504
+ iface: IntrospectedInterface,
1505
+ options: OptionsLoad,
1506
+ ): void {
1507
+ if (element.function) {
1508
+ iface.members.push(
1509
+ ...element.function.map((func) => IntrospectedStaticClassFunction.fromXML(func, iface, options)),
1510
+ );
1511
+ }
1512
+ }
1513
+
1514
+ asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateInterface"]> {
1515
+ return generator.generateInterface(this) as ReturnType<T["generateInterface"]>;
1516
+ }
1517
+ }