Пример #1
0
            public async Task <SyntaxTree> ReplaceVars(SyntaxTree syntaxTree, MonoProxy proxy, MessageId msg_id, int scope_id, CancellationToken token)
            {
                CompilationUnitSyntax root = syntaxTree.GetCompilationUnitRoot();

                foreach (var var in variables)
                {
                    ClassDeclarationSyntax  classDeclaration = root.Members.ElementAt(0) as ClassDeclarationSyntax;
                    MethodDeclarationSyntax method           = classDeclaration.Members.ElementAt(0) as MethodDeclarationSyntax;

                    JToken value = await proxy.TryGetVariableValue(msg_id, scope_id, var.Identifier.Text, false, token);

                    if (value == null)
                    {
                        throw new Exception($"The name {var.Identifier.Text} does not exist in the current context");
                    }

                    values.Add(ConvertJSToCSharpType(value["value"]));

                    var updatedMethod = method.AddParameterListParameters(
                        SyntaxFactory.Parameter(
                            SyntaxFactory.Identifier(var.Identifier.Text))
                        .WithType(SyntaxFactory.ParseTypeName(GetTypeFullName(value["value"]))));
                    root = root.ReplaceNode(method, updatedMethod);
                }
                syntaxTree = syntaxTree.WithRootAndOptions(root, syntaxTree.Options);
                return(syntaxTree);
            }
Пример #2
0
 /// <summary>
 /// Процедура добавления параметра в метод
 /// </summary>
 /// <param name="method">Метод, в который надо добавить параметр</param>
 /// <param name="paramName">Наименование параметра</param>
 /// <param name="paramType">Тип параметра</param>
 /// <returns></returns>
 public MethodDeclarationSyntax AddParameterToMethod(
     MethodDeclarationSyntax method, string paramName, string paramType)
 {
     method = method.AddParameterListParameters(SyntaxFactory.Parameter(
                                                    SyntaxFactory.Identifier(paramName))
                                                .WithType(SyntaxFactory.ParseTypeName(paramType))).NormalizeWhitespace();
     return(method);
 }
Пример #3
0
        public static async Task <Document> RefactorAsync(
            Document document,
            MethodDeclarationSyntax method,
            LocalDeclarationStatementSyntax localDeclaration,
            TypeSyntax type,
            VariableDeclaratorSyntax variable,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            int variableCount = localDeclaration.Declaration.Variables.Count;
            ExpressionSyntax initializerValue = variable.Initializer?.Value;
            SyntaxToken      identifier       = variable.Identifier.WithoutTrivia();

            MethodDeclarationSyntax newMethod = method;

            if (initializerValue != null)
            {
                ExpressionStatementSyntax expressionStatement = ExpressionStatement(
                    SimpleAssignmentExpression(
                        IdentifierName(identifier),
                        initializerValue));

                expressionStatement = expressionStatement.WithFormatterAnnotation();

                if (variableCount > 1)
                {
                    LocalDeclarationStatementSyntax newLocalDeclaration = localDeclaration.RemoveNode(
                        variable,
                        SyntaxRemoveOptions.KeepUnbalancedDirectives);

                    newMethod = newMethod.ReplaceNode(
                        localDeclaration,
                        new SyntaxNode[] { newLocalDeclaration, expressionStatement });
                }
                else
                {
                    newMethod = newMethod.ReplaceNode(
                        localDeclaration,
                        expressionStatement.WithTriviaFrom(localDeclaration));
                }
            }
            else
            {
                if (variableCount > 1)
                {
                    newMethod = newMethod.RemoveNode(variable, SyntaxRemoveOptions.KeepUnbalancedDirectives);
                }
                else
                {
                    newMethod = newMethod.RemoveNode(localDeclaration, SyntaxRemoveOptions.KeepUnbalancedDirectives);
                }
            }

            ParameterSyntax newParameter = Parameter(type, identifier).WithFormatterAnnotation();

            newMethod = newMethod.AddParameterListParameters(newParameter);

            return(await document.ReplaceNodeAsync(method, newMethod, cancellationToken).ConfigureAwait(false));
        }
