Exemple #1
0
        private ClassDeclarationSyntax TranslateClass(ClassDeclarationSyntax classDeclaration)
        {
            for (int i = 0; i < classDeclaration.AttributeLists.Count; i++)
            {
                var attributeList = classDeclaration.AttributeLists.ToList()[i];
                AttributeListSyntax newAttributeList = AttributeTranslator.TranslateClassAttributeList(attributeList);
                classDeclaration = classDeclaration.ReplaceNode(attributeList, newAttributeList);
            }

            classDeclaration = AddClassAnnotationIfNotPresent(classDeclaration);
            classDeclaration = AddPublicModifierIfNotPresent(classDeclaration);

            //methods
            List <MethodDeclarationSyntax> methods = classDeclaration.DescendantNodes().OfType <MethodDeclarationSyntax>().ToList();

            for (int i = 0; i < classDeclaration.DescendantNodes().OfType <MethodDeclarationSyntax>().Count(); i++)
            {
                methods[i] = classDeclaration.DescendantNodes().OfType <MethodDeclarationSyntax>().ToList()[i];
                var methodDeclaration = methods[i];
                if (IsTranslatable(methodDeclaration))
                {
                    MethodDeclarationSyntax translatedMethod = TranslateMethod(methods[i]);
                    classDeclaration = classDeclaration.ReplaceNode(methods[i], translatedMethod);
                }
                else
                {
                    classDeclaration = classDeclaration.ReplaceNode(methods[i], Comment(methodDeclaration));
                    classDeclaration = classDeclaration.RemoveNode(classDeclaration.DescendantNodes().OfType <MethodDeclarationSyntax>().ToList()[i], SyntaxRemoveOptions.KeepExteriorTrivia);
                    i--;
                }
            }
            return(classDeclaration);
        }
Exemple #2
0
        private MethodDeclarationSyntax TranslateMethod(MethodDeclarationSyntax methodDeclaration)
        {
            foreach (var log in methodDeclaration.DescendantTrivia().ToList())
            {
                if (log.Kind() == SyntaxKind.SingleLineCommentTrivia)
                {
                    Logger.Info("Logs: \n" + log.ToString());
                }
            }

            for (int i = 0; i < methodDeclaration.AttributeLists.Count; i++)
            {
                var attributeList = methodDeclaration.AttributeLists.ToList()[i];
                AttributeListSyntax newAttributeList = AttributeTranslator.TranslateMethodAttributeList(attributeList);
                methodDeclaration = methodDeclaration.ReplaceNode(attributeList, newAttributeList);
            }

            return(AssertionTranslator.TranslateAssertions(methodDeclaration));
        }