|
|
|
|
@ -26,7 +26,6 @@
@@ -26,7 +26,6 @@
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using ICSharpCode.NRefactory.CSharp.Resolver; |
|
|
|
|
using ICSharpCode.NRefactory.PatternMatching; |
|
|
|
|
using ICSharpCode.NRefactory.Semantics; |
|
|
|
|
|
|
|
|
|
@ -39,24 +38,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -39,24 +38,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
IssueMarker = IssueMarker.Underline)] |
|
|
|
|
public class ForControlVariableNotModifiedIssue : ICodeIssueProvider |
|
|
|
|
{ |
|
|
|
|
static FindReferences refFinder = new FindReferences (); |
|
|
|
|
|
|
|
|
|
public IEnumerable<CodeIssue> GetIssues (BaseRefactoringContext context) |
|
|
|
|
{ |
|
|
|
|
var unit = context.RootNode as SyntaxTree; |
|
|
|
|
if (unit == null) |
|
|
|
|
return Enumerable.Empty<CodeIssue> (); |
|
|
|
|
|
|
|
|
|
return new GatherVisitor (context, unit).GetIssues (); |
|
|
|
|
return new GatherVisitor (context).GetIssues (); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class GatherVisitor : GatherVisitorBase |
|
|
|
|
{ |
|
|
|
|
SyntaxTree unit; |
|
|
|
|
public GatherVisitor (BaseRefactoringContext ctx, SyntaxTree unit) |
|
|
|
|
LocalReferenceFinder referenceFinder; |
|
|
|
|
|
|
|
|
|
public GatherVisitor (BaseRefactoringContext ctx) |
|
|
|
|
: base (ctx) |
|
|
|
|
{ |
|
|
|
|
this.unit = unit; |
|
|
|
|
this.referenceFinder = new LocalReferenceFinder(ctx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static VariableInitializer GetControlVariable(VariableDeclarationStatement variableDecl, |
|
|
|
|
@ -112,7 +106,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -112,7 +106,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
var modified = false; |
|
|
|
|
refFinder.FindLocalReferences (localResolveResult.Variable, ctx.UnresolvedFile, unit, ctx.Compilation, |
|
|
|
|
referenceFinder.FindReferences (forStatement, localResolveResult.Variable, |
|
|
|
|
(node, resolveResult) => |
|
|
|
|
{ |
|
|
|
|
if (modified) |
|
|
|
|
@ -129,7 +123,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -129,7 +123,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
|
|
|
|
|
var assignment = node.Parent as AssignmentExpression; |
|
|
|
|
modified = assignment != null && assignment.Left == node; |
|
|
|
|
}, ctx.CancellationToken); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (!modified) |
|
|
|
|
AddIssue (controlVariable.NameToken, |
|
|
|
|
|