Commit 8e725585 authored by sharanjan's avatar sharanjan

ariyasuthan backend

parent 6e3c83d6
![DrawToCode](docs/Draw2CodeLogo.png)
DrawToCode receives an UML diagram from [Draw.io](https://www.draw.io/) and
makes code from it.
## Getting Started
We don't have the intent to cover all Draw.io features and all programming
languages, to know what you can
use, go to the [Wiki](https://github.com/CoffeeOverflow/DrawToCode/wiki/Technical-Stuff).
### Programming Languages Accepted
* Python
* Java
### Prerequisites
* Python 3.6.7+
Install required packages by:
```bash
pip install -r requirements.txt
```
### Usage
```bash
python main.py --help
```
#### Example
```
python main.py --xml_file=./examples/orcs.xml --code_path=./tmp/orc/ --language=python
```
## Running the Tests
```bash
pytest test/
```
#### Show Coverage
```bash
pytest --cov=src/ test/
```
<mxfile host="www.draw.io" modified="2019-12-10T21:36:53.869Z" agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0" etag="ZljxbVePsDXASHQnVbqm" version="12.3.9" type="device" pages="1"><diagram id="a3amV8sVZWnodPZqNoU5" name="Page-1">7Zhdb5swFIZ/DZeLwIYmuWxIt0VLpU6ptOSqcsENVg2OjNOQ/fqZYsKHoaUTHdnWmwq/2MZ+z9NjnxjQDZMvHO2Ca+ZjagDTTww4NwCYOLb8mwrHTHDMSSZsOfEzySqEFfmJlWgqdU98HFc6CsaoILuq6LEowp6oaIhzdqh2e2C0+tUd2mJNWHmI6uoP4osg35ZZ6F8x2Qb5ly1TvQlR3lkJcYB8dihJ8MqALmdMZE9h4mKaepf7ko373PL2tDCOI9FlwHRBrVtncX83XR6/x4/J/fLb3Sc1yxOie7Vhd7lQ6xXH3ATO9pGP03lMA84OARF4tUNe+vYgoy61QIRUtiz5qGbEXOCkdanWyQAJDmYhFvwou6gBECrPFDRgotqHIgRW7mtQsv9CaUhFfXuaujBGPihv3uAT0Hxah/QG8Rjzwd2ynKpblj20W1Bza44EcimKY/m/PLRfdbqG98vW/Lplrsykg1vlgHOzytGs0kzCkX+ZZn7Z8lLkiFf1BSdErFMLR8BRzY1yNH2eJ+XGMW9EcvXZKCdvbvIJ00Yx7LmVj8tWh33tlKmFQO6A7bmHX8/VAvEtFq/lKj2kpZA5DRHLNY4pEuSputymMKov3DAiN9KajGyrRkK2TTWqfFzVJgJmdSJYRyrzQZvomarTtn8ftIseQDsxUyamBFALMzmgVpnOkfMinz1yBjpyBj8464Gz8X/LGezImf3BWQ+cTfrkbDSuHIJmR9AKuDYl7N4dNLsjaC13oQ/Q3gSapWe09fVSg01eSkUVr1hw9ohdRhmXSsQi2XP2QCitSYiSbZQyKkGQ5RecpVdcIkv2S/UiJL6ffqbxgly9Qhs9lBN2ze+pfke2G7gB73VFtqZaABqLiX8mAnad+KEjAPqoUloKju65djxIsu1apWSUnk22nfSUbW34Z7Mt6KNOaTyeO9fDYLCCePxXHuznh5psFr9DZ92LH/Ph1S8=</diagram></mxfile>
\ No newline at end of file
<mxfile host="www.draw.io" modified="2019-12-10T21:40:31.767Z" agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0" etag="NCuLqCVERDolwC8xPb6h" version="12.3.9" pages="1"><diagram id="a3amV8sVZWnodPZqNoU5" name="Page-1">7Vbfb5swEP5reMwEeKTNY5t0WbdWapVI654iB1/BmsHIOAT218/ENr+zTlOn9mEvie8739n3fceBg5ZJuRY4i+85Aeb4LikdtHJ8/zL4qH5roNJA4F5qIBKUaMhrgQ39CQZ0DXqgBPLeRsk5kzTrgyFPUwhlD8NC8GN/2zNn/VMzHMEI2ISYjdFvlMjYluW2+GegUWxP9lzjSbDdbIA8xoQfOxC6cdBScC71KimXwGruLC867tMZb3MxAan8k4DFLfO2we1+t7irHvMf5f7u625m1CkwO5iCHX/OVL5rQgu1jOrlli+VrE6dX/v2wrosoo7tBEzkUP84ydTi5KCpBPGMQ2jg32Y70Scrq4ngh5RAXZar3MeYSthkdTK0OqomVFgsE6Ysr4nu0mSYK0BIKDuQoW0NPAEpKrXFei+MhNXAPrYd4VmZ4043zA2GTRNGTepWJ7UwUk3LFs+uZbXzHu+vFuusmHHXK3YzfyTbln/BBX4Nqka8TLB3liq0GFDlvjVVaIKqh0rGPH13ZPnorcmaGgcDkiAlV/VcVVbIcJ7TsM+Lql1UT13je03oBz+w9qo0DGurslZJ5VNnrcMCY7VBtWFj9O2AjGb46GnP+UGE8PIjJbGIQL40MceSdiQLJhSzmACGJS36152S0ZzwwNWoPD+J0LATdJkmqvsyGCRq3ko2kTdIpHkYJTp1VVP23zfa/N812sU7bzT0v9FepdGU2X486e3tFyi6+QU=</diagram></mxfile>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="www.draw.io" modified="2019-12-17T14:16:11.947Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0" etag="_5Xtbm0DHwJIwc00ywYI" version="12.4.2" type="device" pages="1">
<diagram id="AbfsHDoHPodMjdIZsk2k" name="Page-1">
<mxGraphModel dx="1422" dy="791" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="T5OoOEsfuNDpL02fCPJh-1" value="&lt;p style=&quot;margin: 0px ; margin-top: 4px ; text-align: center&quot;&gt;&lt;b&gt;Context&lt;/b&gt;&lt;br&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;&gt;&lt;p style=&quot;margin: 0px ; margin-left: 4px&quot;&gt;+ strategy: Strategy&lt;br&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;&gt;&lt;p style=&quot;margin: 0px ; margin-left: 4px&quot;&gt;+ doSomeBusinessLogic(): void&lt;br&gt;&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;" vertex="1" parent="1">
<mxGeometry x="20" y="340" width="210" height="100" as="geometry"/>
</mxCell>
<mxCell id="T5OoOEsfuNDpL02fCPJh-3" value="&lt;p style=&quot;margin: 0px ; margin-top: 4px ; text-align: center&quot;&gt;&lt;i&gt;&amp;lt;&amp;lt;Interface&amp;gt;&amp;gt;&lt;/i&gt;&lt;br&gt;&lt;b&gt;Strategy&lt;/b&gt;&lt;br&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;&gt;&lt;p style=&quot;margin: 0px ; margin-left: 4px&quot;&gt;+ doAlgorithm(data: ArrayList&amp;lt;String&amp;gt;): ArrayList&amp;lt;String&amp;gt;&lt;br&gt;&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;" vertex="1" parent="1">
<mxGeometry x="300" y="345" width="320" height="90" as="geometry"/>
</mxCell>
<mxCell id="T5OoOEsfuNDpL02fCPJh-5" value="&lt;p style=&quot;margin: 0px ; margin-top: 4px ; text-align: center&quot;&gt;&lt;b&gt;ConcreteStrategyA&lt;/b&gt;&lt;br&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;&gt;&lt;p style=&quot;margin: 0px ; margin-left: 4px&quot;&gt;+ doAlgorithm(data: ArrayList&amp;lt;String&amp;gt;): ArrayList&amp;lt;String&amp;gt;&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;" vertex="1" parent="1">
<mxGeometry x="130" y="536" width="320" height="64" as="geometry"/>
</mxCell>
<mxCell id="T5OoOEsfuNDpL02fCPJh-6" value="" style="endArrow=block;dashed=1;endFill=0;endSize=12;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="T5OoOEsfuNDpL02fCPJh-5" target="T5OoOEsfuNDpL02fCPJh-3">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="210" y="550" as="sourcePoint"/>
<mxPoint x="370" y="550" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="T5OoOEsfuNDpL02fCPJh-7" value="&lt;p style=&quot;margin: 0px ; margin-top: 4px ; text-align: center&quot;&gt;&lt;b&gt;ConcreteStrategyB&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;&gt;&lt;p style=&quot;margin: 0px ; margin-left: 4px&quot;&gt;+ doAlgorithm(data: ArrayList&amp;lt;String&amp;gt;): ArrayList&amp;lt;String&amp;gt;&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="536" width="320" height="64" as="geometry"/>
</mxCell>
<mxCell id="T5OoOEsfuNDpL02fCPJh-8" value="" style="endArrow=block;dashed=1;endFill=0;endSize=12;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="T5OoOEsfuNDpL02fCPJh-7" target="T5OoOEsfuNDpL02fCPJh-3">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="290" y="546" as="sourcePoint"/>
<mxPoint x="470" y="440" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="T5OoOEsfuNDpL02fCPJh-10" value="" style="endArrow=open;endFill=1;endSize=12;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="T5OoOEsfuNDpL02fCPJh-1" target="T5OoOEsfuNDpL02fCPJh-3">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="30" y="630" as="sourcePoint"/>
<mxPoint x="190" y="630" as="targetPoint"/>
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
import click
from src.dataToCode.write_files import write_files
from src.xmlToData.drawIoXmlParser import DrawIoXmlParser
# @click.command()
# @click.option('--xml_file', required=True, prompt=True, type=click.File(mode='r'),
# help='The XML file path')
# @click.option('--code_path', required=True, prompt=True, type=click.Path(exists=True),
# help='The path of the code to be written')
# @click.option('--language', required=True, prompt=True,
# type=click.Choice(['python', 'java'], case_sensitive=False),
# help='The programming language of the code to be written')
def run(xml_file, code_path, language):
"""Program that writes code of an UML class diagram"""
draw_io_xml_parser = DrawIoXmlParser(xml_file)
list_of_classes, list_of_interfaces = draw_io_xml_parser.read_xml()
objects = list_of_classes + list_of_interfaces
write_files(objects, code_path, language)
# if __name__ == '__main__':
# run()
from types import resolve_bases
from flask import Flask,jsonify,request,render_template
from werkzeug.utils import secure_filename
app=Flask(__name__,template_folder='templates')
from main import run
import os
# import xmltodict
UPLOAD_FOLDER =r"C:\Users\Ariyasuthan\Music\GenCode\upload"
ALLOWED_EXTENSIONS = set(['xml'])
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
def home():
return render_template('home.html')
@app.route('/',methods=['POST'])
def upload():
if request.method=='POST':
file = request.files['xml']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
return jsonify({'result':'success'})
else:
return jsonify({'result': 'invalid method'}), 400
@app.route('/submit/',methods=['GET','POST'])
def convert():
path=r'C:\Users\Ariyasuthan\Music\GenCode\examples'
# os.chdir(path)
for file in os.listdir(path):
if file.endswith(".xml"):
file_path = f"{path}\{file}"
run(file_path,'tmp\orc','python')
# return render_template('home.html')
# @app.route('/view/')
# def view_python_script():
# Folder path
path=r'C:\Users\Ariyasuthan\Music\GenCode\tmp\orc'
os.chdir(path)
content=""
for file in os.listdir():
if file.endswith(".py"):
file_path = f"{path}\{file}"
with open(file_path, "r") as f:
content =content+ f.read()
content=content+"-----------------------------------------------"+"\n"
f = open("python.txt", "a")
f.write(content)
f.close()
print(content)
response={"file":content}
return response
if __name__=="__main__":
app.run(port=3001,debug=True)
from src.dataToCode.dataClasses.visibility import Visibility
class Attribute:
def __init__(self, name: str, type_: str,
visibility: Visibility = Visibility.private):
self.name = name
self.type_ = type_
self.visibility = visibility
def __eq__(self, other: "Attribute"):
cond1 = self.name == other.name
cond2 = self.type_ == other.type_
cond3 = self.visibility == other.visibility
if cond1 and cond2 and cond3:
result = True
else:
result = False
return result
from src.dataToCode.dataClasses.attribute import Attribute
from src.dataToCode.dataClasses.method import Method
from src.dataToCode.dataClasses.interface import Interface
from src.dataToCode.dataClasses.visibility import Visibility
from src.dataToCode.dataClasses.modifier import Modifier
from typing import List
class ClassData:
def __init__(self, name: str,
fields: List[Attribute] = [],
methods: List[Method] = [],
inheritances: List['ClassData'] = [],
implementations: List[Interface] = [],
visibility: Visibility = Visibility.public,
modifier: Modifier = Modifier.none):
self.name = name
self.fields = fields
self.methods = methods
self.inheritances = inheritances
self.implementations = implementations
self.visibility = visibility
self.modifier = modifier
def __eq__(self, other: "ClassData"):
cond1 = self.name == other.name
cond2 = self.fields == other.fields
cond3 = self.methods == other.methods
cond4 = self.inheritances == other.inheritances
cond5 = self.implementations == other.implementations
cond6 = self.visibility == other.visibility
cond7 = self.modifier == other.modifier
if cond1 and cond2 and cond3 and cond4 and cond5 and cond6 and cond7:
return True
else:
return False
from src.dataToCode.dataClasses.visibility import Visibility
from typing import List
from src.dataToCode.dataClasses.method import Method
class Interface:
def __init__(self, name: str,
methods: List[Method],
visibility: Visibility = Visibility.public,
interfaces: List['Interface'] = []):
self.name = name
self.methods = methods
self.interfaces = interfaces
self.visibility = visibility
def __eq__(self, other: "Interface"):
cond1 = self.name == other.name
cond2 = self.methods == other.methods
cond3 = self.interfaces == other.interfaces
cond4 = self.visibility == other.visibility
if cond1 and cond2 and cond3 and cond4:
return True
else:
return False
from src.dataToCode.dataClasses.visibility import Visibility
from src.dataToCode.dataClasses.modifier import Modifier
from src.dataToCode.dataClasses.attribute import Attribute
from typing import List
class Method:
def __init__(self, name: str,
return_type: str = "void",
parameters: List[Attribute] = [],
visibility: Visibility = Visibility.public,
modifier: Modifier = Modifier.none):
self.name = name
self.return_type = return_type
self.parameters = parameters
self.visibility = visibility
self.modifier = modifier
def __eq__(self, other: "Method"):
cond1 = self.name == other.name
cond2 = self.return_type == other.return_type
cond3 = self.visibility == other.visibility
cond4 = self.modifier == other.modifier
cond5 = len(self.parameters) == len(other.parameters)
if not(cond1 and cond2 and cond3 and cond4 and cond5):
return False
for x, y in zip(self.parameters, other.parameters):
if x != y:
return False
return True
from enum import Enum
class Modifier(Enum):
static = "static"
abstract = "abstract"
override = "override"
none = ""
from enum import Enum
class Visibility(Enum):
public = "public"
private = "private"
protected = "protected"
package = "package"
from src.dataToCode.languages.classToCode import ClassToCode
from src.dataToCode.dataClasses.classData import ClassData
from src.dataToCode.dataClasses.modifier import Modifier
from src.dataToCode.languages.ToJava.methodToJava import MethodToJava
from src.dataToCode.languages.ToJava.interfaceToJava import InterfaceToJava
from src.dataToCode.languages.ToJava.inheritanceToJava import InheritanceToJava
class ClassToJava(ClassToCode):
def __init__(self, class_data: ClassData):
self.class_data = class_data
self.method_to_code = MethodToJava(self.class_data.methods, False)
self.inheritance_to_code = InheritanceToJava(self.class_data.inheritances)
def convert(self) -> str:
return (f"import java.util.*;\n\n{self.__formatted_class_header()}\n"
f"{self.__formatted_fields()}"
f"{self.method_to_code.get_formatted_methods()}\n"
f"}}")
def __formatted_class_header(self):
return (f"{self.class_data.visibility.name} {self.class_data.modifier.value}"
f"{'' if self.class_data.modifier is Modifier.none else ' '}"
f"class {self.class_data.name}{self.inheritance_to_code.get_formatted()}"
f"{InterfaceToJava.codeImplementedInterfaces(self.class_data.implementations)}"
f" {{\n")
def __formatted_fields(self):
if len(self.class_data.fields) > 0:
class_fields = [f"\t{fields.visibility.value} {fields.type_} {fields.name};"
for fields in self.class_data.fields]
return '\n'.join(class_fields) + \
("\n\n" if self.class_data.methods else "")
else:
return ""
from src.dataToCode.languages.fileNameToCode import FileNameToCode
from src.dataToCode.dataClasses.classData import ClassData
from src.dataToCode.dataClasses.interface import Interface
from typing import Union
class FileNameToJava(FileNameToCode):
def __init__(self, object_data: Union[ClassData, Interface]):
self.name = object_data.name
def get_file_name(self) -> str:
return f"{self.name}.java"
from src.dataToCode.languages.inheritanceToCode import InheritanceToCode
from src.dataToCode.dataClasses.classData import ClassData
class InheritanceToJava(InheritanceToCode):
def __init__(self, inheritances: [ClassData]):
self.inheritances = inheritances
def get_formatted(self) -> str:
if self.inheritances:
return f" extends {self.__formatted_names()}"
else:
return ''
def __formatted_names(self) -> str:
inheritance_list = [f"{class_data.name}"
for class_data in self.inheritances]
return ', '.join(inheritance_list)
from src.dataToCode.languages.interfaceToCode import InterfaceToCode
from src.dataToCode.dataClasses.interface import Interface
from src.dataToCode.languages.ToJava.methodToJava import MethodToJava
from typing import List
class InterfaceToJava(InterfaceToCode):
def __init__(self, interface: Interface):
self.interface = interface
self.method_to_code = MethodToJava(self.interface.methods, True)
def convert(self) -> str:
return (f"import java.util.*;\n\n"
f"{self.interface.visibility.name} interface {self.interface.name}"
f"{self.codeImplementedInterfaces(self.interface.interfaces)} {{\n\n"
f"{self.method_to_code.get_formatted_methods()}\n"
f"}}")
@staticmethod
def codeImplementedInterfaces(interfaces_list: List[Interface]) -> str:
if len(interfaces_list) > 0:
interfaces_names = [x.name for x in interfaces_list]
interfaces_string = ", ".join(interfaces_names)
result = f" implements {interfaces_string}"
else:
result = ""
return result
from src.dataToCode.dataClasses.classData import ClassData
from src.dataToCode.dataClasses.interface import Interface
from src.dataToCode.languages.languageInterface import LanguageInterface
from src.dataToCode.languages.ToJava.classToJava import ClassToJava
from src.dataToCode.languages.ToJava.interfaceToJava import InterfaceToJava
from src.dataToCode.languages.ToJava.fileNameToJava import FileNameToJava
from typing import Union
class LanguageJava(LanguageInterface):
def get_class_code(self, class_data: ClassData) -> str:
class_java = ClassToJava(class_data)
return class_java.convert()
def get_interface_code(self, interface: Interface) -> str:
interface_java = InterfaceToJava(interface)
return interface_java.convert()
def get_file_name(self, object_data: Union[ClassData, Interface]) -> str:
file_name_to_java = FileNameToJava(object_data)
return file_name_to_java.get_file_name()
from src.dataToCode.languages.methodModifierToCode import MethodModifierToCode
from src.dataToCode.dataClasses.method import Method
from src.dataToCode.dataClasses.modifier import Modifier
class MethodModifierToJava(MethodModifierToCode):
def __init__(self, method: Method):
self.method = method
def formatted_modifier(self) -> str:
return f"{self.__get_modifier_value() + self.__get_modifier_space()}"
def formatted_override(self) -> str:
if self.method.modifier is Modifier.override:
return f"@{self.method.modifier.value}\n\t"
else:
return ""
def __get_modifier_value(self) -> str:
if self.method.modifier is Modifier.override:
return ''
else:
return self.method.modifier.value
def __get_modifier_space(self) -> str:
if self.method.modifier in [Modifier.none, Modifier.override]:
return ''
else:
return " "
from src.dataToCode.languages.methodToCode import MethodToCode
from src.dataToCode.dataClasses.method import Method
from src.dataToCode.dataClasses.attribute import Attribute
from src.dataToCode.languages.ToJava.methodModifierToJava \
import MethodModifierToJava
from typing import List
class MethodToJava(MethodToCode):
def __init__(self, methods: List[Method], is_from_interface: bool):
self.methods = methods
self.is_from_interface = is_from_interface
def get_formatted_methods(self) -> str:
methods_str_list = [f"\t{self.__convert_method(method)}"
for method in self.methods]
return '\n\n'.join(methods_str_list)
def __convert_method(self, method: Method) -> str:
modifier_to_java = MethodModifierToJava(method)
return (f"{modifier_to_java.formatted_override()}"
f"{method.visibility.name} "
f"{modifier_to_java.formatted_modifier()}"
f"{method.return_type} {method.name}"
f"({self.__formatted_parameters(method.parameters)})"
f"{self.__formatted_body()}")
def __formatted_body(self) -> str:
if self.is_from_interface:
return ";"
else:
return " {\n\t\tthrow new UnsupportedOperationException();\n\t}"
def __formatted_parameters(self, parameters: List[Attribute]) -> str:
parameters = [f"{parameter.type_} {parameter.name}"
for parameter in parameters]
return ', '.join(parameters)
from abc import ABC, abstractmethod
class ClassToCode(ABC):
@abstractmethod
def convert(self) -> str:
pass
from abc import ABC, abstractmethod
class FileNameToCode(ABC):
@abstractmethod
def get_file_name(self) -> str:
pass
from abc import ABC, abstractmethod
class InheritanceToCode(ABC):
@abstractmethod
def get_formatted(self) -> str:
pass
from abc import ABC, abstractmethod
class InterfaceToCode(ABC):
@abstractmethod
def convert(self) -> str:
pass
from abc import ABC, abstractmethod
from src.dataToCode.dataClasses.classData import ClassData
from src.dataToCode.dataClasses.interface import Interface
from typing import Union
class LanguageInterface(ABC):
@abstractmethod
def get_class_code(self, class_data: ClassData) -> str:
pass
@abstractmethod
def get_interface_code(self, interface: Interface) -> str:
pass
@abstractmethod
def get_file_name(self, object_data: Union[ClassData, Interface]) -> str:
pass
from abc import ABC, abstractmethod
class MethodModifierToCode(ABC):
@abstractmethod
def formatted_modifier(self) -> str:
pass
@abstractmethod
def formatted_override(self) -> str:
pass
from abc import ABC, abstractmethod
class MethodToCode(ABC):
@abstractmethod
def get_formatted_methods(self) -> str:
pass
from src.dataToCode.dataClasses.classData import ClassData
from src.dataToCode.dataClasses.modifier import Modifier
from src.dataToCode.languages.classToCode import ClassToCode
from src.dataToCode.languages.toPython.initToPython import InitToPython
from src.dataToCode.languages.toPython.methodToPython import MethodToPython
from src.dataToCode.languages.toPython.fileNameToPython import FileNameToPython
class ClassToPython(ClassToCode):
def __init__(self, class_data: ClassData):
self.class_data = class_data
all_methods = self.class_data.methods
for implementation in self.class_data.implementations:
for method in implementation.methods:
if method not in all_methods: