internal static string Write(
            ClassStatement classStatement,
            ConstructorStatement constructorDetails,
            ClassGenerationTemplates templates
            )
        {
            GlobalLogger.Info($"Generating Base Constructor: {constructorDetails}");
            var template     = templates.Constructor;
            var extendsClass = classStatement.ExtendedType != null;

            if (extendsClass)
            {
                template = templates.ConstructorToBase;
            }

            return(template.Replace(
                       "[[CLASS_NAME]]",
                       classStatement.Name
                       ).Replace(
                       "[[BASE_CLASS_CALL]]",
                       extendsClass ? " : base()" : string.Empty
                       ));
        }
 public override object Visit(ConstructorStatement that, object value)
 {
     VisitRoutine(that, value);
     return null;
 }
Exemple #3
0
 public override object Visit(ConstructorStatement that, object value)
 {
     _writer.Write("create");
     that.Profile.Visit(this);
     that.Block.Visit(this);
     _writer.WriteLine();
     return null;
 }
Exemple #4
0
        public static string Write(
            ClassStatement classStatement,
            ConstructorStatement constructorDetails,
            ClassGenerationTemplates templates
            )
        {
            var arguments = constructorDetails.Arguments;

            if (arguments.Any())
            {
                GlobalLogger.Info($"Generating Argument Constructor: {constructorDetails}");
                var template     = templates.ConstructorWithArgumentsTemplate;
                var extendsClass = classStatement.ExtendedType != null;

                // Argument String Generation
                var argumentStrings = new List <string>();
                foreach (var argument in arguments.OrderBy(a => a.IsOptional))
                {
                    argumentStrings.Add(
                        ArgumentWriter.Write(
                            argument,
                            true,
                            " = null",
                            ignorePrefix: true
                            )
                        );
                }
                var constructorArguments = string.Join(
                    ", ",
                    argumentStrings
                    );
                var propertyArguments = string.Join(
                    ", ",
                    arguments.Select(
                        argument => DotNetNormalizer.Normalize(
                            argument.Name
                            )
                        )
                    );

                // Generate Namespace
                var entityNamespace = string.Join(
                    ", ",
                    classStatement.Namespace
                    .Split(".")
                    .Select(part => @$ "" "{part}" "")
                    );

                return(template.Replace(
                           "[[CLASS_NAME]]",
                           classStatement.Name
                           ).Replace(
                           "[[ARGUMENTS]]",
                           constructorArguments
                           ).Replace(
                           "[[PROPERTY_NAMESPACE]]",
                           entityNamespace
                           ).Replace(
                           "[[PROPERTY_ARGUMENTS]]",
                           propertyArguments
                           ).Replace(
                           "[[BASE_CLASS_CALL]]",
                           extendsClass ? " : base()" : string.Empty
                           ));
            }
            return(string.Empty);
        }
        public override object Visit(ConstructorStatement that, object value = null)
        {
            PrintPrologue(that);
            PrintRoutine(that);
            PrintEpilogue(that);

            that.Name.Visit(this);
            that.Profile.Visit(this);
            that.Block.Visit(this);

            return null;
        }
