Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-136
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-136
2021-136
Commits
b884fefc
Commit
b884fefc
authored
Nov 26, 2021
by
Ariyasuthan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
59543624
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
classDToCode/datatToCode/Languages/classToPython.py
classDToCode/datatToCode/Languages/classToPython.py
+47
-0
No files found.
classDToCode/datatToCode/Languages/classToPython.py
0 → 100644
View file @
b884fefc
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
:
all_methods
.
append
(
method
)
all_methods
=
list
(
all_methods
)
self
.
method_to_code
=
MethodToPython
(
all_methods
,
False
)
self
.
init_to_python
=
InitToPython
(
self
.
class_data
.
fields
)
def
convert
(
self
)
->
str
:
return
(
f
"{self.__formatted_imports()}"
f
"class {self.class_data.name}"
f
"({self.__formatted_inheritances()}):
\n
"
f
"
\n
{self.init_to_python.get_formatted()}
\n
"
f
"{self.method_to_code.get_formatted_methods()}
\n
"
)
def
__formatted_imports
(
self
)
->
str
:
inheritances
=
self
.
class_data
.
inheritances
+
self
.
class_data
.
implementations
imports
=
[
f
"from {FileNameToPython(inheritance).get_file_name()[:-3]} import {inheritance.name}"
for
inheritance
in
inheritances
]
optional_import
=
self
.
__optional_abc_import
()
space
=
'
\n\n\n
'
if
inheritances
else
'
\n\n
'
if
optional_import
else
""
return
optional_import
+
'
\n
'
.
join
(
imports
)
+
space
def
__optional_abc_import
(
self
)
->
str
:
for
method
in
self
.
class_data
.
methods
:
if
method
.
modifier
is
Modifier
.
abstract
:
return
"from abc import ABC, abstractmethod
\n
"
return
""
def
__formatted_inheritances
(
self
)
->
str
:
inheritances
=
self
.
class_data
.
inheritances
+
self
.
class_data
.
implementations
inheritances_name
=
[
f
"{inheritance.name}"
for
inheritance
in
inheritances
]
return
', '
.
join
(
inheritances_name
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment