Improved output

This commit is contained in:
Sven Heidemann 2022-01-16 02:35:51 +01:00
parent c0b34c1c5e
commit 9a4de29af8
4 changed files with 32 additions and 8 deletions

View File

@ -4,6 +4,7 @@ from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection import ServiceProviderABC
from py_to_uxf_core.abc.python_parser_abc import PythonParserABC from py_to_uxf_core.abc.python_parser_abc import PythonParserABC
from py_to_uxf_core.model.python_class import PythonClass
class Application(ApplicationABC): class Application(ApplicationABC):
@ -24,4 +25,18 @@ class Application(ApplicationABC):
return return
Console.write_line(f'Found path:', self._path) 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()

View File

@ -1,5 +1,9 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from cpl_query.extension import List
from py_to_uxf_core.model.python_class import PythonClass
class PythonParserABC(ABC): class PythonParserABC(ABC):
@ -7,4 +11,4 @@ class PythonParserABC(ABC):
def __init__(self): pass def __init__(self): pass
@abstractmethod @abstractmethod
def parse(self): pass def parse(self) -> List[PythonClass]: pass

View File

@ -16,9 +16,13 @@ class PythonClass:
return self._name return self._name
@property @property
def functions(self) -> List[PythonFunction]: def functions(self) -> list[PythonFunction]:
return self._functions return self._functions
@property
def attributes(self) -> list[PythonClassAttribute]:
return self._attributes
def add_function(self, func: PythonFunction): def add_function(self, func: PythonFunction):
self._functions.append(func) self._functions.append(func)

View File

@ -1,6 +1,7 @@
from typing import Optional from typing import Optional
from cpl_core.console import Console 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.attribute_scanner_abc import AttributeScannerABC
from py_to_uxf_core.abc.class_scanner_abc import ClassScannerABC from py_to_uxf_core.abc.class_scanner_abc import ClassScannerABC
@ -26,10 +27,10 @@ class PythonParserService(PythonParserABC):
self._function_scanner = function_scanner self._function_scanner = function_scanner
self._attribute_scanner = attribute_scanner self._attribute_scanner = attribute_scanner
def parse(self): def parse(self) -> List[PythonClass]:
files = self._file_scanner.scan_files() files = self._file_scanner.scan_files()
classes = List(PythonClass)
for file in files: for file in files:
Console.write_line('\nfi:', file)
is_comment = False is_comment = False
with open(file, 'r') as file_content: with open(file, 'r') as file_content:
cls: Optional[PythonClass] = None cls: Optional[PythonClass] = None
@ -63,16 +64,16 @@ class PythonParserService(PythonParserABC):
if cls is None: if cls is None:
cls = self._class_scanner.scan_line_for_classes(line) cls = self._class_scanner.scan_line_for_classes(line)
if cls is not None: if cls is not None:
Console.write_line('cl:', cls.name) classes.append(cls)
continue continue
func = self._function_scanner.scan_line_for_function(line) func = self._function_scanner.scan_line_for_function(line)
if func is not None: if func is not None:
cls.add_function(func) cls.add_function(func)
Console.write_line('fu:', func.access_modifier.value, func.name, func.args, func.return_type)
continue continue
attribute = self._attribute_scanner.scan_line_for_attribute(line) attribute = self._attribute_scanner.scan_line_for_attribute(line)
if attribute is not None: if attribute is not None:
cls.add_attribute(attribute) cls.add_attribute(attribute)
Console.write_line('at:', attribute.name, attribute.type)
return classes