public static bool Identify(
            TypeStatement typeStatement
            )
        {
            var type = typeStatement;

            if (typeStatement.IsModifier ||
                typeStatement.IsNullable ||
                typeStatement.IsTask)
            {
                if (typeStatement.GenericTypes.Any())
                {
                    return(Identify(
                               typeStatement.GenericTypes.First()
                               ));
                }
            }
            else if (typeStatement.IsTypeAlias)
            {
                return(Identify(
                           typeStatement.AliasType
                           ));
            }
            return(type.IsArray);
        }
        public static bool Identify(
            TypeStatement typeStatement
            )
        {
            // Check for supported Response Type
            if (!typeStatement.IsArray &&
                !typeStatement.IsNullable &&
                !typeStatement.IsAction &&
                !typeStatement.IsTask &&
                typeStatement.GenericTypes.Any() &&
                PrimitiveTypeIdentifier.Identify(
                    typeStatement.GenericTypes.First().Name
                    )
                )
            {
                return(true);
            }
            // Check for Array in Array
            if (HasAnArrayInArray(typeStatement))
            {
                return(true);
            }

            return(false);
        }
        public static IList <string> Identify(
            TypeStatement type,
            IList <string> list = null
            )
        {
            if (list == null)
            {
                list = new List <string>();
            }
            if (!type.IsAction &&
                !type.IsArray &&
                !type.IsLiteral &&
                !type.IsModifier &&
                !type.IsNullable &&
                !type.IsTypeAlias
                )
            {
                // Using The Type get
                switch (type.Name)
                {
                case GenerationIdentifiedTypes.Array:
                case GenerationIdentifiedTypes.Unknown:
                case GenerationIdentifiedTypes.Action:
                case GenerationIdentifiedTypes.Void:
                case GenerationIdentifiedTypes.Task:
                case GenerationIdentifiedTypes.Setter:
                case GenerationIdentifiedTypes.Getter:
                case GenerationIdentifiedTypes.String:
                case GenerationIdentifiedTypes.Bool:
                case GenerationIdentifiedTypes.Number:
                case GenerationIdentifiedTypes.Literal:
                case GenerationIdentifiedTypes.Int:
                case GenerationIdentifiedTypes.Float:
                case GenerationIdentifiedTypes.CachedEntity:
                case GenerationIdentifiedTypes.Object:
                    break;

                default:
                    list.Add(type.Name);
                    break;
                }
            }
            foreach (var genericType in type.GenericTypes)
            {
                Identify(
                    genericType,
                    list
                    );
            }
            if (type.IsTypeAlias)
            {
                Identify(
                    type.AliasType,
                    list
                    );
            }

            return(list);
        }
Example #4
0
 public override StatementBase AddStatement(StatementBase StatementToAdd)
 {
     if (TypeStatement.CountTypes(Elements()) >= 1 && typeof(TypeStatement).IsAssignableFrom(StatementToAdd.GetType()))
     {
         throw new ArgumentOutOfRangeException(StatementToAdd.GetType().ToString(), "Cannot add more " + StatementToAdd.GetType().ToString() + " into " + GetType().ToString() + ", maximum amount reached: 1");
     }
     return(base.AddStatement(StatementToAdd));
 }
Example #5
0
        private static string GenericTypeWriter(
            TypeStatement typeStatement,
            IList <string> usedClassNames,
            bool includeName
            )
        {
            var argumentsTemplate = "System.Nullable<[[TYPE]]>[[NAME]][[DEFAULT_VALUE]]";

            if (typeStatement.IsTypeAlias)
            {
                return(GenericTypeWriter(
                           typeStatement.AliasType,
                           usedClassNames,
                           includeName
                           ));
            }
            else if (typeStatement.IsNullable)
            {
                var genericType = typeStatement.GenericTypes.First();

                if (!genericType.IsEnum &&
                    (ClassIdentifier.Identify(
                         usedClassNames,
                         genericType.Name
                         ) || genericType.IsNullable ||
                     genericType.IsArray ||
                     genericType.IsModifier ||
                     genericType.IsAction ||
                     genericType.IsTypeAlias ||
                     genericType.Name == GenerationIdentifiedTypes.String ||
                     genericType.Name == GenerationIdentifiedTypes.CachedEntity
                    )
                    )
                {
                    argumentsTemplate = "[[TYPE]][[NAME]][[DEFAULT_VALUE]]";
                }
            }
            else if (!typeStatement.IsEnum &&
                     (ClassIdentifier.Identify(
                          usedClassNames,
                          typeStatement.Name
                          ) || typeStatement.IsNullable ||
                      typeStatement.IsArray ||
                      typeStatement.IsModifier ||
                      typeStatement.IsAction ||
                      typeStatement.Name == GenerationIdentifiedTypes.String ||
                      typeStatement.Name == GenerationIdentifiedTypes.CachedEntity
                     )
                     )
            {
                argumentsTemplate = "[[TYPE]][[NAME]][[DEFAULT_VALUE]]";
            }

            return(argumentsTemplate.Replace(
                       "[[NAME]]",
                       includeName ? " [[NAME]]" : string.Empty
                       ));
        }
 public static bool Identify(
     TypeStatement type,
     TypeScriptAST ast
     )
 {
     return(ACTIVE.Identify(
                type,
                ast
                ));
 }
        /// <summary>
        /// Data statement entry.
        ///
        /// type_reference IDENTIFIER ';'
        /// </summary>
        /// <param name="context"></param>
        public override void EnterData_statement(KryptonParser.Data_statementContext context)
        {
            var parent    = _statementContainers.Peek();
            var name      = context.IDENTIFIER().GetText();
            var statement = new TypeStatement(name, parent);

            // Add ourselves to our parent and push us onto the ref container stack
            parent.AddStatement(statement);
            _typeReferenceContainers.Push(statement);
        }
 public override bool Identify(
     TypeStatement type,
     AbstractSyntaxTree ast
     )
 {
     return(base.Identify(
                type,
                ast
                ));
 }
 public static bool Identify(
     TypeStatement type,
     AbstractSyntaxTree ast
     )
 {
     return(ACTIVE.Identify(
                type,
                ast
                ));
 }
 public override bool Identify(
     TypeStatement type,
     TypeScriptAST ast
     )
 {
     return(base.Identify(
                type,
                ast
                ));
 }
Example #11
0
        public static bool Identify(
            TypeStatement typeStatement
            )
        {
            var type = typeStatement;

            if (typeStatement.GenericTypes.Any())
            {
                return(Identify(
                           typeStatement.GenericTypes.First()
                           ));
            }
            return(type.IsEnum);
        }
Example #12
0
        internal static bool Identify(
            Node parameter,
            ClassMetadata classMetadata,
            AbstractSyntaxTree ast,
            TypeOverrideDetails typeOverrideDetails,
            out TypeStatement type
            )
        {
            type = new TypeStatement
            {
                Name = GenerationIdentifiedTypes.Unknown,
            };
            if (IsUnionTypeRule.Check(parameter))
            {
                var unionNode = parameter.OfKind(
                    SyntaxKind.UnionType
                    ).FirstOrDefault()
                                .Children.Where(
                    // Make sure does not contain undefined
                    a => a.Kind != SyntaxKind.UndefinedKeyword &&
                    a.Kind != SyntaxKind.NullKeyword &&
                    a.Kind != SyntaxKind.TypeLiteral &&
                    a.Kind != SyntaxKind.LiteralType
                    ).ToList().FirstOrDefault();

                if (unionNode != null)
                {
                    type = GenericTypeIdentifier.Identify(
                        unionNode,
                        classMetadata,
                        ast,
                        typeOverrideDetails
                        );
                }

                return(true);
            }
            else if (parameter.Kind == SyntaxKind.UnionType)
            {
                type = GenericTypeIdentifier.Identify(
                    parameter.First,
                    classMetadata,
                    ast,
                    typeOverrideDetails
                    );
                return(true);
            }
            return(false);
        }
