183 class Class(ClbrBaseClasses.Class, VisibilityMixin): |
183 class Class(ClbrBaseClasses.Class, VisibilityMixin): |
184 """ |
184 """ |
185 Class to represent a Python class. |
185 Class to represent a Python 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 Function(ClbrBaseClasses.Function, VisibilityMixin): |
211 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
208 """ |
212 """ |
225 |
230 |
226 @param module name of the module containing this function |
231 @param module name of the module containing this function |
227 @type str |
232 @type str |
228 @param name name of this function |
233 @param name name of this function |
229 @type str |
234 @type str |
230 @param file filename containing this class |
235 @param file file name containing this function |
231 @type str |
236 @type str |
232 @param lineno linenumber of the class definition |
237 @param lineno line number of the function definition |
233 @type int |
238 @type int |
234 @param signature parameterlist of the method |
239 @param col_offset column number of the function definition (defaults to 0) |
|
240 @type int (optional) |
|
241 @param signature parameter list of the function |
235 @type str |
242 @type str |
236 @param separator string separating the parameters |
243 @param separator string separating the parameters |
237 @type str |
244 @type str |
238 @param modifierType type of the function |
245 @param modifierType type of the function |
239 @type int |
246 @type int |
244 self, |
251 self, |
245 module, |
252 module, |
246 name, |
253 name, |
247 file, |
254 file, |
248 lineno, |
255 lineno, |
249 signature, |
256 col_offset=col_offset, |
250 separator, |
257 signature=signature, |
251 modifierType, |
258 separator=separator, |
252 annotation, |
259 modifierType=modifierType, |
|
260 annotation=annotation, |
253 ) |
261 ) |
254 VisibilityMixin.__init__(self) |
262 VisibilityMixin.__init__(self) |
255 |
263 |
256 |
264 |
257 class Attribute(ClbrBaseClasses.Attribute, VisibilityMixin): |
265 class Attribute(ClbrBaseClasses.Attribute, VisibilityMixin): |
258 """ |
266 """ |
259 Class to represent a class attribute. |
267 Class to represent a class attribute. |
260 """ |
268 """ |
261 |
269 |
262 def __init__(self, module, name, file, lineno): |
270 def __init__(self, module, name, file, lineno, col_offset=0): |
263 """ |
271 """ |
264 Constructor |
272 Constructor |
265 |
273 |
266 @param module name of the module containing this class |
274 @param module name of the module containing this class |
267 @type str |
275 @type str |
268 @param name name of this class |
276 @param name name of this class |
269 @type str |
277 @type str |
270 @param file filename containing this attribute |
278 @param file file name containing this attribute |
271 @type str |
279 @type str |
272 @param lineno linenumber of the class definition |
280 @param lineno line number of the attribute definition |
273 @type int |
281 @type int |
274 """ |
282 @param col_offset column number of the attribute definition (defaults to 0) |
275 ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno) |
283 @type int (optional) |
|
284 """ |
|
285 ClbrBaseClasses.Attribute.__init__( |
|
286 self, module, name, file, lineno, col_offset=col_offset |
|
287 ) |
276 VisibilityMixin.__init__(self) |
288 VisibilityMixin.__init__(self) |
277 |
289 |
278 |
290 |
279 @dataclass |
291 @dataclass |
280 class Publics: |
292 class Publics: |
515 meth_ret = m.captured("MethodReturnAnnotation") |
527 meth_ret = m.captured("MethodReturnAnnotation") |
516 meth_ret = meth_ret.replace("\\\n", "") |
528 meth_ret = meth_ret.replace("\\\n", "") |
517 meth_ret = _commentsub("", meth_ret) |
529 meth_ret = _commentsub("", meth_ret) |
518 lineno += src.count("\n", last_lineno_pos, start) |
530 lineno += src.count("\n", last_lineno_pos, start) |
519 last_lineno_pos = start |
531 last_lineno_pos = start |
|
532 col_offset = m.capturedStart("MethodName") - m.capturedStart() |
520 if modifierType and modifierIndent == thisindent: |
533 if modifierType and modifierIndent == thisindent: |
521 if modifierType == "@staticmethod": |
534 if modifierType == "@staticmethod": |
522 modifier = ClbrBaseClasses.Function.Static |
535 modifier = ClbrBaseClasses.Function.Static |
523 elif modifierType == "@classmethod": |
536 elif modifierType == "@classmethod": |
524 modifier = ClbrBaseClasses.Function.Class |
537 modifier = ClbrBaseClasses.Function.Class |
595 # close all classes indented at least as much |
610 # close all classes indented at least as much |
596 while classstack and classstack[-1][1] >= thisindent: |
611 while classstack and classstack[-1][1] >= thisindent: |
597 classstack.pop() |
612 classstack.pop() |
598 lineno += src.count("\n", last_lineno_pos, start) |
613 lineno += src.count("\n", last_lineno_pos, start) |
599 last_lineno_pos = start |
614 last_lineno_pos = start |
|
615 col_offset = m.capturedStart("ClassName") - m.capturedStart() |
600 class_name = m.captured("ClassName") |
616 class_name = m.captured("ClassName") |
601 inherit = m.captured("ClassSupers") |
617 inherit = m.captured("ClassSupers") |
602 if inherit: |
618 if inherit: |
603 # the class inherits from other classes |
619 # the class inherits from other classes |
604 inherit = inherit[1:-1].strip() |
620 inherit = inherit[1:-1].strip() |
637 del conditionalsstack[-1] |
653 del conditionalsstack[-1] |
638 if deltastack: |
654 if deltastack: |
639 del deltastack[-1] |
655 del deltastack[-1] |
640 deltaindentcalculated = False |
656 deltaindentcalculated = False |
641 # remember this class |
657 # remember this class |
642 cur_class = Class(module, class_name, inherit, file, lineno) |
658 cur_class = Class( |
|
659 module, class_name, inherit, file, lineno, col_offset=col_offset |
|
660 ) |
643 endlineno = calculateEndline(lineno, srcLines, thisindent) |
661 endlineno = calculateEndline(lineno, srcLines, thisindent) |
644 cur_class.setEndLine(endlineno) |
662 cur_class.setEndLine(endlineno) |
645 if not classstack: |
663 if not classstack: |
646 if class_name in dict_counts: |
664 if class_name in dict_counts: |
647 dict_counts[class_name] += 1 |
665 dict_counts[class_name] += 1 |
654 classstack.append((cur_class, thisindent)) |
672 classstack.append((cur_class, thisindent)) |
655 |
673 |
656 elif m.captured("Attribute") or m.captured("TypedAttribute"): |
674 elif m.captured("Attribute") or m.captured("TypedAttribute"): |
657 if m.captured("Attribute"): |
675 if m.captured("Attribute"): |
658 attribute_name = m.captured("AttributeName") |
676 attribute_name = m.captured("AttributeName") |
|
677 col_offset = m.capturedStart("AttributeName") - m.capturedStart() |
659 else: |
678 else: |
660 attribute_name = m.captured("TypedAttributeName") |
679 attribute_name = m.captured("TypedAttributeName") |
|
680 col_offset = m.capturedStart("TypedAttributeName") - m.capturedStart() |
661 lineno += src.count("\n", last_lineno_pos, start) |
681 lineno += src.count("\n", last_lineno_pos, start) |
662 last_lineno_pos = start |
682 last_lineno_pos = start |
663 index = -1 |
683 index = -1 |
664 while index >= -len(classstack): |
684 while index >= -len(classstack): |
665 if classstack[index][0] is not None and not isinstance( |
685 if classstack[index][0] is not None and not isinstance( |
666 classstack[index][0], Function |
686 classstack[index][0], Function |
667 ): |
687 ): |
668 attr = Attribute(module, attribute_name, file, lineno) |
688 attr = Attribute( |
|
689 module, attribute_name, file, lineno, col_offset=col_offset |
|
690 ) |
669 classstack[index][0]._addattribute(attr) |
691 classstack[index][0]._addattribute(attr) |
670 break |
692 break |
671 else: |
693 else: |
672 index -= 1 |
694 index -= 1 |
673 |
695 |
679 |
701 |
680 elif m.captured("Variable") or m.captured("TypedVariable"): |
702 elif m.captured("Variable") or m.captured("TypedVariable"): |
681 if m.captured("Variable"): |
703 if m.captured("Variable"): |
682 thisindent = _indent(m.captured("VariableIndent")) |
704 thisindent = _indent(m.captured("VariableIndent")) |
683 variable_name = m.captured("VariableName") |
705 variable_name = m.captured("VariableName") |
|
706 col_offset = m.capturedStart("VariableName") - m.capturedStart() |
684 else: |
707 else: |
685 thisindent = _indent(m.captured("TypedVariableIndent")) |
708 thisindent = _indent(m.captured("TypedVariableIndent")) |
686 variable_name = m.captured("TypedVariableName") |
709 variable_name = m.captured("TypedVariableName") |
687 if keyword.iskeyword(variable_name): |
710 if keyword.iskeyword(variable_name): |
688 # only if the determined name is not a keyword (e.g. else, except) |
711 # only if the determined name is not a keyword (e.g. else, except) |
689 continue |
712 continue |
|
713 col_offset = m.capturedStart("TypedVariableName") - m.capturedStart() |
690 lineno += src.count("\n", last_lineno_pos, start) |
714 lineno += src.count("\n", last_lineno_pos, start) |
691 last_lineno_pos = start |
715 last_lineno_pos = start |
692 if thisindent == 0 or not classstack: |
716 if thisindent == 0 or not classstack: |
693 # global variable, reset class stack first |
717 # global variable, reset class stack first |
694 classstack = [] |
718 classstack = [] |
696 if "@@Globals@@" not in dictionary: |
720 if "@@Globals@@" not in dictionary: |
697 dictionary["@@Globals@@"] = ClbrBaseClasses.ClbrBase( |
721 dictionary["@@Globals@@"] = ClbrBaseClasses.ClbrBase( |
698 module, "Globals", file, lineno |
722 module, "Globals", file, lineno |
699 ) |
723 ) |
700 dictionary["@@Globals@@"]._addglobal( |
724 dictionary["@@Globals@@"]._addglobal( |
701 Attribute(module, variable_name, file, lineno) |
725 Attribute( |
|
726 module, variable_name, file, lineno, col_offset=col_offset |
|
727 ) |
702 ) |
728 ) |
703 else: |
729 else: |
704 index = -1 |
730 index = -1 |
705 while index >= -len(classstack): |
731 while index >= -len(classstack): |
706 if classstack[index][1] >= thisindent: |
732 if classstack[index][1] >= thisindent: |
707 index -= 1 |
733 index -= 1 |
708 else: |
734 else: |
709 if isinstance(classstack[index][0], Class): |
735 if isinstance(classstack[index][0], Class): |
710 classstack[index][0]._addglobal( |
736 classstack[index][0]._addglobal( |
711 Attribute(module, variable_name, file, lineno) |
737 Attribute( |
|
738 module, |
|
739 variable_name, |
|
740 file, |
|
741 lineno, |
|
742 col_offset=col_offset, |
|
743 ) |
712 ) |
744 ) |
713 elif isinstance(classstack[index][0], Function): |
745 elif isinstance(classstack[index][0], Function): |
714 classstack[index][0]._addattribute( |
746 classstack[index][0]._addattribute( |
715 Attribute(module, variable_name, file, lineno) |
747 Attribute( |
|
748 module, |
|
749 variable_name, |
|
750 file, |
|
751 lineno, |
|
752 col_offset=col_offset, |
|
753 ) |
716 ) |
754 ) |
717 break |
755 break |
718 |
756 |
719 elif m.captured("Publics"): |
757 elif m.captured("Publics"): |
720 idents = m.captured("Identifiers") |
758 idents = m.captured("Identifiers") |