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 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()

View File

@ -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

View File

@ -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)

View File

@ -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