Example #13
0
        private static TypeStatement NormalizeLiteralTypeStatement(
            TypeStatement type,
            ClassMetadata classMetadata,
            AbstractSyntaxTree ast,
            TypeOverrideDetails typeOverrideDetails
            )
        {
            if (type.IsTypeQuery)
            {
                var(found, className, toGenerateNode) = GetNode(
                    type.TypeQuery.Class,
                    ast
                    );

                if (!found)
                {
                    return(type);
                }

                var typeNode = toGenerateNode.Children.FirstOrDefault(
                    a => a.IdentifierStr == type.TypeQuery.Type
                    );
                if (typeNode is not null)
                {
                    var typedType = GenericTypeIdentifier.Identify(
                        typeNode.Last,
                        classMetadata,
                        ast,
                        typeOverrideDetails
                        );
                    return(typedType);
                }
            }

            if (type.IsLiteral)
            {
                type.Name = GenerationIdentifiedTypes.CachedEntity;
            }
            var literalGenericTypes = type.GenericTypes.Where(
                a => a.IsLiteral
                );

            foreach (var genericType in literalGenericTypes)
            {
                genericType.Name = GenerationIdentifiedTypes.CachedEntity;
            }
            return(type);
        }
 public static bool Identify(
     string typeDeclaration,
     IDictionary <string, string> typeOverrideMap,
     TypeStatement currentType,
     out TypeStatement type
     )
 {
     type = currentType;
     if (typeOverrideMap.TryGetValue(
             typeDeclaration,
             out var overrideType
             ))
     {
         type.Name = overrideType;
         return(true);
     }
     return(false);
 }
        public void ShouldReturnIsArrayOnPassedInTypeWhenIsModiferTrueWithEmptyGenericTypes()
        {
            // Given
            var typeStatement = new TypeStatement
            {
                IsModifier   = true,
                IsArray      = true,
                GenericTypes = new List <TypeStatement>(),
            };

            // When
            var actual = ArrayResponseIdentifier.Identify(
                typeStatement
                );

            // Then
            actual.Should().BeTrue();
        }
 private static bool HasAnArrayInArray(
     TypeStatement typeStatement
     )
 {
     if (typeStatement.IsArray)
     {
         if (typeStatement.GenericTypes.Any(a => a.IsArray))
         {
             return(true);
         }
     }
     foreach (var genericType in typeStatement.GenericTypes)
     {
         return(HasAnArrayInArray(
                    genericType
                    ));
     }
     return(false);
 }
