steep 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (299) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitmodules +3 -0
  4. data/CHANGELOG.md +5 -0
  5. data/README.md +48 -90
  6. data/Rakefile +10 -6
  7. data/Steepfile +1 -0
  8. data/bin/setup +1 -0
  9. data/bin/smoke_runner.rb +9 -14
  10. data/exe/rbs +3 -0
  11. data/exe/ruby-signature +3 -0
  12. data/exe/steep +1 -0
  13. data/lib/steep.rb +32 -26
  14. data/lib/steep/annotation_parser.rb +167 -0
  15. data/lib/steep/ast/annotation/collection.rb +7 -7
  16. data/lib/steep/ast/types.rb +60 -0
  17. data/lib/steep/ast/types/any.rb +1 -1
  18. data/lib/steep/ast/types/factory.rb +535 -0
  19. data/lib/steep/ast/types/name.rb +3 -3
  20. data/lib/steep/ast/types/var.rb +1 -1
  21. data/lib/steep/cli.rb +56 -240
  22. data/lib/steep/drivers/annotations.rb +36 -19
  23. data/lib/steep/drivers/check.rb +55 -91
  24. data/lib/steep/drivers/init.rb +54 -0
  25. data/lib/steep/drivers/langserver.rb +241 -150
  26. data/lib/steep/drivers/print_project.rb +56 -0
  27. data/lib/steep/drivers/signature_error_printer.rb +25 -0
  28. data/lib/steep/drivers/trace_printer.rb +25 -0
  29. data/lib/steep/drivers/utils/driver_helper.rb +26 -0
  30. data/lib/steep/drivers/validate.rb +18 -38
  31. data/lib/steep/drivers/vendor.rb +46 -0
  32. data/lib/steep/drivers/watch.rb +78 -140
  33. data/lib/steep/errors.rb +22 -13
  34. data/lib/steep/interface/interface.rb +91 -0
  35. data/lib/steep/interface/method.rb +0 -4
  36. data/lib/steep/interface/method_type.rb +362 -2
  37. data/lib/steep/interface/substitution.rb +22 -0
  38. data/lib/steep/project.rb +25 -233
  39. data/lib/steep/project/dsl.rb +132 -0
  40. data/lib/steep/project/file.rb +93 -76
  41. data/lib/steep/project/file_loader.rb +63 -0
  42. data/lib/steep/project/options.rb +7 -0
  43. data/lib/steep/project/target.rb +190 -0
  44. data/lib/steep/signature/errors.rb +25 -77
  45. data/lib/steep/signature/validator.rb +122 -0
  46. data/lib/steep/source.rb +12 -7
  47. data/lib/steep/subtyping/check.rb +357 -633
  48. data/lib/steep/subtyping/constraints.rb +2 -2
  49. data/lib/steep/subtyping/trace.rb +23 -0
  50. data/lib/steep/type_construction.rb +509 -455
  51. data/lib/steep/type_inference/constant_env.rb +16 -24
  52. data/lib/steep/type_inference/type_env.rb +26 -18
  53. data/lib/steep/version.rb +1 -1
  54. data/sample/Steepfile +6 -0
  55. data/sample/lib/conference.rb +12 -0
  56. data/sample/sig/conference.rbs +6 -0
  57. data/smoke/alias/Steepfile +4 -0
  58. data/smoke/alias/a.rb +2 -2
  59. data/smoke/alias/{a.rbi → a.rbs} +1 -1
  60. data/smoke/and/Steepfile +4 -0
  61. data/smoke/array/Steepfile +4 -0
  62. data/smoke/array/a.rb +2 -2
  63. data/smoke/array/b.rb +4 -4
  64. data/smoke/array/c.rb +2 -2
  65. data/smoke/block/Steepfile +5 -0
  66. data/smoke/block/{a.rbi → a.rbs} +1 -1
  67. data/smoke/block/{c.rbi → c.rbs} +0 -0
  68. data/smoke/block/d.rb +6 -6
  69. data/smoke/case/Steepfile +4 -0
  70. data/smoke/case/a.rb +4 -3
  71. data/smoke/class/Steepfile +4 -0
  72. data/smoke/class/a.rb +1 -4
  73. data/smoke/class/a.rbs +24 -0
  74. data/smoke/class/h.rb +6 -2
  75. data/smoke/class/{h.rbi → h.rbs} +1 -2
  76. data/smoke/class/i.rb +1 -2
  77. data/smoke/class/i.rbs +9 -0
  78. data/smoke/const/Steepfile +4 -0
  79. data/smoke/dstr/Steepfile +4 -0
  80. data/smoke/ensure/Steepfile +4 -0
  81. data/smoke/ensure/a.rb +1 -1
  82. data/smoke/enumerator/Steepfile +4 -0
  83. data/smoke/enumerator/a.rb +7 -7
  84. data/smoke/enumerator/b.rb +6 -6
  85. data/smoke/extension/Steepfile +4 -0
  86. data/smoke/extension/{a.rbi → a.rbs} +2 -2
  87. data/smoke/extension/{e.rbi → e.rbs} +2 -2
  88. data/smoke/hash/Steepfile +4 -0
  89. data/smoke/hash/{a.rbi → a.rbs} +0 -0
  90. data/smoke/hash/b.rb +2 -2
  91. data/smoke/hash/c.rb +1 -1
  92. data/smoke/hash/e.rbs +3 -0
  93. data/smoke/hash/f.rb +1 -1
  94. data/smoke/hello/Steepfile +4 -0
  95. data/smoke/hello/hello.rbs +7 -0
  96. data/smoke/if/Steepfile +4 -0
  97. data/smoke/implements/Steepfile +4 -0
  98. data/smoke/implements/a.rbs +6 -0
  99. data/smoke/initialize/Steepfile +4 -0
  100. data/smoke/initialize/a.rbs +3 -0
  101. data/smoke/integer/Steepfile +4 -0
  102. data/smoke/integer/a.rb +5 -3
  103. data/smoke/interface/Steepfile +4 -0
  104. data/smoke/interface/{a.rbi → a.rbs} +0 -0
  105. data/smoke/kwbegin/Steepfile +4 -0
  106. data/smoke/lambda/Steepfile +4 -0
  107. data/smoke/lambda/a.rb +9 -2
  108. data/smoke/literal/Steepfile +4 -0
  109. data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
  110. data/smoke/map/Steepfile +4 -0
  111. data/smoke/map/a.rb +1 -1
  112. data/smoke/method/Steepfile +4 -0
  113. data/smoke/method/{a.rbi → a.rbs} +0 -0
  114. data/smoke/method/b.rb +1 -4
  115. data/smoke/method/d.rb +1 -0
  116. data/smoke/method/d.rbs +3 -0
  117. data/smoke/module/Steepfile +4 -0
  118. data/smoke/module/a.rb +1 -1
  119. data/smoke/module/a.rbs +16 -0
  120. data/smoke/module/c.rb +1 -1
  121. data/smoke/regexp/Steepfile +4 -0
  122. data/smoke/regexp/a.rb +2 -2
  123. data/smoke/regexp/b.rb +16 -16
  124. data/smoke/regression/Steepfile +5 -0
  125. data/smoke/regression/array.rb +2 -2
  126. data/smoke/regression/hash.rb +2 -2
  127. data/smoke/regression/poly_new.rb +2 -0
  128. data/smoke/regression/poly_new.rbs +4 -0
  129. data/smoke/regression/set_divide.rb +2 -2
  130. data/smoke/rescue/Steepfile +4 -0
  131. data/smoke/rescue/a.rb +1 -1
  132. data/smoke/self/Steepfile +4 -0
  133. data/smoke/self/a.rbs +4 -0
  134. data/smoke/skip/Steepfile +4 -0
  135. data/smoke/stdout/Steepfile +4 -0
  136. data/smoke/stdout/{a.rbi → a.rbs} +1 -1
  137. data/smoke/super/Steepfile +4 -0
  138. data/smoke/super/a.rbs +10 -0
  139. data/smoke/type_case/Steepfile +4 -0
  140. data/smoke/type_case/a.rb +1 -1
  141. data/smoke/yield/Steepfile +4 -0
  142. data/smoke/yield/a.rb +2 -2
  143. data/steep.gemspec +14 -7
  144. data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
  145. data/vendor/ruby-signature/.gitignore +12 -0
  146. data/vendor/ruby-signature/.rubocop.yml +15 -0
  147. data/vendor/ruby-signature/BSDL +22 -0
  148. data/vendor/ruby-signature/COPYING +56 -0
  149. data/vendor/ruby-signature/Gemfile +6 -0
  150. data/vendor/ruby-signature/README.md +93 -0
  151. data/vendor/ruby-signature/Rakefile +66 -0
  152. data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
  153. data/vendor/ruby-signature/bin/console +14 -0
  154. data/vendor/ruby-signature/bin/query-rdoc +103 -0
  155. data/vendor/ruby-signature/bin/setup +10 -0
  156. data/vendor/ruby-signature/bin/sort +88 -0
  157. data/vendor/ruby-signature/bin/test_runner.rb +17 -0
  158. data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
  159. data/vendor/ruby-signature/docs/sigs.md +148 -0
  160. data/vendor/ruby-signature/docs/stdlib.md +152 -0
  161. data/vendor/ruby-signature/docs/syntax.md +528 -0
  162. data/vendor/ruby-signature/exe/rbs +3 -0
  163. data/vendor/ruby-signature/exe/ruby-signature +7 -0
  164. data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
  165. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
  166. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
  167. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
  168. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
  169. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
  170. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
  171. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
  172. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
  173. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
  174. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
  175. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
  176. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
  177. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
  178. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
  179. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
  180. data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
  181. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
  182. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
  183. data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
  184. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
  185. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
  186. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
  187. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
  188. data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
  189. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
  190. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
  191. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
  192. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
  193. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
  194. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
  195. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
  196. data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
  197. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
  198. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
  199. data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
  200. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
  201. data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
  202. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
  203. data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
  204. data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
  205. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
  206. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
  207. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
  208. data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
  209. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
  210. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
  211. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
  212. data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
  213. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
  214. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
  215. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
  216. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
  217. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
  218. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
  219. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
  220. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
  221. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
  222. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
  223. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
  224. data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
  225. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
  226. data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
  227. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
  228. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
  229. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
  230. data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
  231. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
  232. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
  233. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
  234. data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
  235. data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
  236. data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
  237. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
  238. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
  239. data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
  240. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
  241. data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
  242. data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
  243. data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
  244. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
  245. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
  246. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
  247. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
  248. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
  249. data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
  250. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
  251. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
  252. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
  253. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
  254. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
  255. data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
  256. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
  257. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
  258. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
  259. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
  260. data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
  261. data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
  262. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
  263. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
  264. data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
  265. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
  266. data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
  267. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
  268. metadata +244 -54
  269. data/.travis.yml +0 -7
  270. data/lib/steep/ast/signature/alias.rb +0 -19
  271. data/lib/steep/ast/signature/class.rb +0 -33
  272. data/lib/steep/ast/signature/const.rb +0 -17
  273. data/lib/steep/ast/signature/env.rb +0 -138
  274. data/lib/steep/ast/signature/extension.rb +0 -21
  275. data/lib/steep/ast/signature/gvar.rb +0 -17
  276. data/lib/steep/ast/signature/interface.rb +0 -31
  277. data/lib/steep/ast/signature/members.rb +0 -115
  278. data/lib/steep/ast/signature/module.rb +0 -21
  279. data/lib/steep/drivers/print_interface.rb +0 -94
  280. data/lib/steep/drivers/scaffold.rb +0 -321
  281. data/lib/steep/drivers/utils/each_signature.rb +0 -31
  282. data/lib/steep/interface/abstract.rb +0 -68
  283. data/lib/steep/interface/builder.rb +0 -637
  284. data/lib/steep/interface/instantiated.rb +0 -163
  285. data/lib/steep/interface/ivar_chain.rb +0 -26
  286. data/lib/steep/parser.y +0 -1278
  287. data/lib/steep/project/listener.rb +0 -53
  288. data/smoke/class/a.rbi +0 -24
  289. data/smoke/class/d.rb +0 -9
  290. data/smoke/class/e.rb +0 -12
  291. data/smoke/class/i.rbi +0 -9
  292. data/smoke/hash/e.rbi +0 -3
  293. data/smoke/hello/hello.rbi +0 -7
  294. data/smoke/implements/a.rbi +0 -6
  295. data/smoke/initialize/a.rbi +0 -3
  296. data/smoke/module/a.rbi +0 -16
  297. data/smoke/self/a.rbi +0 -4
  298. data/smoke/super/a.rbi +0 -10
  299. data/stdlib/builtin.rbi +0 -787
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.join(__dir__, "ruby-signature")
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.join(__dir__, "../lib")
4
+ require "ruby/signature"
5
+ require "ruby/signature/cli"
6
+
7
+ Ruby::Signature::CLI.new(stdout: STDOUT, stderr: STDERR).run(ARGV.dup)
@@ -0,0 +1,64 @@
1
+ require "ruby/signature/version"
2
+
3
+ require "set"
4
+ require "json"
5
+ require "pathname"
6
+ require "pp"
7
+ require "ripper"
8
+ require "logger"
9
+ require "tsort"
10
+
11
+ require "ruby/signature/errors"
12
+ require "ruby/signature/buffer"
13
+ require "ruby/signature/location"
14
+ require "ruby/signature/namespace"
15
+ require "ruby/signature/type_name"
16
+ require "ruby/signature/types"
17
+ require "ruby/signature/method_type"
18
+ require "ruby/signature/ast/declarations"
19
+ require "ruby/signature/ast/members"
20
+ require "ruby/signature/ast/annotation"
21
+ require "ruby/signature/environment"
22
+ require "ruby/signature/environment_loader"
23
+ require "ruby/signature/builtin_names"
24
+ require "ruby/signature/definition"
25
+ require "ruby/signature/definition_builder"
26
+ require "ruby/signature/variance_calculator"
27
+ require "ruby/signature/substitution"
28
+ require "ruby/signature/constant"
29
+ require "ruby/signature/constant_table"
30
+ require "ruby/signature/ast/comment"
31
+ require "ruby/signature/writer"
32
+ require "ruby/signature/prototype/rbi"
33
+ require "ruby/signature/prototype/rb"
34
+ require "ruby/signature/prototype/runtime"
35
+ require "ruby/signature/environment_walker"
36
+ require "ruby/signature/vendorer"
37
+
38
+ begin
39
+ require "ruby/signature/parser"
40
+ rescue LoadError
41
+ STDERR.puts "Missing parser Ruby code? Running `rake parser` may solve the issue"
42
+ raise
43
+ end
44
+
45
+ module Ruby::Signature
46
+ class <<self
47
+ attr_reader :logger_level
48
+ attr_reader :logger_output
49
+
50
+ def logger
51
+ @logger ||= Logger.new(logger_output || STDERR, level: logger_level || "warn", progname: "ruby-signature")
52
+ end
53
+
54
+ def logger_output=(val)
55
+ @logger_output = val
56
+ @logger = nil
57
+ end
58
+
59
+ def logger_level=(level)
60
+ @logger_level = level
61
+ @logger = nil
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,29 @@
1
+ module Ruby
2
+ module Signature
3
+ module AST
4
+ class Annotation
5
+ attr_reader :string
6
+ attr_reader :location
7
+
8
+ def initialize(string:, location:)
9
+ @string = string
10
+ @location = location
11
+ end
12
+
13
+ def ==(other)
14
+ other.is_a?(Annotation) && other.string == string
15
+ end
16
+
17
+ alias eql? ==
18
+
19
+ def hash
20
+ self.class.hash ^ string.hash
21
+ end
22
+
23
+ def to_json(*a)
24
+ { string: string, location: location }.to_json(*a)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Ruby
2
+ module Signature
3
+ module AST
4
+ class Comment
5
+ attr_reader :string
6
+ attr_reader :location
7
+
8
+ def initialize(string:, location:)
9
+ @string = string
10
+ @location = location
11
+ end
12
+
13
+ def ==(other)
14
+ other.is_a?(Comment) && other.string == string
15
+ end
16
+
17
+ alias eql? ==
18
+
19
+ def hash
20
+ self.class.hash ^ string.hash
21
+ end
22
+
23
+ def to_json(*a)
24
+ { string: string, location: location }.to_json(*a)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,391 @@
1
+ module Ruby
2
+ module Signature
3
+ module AST
4
+ module Declarations
5
+ class ModuleTypeParams
6
+ attr_reader :params
7
+
8
+ TypeParam = Struct.new(:name, :variance, :skip_validation, keyword_init: true)
9
+
10
+ def initialize()
11
+ @params = []
12
+ end
13
+
14
+ def add(param)
15
+ params << param
16
+ self
17
+ end
18
+
19
+ def ==(other)
20
+ other.is_a?(ModuleTypeParams) && other.params == params
21
+ end
22
+
23
+ def [](name)
24
+ params.find {|p| p.name == name }
25
+ end
26
+
27
+ def to_json(*a)
28
+ {
29
+ params: params
30
+ }.to_json(*a)
31
+ end
32
+
33
+ def each(&block)
34
+ params.each(&block)
35
+ end
36
+
37
+ def self.empty
38
+ new
39
+ end
40
+
41
+ def variance(name)
42
+ self[name].variance
43
+ end
44
+
45
+ def skip_validation?(name)
46
+ self[name].skip_validation
47
+ end
48
+
49
+ def empty?
50
+ params.empty?
51
+ end
52
+
53
+ def size
54
+ params.size
55
+ end
56
+
57
+ def rename_to(names)
58
+ ModuleTypeParams.new().tap do |params|
59
+ names.each.with_index do |new_name, index|
60
+ param = self.params[index]
61
+ params.add(TypeParam.new(name: new_name, variance: param.variance, skip_validation: param.skip_validation))
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ class Class
68
+ class Super
69
+ attr_reader :name
70
+ attr_reader :args
71
+
72
+ def initialize(name:, args:)
73
+ @name = name
74
+ @args = args
75
+ end
76
+
77
+ def ==(other)
78
+ other.is_a?(Super) && other.name == name && other.args == args
79
+ end
80
+
81
+ alias eql? ==
82
+
83
+ def hash
84
+ self.class.hash ^ name.hash ^ args.hash
85
+ end
86
+
87
+ def to_json(*a)
88
+ {
89
+ name: name,
90
+ args: args
91
+ }.to_json(*a)
92
+ end
93
+ end
94
+
95
+ attr_reader :name
96
+ attr_reader :type_params
97
+ attr_reader :members
98
+ attr_reader :super_class
99
+ attr_reader :annotations
100
+ attr_reader :location
101
+ attr_reader :comment
102
+
103
+ def initialize(name:, type_params:, super_class:, members:, annotations:, location:, comment:)
104
+ @name = name
105
+ @type_params = type_params
106
+ @super_class = super_class
107
+ @members = members
108
+ @annotations = annotations
109
+ @location = location
110
+ @comment = comment
111
+ end
112
+
113
+ def ==(other)
114
+ other.is_a?(Class) &&
115
+ other.name == name &&
116
+ other.type_params == type_params &&
117
+ other.super_class == super_class &&
118
+ other.members == members
119
+ end
120
+
121
+ alias eql? ==
122
+
123
+ def hash
124
+ self.class.hash ^ name.hash ^ type_params.hash ^ super_class.hash ^ members.hash
125
+ end
126
+
127
+ def to_json(*a)
128
+ {
129
+ declaration: :class,
130
+ name: name,
131
+ type_params: type_params,
132
+ members: members,
133
+ super_class: super_class,
134
+ annotations: annotations,
135
+ location: location,
136
+ comment: comment
137
+ }.to_json(*a)
138
+ end
139
+ end
140
+
141
+ class Module
142
+ attr_reader :name
143
+ attr_reader :type_params
144
+ attr_reader :members
145
+ attr_reader :location
146
+ attr_reader :annotations
147
+ attr_reader :self_type
148
+ attr_reader :comment
149
+
150
+ def initialize(name:, type_params:, members:, self_type:, annotations:, location:, comment:)
151
+ @name = name
152
+ @type_params = type_params
153
+ @self_type = self_type
154
+ @members = members
155
+ @annotations = annotations
156
+ @location = location
157
+ @comment = comment
158
+ end
159
+
160
+ def ==(other)
161
+ other.is_a?(Module) &&
162
+ other.name == name &&
163
+ other.type_params == type_params &&
164
+ other.self_type == self_type &&
165
+ other.members == members
166
+ end
167
+
168
+ alias eql? ==
169
+
170
+ def hash
171
+ self.class.hash ^ name.hash ^ type_params.hash ^ self_type.hash ^ members.hash
172
+ end
173
+
174
+ def to_json(*a)
175
+ {
176
+ declaration: :module,
177
+ name: name,
178
+ type_params: type_params,
179
+ members: members,
180
+ self_type: self_type,
181
+ annotations: annotations,
182
+ location: location,
183
+ comment: comment
184
+ }.to_json(*a)
185
+ end
186
+ end
187
+
188
+ class Extension
189
+ attr_reader :name
190
+ attr_reader :type_params
191
+ attr_reader :extension_name
192
+ attr_reader :members
193
+ attr_reader :annotations
194
+ attr_reader :location
195
+ attr_reader :comment
196
+
197
+ def initialize(name:, type_params:, extension_name:, members:, annotations:, location:, comment:)
198
+ @name = name
199
+ @type_params = type_params
200
+ @extension_name = extension_name
201
+ @members = members
202
+ @annotations = annotations
203
+ @location = location
204
+ @comment = comment
205
+ end
206
+
207
+ def ==(other)
208
+ other.is_a?(Extension) &&
209
+ other.name == name &&
210
+ other.type_params == type_params &&
211
+ other.extension_name == extension_name &&
212
+ other.members == members
213
+ end
214
+
215
+ alias eql? ==
216
+
217
+ def hash
218
+ self.class.hash ^ name.hash ^ type_params.hash ^ extension_name.hash ^ members.hash
219
+ end
220
+
221
+ def to_json(*a)
222
+ {
223
+ declaration: :extension,
224
+ name: name,
225
+ type_params: type_params,
226
+ extension_name: extension_name,
227
+ members: members,
228
+ annotations: annotations,
229
+ location: location,
230
+ comment: comment
231
+ }.to_json(*a)
232
+ end
233
+ end
234
+
235
+ class Interface
236
+ attr_reader :name
237
+ attr_reader :type_params
238
+ attr_reader :members
239
+ attr_reader :annotations
240
+ attr_reader :location
241
+ attr_reader :comment
242
+
243
+ def initialize(name:, type_params:, members:, annotations:, location:, comment:)
244
+ @name = name
245
+ @type_params = type_params
246
+ @members = members
247
+ @annotations = annotations
248
+ @location = location
249
+ @comment = comment
250
+ end
251
+
252
+ def ==(other)
253
+ other.is_a?(Interface) &&
254
+ other.name == name &&
255
+ other.type_params == type_params &&
256
+ other.members == members
257
+ end
258
+
259
+ alias eql? ==
260
+
261
+ def hash
262
+ self.class.hash ^ type_params.hash ^ members.hash
263
+ end
264
+
265
+ def to_json(*a)
266
+ {
267
+ declaration: :interface,
268
+ name: name,
269
+ type_params: type_params,
270
+ members: members,
271
+ annotations: annotations,
272
+ location: location,
273
+ comment: comment
274
+ }.to_json(*a)
275
+ end
276
+ end
277
+
278
+ class Alias
279
+ attr_reader :name
280
+ attr_reader :type
281
+ attr_reader :annotations
282
+ attr_reader :location
283
+ attr_reader :comment
284
+
285
+ def initialize(name:, type:, annotations:, location:, comment:)
286
+ @name = name
287
+ @type = type
288
+ @annotations = annotations
289
+ @location = location
290
+ @comment = comment
291
+ end
292
+
293
+ def ==(other)
294
+ other.is_a?(Alias) &&
295
+ other.name == name &&
296
+ other.type == type
297
+ end
298
+
299
+ alias eql? ==
300
+
301
+ def hash
302
+ self.class.hash ^ name.hash ^ type.hash
303
+ end
304
+
305
+ def to_json(*a)
306
+ {
307
+ declaration: :alias,
308
+ name: name,
309
+ type: type,
310
+ annotations: annotations,
311
+ location: location,
312
+ comment: comment
313
+ }.to_json(*a)
314
+ end
315
+ end
316
+
317
+ class Constant
318
+ attr_reader :name
319
+ attr_reader :type
320
+ attr_reader :location
321
+ attr_reader :comment
322
+
323
+ def initialize(name:, type:, location:, comment:)
324
+ @name = name
325
+ @type = type
326
+ @location = location
327
+ @comment = comment
328
+ end
329
+
330
+ def ==(other)
331
+ other.is_a?(Constant) &&
332
+ other.name == name &&
333
+ other.type == type
334
+ end
335
+
336
+ alias eql? ==
337
+
338
+ def hash
339
+ self.class.hash ^ name.hash ^ type.hash
340
+ end
341
+
342
+ def to_json(*a)
343
+ {
344
+ declaration: :constant,
345
+ name: name,
346
+ type: type,
347
+ location: location,
348
+ comment: comment
349
+ }.to_json(*a)
350
+ end
351
+ end
352
+
353
+ class Global
354
+ attr_reader :name
355
+ attr_reader :type
356
+ attr_reader :location
357
+ attr_reader :comment
358
+
359
+ def initialize(name:, type:, location:, comment:)
360
+ @name = name
361
+ @type = type
362
+ @location = location
363
+ @comment = comment
364
+ end
365
+
366
+ def ==(other)
367
+ other.is_a?(Global) &&
368
+ other.name == name &&
369
+ other.type == type
370
+ end
371
+
372
+ alias eql? ==
373
+
374
+ def hash
375
+ self.class.hash ^ name.hash ^ type.hash
376
+ end
377
+
378
+ def to_json(*a)
379
+ {
380
+ declaration: :global,
381
+ name: name,
382
+ type: type,
383
+ location: location,
384
+ comment: comment
385
+ }.to_json(*a)
386
+ end
387
+ end
388
+ end
389
+ end
390
+ end
391
+ end