Пример #4
0
        public static MethodDeclarationSyntax CreateMethod(MethodGenerationData data)
        {
            Debug.Assert(!string.IsNullOrEmpty(data.m_MethodName), "Trying to generate a method with null or empty method name!");
            Debug.Assert(!string.IsNullOrEmpty(data.m_MethodReturnType), "Trying to generate a method with null or empty return type!");
            Debug.Assert(data.m_MethodBodyStatements != null && data.m_MethodBodyStatements.Count > 0, "Trying to generate a method with no body!");

            MethodDeclarationSyntax syntax = SyntaxFactory
                                             .MethodDeclaration(SyntaxFactory.ParseTypeName(data.m_MethodReturnType), data.m_MethodName)
                                             .AddModifiers(CodeGenerationUtility.CreateProtectionLevelToken(data.m_ProtectionLevel));

            switch (data.m_InheritanceKeyword)
            {
            case FunctionInheritanceKeyword.STATIC: syntax = syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword)); break;

            case FunctionInheritanceKeyword.OVERRIDE: syntax = syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.OverrideKeyword)); break;

            case FunctionInheritanceKeyword.VIRTUAL: syntax = syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.VirtualKeyword)); break;
            }

            if (data.m_IsAsync)
            {
                bool canMakeAsync = false;

                for (int i = 0; i < s_AcceptedAsyncReturnTypes.Length; i++)
                {
                    if (!data.m_MethodReturnType.Contains(s_AcceptedAsyncReturnTypes[i]))
                    {
                        continue;
                    }

                    canMakeAsync = true;
                    break;
                }

                Debug.Assert(canMakeAsync, "Trying to generate async function but the return type is not supported! Please make the return type either void, Task or UniTask");

                if (canMakeAsync)
                {
                    syntax = syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.AsyncKeyword));
                }
            }

            syntax = syntax.AddAttributeLists(AttributeGenerationService.CreateAttributeListSyntaxes(data.m_Attributes));

            foreach (var param in data.m_MethodParams)
            {
                syntax = syntax.AddParameterListParameters(CodeGenerationUtility.CreateParameterSyntax(param.m_ParamName, param.m_ParamType));
            }

            foreach (var statement in data.m_MethodBodyStatements)
            {
                syntax = syntax.AddBodyStatements((SyntaxFactory.ParseStatement(statement)));
            }

            return(syntax);
        }
Пример #5
0
        //public static MethodDeclarationSyntax AddTypedParametersIfAny(this MethodDeclarationSyntax target, MethodInfo source)
        //{
        //    if (source?.TypeParameterList?.Parameters != null)
        //    {
        //        target = target.AddTypeParameterListParameters(source.TypeParameterList.Parameters.ToArray());
        //    }
        //    return target;
        //}

        public static MethodDeclarationSyntax AddParametersIfAny(this MethodDeclarationSyntax target, MethodInfo source)
        {
            var parameters = source.GetParameters();

            if (parameters.Any())
            {
                target = target.AddParameterListParameters(ToParameterSyntaxArray(parameters));
            }
            return(target);
        }
