Skip to content

Commit 8536cd2

Browse files
authored
Merge pull request #2551 from comintern/next
Start of QualifiedModuleName cleanup.
2 parents e4b06ac + 0fed156 commit 8536cd2

28 files changed

+92
-79
lines changed

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ public static IEnumerable<Declaration> FindFormEventHandlers(this RubberduckPars
364364
var items = state.AllDeclarations.ToList();
365365

366366
var forms = items.Where(item => item.DeclarationType == DeclarationType.ClassModule
367-
&& item.QualifiedName.QualifiedModuleName.Component != null
368-
&& item.QualifiedName.QualifiedModuleName.Component.Type == ComponentType.UserForm)
367+
&& item.QualifiedName.QualifiedModuleName.ComponentType == ComponentType.UserForm)
369368
.ToList();
370369

371370
var result = new List<Declaration>();

RetailCoder.VBE/Inspections/ProcedureNotUsedInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
4646
handlers.AddRange(withEventFields.SelectMany(Declarations.FindEventProcedures));
4747

4848
var forms = declarations.Where(item => item.DeclarationType == DeclarationType.ClassModule
49-
&& item.QualifiedName.QualifiedModuleName.Component.Type == ComponentType.UserForm)
49+
&& item.QualifiedName.QualifiedModuleName.ComponentType == ComponentType.UserForm)
5050
.ToList();
5151

5252
if (forms.Any())
@@ -159,7 +159,7 @@ private IEnumerable<string> GetImplementedInterfaceMembers(IEnumerable<Declarati
159159
{
160160
var interfaces = classes.Where(item => item.References.Any(reference =>
161161
ParserRuleContextHelper.HasParent<VBAParser.ImplementsStmtContext>(reference.Context.Parent)
162-
&& reference.QualifiedModuleName.Component.Name == componentName));
162+
&& reference.QualifiedModuleName.ComponentName == componentName));
163163

164164
var members = interfaces.SelectMany(declarations.InScope)
165165
.Select(member => member.ComponentName + "_" + member.IdentifierName);

