402 """ |
402 """ |
403 def calculateEndline(lineno, lines, indent): |
403 def calculateEndline(lineno, lines, indent): |
404 """ |
404 """ |
405 Function to calculate the end line of a class or method/function. |
405 Function to calculate the end line of a class or method/function. |
406 |
406 |
407 @param lineno line number to start at |
407 @param lineno line number to start at (one based) |
408 @type int |
408 @type int |
409 @param lines list of source lines |
409 @param lines list of source lines |
410 @type list of str |
410 @type list of str |
411 @param indent indent length the class/method/function definition |
411 @param indent indent length the class/method/function definition |
412 @type int |
412 @type int |
413 @return end line of the class/method/function |
413 @return end line of the class/method/function (one based) |
414 @rtype int |
414 @rtype int |
415 """ |
415 """ |
416 # start with zero based line after start line |
416 # start with zero based line after start line |
417 while lineno < len(lines): |
417 while lineno < len(lines): |
418 line = lines[lineno] |
418 line = lines[lineno] |
492 if deltastack: |
491 if deltastack: |
493 del deltastack[-1] |
492 del deltastack[-1] |
494 deltaindentcalculated = 0 |
493 deltaindentcalculated = 0 |
495 # close all classes indented at least as much |
494 # close all classes indented at least as much |
496 while classstack and classstack[-1][1] >= thisindent: |
495 while classstack and classstack[-1][1] >= thisindent: |
497 if classstack[-1][0] is not None: |
|
498 # record the end line |
|
499 classstack[-1][0].setEndLine(lineno - 1) |
|
500 del classstack[-1] |
496 del classstack[-1] |
501 if classstack: |
497 if classstack: |
502 # it's a class method |
498 # it's a class method |
503 cur_class = classstack[-1][0] |
499 cur_class = classstack[-1][0] |
504 if cur_class: |
500 if cur_class: |
505 # it's a method/nested def |
501 # it's a method/nested def |
506 f = Function(None, meth_name, |
502 f = Function(None, meth_name, |
507 file, lineno, meth_sig, annotation=meth_ret, |
503 file, lineno, meth_sig, annotation=meth_ret, |
508 modifierType=modifier) |
504 modifierType=modifier) |
509 cur_class._addmethod(meth_name, f) |
505 cur_class._addmethod(meth_name, f) |
|
506 else: |
|
507 f = None |
510 else: |
508 else: |
511 # it's a function |
509 # it's a function |
512 f = Function(module, meth_name, |
510 f = Function(module, meth_name, |
513 file, lineno, meth_sig, annotation=meth_ret, |
511 file, lineno, meth_sig, annotation=meth_ret, |
514 modifierType=modifier) |
512 modifierType=modifier) |
517 meth_name = "{0}_{1:d}".format( |
515 meth_name = "{0}_{1:d}".format( |
518 meth_name, dict_counts[meth_name]) |
516 meth_name, dict_counts[meth_name]) |
519 else: |
517 else: |
520 dict_counts[meth_name] = 0 |
518 dict_counts[meth_name] = 0 |
521 dictionary[meth_name] = f |
519 dictionary[meth_name] = f |
522 endlineno = calculateEndline(lineno, srcLines, thisindent) |
520 if f: |
523 f.setEndLine(endlineno) |
521 endlineno = calculateEndline(lineno, srcLines, thisindent) |
524 if cur_obj and isinstance(cur_obj, Function): |
522 f.setEndLine(endlineno) |
525 cur_obj.setEndLine(lineno - 1) |
523 classstack.append((f, thisindent)) # Marker for nested fns |
526 cur_obj = f |
|
527 classstack.append((f, thisindent)) # Marker for nested fns |
|
528 |
524 |
529 # reset the modifier settings |
525 # reset the modifier settings |
530 modifierType = ClbrBaseClasses.Function.General |
526 modifierType = ClbrBaseClasses.Function.General |
531 modifierIndent = -1 |
527 modifierIndent = -1 |
532 |
528 |
536 elif m.start("Class") >= 0: |
532 elif m.start("Class") >= 0: |
537 # we found a class definition |
533 # we found a class definition |
538 thisindent = _indent(m.group("ClassIndent")) |
534 thisindent = _indent(m.group("ClassIndent")) |
539 # close all classes indented at least as much |
535 # close all classes indented at least as much |
540 while classstack and classstack[-1][1] >= thisindent: |
536 while classstack and classstack[-1][1] >= thisindent: |
541 if classstack[-1][0] is not None: |
|
542 # record the end line |
|
543 classstack[-1][0].setEndLine(lineno - 1) |
|
544 del classstack[-1] |
537 del classstack[-1] |
545 lineno = lineno + src.count('\n', last_lineno_pos, start) |
538 lineno = lineno + src.count('\n', last_lineno_pos, start) |
546 last_lineno_pos = start |
539 last_lineno_pos = start |
547 class_name = m.group("ClassName") |
540 class_name = m.group("ClassName") |
548 inherit = m.group("ClassSupers") |
541 inherit = m.group("ClassSupers") |