Пример #6
0
        public static MethodDeclarationSyntax AddParameter(this MethodDeclarationSyntax method, string parameterName, string typeName, string defaultValue = null)
        {
            var parameterSyntax = SyntaxFactory.Parameter(SyntaxFactory.Identifier(parameterName)).WithType(SyntaxFactory.ParseTypeName(typeName));

            if (!string.IsNullOrEmpty(defaultValue))
            {
                parameterSyntax = parameterSyntax.WithDefault(SyntaxFactory.EqualsValueClause(SyntaxFactory.ParseExpression(defaultValue)));
            }

            return(method.AddParameterListParameters(parameterSyntax));
        }
 static MethodDeclarationSyntax AddToNodeParameters(MethodDeclarationSyntax method)
 {
     return(method
            .AddParameterListParameters(
                Parameter(
                    Identifier(ParentLocal))
                .WithType(
                    IdentifierName(Names.SourceNode))
                .WithDefault(
                    EqualsValueClause(
                        LiteralExpression(SyntaxKind.NullLiteralExpression)))));
 }
        private MethodDeclarationSyntax BuldEqualsOverrideDeclaration(StructDeclarationSyntax structDeclaration, INamedTypeSymbol structType)
        {
            MethodDeclarationSyntax method = MethodDeclaration(_boolTypeName, "Equals");
            TypeSyntax      structTypeName = ParseTypeName(structType.ToDisplayString());
            ParameterSyntax parameter      = Parameter(ParseToken(_objArg)).WithType(_objectTypeName);

            method = method.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.OverrideKeyword)));
            method = method.AddParameterListParameters(parameter);
            method = method.WithExpressionBody(ArrowExpressionClause(BuildEqualsOverrideBodyExpression(structDeclaration, structTypeName)));
            method = method.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
            method = method.WithAdditionalAnnotations(Simplifier.Annotation);

            return(method);
        }
        private MethodDeclarationSyntax BuldEqualsMethodDeclaration(StructDeclarationSyntax structDeclaration, INamedTypeSymbol structType, SemanticModel semanticModel, ISymbol[] fieldsAndProperties)
        {
            MethodDeclarationSyntax method = MethodDeclaration(_boolTypeName, "Equals");
            TypeSyntax      structTypeName = ParseTypeName(structType.ToDisplayString());
            ParameterSyntax parameter      = Parameter(ParseToken(_otherArg)).WithType(structTypeName);

            method = method.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword)));
            method = method.AddParameterListParameters(parameter);
            method = method.WithExpressionBody(ArrowExpressionClause(BuildEqualsBodyExpression(structDeclaration, semanticModel, fieldsAndProperties)));
            method = method.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
            method = method.WithAdditionalAnnotations(Simplifier.Annotation);

            return(method);
        }
        private MethodDeclarationSyntax CreateFunctionDeclaration(FunctionDeclaration node)
        {
            MethodDeclarationSyntax methodDeclaration = SyntaxFactory.MethodDeclaration(node.Type.ToCsNode <TypeSyntax>(), node.Name.Text);

            methodDeclaration = methodDeclaration.AddModifiers(node.Modifiers.ToCsNodes <SyntaxToken>());
            methodDeclaration = methodDeclaration.AddParameterListParameters(node.Parameters.ToCsNodes <ParameterSyntax>());

            if (node.JsDoc.Count > 0)
            {
                methodDeclaration = methodDeclaration.WithLeadingTrivia(SyntaxFactory.Trivia(node.JsDoc[0].ToCsNode <DocumentationCommentTriviaSyntax>()));
            }
            if (node.TypeParameters.Count > 0)
            {
                methodDeclaration = methodDeclaration.AddTypeParameterListParameters(node.TypeParameters.ToCsNodes <TypeParameterSyntax>());
            }

            return(methodDeclaration.WithBody(node.Body.ToCsNode <BlockSyntax>()));
        }
Пример #11
0
        public MethodDeclarationSyntax CreateMethod2(string methodName,
                                                     AccessStatuses accessStatus = AccessStatuses.Public,
                                                     string outputType           = "void")
        {
            if (string.IsNullOrEmpty(outputType))
            {
                outputType = "void";
            }
            MethodDeclarationSyntax expr = SyntaxFactory.MethodDeclaration(
                SyntaxFactory.ParseName(outputType),
                methodName)
                                           .WithModifiers(SyntaxFactory.TokenList(
                                                              SyntaxFactory.Token(AccessStatus.AccessType(accessStatus))))
                                           .WithBody(
                SyntaxFactory.Block());

            //SyntaxFactory.AttributeList()

            /*SeparatedSyntaxList<AttributeSyntax> spr = new SeparatedSyntaxList<AttributeSyntax>();
             * spr.Add(SyntaxFactory.Attribute(SyntaxFactory.ParseName("string b")));
             * var b = SyntaxFactory.AttributeList(spr);
             * expr = expr.AddAttributeLists(b);*/

            expr = expr.AddParameterListParameters(new ParameterSyntax[]
            {
                SyntaxFactory.Parameter(SyntaxFactory.Identifier("a")).WithType(SyntaxFactory.ParseTypeName("string")),
                SyntaxFactory.Parameter(SyntaxFactory.Identifier("b")).WithType(SyntaxFactory.ParseTypeName("string"))
            });
            //SyntaxFactory.Parameter(SyntaxFactory.ParseToken("string a"));

            //ParameterSyntax parameterSyntax
            //AttributeListSyntax atr =

            /*expr.AddAttributeLists(new AttributeListSyntax[]
             * {
             *
             * });*/
            //SyntaxFactory.Parameter(SyntaxFactory.Token())
            //SyntaxFactory.Token(default(syntaxl))
            return(expr.NormalizeWhitespace());
        }
