Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Fixed some exceptions in RedundantCheckBeforeAssignmentAnalyzer + Cod…
Browse files Browse the repository at this point in the history
…eFix.
  • Loading branch information
Rpinski committed Nov 3, 2015
1 parent c39fc90 commit 70b1cc4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Expand Up @@ -124,7 +124,7 @@ static bool CheckConditionAndAssignment(SyntaxNodeAnalysisContext nodeContext, A
}
else
{
if (!assignmentValue.Equals(condRightSymbol))
if ((assignmentValue == null) || !assignmentValue.Equals(condRightSymbol))
return false;
}
return true;
Expand All @@ -141,7 +141,7 @@ static bool CheckConditionAndAssignment(SyntaxNodeAnalysisContext nodeContext, A
}
else
{
if (!assignmentValue.Equals(condLeftSymbol))
if ((assignmentValue == null) || !assignmentValue.Equals(condLeftSymbol))
return false;
}
return true;
Expand Down
Expand Up @@ -49,14 +49,12 @@ public async override Task RegisterCodeFixesAsync(CodeFixContext context)
if (expression == null)
return;

context.RegisterCodeFix(CodeAction.Create("Remove redundant check", async token => {
var editor = await DocumentEditor.CreateAsync(document, cancellationToken);
expression = expression
.WithOrderedTriviaFromSubTree(ifStatement)
.WithAdditionalAnnotations(Formatter.Annotation);
editor.ReplaceNode(ifStatement, expression);
return editor.GetChangedDocument();
}, string.Empty), diagnostic);
expression = expression
.WithOrderedTriviaFromSubTree(ifStatement)
.WithAdditionalAnnotations(Formatter.Annotation);
var newRoot = root.ReplaceNode(ifStatement, expression);

context.RegisterCodeFix(CodeActionFactory.Create(node.Span, diagnostic.Severity, "Remove redundant check", document.WithSyntaxRoot(newRoot)), diagnostic);
}
}
}

0 comments on commit 70b1cc4

Please sign in to comment.