From f41e31371f6ecffdfcd5e6ad0e45227afbbb9851 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 18 Jan 2022 19:15:48 +0100 Subject: [PATCH] Added support for multiple subclasses --- src/py_to_uxf_core/model/python_class.py | 6 ++++ .../service/implementation_scanner_service.py | 36 +++++++++++-------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/py_to_uxf_core/model/python_class.py b/src/py_to_uxf_core/model/python_class.py index 8463088..f15e1cc 100644 --- a/src/py_to_uxf_core/model/python_class.py +++ b/src/py_to_uxf_core/model/python_class.py @@ -28,3 +28,9 @@ class PythonClass: def add_attribute(self, attribute: PythonClassAttribute): self._attributes.append(attribute) + + def __str__(self): + return f'{self._name}' + + def __repr__(self): + return f'{self._name}' diff --git a/src/py_to_uxf_core/service/implementation_scanner_service.py b/src/py_to_uxf_core/service/implementation_scanner_service.py index 6570563..7f78e55 100644 --- a/src/py_to_uxf_core/service/implementation_scanner_service.py +++ b/src/py_to_uxf_core/service/implementation_scanner_service.py @@ -33,21 +33,27 @@ class ImplementationScannerService(ImplementationScannerABC): line = line.replace('\t', '') if line.startswith('class ') and '(' in line and ')' in line: sub_name = line.split('class ')[1].split('(')[0] - sub: Optional[PythonClass] = classes.where(lambda c: c.name == sub_name).first_or_default() - if sub is None: - return None + subclasses = classes.where(lambda c: c.name == sub_name) + implementations = List(ClassImplementation) + for sub in subclasses: + # sub: Optional[PythonClass] = classes.where(lambda c: c.name == sub_name).first_or_default() + # if sub is None: + # return None - line = line.replace(' ', '') - base_name = line.split('(')[1].split(')')[0] - if ',' in base_name: - implementations = List(ClassImplementation) - for name in base_name.split(','): - if '=' in name: - continue + line = line.replace(' ', '') + base_name = line.split('(')[1].split(')')[0] + if ',' in base_name: + for name in base_name.split(','): + if '=' in name: + continue - implementation = self._get_implementation(name, sub, classes) - if implementation is not None: - implementations.append(implementation) - return implementations - return self._get_implementation(base_name, sub, classes) + implementation = self._get_implementation(name, sub, classes) + if implementation is not None: + implementations.append(implementation) + # return implementations + # return self._get_implementation(base_name, sub, classes) + implementation = self._get_implementation(base_name, sub, classes) + if implementation is not None: + implementations.append(implementation) + return implementations return None