Example #17
0
        public static bool Identify(
            TypeStatement property
            )
        {
            var type = property;

            if (type.IsModifier ||
                type.IsNullable ||
                type.IsTask ||
                type.IsArray)
            {
                if (type.GenericTypes.Any())
                {
                    return(Identify(
                               type.GenericTypes.First()
                               ));
                }
            }
            return(type.IsLiteral);
        }
        public static bool Identify(
            TypeStatement typeStatement,
            IList <string> classNameList
            )
        {
            var name = typeStatement.Name;

            if (typeStatement.IsArray ||
                typeStatement.IsModifier ||
                typeStatement.IsNullable)
            {
                return(Identify(
                           typeStatement.GenericTypes.First(),
                           classNameList
                           ));
            }
            return(ClassIdentifier.Identify(
                       classNameList,
                       name
                       ));
        }
        public void ShouldReturnExpectedIdentificationWhenTypeStatementIsUsedAndNotCachedWithNodeJS(
            string typeName,
            string genericName,
            bool isModifier,
            bool isArray,
            bool isNullable,
            bool expected
            )
        {
            // Given
            var type = new TypeStatement
            {
                Name         = typeName,
                IsModifier   = isModifier,
                IsArray      = isArray,
                IsNullable   = isNullable,
                GenericTypes = new List <TypeStatement>
                {
                    new TypeStatement
                    {
                        Name = genericName
                    }
                }
            };

            var sourceFile = "interface.ts";
            var source     = File.ReadAllText($"./SourceFiles/{sourceFile}");
            var ast        = new NodeJS_ASTWrapper(source);

            // When
            var cachedInterfaceIdentifier = new InterfaceResponseTypeIdentifierNotCached();
            var actual = cachedInterfaceIdentifier.Identify(
                type,
                ast
                );

            // Then
            actual.Should()
            .Be(expected);
        }
        public virtual bool Identify(
            TypeStatement type,
            AbstractSyntaxTree ast
            )
        {
            var identifierString = type.Name;

            if (type.IsModifier ||
                type.IsArray ||
                type.IsNullable
                )
            {
                if (type.GenericTypes.Any())
                {
                    identifierString = type.GenericTypes.First().Name;
                }
            }
            return(Identify(
                       identifierString,
                       ast
                       ));
        }
        public override object Visit(TypeStatement that, object value = null)
        {
            PrintPrologue(that);
            PrintDefinition(that);
            PrintNodeId("Type", that.Type);
            PrintEpilogue(that);

            that.Name.Visit(this);
            that.Type.Visit(this, value);

            return null;
        }
        public static string Write(
            TypeStatement type,
            bool includeArraySymbol = true,
            bool ignorePrefix       = false
            )
        {
            if (type.IsTypeAlias &&
                !type.IsNullable &&
                !type.IsModifier &&
                !type.IsArray
                )
            {
                type = type.AliasType;
            }
            var name = type.Name;
            var genericTypesAsString     = string.Empty;
            var actionResultTypeAsStirng = string.Empty;
            var template         = TypeStatementTemplates.StandardTemplate;
            var interfacePostfix = ignorePrefix ? string.Empty : Constants.INTERFACE_POSTFIX;

            if (type.IsInterface)
            {
                template = TypeStatementTemplates.StandardPostfixTemplate;
            }
            if (type.IsArray)
            {
                template = TypeStatementTemplates.StandardArrayTemplate;
            }

            if (type.GenericTypes.Any())
            {
                template = TypeStatementTemplates.GenericTemplate;
                if (type.IsInterface)
                {
                    template = TypeStatementTemplates.GenericPostfixTemplate;
                }
                if (type.IsArray)
                {
                    template = TypeStatementTemplates.ArrayTemplate;
                }
                var genericTypes = type.GenericTypes.Select(
                    a => Write(
                        a,
                        includeArraySymbol,
                        ignorePrefix
                        )
                    );

                genericTypesAsString = string.Join(
                    ", ",
                    genericTypes
                    );
            }
            if (type.IsNullable ||
                type.IsModifier ||
                (type.IsArray && type.GenericTypes.Any() && !includeArraySymbol)
                )
            {
                template = TypeStatementTemplates.RootArrayTemplate;
            }
            if (type.IsAction)
            {
                if (type.ActionResultType.IsTask ||
                    type.ActionResultType.Name == GenerationIdentifiedTypes.Void)
                {
                    template = TypeStatementTemplates.ActionTemplate;

                    if (!type.GenericTypes.Any())
                    {
                        template = TypeStatementTemplates.ActionVoidTemplate;
                    }
                }
                else
                {
                    template = TypeStatementTemplates.ActionResultTemplate;

                    if (type.GenericTypes.Any())
                    {
                        template = TypeStatementTemplates.ActionResultArgsTemplate;
                    }

                    actionResultTypeAsStirng = Write(
                        type.ActionResultType,
                        includeArraySymbol,
                        ignorePrefix
                        );
                }
            }
            if (type.IsTask)
            {
                template = TypeStatementTemplates.TaskTemplate;
                if (!includeArraySymbol)
                {
                    template = TypeStatementTemplates.RootTaskTemplate;
                }

                if (!type.GenericTypes.Any() ||
                    type.GenericTypes.Any(type => type.Name == GenerationIdentifiedTypes.Void))
                {
                    template = TypeStatementTemplates.TaskVoidTemplate;
                    if (!includeArraySymbol)
                    {
                        template = TypeStatementTemplates.RootTaskTemplate;
                    }
                }
            }
            if (type.IsEnum)
            {
                template = template.Replace(
                    "[[NAME]]",
                    "int"
                    );
            }

            return(template.Replace(
                       "[[NAME]]",
                       name
                       ).Replace(
                       "[[GENERIC_TYPES]]",
                       genericTypesAsString
                       ).Replace(
                       "[[ACTION_RESULT]]",
                       actionResultTypeAsStirng
                       ).Replace(
                       "[[INTERFACE_POSTFIX]]",
                       interfacePostfix
                       ));
        }
 public override object Visit(TypeStatement that, object value = null)
 {
     that.Type.Visit(this, value);
     return null;
 }
