Пример #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);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="translationUnit"></param>
        /// <param name="className"></param>
        /// <param name="baseClassName"></param>
        /// <returns></returns>
        public static ClassDeclarationTranslationUnit AddClass(this ModuleTranslationUnit translationUnit, string className, string baseClassName)
        {
            var classTranslationUnit = ClassDeclarationTranslationUnit.Create(
                VisibilityToken.Public, IdentifierTranslationUnit.Create(className), IdentifierTranslationUnit.Create(baseClassName));

            translationUnit.AddClass(classTranslationUnit);
            return(classTranslationUnit);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="translationUnit"></param>
        /// <param name="className"></param>
        /// <returns></returns>
        public static ClassDeclarationTranslationUnit AddClass(this ModuleTranslationUnit translationUnit, string className)
        {
            var classTranslationUnit = ClassDeclarationTranslationUnit.Create(
                ModifierTokens.Public, IdentifierTranslationUnit.Create(className), null);

            translationUnit.AddClass(classTranslationUnit);
            return(classTranslationUnit);
        }
Пример #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);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="visibility"></param>
        /// <param name="name"></param>
        /// <param name="baseClassName"></param>
        /// <returns></returns>
        public static ITranslationUnit BuildClassTranslationUnit(VisibilityToken visibility, string name, string baseClassName)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(ClassDeclarationTranslationUnit.Create(
                       visibility, IdentifierTranslationUnit.Create(name),
                       baseClassName == null ? null : IdentifierTranslationUnit.Create(baseClassName)));
        }
Пример #6
0
        public void ModuleAddsClass()
        {
            var translationUnit = ModuleTranslationUnit.Create(IdentifierTranslationUnit.Create("Module1"));

            TestInitialNestingLevel(translationUnit);

            var nestedTranslationUnit = ClassDeclarationTranslationUnit.Create(
                VisibilityToken.None, IdentifierTranslationUnit.Create("Class1"), null);

            translationUnit.AddClass(nestedTranslationUnit);
            TestNestingLevels(translationUnit, nestedTranslationUnit);
        }
Пример #7
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);
        }
Пример #8
0
        public void PrivateVisibilityTokenApplied()
        {
            VisibilityToken  visibility      = VisibilityToken.Private;
            ITranslationUnit translationUnit = ClassDeclarationTranslationUnit.Create(
                visibility, IdentifierTranslationUnit.Create("SampleClass"), null);

            string typescript = translationUnit.Translate();

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

            Assert.IsTrue(typescript.Contains(TokenUtility.PrivateVisibilityToken),
                          string.Format("Token {0} expected!", TokenUtility.PrivateVisibilityToken));
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClassASTWalker"/> class.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="classDeclaration"></param>
        /// <param name="semanticModel">The semantic model.</param>
        protected ClassASTWalker(CSharpSyntaxNode node, ClassDeclarationTranslationUnit classDeclaration, SemanticModel semanticModel)
            : base(node, semanticModel)
        {
            var classDeclarationSyntaxNode = node as ClassDeclarationSyntax;

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

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

            this.classDeclaration = classDeclaration;
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClassASTWalker"/> class.
        /// </summary>
        protected ClassASTWalker(CSharpSyntaxNode node)
        {
            var classDeclarationSyntaxNode = node as ClassDeclarationSyntax;

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

            this.node = node;
            ClassDeclaration classHelper = new ClassDeclaration(classDeclarationSyntaxNode);

            this.classDeclaration = ClassDeclarationTranslationUnit.Create(
                classHelper.Visibility,
                IdentifierTranslationUnit.Create(classHelper.Name),
                classHelper.BaseClass == null ? null : IdentifierTranslationUnit.Create(classHelper.BaseClass.Name));

            foreach (BaseTypeReference implementedInterface in classHelper.ImplementedInterfaces)
            {
                this.classDeclaration.AddImplementedInterface(IdentifierTranslationUnit.Create(implementedInterface.Name));
            }
        }
 /// <summary>
 /// Creates the translation unit.
 /// </summary>
 /// <remarks>
 /// Must return a type inheriting from <see cref="ClassDeclarationTranslationUnit"/>.
 /// </remarks>
 /// <param name="visibility"></param>
 /// <param name="name"></param>
 /// <param name="baseClassName"></param>
 /// <returns></returns>
 protected virtual ITranslationUnit CreateTranslationUnit(
     ModifierTokens visibility, ITranslationUnit name, ITranslationUnit baseClassName)
 {
     return(ClassDeclarationTranslationUnit.Create(visibility, name, baseClassName));
 }
Пример #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="translationUnit"></param>
 /// <param name="interfaceName"></param>
 public static void AddInterface(this ClassDeclarationTranslationUnit translationUnit, string interfaceName)
 {
     translationUnit.AddImplementedInterface(IdentifierTranslationUnit.Create(interfaceName));
 }
Пример #13
0
 /// <summary>
 /// Copy initializes a new instance of the <see cref="ClassASTWalker"/> class.
 /// </summary>
 /// <param name="other"></param>
 /// <remarks>
 /// For testability.
 /// </remarks>
 public ClassASTWalker(ClassASTWalker other)
     : base(other)
 {
     this.classDeclaration = other.classDeclaration;
 }
 public static MockedClassDeclarationTranslationUnit Create(ClassDeclarationTranslationUnit classDeclarationTranslationUnit)
 {
     return(new MockedClassDeclarationTranslationUnit(classDeclarationTranslationUnit));
 }
 protected MockedClassDeclarationTranslationUnit(ClassDeclarationTranslationUnit original)
     : base(original)
 {
 }