Skip to content

Commit b0b3e9c

Browse files
committed
alligned the load behaviour of the ICustomDeclarationLoader implementations
1 parent f572046 commit b0b3e9c

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

Rubberduck.Parsing/Symbols/AliasDeclarations.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ public IReadOnlyList<Declaration> Load()
5353

5454
private IReadOnlyList<Declaration> AddAliasDeclarations()
5555
{
56-
UpdateAliasFunctionModulesFromReferencedProjects(_state);
56+
var finder = new DeclarationFinder(_state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });
57+
58+
if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
59+
{
60+
return new List<Declaration>();
61+
}
62+
63+
UpdateAliasFunctionModulesFromReferencedProjects(finder);
5764

5865
if (NoReferenceToProjectContainingTheFunctionAliases())
5966
{
@@ -67,10 +74,8 @@ private IReadOnlyList<Declaration> AddAliasDeclarations()
6774
return functionAliases;
6875
}
6976

70-
private void UpdateAliasFunctionModulesFromReferencedProjects(RubberduckParserState state)
77+
private void UpdateAliasFunctionModulesFromReferencedProjects(DeclarationFinder finder)
7178
{
72-
var finder = new DeclarationFinder(state.AllDeclarations, new CommentNode[] {}, new IAnnotation[] {});
73-
7479
var vba = finder.FindProject("VBA");
7580
if (vba == null)
7681
{
@@ -86,6 +91,19 @@ private void UpdateAliasFunctionModulesFromReferencedProjects(RubberduckParserSt
8691
}
8792

8893

94+
private static bool WeHaveAlreadyLoadedTheDeclarationsBefore(DeclarationFinder finder)
95+
{
96+
return ThereIsAGlobalBuiltInErrVariableDeclaration(finder);
97+
}
98+
99+
private static bool ThereIsAGlobalBuiltInErrVariableDeclaration(DeclarationFinder finder)
100+
{
101+
return finder.MatchName(Grammar.Tokens.Err).Any(declaration => declaration.IsBuiltIn
102+
&& declaration.DeclarationType == DeclarationType.Variable
103+
&& declaration.Accessibility == Accessibility.Global);
104+
}
105+
106+
89107
private bool NoReferenceToProjectContainingTheFunctionAliases()
90108
{
91109
return _conversionModule == null;

Rubberduck.Parsing/Symbols/DebugDeclarations.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public IReadOnlyList<Declaration> Load()
2121
{
2222
var finder = new DeclarationFinder(_state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });
2323

24-
if (ThereIsAGlobalBuiltInErrVariableDeclaration(finder))
24+
if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
2525
{
2626
return new List<Declaration>();
2727
}
@@ -37,9 +37,14 @@ public IReadOnlyList<Declaration> Load()
3737
return LoadDebugDeclarations(vba);
3838
}
3939

40+
private static bool WeHaveAlreadyLoadedTheDeclarationsBefore(DeclarationFinder finder)
41+
{
42+
return ThereIsAGlobalBuiltInErrVariableDeclaration(finder);
43+
}
44+
4045
private static bool ThereIsAGlobalBuiltInErrVariableDeclaration(DeclarationFinder finder)
4146
{
42-
return finder.MatchName(Tokens.Err).Any(declaration => declaration.IsBuiltIn
47+
return finder.MatchName(Grammar.Tokens.Err).Any(declaration => declaration.IsBuiltIn
4348
&& declaration.DeclarationType == DeclarationType.Variable
4449
&& declaration.Accessibility == Accessibility.Global);
4550
}

Rubberduck.Parsing/Symbols/SpecialFormDeclarations.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,51 @@ namespace Rubberduck.Parsing.Symbols
1010
{
1111
public class SpecialFormDeclarations : ICustomDeclarationLoader
1212
{
13-
private readonly DeclarationFinder _finder;
13+
private readonly RubberduckParserState _state;
1414

1515
public SpecialFormDeclarations(RubberduckParserState state)
1616
{
17-
_finder = new DeclarationFinder(state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });
17+
_state = state;
1818
}
1919

2020

2121
public IReadOnlyList<Declaration> Load()
2222
{
23-
if (ThereIsAGlobalBuiltInErrVariableDeclaration(_finder))
23+
var finder = new DeclarationFinder(_state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });
24+
25+
if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
2426
{
2527
return new List<Declaration>();
2628
}
2729

28-
var vba = _finder.FindProject("VBA");
30+
var vba = finder.FindProject("VBA");
2931
if (vba == null)
3032
{
3133
// If the VBA project is null, we haven't loaded any COM references;
3234
// we're in a unit test and the mock project didn't setup any references.
3335
return new List<Declaration>();
3436
}
3537

36-
var informationModule = _finder.FindStdModule("Information", vba, true);
37-
Debug.Assert(informationModule != null, "We expect the information module to exist in the VBA project.");
38+
var informationModule = finder.FindStdModule("Information", vba, true);
39+
if (informationModule == null)
40+
{
41+
//This should not happen under normal circumstances.
42+
//Most probably, we are in a test that only addded parts of the VBA project.
43+
return new List<Declaration>();
44+
}
3845

3946
return LoadSpecialFormDeclarations(informationModule);
4047
}
4148

49+
50+
private static bool WeHaveAlreadyLoadedTheDeclarationsBefore(DeclarationFinder finder)
51+
{
52+
return ThereIsAGlobalBuiltInErrVariableDeclaration(finder);
53+
}
54+
4255
private static bool ThereIsAGlobalBuiltInErrVariableDeclaration(DeclarationFinder finder)
4356
{
44-
return finder.MatchName(Tokens.Err).Any(declaration => declaration.IsBuiltIn
57+
return finder.MatchName(Grammar.Tokens.Err).Any(declaration => declaration.IsBuiltIn
4558
&& declaration.DeclarationType == DeclarationType.Variable
4659
&& declaration.Accessibility == Accessibility.Global);
4760
}

0 commit comments

Comments
 (0)