diff --git a/src/py_to_uxf/startup.py b/src/py_to_uxf/startup.py index 2fca76c..7ace394 100644 --- a/src/py_to_uxf/startup.py +++ b/src/py_to_uxf/startup.py @@ -5,11 +5,13 @@ from cpl_core.configuration import ConfigurationABC, ConsoleArgument from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl_core.environment import ApplicationEnvironment +from py_to_uxf_core.abc.attribute_scanner_abc import AttributeScannerABC from py_to_uxf_core.abc.class_scanner_abc import ClassScannerABC from py_to_uxf_core.abc.file_scanner_abc import FileScannerABC from py_to_uxf_core.abc.function_scanner_abc import FunctionScannerABC from py_to_uxf_core.abc.python_parser_abc import PythonParserABC from py_to_uxf_core.abc.umlet_creator_abc import UmletCreatorABC +from py_to_uxf_core.service.attribute_scanner_service import AttributeScannerService from py_to_uxf_core.service.class_scanner_service import ClassScannerService from py_to_uxf_core.service.file_scanner_service import FileScannerService from py_to_uxf_core.service.function_scanner_service import FunctionScannerService @@ -32,6 +34,7 @@ class Startup(StartupABC): services.add_transient(FileScannerABC, FileScannerService) services.add_transient(ClassScannerABC, ClassScannerService) services.add_transient(FunctionScannerABC, FunctionScannerService) + services.add_transient(AttributeScannerABC, AttributeScannerService) services.add_singleton(PythonParserABC, PythonParserService) services.add_singleton(UmletCreatorABC, UmletCreatorService) diff --git a/src/py_to_uxf_core/abc/attribute_scanner_abc.py b/src/py_to_uxf_core/abc/attribute_scanner_abc.py new file mode 100644 index 0000000..04fb3a3 --- /dev/null +++ b/src/py_to_uxf_core/abc/attribute_scanner_abc.py @@ -0,0 +1,12 @@ +from abc import ABC, abstractmethod + +from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute + + +class AttributeScannerABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + def scan_line_for_attribute(self, line: str) -> PythonClassAttribute: pass diff --git a/src/py_to_uxf_core/model/function_access_modifier_enum.py b/src/py_to_uxf_core/model/access_modifier_enum.py similarity index 68% rename from src/py_to_uxf_core/model/function_access_modifier_enum.py rename to src/py_to_uxf_core/model/access_modifier_enum.py index 5aa1303..7a7801a 100644 --- a/src/py_to_uxf_core/model/function_access_modifier_enum.py +++ b/src/py_to_uxf_core/model/access_modifier_enum.py @@ -1,7 +1,7 @@ from enum import Enum -class FunctionAccessModifierEnum(Enum): +class AccessModifierEnum(Enum): public = '+' private = '-' diff --git a/src/py_to_uxf_core/model/python_class.py b/src/py_to_uxf_core/model/python_class.py index b81944d..12535d5 100644 --- a/src/py_to_uxf_core/model/python_class.py +++ b/src/py_to_uxf_core/model/python_class.py @@ -1,5 +1,6 @@ from cpl_query.extension import List +from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute from py_to_uxf_core.model.python_function import PythonFunction @@ -8,6 +9,7 @@ class PythonClass: def __init__(self, name): self._name = name self._functions = List(PythonFunction) + self._attributes = List(PythonClassAttribute) @property def name(self) -> str: @@ -19,3 +21,6 @@ class PythonClass: def add_function(self, func: PythonFunction): self._functions.append(func) + + def add_attribute(self, attribute: PythonClassAttribute): + self._attributes.append(attribute) diff --git a/src/py_to_uxf_core/model/python_class_attribute.py b/src/py_to_uxf_core/model/python_class_attribute.py new file mode 100644 index 0000000..a7686bd --- /dev/null +++ b/src/py_to_uxf_core/model/python_class_attribute.py @@ -0,0 +1,27 @@ +from py_to_uxf_core.model.access_modifier_enum import AccessModifierEnum + + +class PythonClassAttribute: + + def __init__(self, access_modifier: AccessModifierEnum, name: str, type: str): + self._access_modifier = access_modifier + self._name = name + self._type = type + + @property + def access_modifier(self) -> AccessModifierEnum: + return self._access_modifier + + @property + def name(self) -> str: + return self._name + + @property + def type(self) -> str: + return self._type + + def __str__(self): + return f'{self._name}: {self._type}' + + def __repr__(self): + return f'{self._name}: {self._type}' diff --git a/src/py_to_uxf_core/model/python_function.py b/src/py_to_uxf_core/model/python_function.py index d545154..73004e1 100644 --- a/src/py_to_uxf_core/model/python_function.py +++ b/src/py_to_uxf_core/model/python_function.py @@ -1,12 +1,12 @@ from cpl_query.extension import List -from py_to_uxf_core.model.function_access_modifier_enum import FunctionAccessModifierEnum +from py_to_uxf_core.model.access_modifier_enum import AccessModifierEnum from py_to_uxf_core.model.python_function_argument import PythonFunctionArgument class PythonFunction: - def __init__(self, access_modifier: FunctionAccessModifierEnum, name: str, args: List[PythonFunctionArgument], return_type: str): + def __init__(self, access_modifier: AccessModifierEnum, name: str, args: List[PythonFunctionArgument], return_type: str): self._access_modifier = access_modifier self._name = name self._args = args diff --git a/src/py_to_uxf_core/service/attribute_scanner_service.py b/src/py_to_uxf_core/service/attribute_scanner_service.py new file mode 100644 index 0000000..7959308 --- /dev/null +++ b/src/py_to_uxf_core/service/attribute_scanner_service.py @@ -0,0 +1,11 @@ +from py_to_uxf_core.abc.attribute_scanner_abc import AttributeScannerABC +from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute + + +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 diff --git a/src/py_to_uxf_core/service/function_scanner_service.py b/src/py_to_uxf_core/service/function_scanner_service.py index c015b02..736db7f 100644 --- a/src/py_to_uxf_core/service/function_scanner_service.py +++ b/src/py_to_uxf_core/service/function_scanner_service.py @@ -4,7 +4,7 @@ import value as value from cpl_query.extension import List from py_to_uxf_core.abc.function_scanner_abc import FunctionScannerABC -from py_to_uxf_core.model.function_access_modifier_enum import FunctionAccessModifierEnum +from py_to_uxf_core.model.access_modifier_enum import AccessModifierEnum from py_to_uxf_core.model.python_function import PythonFunction from py_to_uxf_core.model.python_function_argument import PythonFunctionArgument @@ -25,17 +25,17 @@ class FunctionScannerService(FunctionScannerABC): # name name = line.split('def ')[1] name = name.split('(')[0] - access_modifier = FunctionAccessModifierEnum.public + access_modifier = AccessModifierEnum.public args = List() return_type = 'None' # access_modifier if name == '__init__' or name == '__repr__' or name == '__str__': - access_modifier = FunctionAccessModifierEnum.public + access_modifier = AccessModifierEnum.public elif name.startswith('_'): - access_modifier = FunctionAccessModifierEnum.protected + access_modifier = AccessModifierEnum.protected elif name.startswith('__'): - access_modifier = FunctionAccessModifierEnum.private + access_modifier = AccessModifierEnum.private # args args_str = line.split('(')[1] 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 cd950cf..bb93ee9 100644 --- a/src/py_to_uxf_core/service/python_parser_service.py +++ b/src/py_to_uxf_core/service/python_parser_service.py @@ -2,6 +2,7 @@ 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.abc.class_scanner_abc import ClassScannerABC from py_to_uxf_core.abc.file_scanner_abc import FileScannerABC from py_to_uxf_core.abc.function_scanner_abc import FunctionScannerABC @@ -15,13 +16,15 @@ class PythonParserService(PythonParserABC): self, file_scanner: FileScannerABC, class_scanner: ClassScannerABC, - function_scanner: FunctionScannerABC + function_scanner: FunctionScannerABC, + attribute_scanner: AttributeScannerABC ): PythonParserABC.__init__(self) self._file_scanner = file_scanner self._class_scanner = class_scanner self._function_scanner = function_scanner + self._attribute_scanner = attribute_scanner def parse(self): files = self._file_scanner.scan_files() @@ -67,3 +70,8 @@ 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) + + attribute = self._attribute_scanner.scan_line_for_attribute(line) + if attribute is not None: + cls.add_attribute(attribute) + Console.write_line('at:', attribute.name, attribute.type)