Example #24
0
        public override String CreateScript()
        {
            StringBuilder        builder         = new StringBuilder(String.Empty);
            IEnumerable <String> includedColumns = null;

            Boolean isXml = TypeStatement.ToLower().Equals("xml");

            if (isXml)
            {
                builder.AppendLine($"CREATE {( UsingXMLIndexId == 0 ? "PRIMARY" : "" )} XML INDEX {Name}");
                builder.Append($"ON {ParentObject.QualifiedName}");
            }
            else if (IsPrimaryKey)
            {
                builder.AppendFormat($"ALTER TABLE {ParentObject.QualifiedName} ADD CONSTRAINT [{Name}] PRIMARY KEY {TypeStatement}");
            }
            else if (IsUniqueConstraint)
            {
                builder.Append($"ALTER TABLE {ParentObject.QualifiedName} ADD CONSTRAINT [{Name}] UNIQUE {TypeStatement}");
            }
            else
            {
                if (IsUnique)
                {
                    builder.Append($"CREATE UNIQUE {TypeStatement} INDEX [{Name}] ON {ParentObject.QualifiedName}");
                }
                else
                {
                    builder.Append($"CREATE {TypeStatement} INDEX [{Name}] ON {ParentObject.QualifiedName}");
                }
                includedColumns = Columns.Where(c => c.IsIncluded).Select(c => $"[{c.Name}]");
            }



            builder.Append("\r\n(");
            if (isXml)
            {
                builder.Append(String.Join(",", Columns.Where(c => !c.IsIncluded).Select(c => $"[{c.Name}]")));
            }
            else
            {
                builder.Append(String.Join(",", Columns.Where(c => !c.IsIncluded).Select(c => c.ScriptStatement)));
            }
            builder.AppendLine(" )");

            if (includedColumns != null && includedColumns.Count() > 0)
            {
                builder.Append("INCLUDE (");
                builder.Append(String.Join(",", includedColumns));
                builder.AppendLine(" )");
            }
            if (isXml && UsingXMLIndexId != 0)
            {
                builder.AppendLine($"USING XML INDEX {UsingXMLIndex.Name} FOR {XMLSecondaryType} ");
            }

            builder.AppendLine("WITH ( ");
            builder.AppendFormat($"PAD_INDEX = {SqlStatement.GetOnOffStatement(IsPadded)}, ");
            if (!isXml)
            {
                builder.AppendFormat($"STATISTICS_NORECOMPUTE = {SqlStatement.GetOnOffStatement(IsAutoStatistics)}, ");
            }
            builder.AppendFormat($"IGNORE_DUP_KEY = {SqlStatement.GetOnOffStatement(IgnoreDupKey)}, ");
            builder.AppendFormat($"ALLOW_ROW_LOCKS = {SqlStatement.GetOnOffStatement(AllowRowLocks)}, ");
            builder.AppendFormat($"ALLOW_PAGE_LOCKS = {SqlStatement.GetOnOffStatement(AllowPageLocks)} ");
            if (FillFactor != 0)
            {
                builder.AppendFormat($", FILLFACTOR =  {FillFactor.ToString()}");
            }
            builder.Append(" ) ");
            //if (!String.IsNullOrEmpty(FileGroup) && !isXml) builder.Append(" ON [" + FileGroup + "]");

            builder.Append(SqlStatement.GO);
            return(builder.ToString());
        }
