Created
November 5, 2014 18:08
-
-
Save g0t4/a97bcc64dff4ac9394ef to your computer and use it in GitHub Desktop.
Building an QueryAnalysis instances that contain the results of compiling and executing the query, then using this to find rules and rule violations
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
private QueryAnalysis[] GetQueriesToAnalyze() | |
{ | |
var queries = _Project.GetRulesInProjectFileAndInRuleFilesAndDeclaredInSourceCode(_Analysis.RulesExtractedFromCode).RootParent; | |
var activeQueries = queries.GetActiveQueries(); | |
var compiledQueriesByQueryString = GetCompiledQueriesByQueryString(activeQueries); | |
var justMyCode = queries.ComputeJustMyCode(_Analysis.CodeBase); | |
return activeQueries | |
.Select(query => new QueryAnalysis(query, compiledQueriesByQueryString[query.QueryString], justMyCode, _Project)) | |
.ToArray(); | |
} | |
private Dictionary<string, IQueryCompiled> GetCompiledQueriesByQueryString(IEnumerable<IQuery> activeQueries) | |
{ | |
var compareContext = GetCompareContext(); | |
// todo duplicate queries? | |
if (compareContext != null) | |
{ | |
return activeQueries | |
.Select(q => q.QueryString) | |
.CompileMany(compareContext) | |
.ToDictionary(c => c.OriginalQueryString); | |
} | |
return activeQueries | |
.Select(q => q.QueryString) | |
.CompileMany(_Analysis.CodeBase) | |
.ToDictionary(c => c.OriginalQueryString); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment