3 namespace CodeGen.generators
11 private const string ClassFormat =
"{0}class {1}{2}{{{3}{4}{5}}}";
12 private string Indent {
get; set; } = GeneratorConf.GetIndent(
true, 4);
17 string fields =
"", inherits =
" ", methods =
"", classes =
"";
18 if (
@class.Parent?.Length > 0)
20 inherits =
" extends " +
@class.Parent +
' ';
23 fields =
@class.Fields?.Aggregate(
'\n' + fields,
24 (current, field) => current + GenerateField(field) +
'\n');
26 methods =
@class.Methods?.Aggregate(methods,
29 classes =
@class.Classes?.Aggregate(classes,
33 if (
@class.Access?.Length > 0)
35 access =
@class.Access +
" ";
38 return string.Format(ClassFormat, access,
@class.Name, inherits, fields, methods, classes);;
51 result += field.Access +
' ';
65 result += field.Type +
' ';
72 result +=
" = " + field.Default;
87 result += method.Access +
' ';
99 result += method.Type +
' ';
103 result += method.Name +
'(';
105 for (var i = 0; i < method.Parameters?.Length; i++)
107 var parameter = method.Parameters[i];
108 if (parameter.Type ==
"string")
110 parameter.Type =
"String";
113 result += parameter.Type +
' ' + parameter.Name;
122 if (method.
Type?.Length > 0)
124 result +=
'\n' + Indent +
"return 0\n";
string Type
Represents return type of the method. Type: string
The structure that describes class. Contains name, array of fields, methods and subclasses, parent class name, access specifier. Overrides ToString() method.
string Type
Represents the type of the variable. Type: string
bool Static
Denotes if field is static or not. Type: boolean
Parameter[] Parameters
Represents parameters of the method. Type: array of type Parameter
Holds the configuration of generator
override string GenerateMethod(Method method)
Method generator: generates method from given method object Method objectString of generated code of ...
override string GenerateClass(Class @class)
Class generator: generates class with fields, methods and subclasses from given class object Class ob...
override string GenerateField(Field field)
Field generator: generates field from given field object Field objectString of generated code of fiel...
static string ShiftCode(string code, int num, string indent)
Shifts code using given parameters
string Access
Represents access level of the field. Type: string
string Default
Represents default value of the varibale. Type: string
Interface of language generator
string Access
Represents access level of the method. Type: string
The structure that describes method. Contains name, return type, access level, const and static prope...
The structure that describes field. Contains access, const and static properties. Inherits from Varia...