Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="translationUnit"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        public static MethodDeclarationTranslationUnit AddEmptyMethod(this ClassDeclarationTranslationUnit translationUnit, string method)
        {
            var methodDeclaration = MethodDeclarationTranslationUnit.Create(VisibilityToken.Public, null, IdentifierTranslationUnit.Create(method));

            translationUnit.AddMethodDeclaration(methodDeclaration);
            return(methodDeclaration);
        }
Esempio n. 2
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)));
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="translationUnit"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        public static VariableDeclarationTranslationUnit AddVariable(this MethodDeclarationTranslationUnit translationUnit, string type, string name)
        {
            var variableDeclaration = VariableDeclarationTranslationUnit.Create(
                type != null ? IdentifierTranslationUnit.Create("int") : null, IdentifierTranslationUnit.Create(name));

            translationUnit.AddStatement(variableDeclaration);
            return(variableDeclaration);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="translationUnit"></param>
        /// <param name="returnType"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MethodDeclarationTranslationUnit AddMethod(this ClassDeclarationTranslationUnit translationUnit, string returnType, string name)
        {
            var methodTranslationUnit = MethodDeclarationTranslationUnit.Create(VisibilityToken.Public,
                                                                                returnType != null ? IdentifierTranslationUnit.Create(returnType) : null,
                                                                                IdentifierTranslationUnit.Create(name));

            translationUnit.AddMethodDeclaration(methodTranslationUnit);
            return(methodTranslationUnit);
        }
Esempio n. 5
0
        public void ClassAddsMethod()
        {
            var translationUnit = ClassDeclarationTranslationUnit.Create(
                VisibilityToken.None, IdentifierTranslationUnit.Create("Class1"), null);

            TestInitialNestingLevel(translationUnit);

            var nestedTranslationUnit = MethodDeclarationTranslationUnit.Create(
                VisibilityToken.None, null, IdentifierTranslationUnit.Create("Method1"));

            translationUnit.AddMethodDeclaration(nestedTranslationUnit);
            TestNestingLevels(translationUnit, nestedTranslationUnit);
        }
Esempio n. 6
0
        public void MethodAddsStatement()
        {
            var translationUnit = MethodDeclarationTranslationUnit.Create(
                VisibilityToken.None, null, IdentifierTranslationUnit.Create("Method1"));;

            TestInitialNestingLevel(translationUnit);

            var nestedTranslationUnit = VariableDeclarationTranslationUnit.Create(
                TypeIdentifierTranslationUnit.Create("int"),
                IdentifierTranslationUnit.Create("var1"));

            translationUnit.AddStatement(nestedTranslationUnit);
            TestNestingLevels(translationUnit, nestedTranslationUnit);
        }
Esempio n. 7
0
        public void PrivateVisibilityTokenApplied()
        {
            VisibilityToken  visibility      = VisibilityToken.Private;
            ITranslationUnit translationUnit = MethodDeclarationTranslationUnit.Create(
                visibility, IdentifierTranslationUnit.Void, IdentifierTranslationUnit.Create("SampleMethod"));

            string typescript = translationUnit.Translate();

            new Utils.FileWriter(TestSuite.Context).WriteToFile(typescript,
                                                                string.Format("{0}.Method", nameof(this.PrivateVisibilityTokenApplied)),
                                                                Utils.FileType.TypeScript);

            Assert.IsTrue(typescript.Contains(TokenUtility.PrivateVisibilityToken),
                          string.Format("Token {0} expected!", TokenUtility.PrivateVisibilityToken));
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodASTWalker"/> class.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="methodDeclaration"></param>
        /// <param name="semanticModel">The semantic model.</param>
        protected MethodASTWalker(CSharpSyntaxNode node, MethodDeclarationTranslationUnit methodDeclaration, SemanticModel semanticModel)
            : base(node, semanticModel)
        {
            var methodDeclarationSyntaxNode = node as MethodDeclarationSyntax;

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

            if (methodDeclaration == null)
            {
                throw new ArgumentNullException(nameof(methodDeclaration));
            }

            this.methodDeclaration = methodDeclaration;
        }
Esempio n. 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="visibility"></param>
        /// <param name="returnType"></param>
        /// <param name="name"></param>
        /// <param name="statements"></param>
        /// <returns></returns>
        public static ITranslationUnit BuildMethodTranslationUnit(VisibilityToken visibility, string returnType, string name, ITranslationUnit[] statements = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            MethodDeclarationTranslationUnit translationUnit = MethodDeclarationTranslationUnit.Create(
                visibility, returnType == null ? null : IdentifierTranslationUnit.Create(returnType),
                IdentifierTranslationUnit.Create(name));

            if (statements != null)
            {
                foreach (ITranslationUnit statement in statements)
                {
                    translationUnit.AddStatement(statement);
                }
            }

            return(translationUnit);
        }
 /// <summary>
 /// Creates the translation unit.
 /// </summary>
 /// <remarks>
 /// Must return a type inheriting from <see cref="MethodSignatureDeclarationTranslationUnit"/>.
 /// </remarks>
 /// <param name="visibility"></param>
 /// <param name="returnType"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 protected virtual ITranslationUnit CreateTranslationUnit(
     VisibilityToken visibility, ITranslationUnit returnType, ITranslationUnit name)
 {
     return(MethodDeclarationTranslationUnit.Create(visibility, returnType, name));
 }
 /// <summary>
 /// Creates the translation unit.
 /// </summary>
 /// <remarks>
 /// Must return a type inheriting from <see cref="MethodSignatureDeclarationTranslationUnit"/>.
 /// </remarks>
 /// <param name="modifiers"></param>
 /// <param name="returnType"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 protected virtual ITranslationUnit CreateTranslationUnit(
     ModifierTokens modifiers, ITranslationUnit returnType, ITranslationUnit name)
 {
     return(MethodDeclarationTranslationUnit.Create(modifiers, returnType, name));
 }
Esempio n. 12
0
 /// <summary>
 /// Copy initializes a new instance of the <see cref="MethodASTWalker"/> class.
 /// </summary>
 /// <param name="other"></param>
 /// <remarks>
 /// For testability.
 /// </remarks>
 public MethodASTWalker(MethodASTWalker other)
     : base(other)
 {
     this.methodDeclaration = other.methodDeclaration;
 }
Esempio n. 13
0
 public static MockedMethodDeclarationTranslationUnit Create(MethodDeclarationTranslationUnit methodDeclarationTranslationUnit)
 {
     return(new MockedMethodDeclarationTranslationUnit(methodDeclarationTranslationUnit));
 }
Esempio n. 14
0
 protected MockedMethodDeclarationTranslationUnit(MethodDeclarationTranslationUnit original)
     : base(original)
 {
 }