Пример #12
0
        /// <summary> Modify the method found in GetOriginalMethodDeclarationSyntax(). </summary>
        private static MethodDeclarationSyntax GetModifiedMethodDeclarationSyntax(MethodDeclarationSyntax method, MethodModificationData modificationData)
        {
            var nodes = method.DescendantNodes().ToList();

            ParameterListSyntax paramListSyntax = SyntaxFactory.ParameterList();

            foreach (var param in modificationData.m_NewMethodParams)
            {
                paramListSyntax = paramListSyntax.AddParameters(CodeGenerationUtility.CreateParameterSyntax(param.m_ParamName, param.m_ParamType));
            }

            method = modificationData.m_ParamModificationType == MethodParameterModificationType.REPLACE_PARAMS
                ? method.WithParameterList(paramListSyntax)
                : method.AddParameterListParameters(paramListSyntax.Parameters.ToArray());

            BlockSyntax blockSyntax   = SyntaxFactory.Block();
            var         oldStatements = method.Body.Statements.ToList();

            foreach (var statement in modificationData.m_BodyStatements)
            {
                if (modificationData.m_BodyModificationType == MethodBodyModificationType.ADD_OR_REPLACE_BODY)
                {
                    if (oldStatements.Find(x => x.ToFullString().Contains(statement)) != null)
                    {
                        continue;
                    }
                }

                blockSyntax = blockSyntax.AddStatements(SyntaxFactory.ParseStatement(statement));
            }

            // if replacing the body, the statement in the old function with be completely replaced with the new statement
            method = modificationData.m_BodyModificationType == MethodBodyModificationType.REPLACE_BODY
                ? method.WithBody(blockSyntax)
                : method.AddBodyStatements(blockSyntax.Statements.ToArray());

            return(method.NormalizeWhitespace());
        }
Пример #13
0
        private async Task <SyntaxNodeReplacementPair> ConstructDeclarationPairAsync(Document document, InvocationExpressionSyntax syntaxDeclaration, CancellationToken cancellationToken)
        {
            SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            ISymbol symbol = semanticModel.GetSymbolInfo(syntaxDeclaration).Symbol;

            SyntaxReference declaringSyntax = symbol.DeclaringSyntaxReferences.FirstOrDefault();

            MethodDeclarationSyntax methodSyntax = declaringSyntax.GetSyntax(cancellationToken) as MethodDeclarationSyntax;

            SyntaxToken identifier = SyntaxFactory.Identifier(_identifierName);
            TypeSyntax  typeName   = SyntaxFactory.ParseTypeName(typeof(CancellationToken).FullName);

            ParameterSyntax parameter = SyntaxFactory
                                        .Parameter(identifier)
                                        .WithType(typeName);

            MethodDeclarationSyntax updatedMethod = methodSyntax.AddParameterListParameters(parameter);

            document = document.Project.Solution.GetDocument(declaringSyntax.SyntaxTree);

            return(new SyntaxNodeReplacementPair(document, declaringSyntax.SyntaxTree.GetRoot(), methodSyntax, updatedMethod));
        }
Пример #14
0
        public static MethodDeclarationSyntax CreateNotifyProperty()
        {
            MethodDeclarationSyntax method = SyntaxFactory.MethodDeclaration(SyntaxFactory.IdentifierName("void"), "OnPropertyChanged");
            var attribute = SyntaxFactory.Attribute(SyntaxFactory.IdentifierName("CallerMemberName"));

            var attributes = SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList <AttributeSyntax>(new List <AttributeSyntax>()
            {
                attribute
            }));

            var equals     = SyntaxFactory.EqualsValueClause(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression));
            var expression = SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(""));

            equals = equals.WithValue(expression);
            var param = SyntaxFactory.Parameter(new SyntaxList <AttributeListSyntax>(attributes),
                                                new SyntaxTokenList(),
                                                SyntaxFactory.IdentifierName("string"),
                                                SyntaxFactory.Identifier("name"),
                                                equals);

            method = method.AddParameterListParameters(param);
            method = method.WithBody(CreateBlock());
            return(method);
        }
