Skip to content

Instantly share code, notes, and snippets.

@g0t4
Created November 5, 2014 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g0t4/a97bcc64dff4ac9394ef to your computer and use it in GitHub Desktop.
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
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