@@ -9,9 +9,9 @@ class Class {
9
9
final String extendedClass;
10
10
final List <String > implementedInterfaces;
11
11
12
+ final List <Constructor > constructors;
12
13
final List <Field > fields;
13
14
final List <Method > methods;
14
- final List <Constructor > constructors;
15
15
final List <Getter > getters;
16
16
final List <Setter > setters;
17
17
@@ -27,9 +27,28 @@ class Class {
27
27
getters = [],
28
28
setters = [];
29
29
30
- @override
31
- String toString () =>
32
- '''- ${isInterface ? 'interface ' : '' }${isAbstract ? 'abstract ' : '' }class $name ${extendedClass .isNotEmpty ? 'extends $extendedClass ' : '' }${implementedInterfaces .isNotEmpty ? 'implements ${implementedInterfaces .join (', ' )} ' : '' }''' ;
30
+ String toDartLikeRepresentaion () => '''
31
+ ${isInterface ? 'interface ' : '' }${isAbstract ? 'abstract ' : '' }class $name ${extendedClass .isNotEmpty ? 'extends $extendedClass ' : '' }${implementedInterfaces .isNotEmpty ? 'implements ${implementedInterfaces .join (', ' )} ' : '' }
32
+ {
33
+ ${constructors .map ((c ) => '${c .toString ()};' ).join ('\n ' )}
34
+ ${fields .map ((f ) => '${f .toString ()};' ).join ('\n ' )}
35
+ ${methods .map ((m ) => '${m .toString ()};' ).join ('\n ' )}
36
+ ${getters .map ((g ) => '${g .toString ()};' ).join ('\n ' )}
37
+ ${setters .map ((s ) => '${s .toString ()};' ).join ('\n ' )}
38
+ }
39
+ ''' ;
40
+
41
+ void addField (Field field) {
42
+ fields.add (field);
43
+ }
44
+
45
+ void addMethod (Method method) {
46
+ methods.add (method);
47
+ }
48
+
49
+ void addGetter (Getter getter) {
50
+ getters.add (getter);
51
+ }
33
52
}
34
53
35
54
class Field {
@@ -38,46 +57,75 @@ class Field {
38
57
final bool isStatic;
39
58
40
59
Field (this .name, this .type, {this .isStatic = false });
60
+
61
+ String toDartLikeRepresentaion () => '${isStatic ? 'static ' : '' }$type $name ' ;
41
62
}
42
63
43
64
class Method {
44
65
final String name;
45
66
final String returnType;
46
67
final bool isStatic;
47
- final List <Param > parameters;
68
+ final String parameters;
69
+ final String typeParameters;
70
+ final String operatorKeyword;
48
71
49
72
Method (
50
73
this .name,
51
74
this .returnType,
52
- this .isStatic, {
53
- this .parameters = const [],
75
+ this .isStatic,
76
+ this .parameters,
77
+ this .typeParameters, {
78
+ this .operatorKeyword = '' ,
54
79
});
55
- }
56
80
57
- class Param {
58
- final String name;
59
- final String type;
81
+ String toDartLikeRepresentaion () {
82
+ final staticPrefix = isStatic ? 'static ' : '' ;
83
+ final operatorPrefix =
84
+ operatorKeyword.isNotEmpty ? '$operatorKeyword ' : '' ;
60
85
61
- Param (this .name, this .type);
86
+ return '$staticPrefix $returnType $operatorPrefix $name '
87
+ '$typeParameters $parameters ' ;
88
+ }
62
89
}
63
90
64
91
class Constructor {
92
+ final String className;
65
93
final String name;
66
- final List <String > parameters;
94
+ final String parameters;
95
+ final String ? factoryKeyword;
67
96
68
- Constructor (this .name, {this .parameters = const []});
97
+ Constructor (this .className, this .name, this .parameters, this .factoryKeyword);
98
+
99
+ String toDartLikeRepresentaion () {
100
+ final constructorName = name.isNotEmpty ? '$className .$name ' : className;
101
+ return '${factoryKeyword != null ? '$factoryKeyword ' : '' }'
102
+ '$constructorName $parameters ' ;
103
+ }
69
104
}
70
105
71
106
class Getter {
72
107
final String name;
73
108
final String returnType;
109
+ final bool isStatic;
74
110
75
- Getter (this .name, this .returnType);
111
+ Getter (this .name, this .returnType, this .isStatic);
112
+
113
+ String toDartLikeRepresentaion () {
114
+ final staticPrefix = isStatic ? 'static ' : '' ;
115
+ return '$staticPrefix $returnType get $name ' ;
116
+ }
76
117
}
77
118
78
119
class Setter {
79
120
final String name;
80
121
final String parameterType;
122
+ final bool isStatic;
123
+ final String parameter;
124
+
125
+ Setter (this .name, this .parameterType, this .isStatic, this .parameter);
81
126
82
- Setter (this .name, this .parameterType);
127
+ String toDartLikeRepresentaion () {
128
+ final staticPrefix = isStatic ? 'static ' : '' ;
129
+ return '$staticPrefix $parameterType set $name ($parameter )' ;
130
+ }
83
131
}
0 commit comments