Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodASTWalker"/> class.
        /// </summary>
        protected MethodASTWalker(CSharpSyntaxNode node)
        {
            var methodDeclarationSyntaxNode = node as MethodDeclarationSyntax;

            if (methodDeclarationSyntaxNode == null)
            {
                throw new ArgumentException(
                          string.Format("Specified node is not of type {0}",
                                        typeof(MethodDeclarationSyntax).Name));
            }

            this.node = node;
            MethodDeclaration methodHelper = new MethodDeclaration(methodDeclarationSyntaxNode);

            this.methodDeclaration = MethodDeclarationTranslationUnit.Create(
                methodHelper.Visibility,
                IdentifierTranslationUnit.Create(methodHelper.ReturnType),
                IdentifierTranslationUnit.Create(methodHelper.Name));

            foreach (TypedIdentifier parameter in methodHelper.Parameters)
            {
                this.methodDeclaration.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                                       IdentifierTranslationUnit.Create(parameter.TypeName),
                                                       IdentifierTranslationUnit.Create(parameter.IdentifierName)));
            }
        }
        public string RenderEmptyMethod1Argument()
        {
            var translationUnit = TranslationUnitBuilder.BuildMethodSignatureTranslationUnit(
                ModifierTokens.Public, null, "MethodSignature1Argument") as MethodSignatureDeclarationTranslationUnit;

            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Number, IdentifierTranslationUnit.Create("param1")));

            return(translationUnit.Translate());
        }
Beispiel #3
0
        public string RenderEmptyConstructor1Argument()
        {
            var translationUnit = TranslationUnitBuilder.BuildConstructorTranslationUnit(
                VisibilityToken.Public) as MethodDeclarationTranslationUnit;

            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Number, IdentifierTranslationUnit.Create("param1")));

            return(translationUnit.Translate());
        }
Beispiel #4
0
        public string RenderEmptyMethod2Arguments()
        {
            var translationUnit = TranslationUnitBuilder.BuildMethodTranslationUnit(
                ModifierTokens.Public, null, "EmptyMethod2Arguments") as MethodDeclarationTranslationUnit;

            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Number, IdentifierTranslationUnit.Create("param1")));
            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.String, IdentifierTranslationUnit.Create("param2")));

            return(translationUnit.Translate());
        }
        public string RenderEmptyMethodManyArguments()
        {
            var translationUnit = TranslationUnitBuilder.BuildMethodSignatureTranslationUnit(
                ModifierTokens.Public, null, "MethodSignatureManyArguments") as MethodSignatureDeclarationTranslationUnit;

            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Number, IdentifierTranslationUnit.Create("param1")));
            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.String, IdentifierTranslationUnit.Create("param2")));
            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Boolean, IdentifierTranslationUnit.Create("param3")));
            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Any, IdentifierTranslationUnit.Create("param4")));

            return(translationUnit.Translate());
        }
Beispiel #6
0
        public string RenderEmptyConstructorManyArguments()
        {
            var translationUnit = TranslationUnitBuilder.BuildConstructorTranslationUnit(
                ModifierTokens.Public) as MethodDeclarationTranslationUnit;

            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Number, IdentifierTranslationUnit.Create("param1")));
            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.String, IdentifierTranslationUnit.Create("param2")));
            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Boolean, IdentifierTranslationUnit.Create("param3")));
            translationUnit.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                            TypeIdentifierTranslationUnit.Any, IdentifierTranslationUnit.Create("param4")));

            return(translationUnit.Translate());
        }
