1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Threading ;
5- using Antlr4 . Runtime ;
1+ using Antlr4 . Runtime ;
62using Microsoft . Vbe . Interop ;
3+ using Rubberduck . Parsing . Annotations ;
74using Rubberduck . Parsing . Grammar ;
85using Rubberduck . Parsing . Nodes ;
96using Rubberduck . Parsing . VBA ;
107using Rubberduck . VBEditor ;
11- using Rubberduck . VBEditor . Extensions ;
12- using Rubberduck . Parsing . Annotations ;
8+ using System ;
9+ using System . Collections . Generic ;
10+ using System . Linq ;
1311
1412namespace Rubberduck . Parsing . Symbols
1513{
@@ -26,14 +24,16 @@ public class DeclarationSymbolsListener : VBAParserBaseListener
2624 private readonly IEnumerable < CommentNode > _comments ;
2725 private readonly IEnumerable < IAnnotation > _annotations ;
2826 private readonly IDictionary < Tuple < string , DeclarationType > , Attributes > _attributes ;
27+ private readonly HashSet < ReferencePriorityMap > _projectReferences ;
2928
3029 public DeclarationSymbolsListener (
31- QualifiedModuleName qualifiedName ,
32- Accessibility componentAccessibility ,
33- vbext_ComponentType type ,
30+ QualifiedModuleName qualifiedName ,
31+ Accessibility componentAccessibility ,
32+ vbext_ComponentType type ,
3433 IEnumerable < CommentNode > comments ,
3534 IEnumerable < IAnnotation > annotations ,
36- IDictionary < Tuple < string , DeclarationType > , Attributes > attributes )
35+ IDictionary < Tuple < string , DeclarationType > , Attributes > attributes ,
36+ HashSet < ReferencePriorityMap > projectReferences )
3737 {
3838 _qualifiedName = qualifiedName ;
3939 _comments = comments ;
@@ -46,6 +46,7 @@ public DeclarationSymbolsListener(
4646
4747 var project = _qualifiedName . Component . Collection . Parent ;
4848 var projectQualifiedName = new QualifiedModuleName ( project ) ;
49+ _projectReferences = projectReferences ;
4950
5051 _projectDeclaration = CreateProjectDeclaration ( projectQualifiedName , project ) ;
5152
@@ -59,7 +60,7 @@ public DeclarationSymbolsListener(
5960 _projectDeclaration ,
6061 _projectDeclaration ,
6162 _qualifiedName . Component . Name ,
62- false ,
63+ false ,
6364 false ,
6465 componentAccessibility ,
6566 declarationType ,
@@ -69,13 +70,18 @@ public DeclarationSymbolsListener(
6970 SetCurrentScope ( ) ;
7071 }
7172
72- private static Declaration CreateProjectDeclaration ( QualifiedModuleName projectQualifiedName , VBProject project )
73+ private Declaration CreateProjectDeclaration ( QualifiedModuleName projectQualifiedName , VBProject project )
7374 {
74- var declaration = new Declaration (
75- projectQualifiedName . QualifyMemberName ( project . Name ) ,
76- null , ( Declaration ) null , project . Name , false , false , Accessibility . Implicit , DeclarationType . Project , null ,
77- Selection . Home , false ) ;
78- return declaration ;
75+ var qualifiedName = projectQualifiedName . QualifyMemberName ( project . Name ) ;
76+ var projectId = qualifiedName . QualifiedModuleName . ProjectId ;
77+ var projectDeclaration = new ProjectDeclaration ( qualifiedName , project . Name ) ;
78+ var references = _projectReferences . Where ( projectContainingReference => projectContainingReference . ContainsKey ( projectId ) ) ;
79+ foreach ( var reference in references )
80+ {
81+ int priority = reference [ projectId ] ;
82+ projectDeclaration . AddProjectReference ( reference . ReferencedProjectId , priority ) ;
83+ }
84+ return projectDeclaration ;
7985 }
8086
8187 private IEnumerable < IAnnotation > FindAnnotations ( )
@@ -156,7 +162,7 @@ private Declaration CreateDeclaration(string identifierName, string asTypeName,
156162 Declaration result ;
157163 if ( declarationType == DeclarationType . Parameter )
158164 {
159- var argContext = ( VBAParser . ArgContext ) context ;
165+ var argContext = ( VBAParser . ArgContext ) context ;
160166 var isOptional = argContext . OPTIONAL ( ) != null ;
161167 var isByRef = argContext . BYREF ( ) != null ;
162168 var isParamArray = argContext . PARAMARRAY ( ) != null ;
@@ -277,8 +283,8 @@ public override void EnterFunctionStmt(VBAParser.FunctionStmtContext context)
277283 var name = identifier . GetText ( ) ;
278284
279285 var asTypeClause = context . asTypeClause ( ) ;
280- var asTypeName = asTypeClause == null
281- ? Tokens . Variant
286+ var asTypeName = asTypeClause == null
287+ ? Tokens . Variant
282288 : asTypeClause . type ( ) . GetText ( ) ;
283289
284290 var declaration = CreateDeclaration ( name , asTypeName , accessibility , DeclarationType . Function , context , context . ambiguousIdentifier ( ) . GetSelection ( ) ) ;
@@ -392,10 +398,10 @@ public override void EnterDeclareStmt(VBAParser.DeclareStmtContext context)
392398 var hasReturnType = context . FUNCTION ( ) != null ;
393399
394400 var asTypeClause = context . asTypeClause ( ) ;
395- var asTypeName = hasReturnType
401+ var asTypeName = hasReturnType
396402 ? asTypeClause == null
397403 ? Tokens . Variant
398- : asTypeClause . type ( ) . GetText ( )
404+ : asTypeClause . type ( ) . GetText ( )
399405 : null ;
400406
401407 var selection = nameContext . GetSelection ( ) ;
@@ -457,7 +463,7 @@ public override void EnterVariableSubStmt(VBAParser.VariableSubStmtContext conte
457463
458464 var withEvents = parent . WITHEVENTS ( ) != null ;
459465 var selfAssigned = asTypeClause != null && asTypeClause . NEW ( ) != null ;
460-
466+
461467 OnNewDeclaration ( CreateDeclaration ( name , asTypeName , accessibility , DeclarationType . Variable , context , context . ambiguousIdentifier ( ) . GetSelection ( ) , selfAssigned , withEvents ) ) ;
462468 }
463469
0 commit comments