Skip to content
Permalink
Browse files

Reduce searched declarations in CodeMetricsAnalyst

  • Loading branch information...
Vogel612 committed Nov 25, 2017
1 parent 44dfb16 commit fcf9d424adcd39ae8803c2fe35b050d293dff8f3
@@ -54,7 +54,7 @@ private class CodeMetricsListener : VBAParserBaseListener
private readonly DeclarationFinder _finder;
private readonly IIndenterSettings _indenterSettings;

private Declaration currentMember;
private Declaration _currentMember;
private List<CodeMetricsResult> _results = new List<CodeMetricsResult>();
private List<CodeMetricsResult> _moduleResults = new List<CodeMetricsResult>();

@@ -76,7 +76,7 @@ public override void EnterEndOfLine([NotNull] VBAParser.EndOfLineContext context
var followingWhitespace = context.whiteSpace().LastOrDefault();
followingIndentationLevel = IndentationLevelFromWhitespace(followingWhitespace);
}
(currentMember == null ? _moduleResults : _results).Add(new CodeMetricsResult(1, 0, followingIndentationLevel));
(_currentMember == null ? _moduleResults : _results).Add(new CodeMetricsResult(1, 0, followingIndentationLevel));
}

public override void EnterIfStmt([NotNull] VBAParser.IfStmtContext context)
@@ -109,7 +109,7 @@ public override void EnterCaseClause([NotNull] VBAParser.CaseClauseContext conte
public override void EnterSubStmt([NotNull] VBAParser.SubStmtContext context)
{
_results.Add(new CodeMetricsResult(0, 1, 0));
currentMember = _finder.DeclarationsWithType(DeclarationType.Procedure).Where(d => d.Context == context).First();
_currentMember = _finder.UserDeclarations(DeclarationType.Procedure).Where(d => d.Context == context).First();
}

public override void ExitSubStmt([NotNull] VBAParser.SubStmtContext context)
@@ -120,7 +120,7 @@ public override void ExitSubStmt([NotNull] VBAParser.SubStmtContext context)
public override void EnterFunctionStmt([NotNull] VBAParser.FunctionStmtContext context)
{
_results.Add(new CodeMetricsResult(0, 1, 0));
currentMember = _finder.DeclarationsWithType(DeclarationType.Function).Where(d => d.Context == context).First();
_currentMember = _finder.UserDeclarations(DeclarationType.Function).Where(d => d.Context == context).First();
}

public override void ExitFunctionStmt([NotNull] VBAParser.FunctionStmtContext context)
@@ -131,7 +131,7 @@ public override void ExitFunctionStmt([NotNull] VBAParser.FunctionStmtContext co
public override void EnterPropertyGetStmt([NotNull] VBAParser.PropertyGetStmtContext context)
{
_results.Add(new CodeMetricsResult(0, 1, 0));
currentMember = _finder.DeclarationsWithType(DeclarationType.PropertyGet).Where(d => d.Context == context).First();
_currentMember = _finder.UserDeclarations(DeclarationType.PropertyGet).Where(d => d.Context == context).First();
}

public override void ExitPropertyGetStmt([NotNull] VBAParser.PropertyGetStmtContext context)
@@ -142,7 +142,7 @@ public override void ExitPropertyGetStmt([NotNull] VBAParser.PropertyGetStmtCont
public override void EnterPropertyLetStmt([NotNull] VBAParser.PropertyLetStmtContext context)
{
_results.Add(new CodeMetricsResult(0, 1, 0));
currentMember = _finder.DeclarationsWithType(DeclarationType.PropertyLet).Where(d => d.Context == context).First();
_currentMember = _finder.UserDeclarations(DeclarationType.PropertyLet).Where(d => d.Context == context).First();
}

public override void ExitPropertyLetStmt([NotNull] VBAParser.PropertyLetStmtContext context)
@@ -153,7 +153,7 @@ public override void ExitPropertyLetStmt([NotNull] VBAParser.PropertyLetStmtCont
public override void EnterPropertySetStmt([NotNull] VBAParser.PropertySetStmtContext context)
{
_results.Add(new CodeMetricsResult(0, 1, 0));
currentMember = _finder.DeclarationsWithType(DeclarationType.PropertySet).Where(d => d.Context == context).First();
_currentMember = _finder.UserDeclarations(DeclarationType.PropertySet).Where(d => d.Context == context).First();
}

public override void ExitPropertySetStmt([NotNull] VBAParser.PropertySetStmtContext context)
@@ -179,9 +179,9 @@ private int IndentationLevelFromWhitespace(VBAParser.WhiteSpaceContext wsContext

private void ExitMeasurableMember()
{
_memberResults.Add(new MemberMetricsResult(currentMember, _results));
_memberResults.Add(new MemberMetricsResult(_currentMember, _results));
_results = new List<CodeMetricsResult>(); // reinitialize to drop results
currentMember = null;
_currentMember = null;
}

internal ModuleMetricsResult GetMetricsResult(QualifiedModuleName qmn)
@@ -9,7 +9,7 @@
namespace RubberduckTests.Stats
{
[TestClass]
public class ParseTreeMetricsAnalystTests
public class CodeMetricsAnalystTests
{
private CodeMetricsAnalyst cut;

0 comments on commit fcf9d42

Please sign in to comment.
You can’t perform that action at this time.