Beispiel #7
0
        /// <summary>
        /// Creates a <see cref="ConstructorDeclarationTranslationUnitFactory"/>.
        /// </summary>
        /// <returns>A <see cref="ConstructorDeclarationTranslationUnitFactory"/>.</returns>
        public ITranslationUnit Create()
        {
            if (this.DoNotCreateTranslationUnit)
            {
                return(null);
            }

            ConstructorDeclaration helper = this.CreateHelper(this.Node as ConstructorDeclarationSyntax, this.SemanticModel);

            var constructorDeclaration = this.CreateTranslationUnit(helper.Visibility) as MethodSignatureDeclarationTranslationUnit;

            foreach (Parameter parameter in helper.Parameters)
            {
                constructorDeclaration.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                                       TypeIdentifierTranslationUnit.Create(parameter.Type.FullName.MapType()),
                                                       IdentifierTranslationUnit.Create(parameter.IdentifierName)));
            }

            return(constructorDeclaration);
        }
Beispiel #8
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            if (this.hasGet)
            {
                // Opening declaration: [<modifiers>] get <name>() : <type> {
                // TODO: Handle case of no visibility specified
                writer.WriteLine("{0}{1}{2} {3} {4}{5}",
                                 this.RenderedModifiers,
                                 this.RenderedGetterMethodName,
                                 Lexems.OpenRoundBracket + Lexems.CloseRoundBracket,
                                 Lexems.Colon,
                                 this.type.Translate(),
                                 this.hasSet ? Lexems.Semicolon : string.Empty); // TODO: Find a better way for this
            }

            if (this.hasSet)
            {
                var valueParameter = ArgumentDefinitionTranslationUnit.Create(
                    this.type, IdentifierTranslationUnit.Create("value"));

                // Opening declaration: [<modifiers>] set <name>(value : <type>) : void {
                // Emitting `void` in order to prevent errors in case of implicitAllowAny
                writer.WriteLine("{0}{1}{2}{3}{4} {5} {6}",
                                 this.RenderedModifiers,
                                 this.RenderedSetterMethodName,
                                 Lexems.OpenRoundBracket,
                                 valueParameter.Translate(),
                                 Lexems.CloseRoundBracket,
                                 Lexems.Colon,
                                 Lexems.VoidReturnType);
            }

            return(writer.ToString());
        }
Beispiel #9
0
        /// <summary>
        /// Creates a <see cref="MethodDeclarationTranslationUnit"/>.
        /// </summary>
        /// <returns>A <see cref="MethodDeclarationTranslationUnit"/>.</returns>
        public ITranslationUnit Create()
        {
            if (this.DoNotCreateTranslationUnit)
            {
                return(null);
            }

            AnonymousMethodDeclaration helper = new AnonymousMethodDeclaration(this.Node as AnonymousMethodExpressionSyntax, this.SemanticModel);

            var lambdaDeclaration = LambdaTranslationUnit.Create(null);

            //var lambdaDeclaration = LambdaTranslationUnit.Create(TypeIdentifierTranslationUnit.Create(helper.ReturnType.FullName.MapType()));

            foreach (Parameter parameter in helper.Parameters)
            {
                lambdaDeclaration.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                                  TypeIdentifierTranslationUnit.Create(parameter.Type.TypeSyntaxNode.MapType()),
                                                  IdentifierTranslationUnit.Create(parameter.IdentifierName)));
            }

            return(lambdaDeclaration);
        }
        /// <summary>
        /// Creates a <see cref="MethodDeclarationTranslationUnit"/>.
        /// </summary>
        /// <returns>A <see cref="MethodDeclarationTranslationUnit"/>.</returns>
        public ITranslationUnit Create()
        {
            if (this.DoNotCreateTranslationUnit)
            {
                return(null);
            }

            MethodDeclaration helper = this.CreateHelper(this.Node as MethodDeclarationSyntax, this.SemanticModel);

            var methodDeclaration = this.CreateTranslationUnit(
                helper.Modifiers,
                this.MapType(helper.ReturnType.FullName).MappedType,
                IdentifierTranslationUnit.Create(helper.Name)) as MethodSignatureDeclarationTranslationUnit;

            foreach (Parameter parameter in helper.Parameters)
            {
                methodDeclaration.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                                  this.MapType(parameter.Type.FullName).MappedType,
                                                  IdentifierTranslationUnit.Create(parameter.IdentifierName)));
            }

            return(methodDeclaration);
        }