@@ -65,19 +65,19 @@ def parse_member(decl:, context:, outer_name: nil)
65
65
def parse_class_decl ( decl :, context :, outer_name : nil )
66
66
full_name = fully_qualified_name ( outer_name : outer_name , decl : decl )
67
67
klass = context . add_class ( RDoc ::NormalClass , full_name . to_s , decl . super_class &.name &.to_s || "::Object" )
68
- klass . add_comment ( construct_comment ( context : context , comment : decl . comment . string ) , context ) if decl . comment
68
+ klass . add_comment ( construct_comment ( context : context , comment : comment_string ( decl ) ) , context ) if decl . comment
69
69
decl . members . each { |member | parse_member ( decl : member , context : context , outer_name : full_name ) }
70
70
end
71
71
72
72
def parse_module_decl ( decl :, context :, outer_name : nil )
73
73
full_name = fully_qualified_name ( outer_name : outer_name , decl : _ = decl )
74
74
kmodule = context . add_module ( RDoc ::NormalModule , full_name . to_s )
75
- kmodule . add_comment ( construct_comment ( context : context , comment : decl . comment . string ) , context ) if decl . comment
75
+ kmodule . add_comment ( construct_comment ( context : context , comment : comment_string ( decl ) ) , context ) if decl . comment
76
76
decl . members . each { |member | parse_member ( decl : member , context : context , outer_name : full_name ) }
77
77
end
78
78
79
79
def parse_constant_decl ( decl :, context :, outer_name : nil )
80
- comment = decl . comment ? construct_comment ( context : context , comment : decl . comment . string ) : nil
80
+ comment = decl . comment ? construct_comment ( context : context , comment : comment_string ( decl ) ) : nil
81
81
constant = RDoc ::Constant . new ( decl . name . to_s , decl . type . to_s , comment )
82
82
context . add_constant ( constant )
83
83
end
@@ -87,19 +87,19 @@ def parse_method_decl(decl:, context:, outer_name: nil)
87
87
method . singleton = decl . singleton?
88
88
method . visibility = decl . visibility
89
89
method . call_seq = decl . types . map { |type | "#{ decl . name . to_s } #{ type . to_s } " } . join ( "\n " )
90
- if decl . location
90
+ if loc = decl . location
91
91
method . start_collecting_tokens
92
- method . add_token ( { line_no : 1 , char_no : 1 , kind : :on_comment , text : "# File #{ @top_level . relative_name } , line(s) #{ decl . location . start_line } :#{ decl . location . end_line } \n " } )
93
- method . add_token ( { line_no : 1 , char_no : 1 , text : decl . location . source } )
94
- method . line = decl . location . start_line if decl . location
92
+ method . add_token ( { line_no : 1 , char_no : 1 , kind : :on_comment , text : "# File #{ @top_level . relative_name } , line(s) #{ loc . start_line } :#{ loc . end_line } \n " } )
93
+ method . add_token ( { line_no : 1 , char_no : 1 , text : loc . source } )
94
+ method . line = loc . start_line
95
95
end
96
- method . comment = construct_comment ( context : context , comment : decl . comment . string ) if decl . comment
96
+ method . comment = construct_comment ( context : context , comment : comment_string ( decl ) ) if decl . comment
97
97
context . add_method ( method )
98
98
end
99
99
100
100
def parse_method_alias_decl ( decl :, context :, outer_name : nil )
101
101
alias_def = RDoc ::Alias . new ( nil , decl . old_name . to_s , decl . new_name . to_s , nil , decl . kind == :singleton )
102
- alias_def . comment = construct_comment ( context : context , comment : decl . comment . string ) if decl . comment
102
+ alias_def . comment = construct_comment ( context : context , comment : comment_string ( decl ) ) if decl . comment
103
103
context . add_alias ( alias_def )
104
104
end
105
105
@@ -114,7 +114,7 @@ def parse_attr_decl(decl:, context:, outer_name: nil)
114
114
end
115
115
attribute = RDoc ::Attr . new ( nil , decl . name . to_s , rw , nil , decl . kind == :singleton )
116
116
attribute . visibility = decl . visibility
117
- attribute . comment = construct_comment ( context : context , comment : decl . comment . string ) if decl . comment
117
+ attribute . comment = construct_comment ( context : context , comment : comment_string ( decl ) ) if decl . comment
118
118
context . add_attribute ( attribute )
119
119
end
120
120
@@ -130,7 +130,7 @@ def parse_include_decl(decl:, context:, outer_name: nil)
130
130
end
131
131
end
132
132
include_decl = RDoc ::Include . new ( name , nil )
133
- include_decl . comment = construct_comment ( context : context , comment : decl . comment . string ) if decl . comment
133
+ include_decl . comment = construct_comment ( context : context , comment : comment_string ( decl ) ) if decl . comment
134
134
context . add_include ( include_decl )
135
135
end
136
136
@@ -146,7 +146,7 @@ def parse_extend_decl(decl:, context:, outer_name: nil)
146
146
end
147
147
end
148
148
extend_decl = RDoc ::Extend . new ( name , nil )
149
- extend_decl . comment = construct_comment ( context : context , comment : decl . comment . string ) if decl . comment
149
+ extend_decl . comment = construct_comment ( context : context , comment : comment_string ( decl ) ) if decl . comment
150
150
context . add_extend ( extend_decl )
151
151
end
152
152
@@ -158,6 +158,11 @@ def construct_comment(context:, comment:)
158
158
comment
159
159
end
160
160
161
+ def comment_string ( with_comment )
162
+ comment = with_comment . comment or raise "Object with `#comment` returning a object is expected"
163
+ comment . string
164
+ end
165
+
161
166
def fully_qualified_name ( outer_name :, decl :)
162
167
if outer_name
163
168
( outer_name + decl . name )
0 commit comments