public override void VisitYieldStatement(YieldStatementSyntax node) { if (node.Kind() == SyntaxKind.YieldBreakStatement) { IndentWrite("return"); NewLine(); } if (node.Kind() == SyntaxKind.YieldReturnStatement) { IndentWrite("yield ("); Visit(node.Expression); Write(")"); NewLine(); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, YieldStatementSyntax yieldStatement) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.CallToMethod) && yieldStatement.Kind() == SyntaxKind.YieldReturnStatement) { ExpressionSyntax expression = yieldStatement.Expression; if (expression?.IsMissing == false && expression.Span.Contains(context.Span)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); (ISymbol memberSymbol, ITypeSymbol memberTypeSymbol) = ReturnExpressionRefactoring.GetContainingSymbolAndType(expression, semanticModel, context.CancellationToken); if (memberSymbol != null && (memberTypeSymbol is INamedTypeSymbol namedTypeSymbol) && namedTypeSymbol.SpecialType != SpecialType.System_Collections_IEnumerable && namedTypeSymbol.OriginalDefinition.IsIEnumerableOfT()) { ITypeSymbol argumentSymbol = namedTypeSymbol.TypeArguments[0]; ITypeSymbol expressionTypeSymbol = semanticModel.GetTypeSymbol(expression, context.CancellationToken); if (argumentSymbol != expressionTypeSymbol) { ModifyExpressionRefactoring.ComputeRefactoring( context, expression, argumentSymbol, semanticModel, addCastExpression: false); } } } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertReturnToIf) && (context.Span.IsEmptyAndContainedInSpan(yieldStatement.YieldKeyword) || context.Span.IsEmptyAndContainedInSpan(yieldStatement.ReturnOrBreakKeyword) || context.Span.IsBetweenSpans(yieldStatement))) { await ConvertReturnToIfRefactoring.ConvertYieldReturnToIfElse.ComputeRefactoringAsync(context, yieldStatement).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseListInsteadOfYield) && yieldStatement.IsYieldReturn() && context.Span.IsEmptyAndContainedInSpan(yieldStatement.YieldKeyword)) { SyntaxNode declaration = yieldStatement.FirstAncestor(SyntaxKind.MethodDeclaration, SyntaxKind.LocalFunctionStatement, SyntaxKind.GetAccessorDeclaration, ascendOutOfTrivia: false); Debug.Assert(declaration != null); if (declaration != null) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); UseListInsteadOfYieldRefactoring.ComputeRefactoring(context, declaration, semanticModel); } } }
public override void VisitYieldStatement(YieldStatementSyntax node) { SyntaxKind kind = node.Kind(); if (kind == SyntaxKind.YieldReturnStatement) { if (IsSearchingForYieldReturn) { if (_span == null || _span.Value.Contains(node.FullSpan)) { _success = true; } } } else if (kind == SyntaxKind.YieldBreakStatement) { if (IsSearchingForYieldBreak) { if (_span == null || _span.Value.Contains(node.FullSpan)) { _success = true; } } } }
public override SyntaxNode VisitYieldStatement(YieldStatementSyntax node) { SyntaxToken keyword = node.ReturnOrBreakKeyword; ExpressionSyntax expression = node.Expression; SyntaxKind kind = node.Kind(); if (kind == SyntaxKind.YieldReturnStatement) { ParenthesizedExpressionSyntax parenthesizedExpression = expression .Parenthesize(moveTrivia: true) .WithSimplifierAnnotation(); CastExpressionSyntax castExpression = CastExpression( _typeSymbol.ToMinimalTypeSyntax(_semanticModel, node.SpanStart), parenthesizedExpression); InvocationExpressionSyntax invocationExpression = SimpleMemberInvocationExpression( _identifierName, _addName, Argument(castExpression.WithSimplifierAnnotation())); return(ExpressionStatement(invocationExpression.WithoutTrivia()) .WithTriviaFrom(node) .AppendToLeadingTrivia(node.DescendantTrivia(TextSpan.FromBounds(keyword.Span.End, expression.Span.Start)))); } else if (kind == SyntaxKind.YieldBreakStatement) { return(ReturnStatement( Token(keyword.LeadingTrivia, SyntaxKind.ReturnKeyword, keyword.TrailingTrivia), _identifierName, node.SemicolonToken)); } Debug.Fail(node.Kind().ToString()); return(base.VisitYieldStatement(node)); }
public override AccessorOrMutator VisitYieldStatement(YieldStatementSyntax node) { switch (node.Kind()) { case SyntaxKind.YieldReturnStatement: var yielded = Visit(node.Expression); HandleYield(yielded); break; case SyntaxKind.YieldBreakStatement: throw new SymbolicExplorationException("YieldBreak encountered as normal statement but it should be a terminator"); default: throw new SyntaxErrorException("Unsupported syntax: " + node); } return(null); }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, YieldStatementSyntax yieldStatement) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.CallToMethod) && yieldStatement.Kind() == SyntaxKind.YieldReturnStatement) { ExpressionSyntax expression = yieldStatement.Expression; if (expression?.IsMissing == false && expression.Span.Contains(context.Span)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); (ISymbol memberSymbol, ITypeSymbol memberTypeSymbol) = ReturnExpressionRefactoring.GetContainingSymbolAndType(expression, semanticModel, context.CancellationToken); if (memberSymbol != null && (memberTypeSymbol is INamedTypeSymbol namedTypeSymbol) && namedTypeSymbol.SpecialType != SpecialType.System_Collections_IEnumerable && namedTypeSymbol.OriginalDefinition.IsIEnumerableOfT()) { ITypeSymbol argumentSymbol = namedTypeSymbol.TypeArguments[0]; ITypeSymbol expressionTypeSymbol = semanticModel.GetTypeSymbol(expression, context.CancellationToken); if (argumentSymbol != expressionTypeSymbol) { ModifyExpressionRefactoring.ComputeRefactoring( context, expression, argumentSymbol, semanticModel, addCastExpression: false); } } } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceStatementWithIfElse) && (context.Span.IsEmptyAndContainedInSpan(yieldStatement.YieldKeyword) || context.Span.IsEmptyAndContainedInSpan(yieldStatement.ReturnOrBreakKeyword) || context.Span.IsBetweenSpans(yieldStatement))) { await ReplaceStatementWithIfStatementRefactoring.ReplaceYieldReturnWithIfElse.ComputeRefactoringAsync(context, yieldStatement).ConfigureAwait(false); } }
public override void VisitYieldStatement(YieldStatementSyntax node) { switch (node.Kind()) { case SyntaxKind.YieldReturnStatement: _currentBlock.Nodes.Add(node); break; case SyntaxKind.YieldBreakStatement: var remainderBlock = new BasicBlock(_currentBlock.Terminator); _currentBlock.Terminator = new YieldBreakTerminator(); _currentBlock = remainderBlock; break; default: base.VisitYieldStatement(node); break; } }
public override void VisitYieldStatement(YieldStatementSyntax node) { SyntaxKind kind = node.Kind(); Debug.Assert(kind.Is(SyntaxKind.YieldBreakStatement, SyntaxKind.YieldReturnStatement), kind.ToString()); if (kind == SyntaxKind.YieldReturnStatement) { if (SearchForYieldReturn) { YieldStatement = node; } } else if (kind == SyntaxKind.YieldBreakStatement) { if (SearchForYieldBreak) { YieldStatement = node; } } }
public override void VisitYieldStatement(YieldStatementSyntax node) { SyntaxKind kind = node.Kind(); if (kind == SyntaxKind.YieldReturnStatement) { if (IsSearchingForYieldReturn && _span?.Contains(node.FullSpan) != false) { _success = true; } } else if (kind == SyntaxKind.YieldBreakStatement) { if (IsSearchingForYieldBreak && _span?.Contains(node.FullSpan) != false) { _success = true; } } }