From 9a4de29af80dd5d3384ed1f7ed17fe8070e5a7ec Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 16 Jan 2022 02:35:51 +0100 Subject: [PATCH] Improved output --- src/py_to_uxf/application.py | 17 ++++++++++++++++- src/py_to_uxf_core/abc/python_parser_abc.py | 6 +++++- src/py_to_uxf_core/model/python_class.py | 6 +++++- .../service/python_parser_service.py | 11 ++++++----- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/py_to_uxf/application.py b/src/py_to_uxf/application.py index 6f96744..eef361f 100644 --- a/src/py_to_uxf/application.py +++ b/src/py_to_uxf/application.py @@ -4,6 +4,7 @@ from cpl_core.console import Console from cpl_core.dependency_injection import ServiceProviderABC from py_to_uxf_core.abc.python_parser_abc import PythonParserABC +from py_to_uxf_core.model.python_class import PythonClass class Application(ApplicationABC): @@ -24,4 +25,18 @@ class Application(ApplicationABC): return Console.write_line(f'Found path:', self._path) - self._parser.parse() + classes: list[PythonClass] = self._parser.parse() + + for cls in classes: + Console.write_line(f'Class {cls.name}') + if len(cls.attributes) > 0: + Console.write_line('\tAttributes:') + for atr in cls.attributes: + Console.write_line(f'\t{atr.access_modifier.value}{atr.name}: {atr.type}') + + if len(cls.functions) > 0: + Console.write_line('\tFunctions:') + for func in cls.functions: + args = '' + Console.write_line(f'\t{func.access_modifier.value}{func.name}({args}): {func.return_type}') + Console.write_line() diff --git a/src/py_to_uxf_core/abc/python_parser_abc.py b/src/py_to_uxf_core/abc/python_parser_abc.py index c4796ea..866cba1 100644 --- a/src/py_to_uxf_core/abc/python_parser_abc.py +++ b/src/py_to_uxf_core/abc/python_parser_abc.py @@ -1,5 +1,9 @@ from abc import ABC, abstractmethod +from cpl_query.extension import List + +from py_to_uxf_core.model.python_class import PythonClass + class PythonParserABC(ABC): @@ -7,4 +11,4 @@ class PythonParserABC(ABC): def __init__(self): pass @abstractmethod - def parse(self): pass + def parse(self) -> List[PythonClass]: pass diff --git a/src/py_to_uxf_core/model/python_class.py b/src/py_to_uxf_core/model/python_class.py index 12535d5..76ac337 100644 --- a/src/py_to_uxf_core/model/python_class.py +++ b/src/py_to_uxf_core/model/python_class.py @@ -16,9 +16,13 @@ class PythonClass: return self._name @property - def functions(self) -> List[PythonFunction]: + def functions(self) -> list[PythonFunction]: return self._functions + @property + def attributes(self) -> list[PythonClassAttribute]: + return self._attributes + def add_function(self, func: PythonFunction): self._functions.append(func) 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 3092225..5e7ef59 100644 --- a/src/py_to_uxf_core/service/python_parser_service.py +++ b/src/py_to_uxf_core/service/python_parser_service.py @@ -1,6 +1,7 @@ from typing import Optional from cpl_core.console import Console +from cpl_query.extension import List from py_to_uxf_core.abc.attribute_scanner_abc import AttributeScannerABC from py_to_uxf_core.abc.class_scanner_abc import ClassScannerABC @@ -26,10 +27,10 @@ class PythonParserService(PythonParserABC): self._function_scanner = function_scanner self._attribute_scanner = attribute_scanner - def parse(self): + def parse(self) -> List[PythonClass]: files = self._file_scanner.scan_files() + classes = List(PythonClass) for file in files: - Console.write_line('\nfi:', file) is_comment = False with open(file, 'r') as file_content: cls: Optional[PythonClass] = None @@ -63,16 +64,16 @@ class PythonParserService(PythonParserABC): if cls is None: cls = self._class_scanner.scan_line_for_classes(line) if cls is not None: - Console.write_line('cl:', cls.name) + classes.append(cls) continue func = self._function_scanner.scan_line_for_function(line) 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: cls.add_attribute(attribute) - Console.write_line('at:', attribute.name, attribute.type) + + return classes