@ts-for-gir/lib 4.0.0-beta.8 → 4.0.0-rc.1

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