diff --git a/src/py_to_uxf_core/abc/attribute_scanner_abc.py b/src/py_to_uxf_core/abc/attribute_scanner_abc.py index 04fb3a3..2e983a9 100644 --- a/src/py_to_uxf_core/abc/attribute_scanner_abc.py +++ b/src/py_to_uxf_core/abc/attribute_scanner_abc.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +from typing import Optional from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute @@ -9,4 +10,4 @@ class AttributeScannerABC(ABC): def __init__(self): pass @abstractmethod - def scan_line_for_attribute(self, line: str) -> PythonClassAttribute: pass + def scan_line_for_attribute(self, line: str) -> Optional[PythonClassAttribute]: pass diff --git a/src/py_to_uxf_core/service/attribute_scanner_service.py b/src/py_to_uxf_core/service/attribute_scanner_service.py index 7959308..2eed1f2 100644 --- a/src/py_to_uxf_core/service/attribute_scanner_service.py +++ b/src/py_to_uxf_core/service/attribute_scanner_service.py @@ -1,4 +1,9 @@ +from typing import Optional + +from cpl_core.console import Console + from py_to_uxf_core.abc.attribute_scanner_abc import AttributeScannerABC +from py_to_uxf_core.model.access_modifier_enum import AccessModifierEnum from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute @@ -7,5 +12,36 @@ class AttributeScannerService(AttributeScannerABC): def __init__(self): AttributeScannerABC.__init__(self) - def scan_line_for_attribute(self, line: str) -> PythonClassAttribute: - pass \ No newline at end of file + def scan_line_for_attribute(self, line: str) -> Optional[PythonClassAttribute]: + # ATR=1 + # ATR:int=1 + # self.ATR=1 + # self._ATR=1 + # self.__ATR=1 + # self._ATR:int=1 + if '=' in line: + line.replace(' ', '') + name = line.split('=')[0] + + if name.startswith('self.'): + name = name.split('self.')[1] + + access_modifier = AccessModifierEnum.public + type_str = 'any' + + # access_modifier + if name == '__init__' or name == '__repr__' or name == '__str__': + access_modifier = AccessModifierEnum.public + elif name.startswith('_'): + access_modifier = AccessModifierEnum.protected + elif name.startswith('__'): + access_modifier = AccessModifierEnum.private + + if ':' in line: + type_str = line.split(':')[1] + if '=' in type_str: + type_str = type_str.split('=')[0] + + return PythonClassAttribute(access_modifier, name, type_str) + + return None diff --git a/src/py_to_uxf_core/service/python_parser_service.py b/src/py_to_uxf_core/service/python_parser_service.py index bb93ee9..3092225 100644 --- a/src/py_to_uxf_core/service/python_parser_service.py +++ b/src/py_to_uxf_core/service/python_parser_service.py @@ -70,6 +70,7 @@ class PythonParserService(PythonParserABC): if func is not None: cls.add_function(func) Console.write_line('fu:', func.access_modifier.value, func.name, func.args, func.return_type) + continue attribute = self._attribute_scanner.scan_line_for_attribute(line) if attribute is not None: