Skip to content

Commit 29f98b9

Browse files
committed
Merge pull request #1367 from rubberduck-vba/next
v2.0.1a-pre
2 parents 6632444 + 7873285 commit 29f98b9

File tree

101 files changed

+16084
-4736
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+16084
-4736
lines changed

RetailCoder.VBE/App.cs

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Rubberduck.UI.Command.MenuItems;
1818
using Infralution.Localization.Wpf;
1919
using Rubberduck.Common.Dispatch;
20+
using Rubberduck.VBEditor.Extensions;
2021

2122
namespace Rubberduck
2223
{
@@ -39,10 +40,10 @@ public class App : IDisposable
3940
private readonly IConnectionPoint _projectsEventsConnectionPoint;
4041
private readonly int _projectsEventsCookie;
4142

42-
private readonly IDictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
43-
new Dictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>>();
44-
private readonly IDictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>> _referencesEventsConnectionPoints =
45-
new Dictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>>();
43+
private readonly IDictionary<string, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
44+
new Dictionary<string, Tuple<IConnectionPoint, int>>();
45+
private readonly IDictionary<string, Tuple<IConnectionPoint, int>> _referencesEventsConnectionPoints =
46+
new Dictionary<string, Tuple<IConnectionPoint, int>>();
4647

4748
public App(VBE vbe, IMessageBox messageBox,
4849
IRubberduckParser parser,
@@ -127,11 +128,6 @@ public void Startup()
127128
{
128129
CleanReloadConfig();
129130

130-
foreach (var project in _vbe.VBProjects.Cast<VBProject>())
131-
{
132-
_parser.State.AddProject(project);
133-
}
134-
135131
_appMenus.Initialize();
136132
_appMenus.Localize();
137133

@@ -150,40 +146,51 @@ public void Startup()
150146
#region sink handlers. todo: move to another class
151147
async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
152148
{
153-
var sink = (VBProjectsEventsSink)sender;
154-
_componentsEventSinks.Remove(sink);
155-
_referencesEventsSinks.Remove(sink);
149+
if (e.Item.Protection == vbext_ProjectProtection.vbext_pp_locked)
150+
{
151+
Debug.WriteLine(string.Format("Locked project '{0}' was removed.", e.Item.Name));
152+
return;
153+
}
154+
155+
var projectId = e.Item.HelpFile;
156+
_componentsEventsSinks.Remove(projectId);
157+
_referencesEventsSinks.Remove(projectId);
156158
_parser.State.RemoveProject(e.Item);
157159

158160
Debug.WriteLine(string.Format("Project '{0}' was removed.", e.Item.Name));
159161
Tuple<IConnectionPoint, int> componentsTuple;
160-
if (_componentsEventsConnectionPoints.TryGetValue(sink, out componentsTuple))
162+
if (_componentsEventsConnectionPoints.TryGetValue(projectId, out componentsTuple))
161163
{
162164
componentsTuple.Item1.Unadvise(componentsTuple.Item2);
163-
_componentsEventsConnectionPoints.Remove(sink);
165+
_componentsEventsConnectionPoints.Remove(projectId);
164166
}
165167

166168
Tuple<IConnectionPoint, int> referencesTuple;
167-
if (_referencesEventsConnectionPoints.TryGetValue(sink, out referencesTuple))
169+
if (_referencesEventsConnectionPoints.TryGetValue(projectId, out referencesTuple))
168170
{
169171
referencesTuple.Item1.Unadvise(referencesTuple.Item2);
170-
_referencesEventsConnectionPoints.Remove(sink);
172+
_referencesEventsConnectionPoints.Remove(projectId);
171173
}
172-
173-
_parser.State.ClearDeclarations(e.Item);
174174
}
175175

176-
private readonly IDictionary<VBProjectsEventsSink, VBComponentsEventsSink> _componentsEventSinks =
177-
new Dictionary<VBProjectsEventsSink, VBComponentsEventsSink>();
176+
private readonly IDictionary<string,VBComponentsEventsSink> _componentsEventsSinks =
177+
new Dictionary<string,VBComponentsEventsSink>();
178178

179-
private readonly IDictionary<VBProjectsEventsSink, ReferencesEventsSink> _referencesEventsSinks =
180-
new Dictionary<VBProjectsEventsSink, ReferencesEventsSink>();
179+
private readonly IDictionary<string,ReferencesEventsSink> _referencesEventsSinks =
180+
new Dictionary<string, ReferencesEventsSink>();
181181

182182
async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
183183
{
184-
var sink = (VBProjectsEventsSink)sender;
185-
RegisterComponentsEventSink(e, sink);
186-
_parser.State.AddProject(e.Item);
184+
Debug.WriteLine(string.Format("Project '{0}' was added.", e.Item.Name));
185+
if (e.Item.Protection == vbext_ProjectProtection.vbext_pp_locked)
186+
{
187+
Debug.WriteLine("Project is protected and will not be added to parser state.");
188+
return;
189+
}
190+
191+
_parser.State.AddProject(e.Item); // note side-effect: assigns ProjectId/HelpFile
192+
var projectId = e.Item.HelpFile;
193+
RegisterComponentsEventSink(e.Item.VBComponents, projectId);
187194

188195
if (!_parser.State.AllDeclarations.Any())
189196
{
@@ -193,13 +200,19 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
193200
return;
194201
}
195202

196-
Debug.WriteLine(string.Format("Project '{0}' was added.", e.Item.Name));
197203
_parser.State.OnParseRequested(sender);
198204
}
199205

200-
private void RegisterComponentsEventSink(DispatcherEventArgs<VBProject> e, VBProjectsEventsSink sink)
206+
private void RegisterComponentsEventSink(VBComponents components, string projectId)
201207
{
202-
var connectionPointContainer = (IConnectionPointContainer) e.Item.VBComponents;
208+
if (_componentsEventsSinks.ContainsKey(projectId))
209+
{
210+
// already registered - this is caused by the initial load+rename of a project in the VBE
211+
Debug.WriteLine("Components sink already registered.");
212+
return;
213+
}
214+
215+
var connectionPointContainer = (IConnectionPointContainer)components;
203216
var interfaceId = typeof (_dispVBComponentsEvents).GUID;
204217

205218
IConnectionPoint connectionPoint;
@@ -212,12 +225,13 @@ private void RegisterComponentsEventSink(DispatcherEventArgs<VBProject> e, VBPro
212225
componentsSink.ComponentRemoved += sink_ComponentRemoved;
213226
componentsSink.ComponentRenamed += sink_ComponentRenamed;
214227
componentsSink.ComponentSelected += sink_ComponentSelected;
215-
_componentsEventSinks.Add(sink, componentsSink);
228+
_componentsEventsSinks.Add(projectId, componentsSink);
216229

217230
int cookie;
218231
connectionPoint.Advise(componentsSink, out cookie);
219232

220-
_componentsEventsConnectionPoints.Add(sink, Tuple.Create(connectionPoint, cookie));
233+
_componentsEventsConnectionPoints.Add(projectId, Tuple.Create(connectionPoint, cookie));
234+
Debug.WriteLine("Components sink registered and advising.");
221235
}
222236

223237
async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent> e)
@@ -251,7 +265,7 @@ async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent>
251265
}
252266

253267
Debug.WriteLine(string.Format("Component '{0}' was removed.", e.Item.Name));
254-
_parser.State.ClearDeclarations(e.Item);
268+
_parser.State.ClearStateCache(e.Item);
255269
}
256270

257271
async void sink_ComponentReloaded(object sender, DispatcherEventArgs<VBComponent> e)
@@ -364,7 +378,10 @@ public void Dispose()
364378
{
365379
item.Value.Item1.Unadvise(item.Value.Item2);
366380
}
367-
381+
foreach (var item in _referencesEventsConnectionPoints)
382+
{
383+
item.Value.Item1.Unadvise(item.Value.Item2);
384+
}
368385
_hooks.Dispose();
369386
}
370387
}

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public static IEnumerable<Declaration> InScope(this IEnumerable<Declaration> dec
191191

192192
public static IEnumerable<Declaration> FindInterfaces(this IEnumerable<Declaration> declarations)
193193
{
194-
var classes = declarations.Where(item => item.DeclarationType == DeclarationType.Class);
194+
var classes = declarations.Where(item => item.DeclarationType == DeclarationType.ClassModule);
195195
var interfaces = classes.Where(item => item.References.Any(reference =>
196196
reference.Context.Parent is VBAParser.ImplementsStmtContext));
197197

@@ -279,7 +279,7 @@ public static IEnumerable<Declaration> FindFormEventHandlers(this IEnumerable<De
279279
{
280280
var items = declarations.ToList();
281281

282-
var forms = items.Where(item => item.DeclarationType == DeclarationType.Class
282+
var forms = items.Where(item => item.DeclarationType == DeclarationType.ClassModule
283283
&& item.QualifiedName.QualifiedModuleName.Component != null
284284
&& item.QualifiedName.QualifiedModuleName.Component.Type == vbext_ComponentType.vbext_ct_MSForm)
285285
.ToList();
@@ -318,7 +318,7 @@ public static IEnumerable<Tuple<Declaration,Declaration>> FindHandlersForEvent(t
318318
.Select(item => new
319319
{
320320
WithEventDeclaration = item,
321-
EventProvider = items.SingleOrDefault(type => type.DeclarationType == DeclarationType.Class && type.QualifiedName.QualifiedModuleName == item.QualifiedName.QualifiedModuleName)
321+
EventProvider = items.SingleOrDefault(type => type.DeclarationType == DeclarationType.ClassModule && type.QualifiedName.QualifiedModuleName == item.QualifiedName.QualifiedModuleName)
322322
})
323323
.Select(item => new
324324
{
@@ -341,7 +341,7 @@ public static IEnumerable<Declaration> FindEventProcedures(this IEnumerable<Decl
341341
}
342342

343343
var items = declarations as IList<Declaration> ?? declarations.ToList();
344-
var type = items.SingleOrDefault(item => item.DeclarationType == DeclarationType.Class
344+
var type = items.SingleOrDefault(item => item.DeclarationType == DeclarationType.ClassModule
345345
&& item.Project != null
346346
&& item.IdentifierName == withEventsDeclaration.AsTypeName.Split('.').Last());
347347

RetailCoder.VBE/Common/DeclarationIconCache.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public static BitmapImage ComponentIcon(vbext_ComponentType componentType)
3535
switch (componentType)
3636
{
3737
case vbext_ComponentType.vbext_ct_StdModule:
38-
key = Tuple.Create(DeclarationType.Module, Accessibility.Public);
38+
key = Tuple.Create(DeclarationType.ProceduralModule, Accessibility.Public);
3939
break;
4040
case vbext_ComponentType.vbext_ct_ClassModule:
41-
key = Tuple.Create(DeclarationType.Class, Accessibility.Public);
41+
key = Tuple.Create(DeclarationType.ClassModule, Accessibility.Public);
4242
break;
4343
case vbext_ComponentType.vbext_ct_Document:
4444
key = Tuple.Create(DeclarationType.Document, Accessibility.Public);
@@ -61,19 +61,19 @@ private static Uri GetIconUri(DeclarationType declarationType, Accessibility acc
6161
string path;
6262
switch (declarationType)
6363
{
64-
case DeclarationType.Module:
64+
case DeclarationType.ProceduralModule:
6565
path = "VSObject_Module.png";
6666
break;
6767

68-
case DeclarationType.Document | DeclarationType.Class:
68+
case DeclarationType.Document | DeclarationType.ClassModule:
6969
path = "document.png";
7070
break;
7171

72-
case DeclarationType.UserForm | DeclarationType.Class | DeclarationType.Control:
72+
case DeclarationType.UserForm | DeclarationType.ClassModule | DeclarationType.Control:
7373
path = "VSProject_Form.png";
7474
break;
7575

76-
case DeclarationType.Class | DeclarationType.Module:
76+
case DeclarationType.ClassModule | DeclarationType.ProceduralModule:
7777
path = "VSProject_Class.png";
7878
break;
7979

RetailCoder.VBE/Inspections/ConstantNotUsedInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2222
declaration.DeclarationType == DeclarationType.Constant && !declaration.References.Any());
2323

2424
return results.Select(issue =>
25-
new IdentifierNotUsedInspectionResult(this, issue, ((dynamic)issue.Context).ambiguousIdentifier(), issue.QualifiedName.QualifiedModuleName)).Cast<InspectionResultBase>();
25+
new IdentifierNotUsedInspectionResult(this, issue, ((dynamic)issue.Context).identifier(), issue.QualifiedName.QualifiedModuleName)).Cast<InspectionResultBase>();
2626
}
2727
}
2828
}

RetailCoder.VBE/Inspections/ConvertToProcedureQuickFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override void Fix()
4545
: Tokens.Property;
4646

4747
string visibility = context.visibility() == null ? string.Empty : context.visibility().GetText() + ' ';
48-
string name = ' ' + context.ambiguousIdentifier().GetText();
48+
string name = ' ' + context.identifier().GetText();
4949
bool hasTypeHint = context.typeHint() != null;
5050

5151
string args = context.argList().GetText();

RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3333
let arg = item.Context as VBAParser.ArgContext
3434
where arg != null && arg.BYREF() == null && arg.BYVAL() == null
3535
select new QualifiedContext<VBAParser.ArgContext>(item.QualifiedName, arg))
36-
.Select(issue => new ImplicitByRefParameterInspectionResult(this, issue.Context.ambiguousIdentifier().GetText(), issue));
36+
.Select(issue => new ImplicitByRefParameterInspectionResult(this, issue.Context.identifier().GetText(), issue));
3737

3838

3939
return issues;

RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspectionResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private ProcedureNode GetNode(VBAParser.FunctionStmtContext context)
7171
}
7272

7373
var scope = Selection.QualifiedName.ToString();
74-
var localScope = scope + "." + context.ambiguousIdentifier().GetText();
74+
var localScope = scope + "." + context.identifier().GetText();
7575
return new ProcedureNode(context, scope, localScope);
7676
}
7777

@@ -83,7 +83,7 @@ private ProcedureNode GetNode(VBAParser.PropertyGetStmtContext context)
8383
}
8484

8585
var scope = Selection.QualifiedName.ToString();
86-
var localScope = scope + "." + context.ambiguousIdentifier().GetText();
86+
var localScope = scope + "." + context.identifier().GetText();
8787
return new ProcedureNode(context, scope, localScope);
8888
}
8989
}

RetailCoder.VBE/Inspections/InspectionsUI.de.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,16 @@
509509
<data name="QualifiedSelectionInspection" xml:space="preserve">
510510
<value>{0}: {1} - {2}.{3}, Zeile {4}</value>
511511
</data>
512+
<data name="SetObjectVariableQuickFix" xml:space="preserve">
513+
<value>Benutze das Schlüsselwort 'Set'</value>
514+
</data>
515+
<data name="ObjectVariableNotSetInspectionResultFormat" xml:space="preserve">
516+
<value>Objektvariable '{0}' wird ohne das 'Set' Schlüsselwort zugewiesen</value>
517+
</data>
518+
<data name="ObjectVariableNotSetInspectionMeta" xml:space="preserve">
519+
<value>Rubberduck hat festgestellt, dass die Variable eine Objektvaribale ist, die ohne 'Set' Schlüsselwort zugewiesen wird. Dies führt zu dem Laufzeitfehler 91 'Objekt oder With Block Variable wurden nicht gesetzt'.</value>
520+
</data>
521+
<data name="ObjectVariableNotSetInspectionName" xml:space="preserve">
522+
<value>Zuweiseung in eine Objektvariable benötigt das 'Set'-Schlüsselwort.</value>
523+
</data>
512524
</root>

RetailCoder.VBE/Inspections/MoveFieldCloserToUsageInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2828
{
2929

3030
if (declaration.DeclarationType != DeclarationType.Variable ||
31-
!new[] {DeclarationType.Class, DeclarationType.Module}.Contains(declaration.ParentDeclaration.DeclarationType))
31+
!new[] {DeclarationType.ClassModule, DeclarationType.ProceduralModule}.Contains(declaration.ParentDeclaration.DeclarationType))
3232
{
3333
return false;
3434
}

RetailCoder.VBE/Inspections/MultipleFolderAnnotationsInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public MultipleFolderAnnotationsInspection(RubberduckParserState state)
2020
public override IEnumerable<InspectionResultBase> GetInspectionResults()
2121
{
2222
var issues = UserDeclarations.Where(declaration =>
23-
(declaration.DeclarationType == DeclarationType.Class
24-
|| declaration.DeclarationType == DeclarationType.Module)
23+
(declaration.DeclarationType == DeclarationType.ClassModule
24+
|| declaration.DeclarationType == DeclarationType.ProceduralModule)
2525
&& declaration.Annotations.Count(annotation => annotation.AnnotationType == AnnotationType.Folder) > 1);
2626
return issues.Select(issue =>
2727
new MultipleFolderAnnotationsInspectionResult(this, issue));

RetailCoder.VBE/Inspections/OptionExplicitInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public OptionExplicitInspection(RubberduckParserState state)
1919

2020
private static readonly DeclarationType[] ModuleTypes =
2121
{
22-
DeclarationType.Module,
23-
DeclarationType.Class
22+
DeclarationType.ProceduralModule,
23+
DeclarationType.ClassModule
2424
};
2525

2626
public override IEnumerable<InspectionResultBase> GetInspectionResults()

RetailCoder.VBE/Inspections/ParameterCanBeByValInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
7171
&& ((VBAParser.ArgContext) declaration.Context).BYVAL() == null
7272
&& !IsUsedAsByRefParam(declarations, declaration)
7373
&& !declaration.References.Any(reference => reference.IsAssignment))
74-
.Select(issue => new ParameterCanBeByValInspectionResult(this, issue, ((dynamic)issue.Context).ambiguousIdentifier(), issue.QualifiedName));
74+
.Select(issue => new ParameterCanBeByValInspectionResult(this, issue, ((dynamic)issue.Context).identifier(), issue.QualifiedName));
7575

7676
return issues;
7777
}

RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
5656
&& !builtInHandlers.Contains(parameter.ParentDeclaration))
5757
let isInterfaceImplementationMember = IsInterfaceMemberImplementationParameter(issue, interfaceImplementationMemberScopes)
5858
select new ParameterNotUsedInspectionResult(this, issue,
59-
((dynamic) issue.Context).ambiguousIdentifier(), issue.QualifiedName,
59+
((dynamic) issue.Context).identifier(), issue.QualifiedName,
6060
isInterfaceImplementationMember, quickFixRefactoring, State);
6161

6262
return issues.ToList();

RetailCoder.VBE/Inspections/ProcedureCanBeWrittenAsFunctionInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3131
{
3232
var declaration =
3333
UserDeclarations.SingleOrDefault(d => d.DeclarationType == DeclarationType.Procedure &&
34-
d.IdentifierName == c.ambiguousIdentifier().GetText() &&
34+
d.IdentifierName == c.identifier().GetText() &&
3535
d.Context.GetSelection().Equals(c.GetSelection()));
3636

3737
var interfaceImplementation = UserDeclarations.FindInterfaceImplementationMembers().SingleOrDefault(m => m.Equals(declaration));
@@ -46,7 +46,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
4646
.Where(c =>
4747
{
4848
var declaration = UserDeclarations.SingleOrDefault(d => d.DeclarationType == DeclarationType.Procedure &&
49-
d.IdentifierName == c.ambiguousIdentifier().GetText() &&
49+
d.IdentifierName == c.identifier().GetText() &&
5050
d.Context.GetSelection().Equals(c.GetSelection()));
5151

5252
if (declaration == null) { return false; } // rather be safe than sorry

0 commit comments

Comments
 (0)