4 namespace CodeGen.generators
12 private const string ClassFormat =
"{0}Class {1}\n{2}{3}{4}{5}";
13 private string Indent {
get; set; } = GeneratorConf.GetIndent(
true, 4);
18 string fields =
"", inherits =
"", methods =
"", classes =
"";
20 if (
@class.Parent?.Length > 0)
22 inherits = Indent +
"Inherits " +
@class.Parent +
"\n\n";
25 fields =
@class.Fields?.Aggregate(fields,
26 (current, field) => current + GenerateField(field) +
'\n');
28 methods =
@class.Methods?.Aggregate(methods,
31 classes =
@class.Classes?.Aggregate(
'\n' + classes,
35 if (
@class.Access?.Length > 0)
37 access =
@class.Access +
' ';
40 return string.Format(ClassFormat, access,
@class.Name, inherits, fields, methods, classes) +
"\nEnd Class";
46 var result = Indent + field.Access +
' ' + field.Name +
" As " + field.Type;
49 result +=
" = " + field.Default;
57 var result = method.Access +
' ';
58 var type = method.Type?.Length > 0 ?
"Function" :
"Sub";
59 result += type +
' ' + method.Name +
'(';
61 for (var i = 0; i < method.Parameters?.Length; i++)
63 var parameter = method.Parameters[i].Name +
" As " + method.Parameters[i].Type;
66 result +=
"Optional " + parameter +
" = " + method.Parameters[i].Default;
70 result +=
"ByVal " + parameter;
80 if (type ==
"Function")
82 result +=
" As " + method.Type +
'\n' + Indent +
"Return 0";
86 result +=
'\n' + Indent +
"Return";
89 result +=
"\nEnd " + type;
111 return _singletonInstance ?? (_singletonInstance =
new VbNormalizer());
117 base.NormalizeClass(ref
@class);
118 @class.Access = Utils.Title(
@class.Access);
125 base.NormalizeField(ref field);
126 field.Access = string.IsNullOrWhiteSpace(field.Access) ?
"Public" : Utils.Title(field.Access);
133 base.NormalizeMethod(ref method);
134 method.Access = string.IsNullOrWhiteSpace(method.Access) ?
"Public" : Utils.Title(method.Access);
150 type = Utils.Title(type);
static Normalizer GetNormalizer()
Method for getting a singleton
override string GenerateField(Field field)
Field generator: generates field from given field object Field objectString of generated code of fiel...
The structure that describes class. Contains name, array of fields, methods and subclasses, parent class name, access specifier. Overrides ToString() method.
Parameter[] Parameters
Represents parameters of the method. Type: array of type Parameter
Holds the configuration of generator
Normalizer for Visual Basic
override Method NormalizeMethod(ref Method method)
Method normalizer: normalizes method Method objectNormalized method object
override string GenerateMethod(Method method)
Method generator: generates method from given method object Method objectString of generated code of ...
Interface of language normalizer: normalizes package data according to specified language ...
override Class NormalizeClass(ref Class @class)
Class normalizer: normalizes class with fields, methods and subclasses Class objectNormalized class o...
override string GenerateClass(Class @class)
Class generator: generates class with fields, methods and subclasses from given class object Class ob...
override string NormalizeType(string type)
Type normalizer: fixes the type to language's built in
Generator for Visual Basic
override Field NormalizeField(ref Field field)
Field normalizer: normalizes field Field objectNormalized field object
static string ShiftCode(string code, int num, string indent)
Shifts code using given parameters
string Default
Represents default value of the varibale. Type: string
Interface of language generator
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...