data.SourceFile
1from utils.PackageTools import get_matching_module 2from .SourceClass import SourceClass 3from .SourceFunction import SourceFunction 4from .SourceVariable import SourceVariable 5 6 7class SourceFile: 8 """ 9 Data class representing a python file. 10 """ 11 12 def __init__(self) -> None: 13 self.name: str = '' 14 self.imports: list[str] = [] 15 self.variables: list[SourceVariable] = [] 16 self.functions: list[SourceFunction] = [] 17 self.classes: list[SourceClass] = [] 18 19 def get_connection_strings(self) -> str: 20 """ 21 Generates a valid PlantUML string for class associations. 22 23 :return: A string describing associations between classes. 24 """ 25 dependencies: list[str] = [] 26 imports: list[str] = self.imports 27 # noinspection PyTypeChecker 28 for item in self.variables + self.functions + self.classes: 29 source_package = self.name + '.' + item.name + ' o--> ' 30 for dependency in item.get_dependencies(): 31 matching_module: str | None = get_matching_module(self.imports, dependency) 32 if matching_module: 33 dependencies.append(source_package + matching_module) 34 if matching_module in imports: 35 imports.remove(matching_module) 36 for item in self.classes: 37 source_package = self.name + '.' + item.name + ' --|> ' 38 for base in item.bases: 39 matching_module = get_matching_module(self.imports, base) 40 if matching_module: 41 dependencies.append(source_package + matching_module) 42 if matching_module in imports: 43 imports.remove(matching_module) 44 return '\n'.join(dependencies + 45 [self.name + ' ..> ' + source_import for source_import in imports]) 46 47 def __str__(self) -> str: 48 return 'package ' + \ 49 self.name + \ 50 ' {\n' + \ 51 '\n'.join([ 52 'object "' + str(function) + '" as ' + function.name 53 for function in self.functions 54 ]) + \ 55 '\n' + \ 56 '\n'.join([ 57 'class "' + str(variable) + '" as ' + variable.name 58 for variable in self.variables 59 ]) + \ 60 '\n' + \ 61 '\n'.join([str(source_class) for source_class in self.classes]) + \ 62 '\n}'
class
SourceFile:
8class SourceFile: 9 """ 10 Data class representing a python file. 11 """ 12 13 def __init__(self) -> None: 14 self.name: str = '' 15 self.imports: list[str] = [] 16 self.variables: list[SourceVariable] = [] 17 self.functions: list[SourceFunction] = [] 18 self.classes: list[SourceClass] = [] 19 20 def get_connection_strings(self) -> str: 21 """ 22 Generates a valid PlantUML string for class associations. 23 24 :return: A string describing associations between classes. 25 """ 26 dependencies: list[str] = [] 27 imports: list[str] = self.imports 28 # noinspection PyTypeChecker 29 for item in self.variables + self.functions + self.classes: 30 source_package = self.name + '.' + item.name + ' o--> ' 31 for dependency in item.get_dependencies(): 32 matching_module: str | None = get_matching_module(self.imports, dependency) 33 if matching_module: 34 dependencies.append(source_package + matching_module) 35 if matching_module in imports: 36 imports.remove(matching_module) 37 for item in self.classes: 38 source_package = self.name + '.' + item.name + ' --|> ' 39 for base in item.bases: 40 matching_module = get_matching_module(self.imports, base) 41 if matching_module: 42 dependencies.append(source_package + matching_module) 43 if matching_module in imports: 44 imports.remove(matching_module) 45 return '\n'.join(dependencies + 46 [self.name + ' ..> ' + source_import for source_import in imports]) 47 48 def __str__(self) -> str: 49 return 'package ' + \ 50 self.name + \ 51 ' {\n' + \ 52 '\n'.join([ 53 'object "' + str(function) + '" as ' + function.name 54 for function in self.functions 55 ]) + \ 56 '\n' + \ 57 '\n'.join([ 58 'class "' + str(variable) + '" as ' + variable.name 59 for variable in self.variables 60 ]) + \ 61 '\n' + \ 62 '\n'.join([str(source_class) for source_class in self.classes]) + \ 63 '\n}'
Data class representing a python file.
variables: list[data.SourceVariable.SourceVariable]
functions: list[data.SourceFunction.SourceFunction]
classes: list[data.SourceClass.SourceClass]
def
get_connection_strings(self) -> str:
20 def get_connection_strings(self) -> str: 21 """ 22 Generates a valid PlantUML string for class associations. 23 24 :return: A string describing associations between classes. 25 """ 26 dependencies: list[str] = [] 27 imports: list[str] = self.imports 28 # noinspection PyTypeChecker 29 for item in self.variables + self.functions + self.classes: 30 source_package = self.name + '.' + item.name + ' o--> ' 31 for dependency in item.get_dependencies(): 32 matching_module: str | None = get_matching_module(self.imports, dependency) 33 if matching_module: 34 dependencies.append(source_package + matching_module) 35 if matching_module in imports: 36 imports.remove(matching_module) 37 for item in self.classes: 38 source_package = self.name + '.' + item.name + ' --|> ' 39 for base in item.bases: 40 matching_module = get_matching_module(self.imports, base) 41 if matching_module: 42 dependencies.append(source_package + matching_module) 43 if matching_module in imports: 44 imports.remove(matching_module) 45 return '\n'.join(dependencies + 46 [self.name + ' ..> ' + source_import for source_import in imports])
Generates a valid PlantUML string for class associations.
Returns
A string describing associations between classes.