public SyntaxList <StatementSyntax> ConvertBody(CSS.BlockSyntax body, CSS.ArrowExpressionClauseSyntax expressionBody, bool hasReturnType, MethodBodyExecutableStatementVisitor iteratorState = null) { if (body != null) { return(ConvertStatements(body.Statements, iteratorState)); } if (expressionBody != null) { var convertedBody = expressionBody.Expression.Accept(_nodesVisitor); if (convertedBody is ExpressionSyntax convertedBodyExpression) { convertedBody = hasReturnType ? (ExecutableStatementSyntax)SyntaxFactory.ReturnStatement(convertedBodyExpression) : SyntaxFactory.ExpressionStatement(convertedBodyExpression); } return(SyntaxFactory.SingletonList((StatementSyntax)convertedBody)); } return(SyntaxFactory.List <StatementSyntax>()); }
public override void VisitBlock(Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax node) { cancellationToken.ThrowIfCancellationRequested(); AddFolding(node.OpenBraceToken, node.CloseBraceToken, node.Parent is MemberDeclarationSyntax ? FoldType.Member : FoldType.Undefined); base.VisitBlock(node); }
public override void VisitBlock(Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax node) { context.CancellationToken.ThrowIfCancellationRequested(); base.VisitBlock(node); }
public static glsl.BlockSyntax Translate(this cs.BlockSyntax node) { var body = new glsl.BlockSyntax(); return(body.Update(node.OpenBraceToken, node.Statements.Translate(), node.CloseBraceToken)); }
private static SyntaxList <VBS.StatementSyntax> WithConvertedTrivia(this SyntaxList <VBS.StatementSyntax> vbStatements, CSS.BlockSyntax csBlock) { var last = csBlock.ChildNodesAndTokens().LastOrDefault(); if (last != null) { if (last.IsKind(CS.SyntaxKind.CloseBraceToken)) { var lastToken = last.AsToken(); var vbLastTriviaList = ConvertTriviaList(lastToken.LeadingTrivia); var vbOldLast = vbStatements.Last(); var vbNewLast = vbOldLast.WithTrailingTrivia(vbOldLast.GetTrailingTrivia().AddRange(vbLastTriviaList)); vbStatements = vbStatements.Replace(vbOldLast, vbNewLast); } else if (last.IsKind(CS.SyntaxKind.Block)) { var lastBlock = last.AsNode(); var vbLastTriviaList = ConvertTriviaList(lastBlock.GetLastToken().LeadingTrivia); var vbOldLast = vbStatements.Last(); var vbNewLast = vbOldLast.WithTrailingTrivia(vbLastTriviaList); vbStatements = vbStatements.Replace(vbOldLast, vbNewLast); } } return(vbStatements); }
private static bool IsInBody(int position, BlockSyntax blockOpt, ArrowExpressionClauseSyntax exprOpt, SyntaxToken semiOpt) { return(IsInExpressionBody(position, exprOpt, semiOpt) || IsInBlock(position, blockOpt)); }
/// <summary> /// A position is considered to be inside a block if it is on or after /// the open brace and strictly before the close brace. /// </summary> internal static bool IsInBlock(int position, BlockSyntax blockOpt) { return(blockOpt != null && IsBeforeToken(position, blockOpt, blockOpt.CloseBraceToken)); }
public AccessorDeclarationSyntax Update(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken keyword, BlockSyntax body, SyntaxToken semicolonToken) => Update(attributeLists, modifiers, keyword, body, expressionBody: null, semicolonToken);
public LocalFunctionStatementSyntax Update(SyntaxTokenList modifiers, TypeSyntax returnType, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax body, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken) { return(Update(attributeLists: default, modifiers, returnType, identifier, typeParameterList, parameterList, constraintClauses, body, expressionBody, semicolonToken));
public CheckedStatementSyntax Update(SyntaxToken keyword, BlockSyntax block) => Update(attributeLists: default, keyword, block);