Example #25
0
        public static string Write(
            TypeStatement type,
            bool includeArraySymbol = true,
            bool ignorePrefix       = false
            )
        {
            var name = type.Name;
            var genericTypesAsString = string.Empty;
            // Observer -> PickerInfo -> PickerData
            // Observer<PickerInfo<PickerData>>   [[INTERFACE_POSTFIX]]
            var standardTemplate        = "[[NAME]]";
            var actionVoidTemplate      = "ActionCallback";
            var actionTemplate          = "ActionCallback<[[GENERIC_TYPES]]>";
            var standardArrayTemplate   = "[[NAME]][]";
            var standardPostfixTemplate = "[[NAME]][[INTERFACE_POSTFIX]]";
            var genericTemplate         = "[[NAME]]<[[GENERIC_TYPES]]>";
            var genericPostfixTemplate  = "[[NAME]][[INTERFACE_POSTFIX]]<[[GENERIC_TYPES]]>";
            var arrayTemplate           = "[[GENERIC_TYPES]][]";
            var rootArrayTemplate       = "[[GENERIC_TYPES]]";
            var template = standardTemplate;

            if (type.IsInterface)
            {
                template = standardPostfixTemplate;
            }
            if (type.IsArray)
            {
                template = standardArrayTemplate;
            }

            if (type.GenericTypes.Any())
            {
                template = genericTemplate;
                if (type.IsInterface)
                {
                    template = genericPostfixTemplate;
                }
                if (type.IsArray)
                {
                    template = arrayTemplate;
                }
                var genericTypes = type.GenericTypes.Select(
                    a => Write(
                        a,
                        includeArraySymbol,
                        ignorePrefix
                        )
                    );

                genericTypesAsString = string.Join(
                    ", ",
                    genericTypes
                    );
            }
            if (type.IsNullable ||
                type.IsModifier ||
                (type.IsArray && type.GenericTypes.Any() && !includeArraySymbol)
                )
            {
                template = rootArrayTemplate;
            }
            if (type.IsAction)
            {
                template = actionTemplate;

                if (!type.GenericTypes.Any())
                {
                    template = actionVoidTemplate;
                }
            }
            if (type.IsEnum)
            {
                template = template.Replace(
                    "[[NAME]]",
                    "int"
                    );
            }

            return(template.Replace(
                       "[[NAME]]",
                       name
                       ).Replace(
                       "[[GENERIC_TYPES]]",
                       genericTypesAsString
                       ).Replace(
                       "[[INTERFACE_POSTFIX]]",
                       ignorePrefix ? string.Empty : Constants.INTERFACE_POSTFIX
                       ));
        }
Example #26
0
 public override object Visit(TypeStatement that, object value)
 {
     _writer.Write("type ");
     that.Name.Visit(this);
     _writer.Write(" is ");
     that.Type.Visit(this);
     _writer.WriteLine();
     return null;
 }
Example #27
0
 public FieldStatement(TypeStatement type, LiteralToken name, Expression expression)
 {
     Type = type;
     Name = name;
     Expression = expression;
 }
Example #28
0
 public virtual object Visit(TypeStatement that, object value)
 {
     throw new System.NotImplementedException();
 }