Added attribute parsing
This commit is contained in:
parent
4b14443fa1
commit
c0b34c1c5e
@ -1,4 +1,5 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute
|
from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute
|
||||||
|
|
||||||
@ -9,4 +10,4 @@ class AttributeScannerABC(ABC):
|
|||||||
def __init__(self): pass
|
def __init__(self): pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def scan_line_for_attribute(self, line: str) -> PythonClassAttribute: pass
|
def scan_line_for_attribute(self, line: str) -> Optional[PythonClassAttribute]: pass
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
|
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.attribute_scanner_abc import AttributeScannerABC
|
||||||
|
from py_to_uxf_core.model.access_modifier_enum import AccessModifierEnum
|
||||||
from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute
|
from py_to_uxf_core.model.python_class_attribute import PythonClassAttribute
|
||||||
|
|
||||||
|
|
||||||
@ -7,5 +12,36 @@ class AttributeScannerService(AttributeScannerABC):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
AttributeScannerABC.__init__(self)
|
AttributeScannerABC.__init__(self)
|
||||||
|
|
||||||
def scan_line_for_attribute(self, line: str) -> PythonClassAttribute:
|
def scan_line_for_attribute(self, line: str) -> Optional[PythonClassAttribute]:
|
||||||
pass
|
# ATR=1
|
||||||
|
# ATR:int=1
|
||||||
|
# self.ATR=1
|
||||||
|
# self._ATR=1
|
||||||
|
# self.__ATR=1
|
||||||
|
# self._ATR:int=1
|
||||||
|
if '=' in line:
|
||||||
|
line.replace(' ', '')
|
||||||
|
name = line.split('=')[0]
|
||||||
|
|
||||||
|
if name.startswith('self.'):
|
||||||
|
name = name.split('self.')[1]
|
||||||
|
|
||||||
|
access_modifier = AccessModifierEnum.public
|
||||||
|
type_str = 'any'
|
||||||
|
|
||||||
|
# access_modifier
|
||||||
|
if name == '__init__' or name == '__repr__' or name == '__str__':
|
||||||
|
access_modifier = AccessModifierEnum.public
|
||||||
|
elif name.startswith('_'):
|
||||||
|
access_modifier = AccessModifierEnum.protected
|
||||||
|
elif name.startswith('__'):
|
||||||
|
access_modifier = AccessModifierEnum.private
|
||||||
|
|
||||||
|
if ':' in line:
|
||||||
|
type_str = line.split(':')[1]
|
||||||
|
if '=' in type_str:
|
||||||
|
type_str = type_str.split('=')[0]
|
||||||
|
|
||||||
|
return PythonClassAttribute(access_modifier, name, type_str)
|
||||||
|
|
||||||
|
return None
|
||||||
|
@ -70,6 +70,7 @@ class PythonParserService(PythonParserABC):
|
|||||||
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)
|
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)
|
attribute = self._attribute_scanner.scan_line_for_attribute(line)
|
||||||
if attribute is not None:
|
if attribute is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user