Пример #15
0
 public static MethodDeclarationSyntax AddParameterListParameters(this MethodDeclarationSyntax syntax, IEnumerable <ParameterSyntax> parameters)
 {
     return(syntax.AddParameterListParameters(parameters.ToArray()));
 }
        public void Generate()
        {
            // standard using directives
            CompilationUnitSyntax cu = SyntaxFactory.CompilationUnit()
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Collections.Generic")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Linq")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Text")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Threading.Tasks")));

            NamespaceDeclarationSyntax localNamespace = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.IdentifierName(directoryName));

            ClassDeclarationSyntax localClass = SyntaxFactory.ClassDeclaration(Name);

            foreach (var member in Declarations)
            {
                switch (member.DeclarationType)
                {
                case "method":
                    var currentMethod = member as Method;

                    //currentMethod.Type is a string parsed from the uml diagram
                    MethodDeclarationSyntax method = SyntaxFactory.MethodDeclaration(SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(currentMethod.Type)), currentMethod.Name);

                    List <SyntaxToken> mods = new List <SyntaxToken>();

                    foreach (var modifier in currentMethod.Modifiers)
                    {
                        mods.Add(SyntaxFactory.ParseToken(modifier));
                    }

                    method = method.AddModifiers(mods.ToArray());

                    SeparatedSyntaxList <ParameterSyntax> ssl = SyntaxFactory.SeparatedList <ParameterSyntax>();
                    foreach (var param in currentMethod.Arguments)
                    {
                        ParameterSyntax ps = SyntaxFactory.Parameter(
                            new SyntaxList <AttributeListSyntax>(),
                            new SyntaxTokenList(),
                            SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(param.Type)),
                            SyntaxFactory.Identifier(param.Name), null);

                        ssl = ssl.Add(ps);
                    }

                    method = method.AddParameterListParameters(ssl.ToArray());

                    // we add an exception to the body of an otherwise empty method
                    ThrowStatementSyntax notReady = SyntaxFactory.ThrowStatement(SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName("NotImplementedException"), SyntaxFactory.ArgumentList(), null));

                    method = method.AddBodyStatements(notReady);

                    localClass = localClass.AddMembers(method);
                    break;

                case "field":
                    var currentField = member as Field;

                    SyntaxTokenList stl = new SyntaxTokenList();

                    foreach (var modifier in currentField.Modifiers)
                    {
                        stl = stl.Add(SyntaxFactory.ParseToken(modifier));
                    }

                    SeparatedSyntaxList <VariableDeclaratorSyntax> svd = SyntaxFactory.SeparatedList <VariableDeclaratorSyntax>();

                    svd = svd.Add(SyntaxFactory.VariableDeclarator(currentField.Name));

                    // currentField.Type is a string parsed from the uml diagram
                    VariableDeclarationSyntax variable = SyntaxFactory.VariableDeclaration(SyntaxFactory.ParseTypeName(currentField.Type), svd);

                    FieldDeclarationSyntax field = SyntaxFactory.FieldDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        stl,
                        variable
                        );

                    localClass = localClass.AddMembers(field);
                    break;
                }
            }

            localNamespace = localNamespace.AddMembers(localClass);
            cu             = cu.AddMembers(localNamespace);

            AdhocWorkspace cw      = new AdhocWorkspace();
            OptionSet      options = cw.Options;

            cw.Options.WithChangedOption(CSharpFormattingOptions.IndentBraces, true);
            SyntaxNode formattedNode = Formatter.Format(cu, cw, options);

            formattedNode.WriteTo(writer);
        }
