Created
September 17, 2012 19:34
-
-
Save fekberg/3739296 to your computer and use it in GitHub Desktop.
Listing 10.15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxNode node, CancellationToken cancellationToken) | |
| { | |
| if (node.GetType() != typeof(LocalDeclarationStatementSyntax)) return null; | |
| var localDeclaration = (LocalDeclarationStatementSyntax)node; | |
| var semanticModel = document.GetSemanticModel(cancellationToken); | |
| var containingBlock = localDeclaration.FirstAncestorOrSelf<BlockSyntax>(); | |
| if (containingBlock == null) return null; | |
| var dataFlowAnalysis = semanticModel.AnalyzeDataFlow(containingBlock); | |
| var variable = localDeclaration.Declaration.Variables.First(); | |
| var symbol = semanticModel.GetDeclaredSymbol(variable); | |
| if (dataFlowAnalysis.ReadInside.Contains(symbol)) return null; | |
| return new[] { new CodeIssue(CodeIssueKind.Warning, localDeclaration.Span, string.Format("Variable {0} is declared but never used", variable.Identifier)) }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment