2 using System.Collections.Generic;
5 namespace CodeGen.generators
13 private const string ClassFormat =
"{0}class {1} {2}{{{3}{4}{5}}}";
14 private string Indent {
get; } = GeneratorConf.GetIndent(
true, 4);
19 string access =
"", fields =
"", inherits =
"", methods =
"", classes =
"";
21 if (
@class.Parent?.Length > 0)
23 inherits =
"extends " +
@class.Parent +
" ";
26 fields =
@class.Fields?.Aggregate(
'\n' + fields,
27 (current, field) => current + GenerateField(field) +
'\n');
29 methods =
@class.Methods?.Aggregate(methods,
32 classes =
@class.Classes?.Aggregate(classes,
35 if (
@class.Access?.Length > 0)
37 access =
@class.Access +
' ';
40 return string.Format(ClassFormat, access,
@class.Name, inherits, fields, methods, classes);
48 throw new ArgumentNullException();
51 if (
string.IsNullOrWhiteSpace(field.
Access) || field.
Access ==
"default")
57 result += field.Access +
' ';
70 result += field.Type +
" ";
75 result +=
" = " + field.Default;
92 result += method.Access +
' ';
100 result += method.Type +
" ";
102 result += method.Name;
105 for (var i = 0; i < method.Parameters?.Length; i++)
107 var parameter = method.Parameters[i];
108 result += parameter.Type +
" " + parameter.Name;
117 if (!
string.IsNullOrWhiteSpace(method.
Type) && method.
Type !=
"void")
122 defaultVal = JavaNormalizer.BuiltInDefaults[method.Type];
126 defaultVal =
"new " + method.Type +
"()";
129 result +=
'\n' + Indent +
"return " + defaultVal +
";\n";
147 private static Normalizer _singletonInstance = null;
156 public static readonly Dictionary<string, string> BuiltInDefaults =
new Dictionary<string, string>
161 {
"boolean",
"false"},
171 return _singletonInstance ?? (_singletonInstance =
new JavaNormalizer());
179 else if (type ==
"string")
181 else if (type ==
"float")
183 else if (
string.IsNullOrWhiteSpace(type))
override string GetIndent()
Gets indentation of current generator identation
bool Const
Denotes if field is constant or not. Type: boolean
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.
bool Static
Denotes if the mathod is static or not. Type: boolean
bool Static
Denotes if field is static or not. Type: boolean
static Normalizer GetNormalizer()
Method for getting a singleton
Parameter[] Parameters
Represents parameters of the method. Type: array of type Parameter
Holds the configuration of generator
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)
Interface of language normalizer: normalizes package data according to specified language ...
static readonly Dictionary< string, string > BuiltInDefaults
The dictionary of built in values
override string NormalizeType(string type)
Type normalizer: fixes the type to language's built in
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...
override string GenerateMethod(Method method)
Method generator: generates method from given method object Method objectString of generated code of ...
The structure that describes field. Contains access, const and static properties. Inherits from Varia...