Пример #17
0
        private MethodDeclarationSyntax FixAsyncFunctionMethod(MethodDeclarationSyntax targetMethod, CancellationToken cancellationToken)
        {
            MethodDeclarationSyntax updatedmethod = targetMethod;

            var name      = SyntaxFactory.ParseName("NetStitch.Operation");
            var attribute = SyntaxFactory.Attribute(name);

            var attributeList = new SeparatedSyntaxList <AttributeSyntax>();

            attributeList = attributeList.Add(attribute);
            var list = SyntaxFactory.AttributeList(attributeList);

            updatedmethod = updatedmethod.AddAttributeLists(list);

            if (updatedmethod.Identifier.Text.IsAsyncSuffixTarget())
            {
                updatedmethod = updatedmethod.ReplaceToken(updatedmethod.Identifier, SyntaxFactory.Identifier(updatedmethod.Identifier + "Async"));
            }

            if (updatedmethod.ParameterList.Parameters.Count == 0)
            {
                /*
                 * #if !___server___
                 *      System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)
                 * #endif
                 */
                updatedmethod = updatedmethod.AddParameterListParameters(
                    SyntaxFactory.Parameter(
                        SyntaxFactory.Identifier("cancellationToken")
                        .WithLeadingTrivia(SyntaxFactory.Whitespace(" "))
                        .WithTrailingTrivia(SyntaxFactory.Whitespace(" "))
                        )
                    .WithLeadingTrivia(SyntaxFactory.Whitespace(" "))
                    .WithType(
                        SyntaxFactory.ParseTypeName(typeof(CancellationToken).FullName))
                    .WithLeadingTrivia(SyntaxFactory.Whitespace("    " + "    "))
                    .WithDefault(
                        SyntaxFactory.EqualsValueClause(
                            SyntaxFactory.DefaultExpression(
                                SyntaxFactory.ParseTypeName(typeof(CancellationToken).FullName)
                                )
                            .WithLeadingTrivia(SyntaxFactory.Whitespace(" "))
                            )
                        )
                    .WithLeadingTrivia(
                        SyntaxFactory.Trivia(SyntaxFactory.IfDirectiveTrivia(SyntaxFactory.IdentifierName("!___server___"), false, false, false)),
                        SyntaxFactory.EndOfLine("\r\n"),
                        SyntaxFactory.Whitespace("    " + "    ")
                        )
                    .WithTrailingTrivia(
                        SyntaxFactory.EndOfLine("\r\n"),
                        SyntaxFactory.Trivia(
                            SyntaxFactory.EndIfDirectiveTrivia(false)
                            .WithTrailingTrivia(
                                SyntaxFactory.EndOfLine("\r\n"),
                                SyntaxFactory.Whitespace("    " + "    ")
                                ))
                        ));
            }
            else
            {
                /*
                 * #if !___server___
                 *     , System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)
                 * #endif
                 */
                updatedmethod = updatedmethod.AddParameterListParameters(
                    SyntaxFactory.Parameter(
                        SyntaxFactory.Identifier("cancellationToken")
                        .WithLeadingTrivia(SyntaxFactory.Whitespace(" "))
                        .WithTrailingTrivia(SyntaxFactory.Whitespace(" "))
                        )
                    .WithLeadingTrivia(SyntaxFactory.Whitespace(" "))
                    .WithType(
                        SyntaxFactory.ParseTypeName(typeof(CancellationToken).FullName))
                    .WithLeadingTrivia(SyntaxFactory.Whitespace("    " + "    "))
                    .WithDefault(
                        SyntaxFactory.EqualsValueClause(
                            SyntaxFactory.DefaultExpression(
                                SyntaxFactory.ParseTypeName(typeof(CancellationToken).FullName)
                                )
                            .WithLeadingTrivia(SyntaxFactory.Whitespace(" "))
                            )
                        )
                    .WithLeadingTrivia(SyntaxFactory.Whitespace(" "))
                    .WithTrailingTrivia(
                        SyntaxFactory.EndOfLine("\r\n"),
                        SyntaxFactory.Trivia(
                            SyntaxFactory.EndIfDirectiveTrivia(false)
                            .WithTrailingTrivia(
                                SyntaxFactory.EndOfLine("\r\n"),
                                SyntaxFactory.Whitespace("    " + "    ")
                                ))
                        ));

                var commaToken = updatedmethod.ParameterList.ChildTokens().Where(x => x.IsKind(SyntaxKind.CommaToken)).Last();

                var newToken = commaToken.WithLeadingTrivia(
                    SyntaxFactory.Whitespace("\r\n"),
                    SyntaxFactory.Trivia(SyntaxFactory.IfDirectiveTrivia(SyntaxFactory.IdentifierName("!___server___"), false, false, false)),
                    SyntaxFactory.EndOfLine("\r\n"),
                    SyntaxFactory.Whitespace("    " + "    ")
                    );

                var newParameterList = updatedmethod.ParameterList.ReplaceToken(commaToken, newToken);

                updatedmethod = updatedmethod.ReplaceNode(updatedmethod.ParameterList, newParameterList);
            }

            return(updatedmethod);
        }