Exemple #6
0
        public static ClassStatement Generate(
            string projectAssembly,
            string classIdentifier,
            AbstractSyntaxTree ast,
            IDictionary <string, string> typeOverrideMap
            )
        {
            var(found, className, toGenerateNode) = GetNode(
                classIdentifier,
                ast
                );
            if (!found)
            {
                return(null);
            }

            var namespaceIdentifier = string.Join(".", GetNamespace(toGenerateNode));
            var classMetadata       = new ClassMetadata
            {
                Namespace = namespaceIdentifier,
                Name      = className,
            };


            var typeOverrideDetails = new TypeOverrideDetails
            {
                IsStatic        = false,
                TypeOverrideMap = typeOverrideMap,
            };
            // Get ExtendedClassNames
            var extendedClassType = ExtendedClassTypesIdentifier.Identify(
                toGenerateNode,
                ast,
                classMetadata,
                typeOverrideDetails
                );
            // Get ImplementedInterfaces
            var implementedInterfaces = ImplementedInterfacesIdentifier.Identify(
                toGenerateNode,
                ast,
                classMetadata,
                typeOverrideDetails
                );

            // Public Properties
            var publicProperties = toGenerateNode
                                   .Children.Where(
                child => IsNotPrivate(child) && IsPropertyType(child, classMetadata)
                );

            // Public Methods/Functions
            var publicMethods = toGenerateNode
                                .Children.Where(
                child => IsNotPrivate(child) && IsMethodType(child, classMetadata)
                );

            // Get/Set Accessors
            var accessorMethods = toGenerateNode
                                  .Children.Where(
                child => IsNotPrivate(child) && IsAccessorType(child)
                );

            // Is Observer Method/Function
            var observalbleMethods = publicProperties.Where(
                a => IsObservablePropertyRule.Check(a)
                ).ToList();

            var classStatement = new ClassStatement
            {
                ProjectAssembly = projectAssembly,
                Namespace       = namespaceIdentifier,
                Name            = DotNetClassNormalizer.Normalize(
                    className
                    ),
                IsInterface = IsInterfaceRule.Check(
                    toGenerateNode
                    ),
                GenericTypes = GetGenericTypes(
                    toGenerateNode,
                    classMetadata,
                    ast,
                    new TypeOverrideDetails
                {
                    IsStatic        = false,
                    TypeOverrideMap = typeOverrideMap,
                }
                    ),
                ExtendedType          = extendedClassType,
                ImplementedInterfaces = implementedInterfaces,
                ConstructorStatement  = new ConstructorStatement
                {
                    Arguments = ConstructorArgumentIdentifier.Identify(
                        toGenerateNode,
                        classMetadata,
                        ast,
                        new TypeOverrideDetails
                    {
                        IsStatic        = false,
                        TypeOverrideMap = typeOverrideMap,
                    }
                        ),
                },
                PublicPropertyStatements = publicProperties.ToList().Select(
                    a =>
                {
                    var name                = a.IdentifierStr;
                    var isStatic            = IsStaticRule.Check(a);
                    var typeOverrideDetails = new TypeOverrideDetails
                    {
                        IsStatic        = isStatic,
                        TypeOverrideMap = typeOverrideMap,
                    };
                    var type = GenericTypeIdentifier.Identify(
                        a.Last,
                        classMetadata,
                        ast,
                        typeOverrideDetails
                        );
                    if (TypeOverrideIdentifier.Identify(
                            TypeOverrideDeclarationIdentifier.Identify(
                                classMetadata,
                                typeOverrideDetails.IsStatic,
                                name
                                ),
                            typeOverrideDetails.TypeOverrideMap,
                            type,
                            out var overrideType
                            ))
                    {
                        type = overrideType;
                    }
                    return(new PublicPropertyStatement
                    {
                        Name = name,
                        Type = NormalizeLiteralTypeStatement(
                            type,
                            classMetadata,
                            ast,
                            typeOverrideDetails
                            ),
                        IsStatic = isStatic,
                        IsInterfaceResponse = InterfaceResponseTypeIdentifier.Identify(
                            type,
                            ast
                            ),
                        //IsArrayResponse = IsArrayResposneTypeRule.Check(a),
                        IsReadonly = IsReadonlyRule.Check(a),
                        UsedClassNames = UsedClassNamesIdentifier.Identify(type),
                    });
                }
                    ).ToList(),
                PublicMethodStatements = publicMethods.ToList().Select(
                    a =>
                {
                    var name                = a.IdentifierStr;
                    var isStatic            = IsStaticRule.Check(a);
                    var typeOverrideDetails = new TypeOverrideDetails
                    {
                        IsStatic        = isStatic,
                        TypeOverrideMap = typeOverrideMap,
                    };
                    var type = GenericTypeIdentifier.Identify(
                        a.Last,
                        classMetadata,
                        ast,
                        typeOverrideDetails
                        );
                    if (TypeOverrideIdentifier.Identify(
                            TypeOverrideDeclarationIdentifier.Identify(
                                classMetadata,
                                typeOverrideDetails.IsStatic,
                                name
                                ),
                            typeOverrideDetails.TypeOverrideMap,
                            type,
                            out var overrideType
                            ))
                    {
                        type = overrideType;
                    }
                    return(new PublicMethodStatement
                    {
                        Name = name,
                        Type = NormalizeLiteralTypeStatement(
                            type,
                            classMetadata,
                            ast,
                            typeOverrideDetails
                            ),
                        GenericTypes = DeclarationGenericTypesIdentifier.Identify(
                            a
                            ),
                        Arguments = ArgumentIdentifier.Identify(
                            a,
                            classMetadata,
                            ast,
                            typeOverrideDetails
                            ),
                        IsStatic = isStatic,
                        IsInterfaceResponse = InterfaceResponseTypeIdentifier.Identify(
                            type,
                            ast
                            ),
                        UsedClassNames = UsedClassNamesIdentifier.Identify(type),
                    });
                }
                    ).Distinct().ToList(),
                AccessorStatements = accessorMethods.FlattenAccessorStatements(
                    ast,
                    classMetadata,
                    typeOverrideMap
                    ),
            };

            classStatement.ConstructorStatement.NeedsInvokableReference = InvokableReferenceIdentifier.Identify(
                classStatement
                );

            return(classStatement);
        }
 public override object Visit(ConstructorStatement that, object value = null)
 {
     _symbols.EnterBlock(that.Name.Symbol, that);
     that.Profile.Visit(this);
     that.Block.Visit(this);
     _symbols.LeaveBlock(that.Name.Symbol);
     return null;
 }
Exemple #8
0
 public virtual object Visit(ConstructorStatement that, object value)
 {
     throw new System.NotImplementedException();
 }