提交 8b8d4cca 编写于 作者: C CyrusNajmabadi

Simplify lambdas

上级 f8b1d566
......@@ -68,7 +68,7 @@ internal class OpenTextBufferManager : ForegroundThreadAffinitizedObject
session.UndoManager.CreateStartRenameUndoTransaction(workspace, subjectBuffer, session);
_isBufferReadOnly = new DynamicReadOnlyRegionQuery((isEdit) => !_session._isApplyingEdit);
_isBufferReadOnly = new DynamicReadOnlyRegionQuery(isEdit => !_session._isApplyingEdit);
UpdateReadOnlyRegions();
}
......
......@@ -156,7 +156,7 @@ public DiagnosticAnalyzerCategory GetAnalyzerCategory()
public override void Initialize(AnalysisContext analysisContext)
{
analysisContext.RegisterSyntaxTreeAction(
(context) =>
context =>
{
foreach (var node in AllNodes)
{
......
......@@ -173,7 +173,7 @@ protected void WaitForDocumentationComment(object content)
internal Action<object> SymbolGlyph(Glyph expectedGlyph)
{
return (content) =>
return content =>
{
var actualIcon = ((QuickInfoDisplayDeferredContent)content).SymbolGlyph;
Assert.Equal(expectedGlyph, actualIcon.Glyph);
......@@ -238,7 +238,7 @@ internal Action<object> SymbolGlyph(Glyph expectedGlyph)
string expectedText,
Tuple<string, string>[] expectedClassifications = null)
{
return (content) =>
return content =>
{
var actualContent = ((QuickInfoDisplayDeferredContent)content).TypeParameterMap.ClassifiableContent;
......@@ -255,7 +255,7 @@ internal Action<object> SymbolGlyph(Glyph expectedGlyph)
string expectedText,
Tuple<string, string>[] expectedClassifications = null)
{
return (content) =>
return content =>
{
var actualContent = ((QuickInfoDisplayDeferredContent)content).AnonymousTypes.ClassifiableContent;
......@@ -272,7 +272,7 @@ protected Action<object> NoTypeParameterMap
{
get
{
return (content) =>
return content =>
{
Assert.Equal(string.Empty, ((QuickInfoDisplayDeferredContent)content).TypeParameterMap.ClassifiableContent.GetFullText());
};
......@@ -281,7 +281,7 @@ protected Action<object> NoTypeParameterMap
protected Action<object> Usage(string expectedText, bool expectsWarningGlyph = false)
{
return (content) =>
return content =>
{
var quickInfoContent = (QuickInfoDisplayDeferredContent)content;
Assert.Equal(expectedText, quickInfoContent.UsageText.ClassifiableContent.GetFullText());
......@@ -291,7 +291,7 @@ protected Action<object> Usage(string expectedText, bool expectsWarningGlyph = f
protected Action<object> Exceptions(string expectedText)
{
return (content) =>
return content =>
{
var quickInfoContent = (QuickInfoDisplayDeferredContent)content;
Assert.Equal(expectedText, quickInfoContent.ExceptionText.ClassifiableContent.GetFullText());
......
......@@ -197,7 +197,7 @@ protected override bool TryGetNode(SyntaxNode root, TextSpan span, out SyntaxNod
return false;
}
node = ancestors.FirstOrDefault((n) => n.Span.Contains(span) && n != root && n.IsKind(SyntaxKind.ReturnStatement));
node = ancestors.FirstOrDefault(n => n.Span.Contains(span) && n != root && n.IsKind(SyntaxKind.ReturnStatement));
return node != null;
}
......
......@@ -90,7 +90,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
context.RegisterRefactoring(
new MyCodeAction(
CSharpFeaturesResources.Inline_temporary_variable,
(c) => this.InlineTemporaryAsync(document, variableDeclarator, c)));
c => this.InlineTemporaryAsync(document, variableDeclarator, c)));
}
private async Task<IEnumerable<ReferenceLocation>> GetReferencesAsync(
......
......@@ -66,7 +66,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
context.RegisterRefactoring(
new MyCodeAction(
CSharpFeaturesResources.Invert_if_statement,
(c) => InvertIfAsync(document, ifStatement, c)));
c => InvertIfAsync(document, ifStatement, c)));
}
private async Task<Document> InvertIfAsync(Document document, IfStatementSyntax ifStatement, CancellationToken cancellationToken)
......
......@@ -51,12 +51,12 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
context.RegisterRefactoring(
new MyCodeAction(
CSharpFeaturesResources.Simplify_lambda_expression,
(c) => SimplifyLambdaAsync(document, lambda, c)));
c => SimplifyLambdaAsync(document, lambda, c)));
context.RegisterRefactoring(
new MyCodeAction(
CSharpFeaturesResources.Simplify_all_occurrences,
(c) => SimplifyAllLambdasAsync(document, c)));
c => SimplifyAllLambdasAsync(document, c)));
}
private async Task<Document> SimplifyLambdaAsync(
......@@ -65,7 +65,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
CancellationToken cancellationToken)
{
var semanticDocument = await SemanticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);
var rewriter = new Rewriter(this, semanticDocument, (n) => n == lambda, cancellationToken);
var rewriter = new Rewriter(this, semanticDocument, n => n == lambda, cancellationToken);
var result = rewriter.Visit(semanticDocument.Root);
return document.WithSyntaxRoot(result);
}
......@@ -75,7 +75,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
CancellationToken cancellationToken)
{
var semanticDocument = await SemanticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);
var rewriter = new Rewriter(this, semanticDocument, (n) => true, cancellationToken);
var rewriter = new Rewriter(this, semanticDocument, n => true, cancellationToken);
var result = rewriter.Visit(semanticDocument.Root);
return document.WithSyntaxRoot(result);
}
......
......@@ -54,7 +54,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
context.RegisterRefactoring(
new MyCodeAction(
CSharpFeaturesResources.Move_declaration_near_reference,
(c) => MoveDeclarationNearReferenceAsync(document, state, c)));
c => MoveDeclarationNearReferenceAsync(document, state, c)));
}
private async Task<Document> MoveDeclarationNearReferenceAsync(Document document, State state, CancellationToken cancellationToken)
......
......@@ -146,7 +146,7 @@ private IEnumerable<CompletionItem> GetTopLevelSingleUseNames(DocumentationComme
{
var names = new HashSet<string>(new[] { SummaryTagName, RemarksTagName, ExampleTagName, CompletionListTagName });
RemoveExistingTags(parentTrivia, names, (x) => x.StartTag.Name.LocalName.ValueText);
RemoveExistingTags(parentTrivia, names, x => x.StartTag.Name.LocalName.ValueText);
return names.Select(GetItem);
}
......
......@@ -357,7 +357,7 @@ protected override bool TryGetNameParts(ExpressionSyntax expression, out IList<s
outerMostMemberAccessExpression = (ExpressionSyntax)nameOrMemberAccessExpression.Parent;
}
outerMostMemberAccessExpression = outerMostMemberAccessExpression.GetAncestorsOrThis<ExpressionSyntax>().SkipWhile((n) => n != null && n.IsKind(SyntaxKind.SimpleMemberAccessExpression)).FirstOrDefault();
outerMostMemberAccessExpression = outerMostMemberAccessExpression.GetAncestorsOrThis<ExpressionSyntax>().SkipWhile(n => n != null && n.IsKind(SyntaxKind.SimpleMemberAccessExpression)).FirstOrDefault();
if (outerMostMemberAccessExpression != null && outerMostMemberAccessExpression is InvocationExpressionSyntax)
{
generateTypeServiceStateOptions.IsEnumNotAllowed = true;
......
......@@ -40,7 +40,7 @@ protected virtual bool TryGetNode(SyntaxNode root, TextSpan span, out SyntaxNode
return false;
}
node = ancestors.FirstOrDefault((n) => n.Span.Contains(span) && n != root);
node = ancestors.FirstOrDefault(n => n.Span.Contains(span) && n != root);
return node != null;
}
}
......
......@@ -70,7 +70,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var description = documentOptions.GetOption(ExtractMethodOptions.AllowMovingDeclaration) ?
FeaturesResources.Extract_Method_plus_Local : FeaturesResources.Extract_Method;
var codeAction = new MyCodeAction(description, (c) => AddRenameAnnotationAsync(result.Document, result.InvocationNameToken, c));
var codeAction = new MyCodeAction(description, c => AddRenameAnnotationAsync(result.Document, result.InvocationNameToken, c));
var methodBlock = result.MethodDeclarationNode;
return Tuple.Create<CodeAction, string>(codeAction, methodBlock.ToString());
......
......@@ -275,7 +275,7 @@ public override bool GetUseSaferDeclarationBehavior(CancellationToken cancellati
return true;
}
var declStatement = identifier.Parent.FirstAncestorOrSelf<T>((n) => true);
var declStatement = identifier.Parent.FirstAncestorOrSelf<T>(n => true);
if (declStatement == null)
{
return true;
......
......@@ -93,7 +93,7 @@ public void AddAnalyzerProvider(IIncrementalAnalyzerProvider provider, Increment
var lazyProvider = new Lazy<IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata>(() => provider, metadata);
// update existing map for future solution crawler registration - no need for interlock but this makes add or update easier
ImmutableInterlocked.AddOrUpdate(ref _analyzerProviders, metadata.Name, (n) => ImmutableArray.Create(lazyProvider), (n, v) => v.Add(lazyProvider));
ImmutableInterlocked.AddOrUpdate(ref _analyzerProviders, metadata.Name, n => ImmutableArray.Create(lazyProvider), (n, v) => v.Add(lazyProvider));
// assert map integrity
AssertAnalyzerProviders(_analyzerProviders);
......
......@@ -82,7 +82,7 @@ class C {
class C {
void Foo() {
//[
Func<int, int> f = (x) => {
Func<int, int> f = x => {
return 2 * x;
};
//]
......
......@@ -23,7 +23,7 @@ internal static class AttributeGenerator
{
if (options.MergeAttributes)
{
var attributeNodes = attributes.OrderBy(a => a.AttributeClass.Name).Select((a) => GenerateAttribute(a, options)).WhereNotNull().ToList();
var attributeNodes = attributes.OrderBy(a => a.AttributeClass.Name).Select(a => GenerateAttribute(a, options)).WhereNotNull().ToList();
return attributeNodes.Count == 0
? default(SyntaxList<AttributeListSyntax>)
: SyntaxFactory.SingletonList(SyntaxFactory.AttributeList(
......
......@@ -144,7 +144,7 @@ public static string AsString(this IEnumerable<SyntaxTrivia> trivia)
if (trivia.Any())
{
var sb = new StringBuilder();
trivia.Select(t => t.ToFullString()).Do((s) => sb.Append(s));
trivia.Select(t => t.ToFullString()).Do(s => sb.Append(s));
return sb.ToString();
}
else
......
......@@ -93,7 +93,7 @@ private SyntaxNode GetNodeInStructuredTrivia(SyntaxNode parent)
// Syntax references to nonterminals in structured trivia should be uncommon.
// Provide more efficient implementation if that is not true
var descendantsIntersectingSpan = parent.DescendantNodes(_textSpan, descendIntoTrivia: true);
return descendantsIntersectingSpan.First((node) => node.IsKind(_kind) && node.Span == _textSpan);
return descendantsIntersectingSpan.First(node => node.IsKind(_kind) && node.Span == _textSpan);
}
}
}
......
......@@ -345,7 +345,7 @@ public static IDisposable LogBlock(FunctionId functionId, LogMessage logMessage,
var functionIds = Enum.GetValues(typeof(FunctionId)).Cast<FunctionId>();
var functionIdOptions = functionIds.ToDictionary(id => id, id => optionService.GetOption(FunctionIdOptions.GetOption(id)));
return (functionId) => functionIdOptions[functionId];
return functionId => functionIdOptions[functionId];
}
}
}
......@@ -98,7 +98,7 @@ protected virtual SyntaxNode TransformReducedNode(SyntaxNode reducedNode, Syntax
// Create a simple interval tree for simplification spans.
var spansTree = new SimpleIntervalTree<TextSpan>(TextSpanIntervalIntrospector.Instance, spans);
Func<SyntaxNodeOrToken, bool> isNodeOrTokenOutsideSimplifySpans = (nodeOrToken) =>
Func<SyntaxNodeOrToken, bool> isNodeOrTokenOutsideSimplifySpans = nodeOrToken =>
!spansTree.HasIntervalThatOverlapsWith(nodeOrToken.FullSpan.Start, nodeOrToken.FullSpan.Length);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
......@@ -219,7 +219,7 @@ protected virtual SyntaxNode TransformReducedNode(SyntaxNode reducedNode, Syntax
currentNodeOrToken = replacedParent
.ChildNodesAndTokens()
.Single((c) => c.HasAnnotation(annotation));
.Single(c => c.HasAnnotation(annotation));
}
if (isNode)
......@@ -233,7 +233,7 @@ protected virtual SyntaxNode TransformReducedNode(SyntaxNode reducedNode, Syntax
var newDocument = document.WithSyntaxRoot(newRoot);
semanticModelForReduce = await newDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
newRoot = await semanticModelForReduce.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
currentNodeOrToken = newRoot.DescendantNodes().Single((c) => c.HasAnnotation(marker));
currentNodeOrToken = newRoot.DescendantNodes().Single(c => c.HasAnnotation(marker));
}
else
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册