/// <summary> /// Factory method for class <see cref="LocalDeclarationStatementASTWalker"/>. /// </summary> /// <param name="node"><see cref="CSharpSyntaxNode"/> Used to initialize the walker.</param> /// <param name="semanticModel">The semantic model.</param> /// <returns></returns> public static LocalDeclarationStatementASTWalker Create(CSharpSyntaxNode node, SemanticModel semanticModel = null) { // TODO: Use TranslationUnitFactory in order to have AST walkers decoupled from helpers // via factories (which will be using helpers) var variableDeclaration = new VariableDeclaration((node as LocalDeclarationStatementSyntax).Declaration, semanticModel); ExpressionSyntax expression = variableDeclaration.Expressions[0]; // This can contain null, so need to act accordingly ITranslationUnit expressionTranslationUnit = expression == null ? null : new ExpressionTranslationUnitBuilder(expression, semanticModel).Build(); var variableDeclarationTranslationUnit = VariableDeclarationTranslationUnit.Create( TypeIdentifierTranslationUnit.Create(variableDeclaration.Type), IdentifierTranslationUnit.Create(variableDeclaration.Names[0]), expressionTranslationUnit); var statement = LocalDeclarationStatementTranslationUnit.Create(variableDeclarationTranslationUnit); return new LocalDeclarationStatementASTWalker(node, statement, semanticModel); }
/// <summary> /// Initializes a new instance of the <see cref="FieldDeclaration"/> class. /// </summary> /// <param name="syntaxNode"></param> /// <param name="semanticModel"></param> public FieldDeclaration(FieldDeclarationSyntax syntaxNode, SemanticModel semanticModel) : base(syntaxNode, semanticModel) { this.variableDeclaration = new VariableDeclaration(syntaxNode.Declaration); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override void VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) { base.VisitLocalDeclarationStatement(node); var variableDeclaration = new VariableDeclaration(node.Declaration); var variableDeclarationTranslationUnit = VariableDeclarationTranslationUnit.Create( IdentifierTranslationUnit.Create(variableDeclaration.Type), IdentifierTranslationUnit.Create(variableDeclaration.Name)); this.methodDeclaration.AddStatement(variableDeclarationTranslationUnit); this.VisitStatement(node); }