22using Antlr4 . Runtime . Tree ;
33using Rubberduck . Parsing . Symbols ;
44using System ;
5+ using System . Collections ;
56using System . Collections . Generic ;
67using System . IO ;
78using System . Text ;
@@ -16,13 +17,13 @@ namespace Rubberduck.Parsing.VBA
1617{
1718 public class AttributeParser : IAttributeParser
1819 {
19- private readonly IModuleExporter _exporter ;
20+ private readonly ISourceCodeHandler _sourceCodeHandler ;
2021 private readonly Func < IVBAPreprocessor > _preprocessorFactory ;
2122 private readonly IProjectsProvider _projectsProvider ;
2223
23- public AttributeParser ( IModuleExporter exporter , Func < IVBAPreprocessor > preprocessorFactory , IProjectsProvider projectsProvider )
24+ public AttributeParser ( ISourceCodeHandler sourceCodeHandler , Func < IVBAPreprocessor > preprocessorFactory , IProjectsProvider projectsProvider )
2425 {
25- _exporter = exporter ;
26+ _sourceCodeHandler = sourceCodeHandler ;
2627 _preprocessorFactory = preprocessorFactory ;
2728 _projectsProvider = projectsProvider ;
2829 }
@@ -37,38 +38,12 @@ public AttributeParser(IModuleExporter exporter, Func<IVBAPreprocessor> preproce
3738 cancellationToken . ThrowIfCancellationRequested ( ) ;
3839 var component = _projectsProvider . Component ( module ) ;
3940
40- var path = component . VBE . Kind == VBEKind . Hosted
41- ? _exporter . Export ( component )
42- : component . GetFileName ( 1 ) ;
43-
44- if ( ! File . Exists ( path ) )
41+ var code = _sourceCodeHandler . Read ( component ) ;
42+ if ( code == null )
4543 {
46- // a document component without any code wouldn't be exported (file would be empty anyway).
4744 return ( null , null , new Dictionary < Tuple < string , DeclarationType > , Attributes > ( ) ) ;
4845 }
4946
50- string code ;
51- if ( module . ComponentType == ComponentType . Document )
52- {
53- code = File . ReadAllText ( path , Encoding . UTF8 ) ; //We export the code from Documents as UTF8.
54- }
55- else
56- {
57- code = File . ReadAllText ( path , Encoding . Default ) ; //The VBE exports encoded in the current ANSI codepage from the windows settings.
58- }
59-
60- if ( component . VBE . Kind == VBEKind . Hosted )
61- {
62- try
63- {
64- File . Delete ( path ) ;
65- }
66- catch
67- {
68- // Meh.
69- }
70- }
71-
7247 cancellationToken . ThrowIfCancellationRequested ( ) ;
7348
7449 var type = module . ComponentType == ComponentType . StandardModule
0 commit comments