void CollectIssues(AstNode variableDecl, AstNode rootNode, LocalResolveResult resolveResult) { if (resolveResult == null) { return; } var type = resolveResult.Type; var typeDef = type.GetDefinition(); if (typeDef == null || (typeDef.KnownTypeCode != KnownTypeCode.IEnumerable && typeDef.KnownTypeCode != KnownTypeCode.IEnumerableOfT)) { return; } FindReferences(variableDecl, rootNode, resolveResult.Variable); var statements = AnalysisStatementCollector.Collect(variableDecl); var builder = new VariableReferenceGraphBuilder(ctx); foreach (var statement in statements) { var vrNode = builder.Build(statement, references, refStatements, ctx); FindMultipleEnumeration(vrNode); } foreach (var lambda in lambdaExpressions) { var vrNode = builder.Build(references, ctx.Resolver, (Expression)lambda.Body); FindMultipleEnumeration(vrNode); } }
void CollectIssues(AstNode variableDecl, BlockStatement rootStatement, LocalResolveResult resolveResult) { if (rootStatement == null || resolveResult == null) { return; } var references = new HashSet <AstNode> (); var refStatements = new HashSet <Statement> (); var usedInLambda = false; refFinder.FindLocalReferences(resolveResult.Variable, ctx.UnresolvedFile, unit, ctx.Compilation, (astNode, rr) => { if (usedInLambda || astNode == variableDecl) { return; } var parent = astNode.Parent; while (!(parent == null || parent is Statement || parent is LambdaExpression)) { parent = parent.Parent; } if (parent == null) { return; } var statement = parent as Statement; if (statement != null) { references.Add(astNode); refStatements.Add(statement); } while (parent != null && parent != rootStatement) { if (parent is LambdaExpression || parent is AnonymousMethodExpression) { usedInLambda = true; break; } parent = parent.Parent; } }, ctx.CancellationToken); // stop analyzing if the variable is used in any lambda expression or anonymous method if (usedInLambda) { return; } var startNode = VariableReferenceGraphBuilder.Build(rootStatement, references, refStatements, ctx); var variableInitializer = variableDecl as VariableInitializer; if (variableInitializer != null && !variableInitializer.Initializer.IsNull) { startNode.References.Insert(0, variableInitializer); } ProcessNodes(startNode); }