Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions Rubberduck.Parsing/Symbols/AliasDeclarations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ public IReadOnlyList<Declaration> Load()

private IReadOnlyList<Declaration> AddAliasDeclarations()
{
UpdateAliasFunctionModulesFromReferencedProjects(_state);
var finder = new DeclarationFinder(_state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });

if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
{
return new List<Declaration>();
}

UpdateAliasFunctionModulesFromReferencedProjects(finder);

if (NoReferenceToProjectContainingTheFunctionAliases())
{
Expand All @@ -70,10 +77,8 @@ private IReadOnlyList<Declaration> AddAliasDeclarations()
return functionAliases.Concat<Declaration>(PropertyGetDeclarations()).ToList();
}

private void UpdateAliasFunctionModulesFromReferencedProjects(RubberduckParserState state)
private void UpdateAliasFunctionModulesFromReferencedProjects(DeclarationFinder finder)
{
var finder = new DeclarationFinder(state.AllDeclarations, new CommentNode[] {}, new IAnnotation[] {});

var vba = finder.FindProject("VBA");
if (vba == null)
{
Expand All @@ -90,6 +95,19 @@ private void UpdateAliasFunctionModulesFromReferencedProjects(RubberduckParserSt
}


private static bool WeHaveAlreadyLoadedTheDeclarationsBefore(DeclarationFinder finder)
{
return ThereIsAGlobalBuiltInErrVariableDeclaration(finder);
}

private static bool ThereIsAGlobalBuiltInErrVariableDeclaration(DeclarationFinder finder)
{
return finder.MatchName(Grammar.Tokens.Err).Any(declaration => declaration.IsBuiltIn
&& declaration.DeclarationType == DeclarationType.Variable
&& declaration.Accessibility == Accessibility.Global);
}


private bool NoReferenceToProjectContainingTheFunctionAliases()
{
return _conversionModule == null;
Expand Down
9 changes: 7 additions & 2 deletions Rubberduck.Parsing/Symbols/DebugDeclarations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IReadOnlyList<Declaration> Load()
{
var finder = new DeclarationFinder(_state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });

if (ThereIsAGlobalBuiltInErrVariableDeclaration(finder))
if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
{
return new List<Declaration>();
}
Expand All @@ -37,9 +37,14 @@ public IReadOnlyList<Declaration> Load()
return LoadDebugDeclarations(vba);
}

private static bool WeHaveAlreadyLoadedTheDeclarationsBefore(DeclarationFinder finder)
{
return ThereIsAGlobalBuiltInErrVariableDeclaration(finder);
}

private static bool ThereIsAGlobalBuiltInErrVariableDeclaration(DeclarationFinder finder)
{
return finder.MatchName(Tokens.Err).Any(declaration => declaration.IsBuiltIn
return finder.MatchName(Grammar.Tokens.Err).Any(declaration => declaration.IsBuiltIn
&& declaration.DeclarationType == DeclarationType.Variable
&& declaration.Accessibility == Accessibility.Global);
}
Expand Down
18 changes: 18 additions & 0 deletions Rubberduck.Parsing/Symbols/DeclarationFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ public Declaration FindStdModule(string name, Declaration parent = null, bool in
return result;
}

public Declaration FindClassModule(string name, Declaration parent = null, bool includeBuiltIn = false)
{
Declaration result = null;
try
{
var matches = MatchName(name);
result = matches.SingleOrDefault(declaration => declaration.DeclarationType.HasFlag(DeclarationType.ClassModule)
&& (parent == null || parent.Equals(declaration.ParentDeclaration))
&& (includeBuiltIn || !declaration.IsBuiltIn));
}
catch (InvalidOperationException exception)
{
Logger.Error(exception, "Multiple matches found for class module '{0}'.", name);
}

return result;
}

public Declaration FindReferencedProject(Declaration callingProject, string referencedProjectName)
{
return FindInReferencedProjectByPriority(callingProject, referencedProjectName, p => p.DeclarationType.HasFlag(DeclarationType.Project));
Expand Down
5 changes: 2 additions & 3 deletions Rubberduck.Parsing/Symbols/FormEventDeclarations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ private static Declaration FormsClassModuleFromParserState(RubberduckParserState
var msForms = finder.FindProject("MSForms");
if (msForms == null)
{
// If the VBA project is null, we haven't loaded any COM references;
// we're in a unit test and the mock project didn't setup any references.
//The corresponding COM reference has not been loaded.
return null;
}

return finder.FindStdModule("FormEvents", msForms, true);
return finder.FindClassModule("FormEvents", msForms, true);
}


Expand Down
27 changes: 20 additions & 7 deletions Rubberduck.Parsing/Symbols/SpecialFormDeclarations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,51 @@ namespace Rubberduck.Parsing.Symbols
{
public class SpecialFormDeclarations : ICustomDeclarationLoader
{
private readonly DeclarationFinder _finder;
private readonly RubberduckParserState _state;

public SpecialFormDeclarations(RubberduckParserState state)
{
_finder = new DeclarationFinder(state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });
_state = state;
}


public IReadOnlyList<Declaration> Load()
{
if (ThereIsAGlobalBuiltInErrVariableDeclaration(_finder))
var finder = new DeclarationFinder(_state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });

if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
{
return new List<Declaration>();
}

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

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

return LoadSpecialFormDeclarations(informationModule);
}


private static bool WeHaveAlreadyLoadedTheDeclarationsBefore(DeclarationFinder finder)
{
return ThereIsAGlobalBuiltInErrVariableDeclaration(finder);
}

private static bool ThereIsAGlobalBuiltInErrVariableDeclaration(DeclarationFinder finder)
{
return finder.MatchName(Tokens.Err).Any(declaration => declaration.IsBuiltIn
return finder.MatchName(Grammar.Tokens.Err).Any(declaration => declaration.IsBuiltIn
&& declaration.DeclarationType == DeclarationType.Variable
&& declaration.Accessibility == Accessibility.Global);
}
Expand Down
Loading