public static TypeStatement Identify(
            Node node,
            ClassMetadata classMetadata,
            TypeScriptAST ast,
            TypeOverrideDetails typeOverrideDetails
            )
        {
            var typeIdentifier = TypeIdentifier.Identify(
                node,
                classMetadata
                );
            var isTypeAlias = AliasTypeIdentifier.Identify(
                node,
                ast
                );
            var aliasType = isTypeAlias ? AliasTypeStatementIdentifier.Identify(
                typeIdentifier,
                classMetadata,
                ast,
                typeOverrideDetails
                ) : null;
            var isLiteral = IsTypeLiteralRule.Check(
                node
                ) || TypeLiteralIdentifier.Identify(
                typeIdentifier
                );
            var genericTypes = new List <TypeStatement>();

            if (node is TypeReferenceNode referenceNode &&
                referenceNode.TypeArguments != null &&
                referenceNode.TypeArguments.Any())
            {
                foreach (var typeArgument in referenceNode.TypeArguments)
                {
                    if (typeArgument is Node typeArgumentNode)
                    {
                        genericTypes.Add(
                            Identify(
                                typeArgumentNode,
                                classMetadata,
                                ast,
                                typeOverrideDetails
                                )
                            );
                    }
                }
            }
Example #2
0
        public static TypeStatement Identify(
            Node node,
            ClassMetadata classMetadata,
            AbstractSyntaxTree ast,
            TypeOverrideDetails typeOverrideDetails
            )
        {
            var typeIdentifier = TypeIdentifier.Identify(
                node,
                classMetadata
                );
            var isAction = ActionTypeIdentifier.Identify(
                typeIdentifier
                );
            var isTypeQuery = IsTypeQueryRule.Check(
                node
                );
            var isTypeAlias = AliasTypeIdentifier.Identify(
                node,
                ast
                );
            var aliasType = isTypeAlias ? AliasTypeStatementIdentifier.Identify(
                typeIdentifier,
                classMetadata,
                ast,
                typeOverrideDetails
                ) : null;
            var isLiteral = IsTypeLiteralRule.Check(
                node
                ) || TypeLiteralIdentifier.Identify(
                typeIdentifier
                );
            var actionResultType = default(TypeStatement);
            var genericTypes     = new List <TypeStatement>();

            if (node.TypeArguments != null &&
                node.TypeArguments.Any())
            {
                foreach (var typeArgument in node.TypeArguments)
                {
                    genericTypes.Add(
                        Identify(
                            typeArgument,
                            classMetadata,
                            ast,
                            typeOverrideDetails
                            )
                        );
                }
            }
            else if (node.Parameters != null &&
                     node.Parameters.Any())
            {
                foreach (var functionParamerter in node.Parameters)
                {
                    genericTypes.Add(
                        Identify(
                            functionParamerter,
                            classMetadata,
                            ast,
                            typeOverrideDetails
                            )
                        );
                }
            }
            else if (typeIdentifier == GenerationIdentifiedTypes.Array &&
                     node.Type != null &&
                     node.Type.Kind == SyntaxKind.ArrayType)
            {
                // This Type is an Array, so we will take the ElementType and use that as the result.
                var resultType = Identify(
                    node.Type.ElementType,
                    classMetadata,
                    ast,
                    typeOverrideDetails
                    );
                resultType.IsArray = true;
                return(resultType);
            }
            else if (IsNumericArrayRule.Check(node))
            {
                genericTypes.Add(
                    new TypeStatement
                {
                    Name = GenerationIdentifiedTypes.Number,
                }
                    );
            }
            else if (IsArrayResposneTypeRule.Check(node))
            {
                genericTypes.Add(
                    Identify(
                        node.First,
                        classMetadata,
                        ast,
                        typeOverrideDetails
                        )
                    );
            }
            else if (IsVoidTypeRule.Check(node))
            {
                if (node.Kind == SyntaxKind.Identifier &&
                    node.IdentifierStr == typeIdentifier)
                {
                    typeIdentifier = GenerationIdentifiedTypes.Void;
                }
            }
            else if (NullableTypeIdentifier.Identify(
                         typeIdentifier
                         ) && node.Type is not null &&
                     node.Type.TypeArguments is not null &&
                     node.Type.TypeArguments.Any() &&
                     node.Type.TypeArguments.First() is Node typeArgumentFirst)
            {
                genericTypes.Add(
                    Identify(
                        typeArgumentFirst,
                        classMetadata,
                        ast,
                        typeOverrideDetails
                        )
                    );
            }