Browse Source

Replace FindReferences with LocalReferenceFinder in ForControlVariableNotModifiedIssue.

Simon Lindgren 14 years ago
parent
commit
6458118ceb
  1. 20
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ForControlVariableNotModifiedIssue.cs

20
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ForControlVariableNotModifiedIssue.cs

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

Loading…
Cancel
Save