yard2steep 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6288038fd78f492af6aa413b15c40ac3c6f3ada8068e56a3cf4ec252cfccec1d
4
- data.tar.gz: 9fb5f345434b127bd61f96f1081874b8157698a8f7eaf5a8e6779ff891480642
3
+ metadata.gz: 2d4e6a8130a1312dc38b74c326380d9e23f5e15ef536f5486b335694af8adc4e
4
+ data.tar.gz: be238532e8c75224380d54a5494b27cf3578122b4fe59f4f454609bbf309ada2
5
5
  SHA512:
6
- metadata.gz: 478577c07127351b4080ccbcf48f87656b65cafd6481ebd188bf3d110d26fc04da2513d520d6e99182981bbb84450ebab1c9651ce14569dd6ca3c1941684afaa
7
- data.tar.gz: 8146d573e9f52dbac2309df6651c7b39733f3e5a6d267ec279985a6ec6459866bc61f84e4c4061aa75257444443a03eabbb91c192aadeae13ad62c8307bb02b6
6
+ metadata.gz: 7b52ffb2e6478def16ea64c5d9e68d46d54084f318376fbe2dc38f7f1be5fe87ae2750cf31d37c1edc76473ba2cd42257c43aba53df9453d8991c047e84c3d72
7
+ data.tar.gz: 778099a6c15f9fa648921f909236eebf5fceae28b2b2455188370269144e23f1b0c079377942666452b7dbb682f763ffc03d3c285c8fdfd0ac61b5037c36af46
@@ -1,5 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.5.0
5
- before_install: gem install bundler -v 1.16.1
4
+ - 2.5.1
5
+ before_install:
6
+ - gem install bundler -v 1.16.1
7
+ script:
8
+ - bundle exec rspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yard2steep (0.1.3)
4
+ yard2steep (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Yard2steep
2
2
 
3
+ [![Build Status](https://travis-ci.org/south37/yard2steep.svg?branch=master)](https://travis-ci.org/south37/yard2steep)
4
+ [![Gem Version](https://badge.fury.io/rb/yard2steep.svg)](https://badge.fury.io/rb/yard2steep)
5
+
3
6
  Generate [steep](https://github.com/soutaro/steep) type definition file from yard annotation.
4
7
 
5
- :warning: **This is highly experimental project. Current version is 0.1.2.**
8
+ :warning: **This is highly experimental project.**
6
9
 
7
10
  ## Installation
8
11
 
@@ -13,9 +13,11 @@ end
13
13
  # @param [Array] contents
14
14
 
15
15
  class SomeClass
16
- # @dynamic index, comment
16
+ # @dynamic index, index=, comment, count, count=
17
17
  attr_reader :index
18
+ attr_writer :index
18
19
  attr_reader("comment")
20
+ attr_accessor :count
19
21
  end
20
22
 
21
23
  module SomeModule
@@ -1,8 +1,12 @@
1
1
  class SomeClass
2
2
  @index: any
3
3
  @comment: any
4
+ @count: any
4
5
  def index: -> any
6
+ def index=: (any) -> any
5
7
  def comment: -> any
8
+ def count: -> any
9
+ def count=: (any) -> any
6
10
  end
7
11
  class MyClass
8
12
  def self.name: -> String
@@ -28,14 +28,15 @@ module Yard2steep
28
28
  parent.is_a?(AST::ClassNode) ||
29
29
  (parent == nil && c_name == 'main')
30
30
  }
31
- @kind = kind
32
- @c_name = c_name
33
- @super_c = super_c
34
- @c_list = [] # list of constants
35
- @m_list = [] # list of methods
36
- @ivar_list = [] # list of instance variables
37
- @children = [] # list of child classes
38
- @parent = parent
31
+ @kind = kind
32
+ @c_name = c_name
33
+ @super_c = super_c
34
+ @c_list = [] # list of constants
35
+ @m_list = [] # list of methods
36
+ @ivar_list = [] # list of instance variables
37
+ @ivarname_s = Set.new
38
+ @children = [] # list of child classes
39
+ @parent = parent
39
40
  end
40
41
 
41
42
  # @param [AST::ConstantNode] c
@@ -53,7 +54,10 @@ module Yard2steep
53
54
  # @param [AST::IVarNode] ivar
54
55
  # @return [void]
55
56
  def append_ivar(ivar)
56
- @ivar_list.push(ivar)
57
+ if !@ivarname_s.include?(ivar.name)
58
+ @ivar_list.push(ivar)
59
+ @ivarname_s << ivar.name
60
+ end
57
61
  end
58
62
 
59
63
  # @param [AST::ClassNode] child
@@ -516,11 +516,9 @@ module Yard2steep
516
516
  when "attr_reader"
517
517
  parse_attr_reader(parse_command_args_add_block(r_ast[2]))
518
518
  when "attr_writer"
519
- # TODO(south37) Impl
520
- # parse_attr_writer(parse_command_args_add_block(r_ast[2]))
519
+ parse_attr_writer(parse_command_args_add_block(r_ast[2]))
521
520
  when "attr_accessor"
522
- # TODO(south37) Impl
523
- # parse_attr_accessor(parse_command_args_add_block(r_ast[2]))
521
+ parse_attr_accessor(parse_command_args_add_block(r_ast[2]))
524
522
  end
525
523
 
526
524
  # Do nothing for other case
@@ -605,17 +603,15 @@ module Yard2steep
605
603
  when "attr_reader"
606
604
  parse_attr_reader(parse_command_args_add_block(r_ast[2][1]))
607
605
  when "attr_writer"
608
- # TODO(south37) Impl
609
- # parse_attr_writer(parse_command_args_add_block(r_ast[2][1]))
606
+ parse_attr_writer(parse_command_args_add_block(r_ast[2][1]))
610
607
  when "attr_accessor"
611
- # TODO(south37) Impl
612
- # parse_attr_accessor(parse_command_args_add_block(r_ast[2][1]))
608
+ parse_attr_accessor(parse_command_args_add_block(r_ast[2][1]))
613
609
  end
614
610
  # Do nothing for other case
615
611
  end
616
612
  end
617
613
 
618
- # @param [Array<String>] vars
614
+ # @param [Array<String>] ivars
619
615
  # @return [void]
620
616
  def parse_attr_reader(ivars)
621
617
  ivars.each do |ivarname|
@@ -625,17 +621,71 @@ module Yard2steep
625
621
  )
626
622
  )
627
623
 
628
- # NOTE: Attr reader should add getter method
629
- @current_class.append_m(
630
- AST::MethodNode.new(
631
- p_list: [],
632
- r_type: ANY_TYPE,
633
- m_name: ivarname,
624
+ # NOTE: attr_reader should add a getter method
625
+ @current_class.append_m(getter_method_node(ivarname))
626
+ end
627
+ end
628
+
629
+ # @param [Array<String>] ivars
630
+ # @return [void]
631
+ def parse_attr_writer(ivars)
632
+ ivars.each do |ivarname|
633
+ @current_class.append_ivar(
634
+ AST::IVarNode.new(
635
+ name: ivarname
636
+ )
637
+ )
638
+
639
+ # NOTE: attr_writer should add a setter method
640
+ @current_class.append_m(setter_method_node(ivarname))
641
+ end
642
+ end
643
+
644
+ # @param [Array<String>] ivars
645
+ # @return [void]
646
+ def parse_attr_accessor(ivars)
647
+ ivars.each do |ivarname|
648
+ @current_class.append_ivar(
649
+ AST::IVarNode.new(
650
+ name: ivarname
634
651
  )
635
652
  )
653
+
654
+ # NOTE: attr_accessor should add getter and setter methods
655
+ @current_class.append_m(getter_method_node(ivarname))
656
+ @current_class.append_m(setter_method_node(ivarname))
636
657
  end
637
658
  end
638
659
 
660
+ # @param [String] ivarname
661
+ # @return [AST::MethodNode]
662
+ def getter_method_node(ivarname)
663
+ AST::MethodNode.new(
664
+ p_list: [],
665
+ r_type: ANY_TYPE,
666
+ m_name: ivarname,
667
+ )
668
+ end
669
+
670
+ # @param [String] ivarname
671
+ # @return [AST::MethodNode]
672
+ def setter_method_node(ivarname)
673
+ AST::MethodNode.new(
674
+ p_list: [
675
+ AST::PNode.new(
676
+ type_node: AST::PTypeNode.new(
677
+ p_type: ANY_TYPE,
678
+ p_name: '',
679
+ kind: AST::PTypeNode::KIND[:normal],
680
+ ),
681
+ style: AST::PNode::STYLE[:normal],
682
+ )
683
+ ],
684
+ r_type: ANY_TYPE,
685
+ m_name: "#{ivarname}=",
686
+ )
687
+ end
688
+
639
689
  ##
640
690
  # Helper
641
691
 
@@ -1,3 +1,3 @@
1
1
  module Yard2steep
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -49,6 +49,10 @@ class Yard2steep::Parser
49
49
  def parse_command_args_add_block: (any) -> any
50
50
  def parse_method_add_arg: (any) -> void
51
51
  def parse_attr_reader: (any) -> any
52
+ def parse_attr_writer: (any) -> any
53
+ def parse_attr_accessor: (any) -> any
54
+ def getter_method_node: (any) -> any
55
+ def setter_method_node: (any) -> any
52
56
  def debug_print!: (any) -> void
53
57
  def type_node: (any) -> any
54
58
  def block_type_node: (any) -> any
@@ -163,6 +167,7 @@ class Yard2steep::AST::ClassNode
163
167
  @c_list: any
164
168
  @m_list: any
165
169
  @ivar_list: any
170
+ @ivarname_s: any
166
171
  @children: any
167
172
  @parent: any
168
173
  @long_name: any
@@ -170,7 +175,7 @@ class Yard2steep::AST::ClassNode
170
175
  def initialize: (kind: any, c_name: any, super_c: any, parent: any) -> any
171
176
  def append_constant: (any) -> any
172
177
  def append_m: (any) -> any
173
- def append_ivar: (any) -> any
178
+ def append_ivar: (any) -> void
174
179
  def append_child: (any) -> any
175
180
  def long_name: () -> any
176
181
  def long_super: () -> any
@@ -19,7 +19,11 @@ class Yard2steep::Parser
19
19
  def parse_command: (Array<any>) -> void
20
20
  def parse_command_args_add_block: (Array<any>) -> Array<String>
21
21
  def parse_method_add_arg: (Array<any>) -> void
22
- def parse_attr_reader: (any) -> void
22
+ def parse_attr_reader: (Array<String>) -> void
23
+ def parse_attr_writer: (Array<String>) -> void
24
+ def parse_attr_accessor: (Array<String>) -> void
25
+ def getter_method_node: (String) -> AST::MethodNode
26
+ def setter_method_node: (String) -> AST::MethodNode
23
27
  def debug_print!: (String) -> void
24
28
  def type_node: (String) -> AST::PTypeNode
25
29
  def block_type_node: (String) -> AST::PTypeNode
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard2steep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nao Minami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-11 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler