183 class Class(ClbrBaseClasses.Class, VisibilityMixin): |
183 class Class(ClbrBaseClasses.Class, VisibilityMixin): |
184 """ |
184 """ |
185 Class to represent a Ruby class. |
185 Class to represent a Ruby class. |
186 """ |
186 """ |
187 |
187 |
188 def __init__(self, module, name, superClasses, file, lineno): |
188 def __init__(self, module, name, superClasses, file, lineno, col_offset=0): |
189 """ |
189 """ |
190 Constructor |
190 Constructor |
191 |
191 |
192 @param module name of the module containing this class |
192 @param module name of the module containing this class |
193 @type str |
193 @type str |
194 @param name name of this class |
194 @param name name of this class |
195 @type str |
195 @type str |
196 @param superClasses list of class names this class is inherited from |
196 @param superClasses list of class names this class is inherited from |
197 @type list of str |
197 @type list of str |
198 @param file filename containing this class |
198 @param file file name containing this class |
199 @type str |
199 @type str |
200 @param lineno linenumber of the class definition |
200 @param lineno line number of the class definition |
201 @type int |
201 @type int |
202 """ |
202 @param col_offset column number of the class definition (defaults to 0) |
203 ClbrBaseClasses.Class.__init__(self, module, name, superClasses, file, lineno) |
203 @type int (optional) |
|
204 """ |
|
205 ClbrBaseClasses.Class.__init__( |
|
206 self, module, name, superClasses, file, lineno, col_offset=col_offset |
|
207 ) |
204 VisibilityMixin.__init__(self) |
208 VisibilityMixin.__init__(self) |
205 |
209 |
206 |
210 |
207 class Module(ClbrBaseClasses.Module, VisibilityMixin): |
211 class Module(ClbrBaseClasses.Module, VisibilityMixin): |
208 """ |
212 """ |
209 Class to represent a Ruby module. |
213 Class to represent a Ruby module. |
210 """ |
214 """ |
211 |
215 |
212 def __init__(self, module, name, file, lineno): |
216 def __init__(self, module, name, file, lineno, col_offset=0): |
213 """ |
217 """ |
214 Constructor |
218 Constructor |
215 |
219 |
216 @param module name of the module containing this class |
220 @param module name of the module containing this module |
217 @type str |
221 @type str |
218 @param name name of this class |
222 @param name name of this module |
219 @type str |
223 @type str |
220 @param file filename containing this class |
224 @param file file name containing this module |
221 @type str |
225 @type str |
222 @param lineno linenumber of the class definition |
226 @param lineno linenumber of the module definition |
223 @type int |
227 @type int |
224 """ |
228 @param col_offset column number of the module definition (defaults to 0) |
225 ClbrBaseClasses.Module.__init__(self, module, name, file, lineno) |
229 @type int (optional) |
|
230 """ |
|
231 ClbrBaseClasses.Module.__init__( |
|
232 self, module, name, file, lineno, col_offset=col_offset |
|
233 ) |
226 VisibilityMixin.__init__(self) |
234 VisibilityMixin.__init__(self) |
227 |
235 |
228 |
236 |
229 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
237 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
230 """ |
238 """ |
231 Class to represent a Ruby function. |
239 Class to represent a Ruby function. |
232 """ |
240 """ |
233 |
241 |
234 def __init__(self, module, name, file, lineno, signature="", separator=","): |
242 def __init__( |
|
243 self, module, name, file, lineno, col_offset=0, signature="", separator="," |
|
244 ): |
235 """ |
245 """ |
236 Constructor |
246 Constructor |
237 |
247 |
238 @param module name of the module containing this function |
248 @param module name of the module containing this function |
239 @type str |
249 @type str |
240 @param name name of this function |
250 @param name name of this function |
241 @type str |
251 @type str |
242 @param file filename containing this class |
252 @param file file name containing this function |
243 @type str |
253 @type str |
244 @param lineno linenumber of the class definition |
254 @param lineno line number of the function definition |
245 @type int |
255 @type int |
246 @param signature parameter list of the method |
256 @param col_offset column number of the function definition (defaults to 0) |
|
257 @type int (optional) |
|
258 @param signature parameter list of the function |
247 @type str |
259 @type str |
248 @param separator string separating the parameters |
260 @param separator string separating the parameters |
249 @type str |
261 @type str |
250 """ |
262 """ |
251 ClbrBaseClasses.Function.__init__( |
263 ClbrBaseClasses.Function.__init__( |
252 self, module, name, file, lineno, signature, separator |
264 self, |
|
265 module, |
|
266 name, |
|
267 file, |
|
268 lineno, |
|
269 col_offset=col_offset, |
|
270 signature=signature, |
|
271 separator=separator, |
253 ) |
272 ) |
254 VisibilityMixin.__init__(self) |
273 VisibilityMixin.__init__(self) |
255 |
274 |
256 |
275 |
257 class Attribute(ClbrBaseClasses.Attribute, VisibilityMixin): |
276 class Attribute(ClbrBaseClasses.Attribute, VisibilityMixin): |
258 """ |
277 """ |
259 Class to represent a class or module attribute. |
278 Class to represent a class or module attribute. |
260 """ |
279 """ |
261 |
280 |
262 def __init__(self, module, name, file, lineno): |
281 def __init__(self, module, name, file, lineno, col_offset=0): |
263 """ |
282 """ |
264 Constructor |
283 Constructor |
265 |
284 |
266 @param module name of the module containing this class |
285 @param module name of the module containing this attribute |
267 @type str |
286 @type str |
268 @param name name of this class |
287 @param name name of this attribute |
269 @type str |
288 @type str |
270 @param file filename containing this attribute |
289 @param file file name containing this attribute |
271 @type str |
290 @type str |
272 @param lineno linenumber of the class definition |
291 @param lineno line number of the attribute definition |
273 @type int |
292 @type int |
274 """ |
293 @param col_offset column number of the attribute definition (defaults to 0) |
275 ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno) |
294 @type int (optional) |
|
295 """ |
|
296 ClbrBaseClasses.Attribute.__init__( |
|
297 self, module, name, file, lineno, col_offset=col_offset |
|
298 ) |
276 VisibilityMixin.__init__(self) |
299 VisibilityMixin.__init__(self) |
277 self.setPrivate() |
300 self.setPrivate() |
278 |
301 |
279 |
302 |
280 def readmodule_ex(module, path=None, isTypeFile=False): # noqa: U100 |
303 def readmodule_ex(module, path=None, isTypeFile=False): # noqa: U100 |
354 meth_sig = m.captured("MethodSignature") |
377 meth_sig = m.captured("MethodSignature") |
355 meth_sig = meth_sig and meth_sig.replace("\\\n", "") or "" |
378 meth_sig = meth_sig and meth_sig.replace("\\\n", "") or "" |
356 meth_sig = _commentsub("", meth_sig) |
379 meth_sig = _commentsub("", meth_sig) |
357 lineno += src.count("\n", last_lineno_pos, start) |
380 lineno += src.count("\n", last_lineno_pos, start) |
358 last_lineno_pos = start |
381 last_lineno_pos = start |
|
382 if m.captured("MethodName"): |
|
383 col_offset = m.capturedStart("MethodName") - m.capturedStart() |
|
384 elif m.captured("MethodName2"): |
|
385 col_offset = m.capturedStart("MethodName2") - m.capturedStart() |
|
386 elif m.captured("MethodName3"): |
|
387 col_offset = m.capturedStart("MethodName3") - m.capturedStart() |
359 if meth_name.startswith("self."): |
388 if meth_name.startswith("self."): |
360 meth_name = meth_name[5:] |
389 meth_name = meth_name[5:] |
361 elif meth_name.startswith("self::"): |
390 elif meth_name.startswith("self::"): |
362 meth_name = meth_name[6:] |
391 meth_name = meth_name[6:] |
363 # close all classes/modules indented at least as much |
392 # close all classes/modules indented at least as much |
424 if classstack[-1][0] is not None: |
467 if classstack[-1][0] is not None: |
425 # record the end line |
468 # record the end line |
426 classstack[-1][0].setEndLine(lineno - 1) |
469 classstack[-1][0].setEndLine(lineno - 1) |
427 del classstack[-1] |
470 del classstack[-1] |
428 class_name = m.captured("ClassName") or m.captured("ClassName2") |
471 class_name = m.captured("ClassName") or m.captured("ClassName2") |
|
472 col_offset = m.capturedStart("ClassName") - m.capturedStart() |
429 inherit = m.captured("ClassSupers") |
473 inherit = m.captured("ClassSupers") |
430 if inherit: |
474 if inherit: |
431 # the class inherits from other classes |
475 # the class inherits from other classes |
432 inherit = inherit[1:].strip() |
476 inherit = inherit[1:].strip() |
433 inherit = [_commentsub("", inherit)] |
477 inherit = [_commentsub("", inherit)] |
434 # remember this class |
478 # remember this class |
435 cur_class = Class(module, class_name, inherit, file, lineno) |
479 cur_class = Class( |
|
480 module, class_name, inherit, file, lineno, col_offset=col_offset |
|
481 ) |
436 if not classstack: |
482 if not classstack: |
437 if class_name in dictionary: |
483 if class_name in dictionary: |
438 cur_class = dictionary[class_name] |
484 cur_class = dictionary[class_name] |
439 else: |
485 else: |
440 dictionary[class_name] = cur_class |
486 dictionary[class_name] = cur_class |