RetailCoder.VBE/Inspections/QuickFixes/EncapsulateFieldQuickFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public EncapsulateFieldQuickFix(ParserRuleContext context, QualifiedSelection se
3030

3131
public override void Fix()
3232
{
33-
var vbe = Selection.QualifiedName.Project.VBE;
33+
var vbe = _target.Project.VBE;
3434

3535
using (var view = new EncapsulateFieldDialog(_state, _indenter))
3636
{

RetailCoder.VBE/Inspections/QuickFixes/MoveFieldCloserToUsageQuickFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public MoveFieldCloserToUsageQuickFix(ParserRuleContext context, QualifiedSelect
2828

2929
public override void Fix()
3030
{
31-
var vbe = Selection.QualifiedName.Project.VBE;
31+
var vbe = _target.Project.VBE;
3232

3333
var refactoring = new MoveCloserToUsageRefactoring(vbe, _state, _messageBox);
3434

RetailCoder.VBE/Inspections/QuickFixes/RenameDeclarationQuickFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public RenameDeclarationQuickFix(ParserRuleContext context, QualifiedSelection s
2929

3030
public override void Fix()
3131
{
32-
var vbe = Selection.QualifiedName.Project.VBE;
32+
var vbe = _target.Project.VBE;
3333

3434
using (var view = new RenameDialog())
3535
{

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public bool IsTestModule
123123

124124
public override QualifiedSelection? QualifiedSelection { get { return _declaration.QualifiedSelection; } }
125125

126-
private ComponentType ComponentType { get { return _declaration.QualifiedName.QualifiedModuleName.Component.Type; } }
126+
private ComponentType ComponentType { get { return _declaration.QualifiedName.QualifiedModuleName.ComponentType; } }
127127

128128
private static readonly IDictionary<ComponentType, DeclarationType> DeclarationTypes = new Dictionary<ComponentType, DeclarationType>
129129
{

RetailCoder.VBE/UI/CodeExplorer/Commands/ExportCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override bool CanExecuteImpl(object parameter)
3838
try
3939
{
4040
var node = (CodeExplorerComponentViewModel)parameter;
41-
var componentType = node.Declaration.QualifiedName.QualifiedModuleName.Component.Type;
41+
var componentType = node.Declaration.QualifiedName.QualifiedModuleName.ComponentType;
4242
return _exportableFileExtensions.Select(s => s.Key).Contains(componentType);
4343
}
4444
catch (COMException)

RetailCoder.VBE/UI/CodeExplorer/Commands/ImportCommand.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,28 @@ protected override void ExecuteImpl(object parameter)
4848
}
4949
}
5050

51-
if (_openFileDialog.ShowDialog() == DialogResult.OK)
51+
if (project == null || _openFileDialog.ShowDialog() != DialogResult.OK)
5252
{
53-
var fileExts = _openFileDialog.FileNames.Select(s => s.Split('.').Last());
54-
if (fileExts.Any(fileExt => !new[] {"bas", "cls", "frm"}.Contains(fileExt)))
55-
{
56-
return;
57-
}
53+
return;
54+
}
5855

59-
foreach (var filename in _openFileDialog.FileNames)
60-
{
61-
project.VBComponents.Import(filename);
62-
}
56+
var fileExts = _openFileDialog.FileNames.Select(s => s.Split('.').Last());
57+
if (fileExts.Any(fileExt => !new[] {"bas", "cls", "frm"}.Contains(fileExt)))
58+
{
59+
return;
60+
}
61+
62+
foreach (var filename in _openFileDialog.FileNames)
63+
{
64+
project.VBComponents.Import(filename);
6365
}
6466
}
6567

6668
private IVBProject GetNodeProject(CodeExplorerItemViewModel parameter)
6769
{
6870
if (parameter is ICodeExplorerDeclarationViewModel)
6971
{
70-
return parameter.GetSelectedDeclaration().QualifiedName.QualifiedModuleName.Project;
72+
return parameter.GetSelectedDeclaration().Project;
7173
}
7274

7375
var node = parameter.Parent;
@@ -76,7 +78,7 @@ private IVBProject GetNodeProject(CodeExplorerItemViewModel parameter)
7678
node = node.Parent;
7779
}
7880

79-
return ((ICodeExplorerDeclarationViewModel)node).Declaration.QualifiedName.QualifiedModuleName.Project;
81+
return ((ICodeExplorerDeclarationViewModel)node).Declaration.Project;
8082
}
8183

8284
public void Dispose()

RetailCoder.VBE/UI/CodeExplorer/Commands/RemoveCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected override bool CanExecuteImpl(object parameter)
3939
}
4040

4141
var node = (CodeExplorerComponentViewModel)parameter;
42-
var componentType = node.Declaration.QualifiedName.QualifiedModuleName.Component.Type;
42+
var componentType = node.Declaration.QualifiedName.QualifiedModuleName.ComponentType;
4343
return _exportableFileExtensions.Select(s => s.Key).Contains(componentType);
4444
}
4545

@@ -64,7 +64,7 @@ protected override void ExecuteImpl(object parameter)
6464
// I know this will never be null because of the CanExecute
6565
var declaration = ((CodeExplorerComponentViewModel)parameter).Declaration;
6666

67-
var components = declaration.QualifiedName.QualifiedModuleName.Project.VBComponents;
67+
var components = declaration.Project.VBComponents;
6868
components.Remove(declaration.QualifiedName.QualifiedModuleName.Component);
6969
}
7070

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public Declaration(
141141
Attributes attributes = null)
142142
{
143143
_qualifiedName = qualifiedName;
144+
_project = qualifiedName.QualifiedModuleName.Project;
144145
_parentDeclaration = parentDeclaration;
145146
_parentScopeDeclaration = _parentDeclaration;
146147
_parentScope = parentScope ?? string.Empty;
@@ -174,22 +175,23 @@ public Declaration(
174175
}
175176

176177
public Declaration(ComEnumeration enumeration, Declaration parent, QualifiedModuleName module) : this(
177-
module.QualifyMemberName(enumeration.Name),
178-
parent,
179-
parent,
180-
"Long", //Match the VBA default type declaration. Technically these *can* be a LongLong on 64 bit systems, but would likely crash the VBE...
181-
null,
182-
false,
183-
false,
184-
Accessibility.Global,
185-
DeclarationType.Enumeration,
186-
null,
187-
Selection.Home,
188-
false,
189-
null,
190-
true,
191-
null,
192-
new Attributes()) { }
178+
module.QualifyMemberName(enumeration.Name),
179+
parent,
180+
parent,
181+
"Long",
182+
//Match the VBA default type declaration. Technically these *can* be a LongLong on 64 bit systems, but would likely crash the VBE...
183+
null,
184+
false,
185+
false,
186+
Accessibility.Global,
187+
DeclarationType.Enumeration,
188+
null,
189+
Selection.Home,
190+
false,
191+
null,
192+
true,
193+
null,
194+
new Attributes()) { }
193195

194196
public Declaration(ComStruct structure, Declaration parent, QualifiedModuleName module)
195197
: this(
@@ -247,9 +249,9 @@ private string FolderFromAnnotations()
247249
string result;
248250
if (@namespace == null)
249251
{
250-
result = _qualifiedName.QualifiedModuleName.Project == null
252+
result = string.IsNullOrEmpty(_qualifiedName.QualifiedModuleName.ProjectName)
251253
? _projectId
252-
: _qualifiedName.QualifiedModuleName.Project.Name;
254+
: _qualifiedName.QualifiedModuleName.ProjectName;
253255
}
254256
else
255257
{
@@ -404,13 +406,14 @@ public void AddReference(
404406

405407
public QualifiedSelection QualifiedSelection { get { return new QualifiedSelection(_qualifiedName.QualifiedModuleName, _selection); } }
406408

409+
private readonly IVBProject _project;
407410
/// <summary>
408411
/// Gets a reference to the VBProject the declaration is made in.
409412
/// </summary>
410413
/// <remarks>
411414
/// This property is intended to differenciate identically-named VBProjects.
412415
/// </remarks>
413-
public IVBProject Project { get { return _qualifiedName.QualifiedModuleName.Project; } }
416+
public virtual IVBProject Project { get { return _project ?? _parentDeclaration.Project; } }
414417

415418
private readonly string _projectId;
416419
/// <summary>

0 commit comments

Comments
 (0)