Skip to content

Commit

Permalink
Merge pull request #1367 from rubberduck-vba/next
Browse files Browse the repository at this point in the history
v2.0.1a-pre
  • Loading branch information
retailcoder committed Apr 25, 2016
2 parents 6632444 + 7873285 commit 29f98b9
Show file tree
Hide file tree
Showing 101 changed files with 16,084 additions and 4,736 deletions.
81 changes: 49 additions & 32 deletions RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Rubberduck.UI.Command.MenuItems;
using Infralution.Localization.Wpf;
using Rubberduck.Common.Dispatch;
using Rubberduck.VBEditor.Extensions;

namespace Rubberduck
{
Expand All @@ -39,10 +40,10 @@ public class App : IDisposable
private readonly IConnectionPoint _projectsEventsConnectionPoint;
private readonly int _projectsEventsCookie;

private readonly IDictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
new Dictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>>();
private readonly IDictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>> _referencesEventsConnectionPoints =
new Dictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>>();
private readonly IDictionary<string, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
new Dictionary<string, Tuple<IConnectionPoint, int>>();
private readonly IDictionary<string, Tuple<IConnectionPoint, int>> _referencesEventsConnectionPoints =
new Dictionary<string, Tuple<IConnectionPoint, int>>();

public App(VBE vbe, IMessageBox messageBox,
IRubberduckParser parser,
Expand Down Expand Up @@ -127,11 +128,6 @@ public void Startup()
{
CleanReloadConfig();

foreach (var project in _vbe.VBProjects.Cast<VBProject>())
{
_parser.State.AddProject(project);
}

_appMenus.Initialize();
_appMenus.Localize();

Expand All @@ -150,40 +146,51 @@ public void Startup()
#region sink handlers. todo: move to another class
async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
{
var sink = (VBProjectsEventsSink)sender;
_componentsEventSinks.Remove(sink);
_referencesEventsSinks.Remove(sink);
if (e.Item.Protection == vbext_ProjectProtection.vbext_pp_locked)
{
Debug.WriteLine(string.Format("Locked project '{0}' was removed.", e.Item.Name));
return;
}

var projectId = e.Item.HelpFile;
_componentsEventsSinks.Remove(projectId);
_referencesEventsSinks.Remove(projectId);
_parser.State.RemoveProject(e.Item);

Debug.WriteLine(string.Format("Project '{0}' was removed.", e.Item.Name));
Tuple<IConnectionPoint, int> componentsTuple;
if (_componentsEventsConnectionPoints.TryGetValue(sink, out componentsTuple))
if (_componentsEventsConnectionPoints.TryGetValue(projectId, out componentsTuple))
{
componentsTuple.Item1.Unadvise(componentsTuple.Item2);
_componentsEventsConnectionPoints.Remove(sink);
_componentsEventsConnectionPoints.Remove(projectId);
}

Tuple<IConnectionPoint, int> referencesTuple;
if (_referencesEventsConnectionPoints.TryGetValue(sink, out referencesTuple))
if (_referencesEventsConnectionPoints.TryGetValue(projectId, out referencesTuple))
{
referencesTuple.Item1.Unadvise(referencesTuple.Item2);
_referencesEventsConnectionPoints.Remove(sink);
_referencesEventsConnectionPoints.Remove(projectId);
}

_parser.State.ClearDeclarations(e.Item);
}

private readonly IDictionary<VBProjectsEventsSink, VBComponentsEventsSink> _componentsEventSinks =
new Dictionary<VBProjectsEventsSink, VBComponentsEventsSink>();
private readonly IDictionary<string,VBComponentsEventsSink> _componentsEventsSinks =
new Dictionary<string,VBComponentsEventsSink>();

private readonly IDictionary<VBProjectsEventsSink, ReferencesEventsSink> _referencesEventsSinks =
new Dictionary<VBProjectsEventsSink, ReferencesEventsSink>();
private readonly IDictionary<string,ReferencesEventsSink> _referencesEventsSinks =
new Dictionary<string, ReferencesEventsSink>();

async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
{
var sink = (VBProjectsEventsSink)sender;
RegisterComponentsEventSink(e, sink);
_parser.State.AddProject(e.Item);
Debug.WriteLine(string.Format("Project '{0}' was added.", e.Item.Name));
if (e.Item.Protection == vbext_ProjectProtection.vbext_pp_locked)
{
Debug.WriteLine("Project is protected and will not be added to parser state.");
return;
}

_parser.State.AddProject(e.Item); // note side-effect: assigns ProjectId/HelpFile
var projectId = e.Item.HelpFile;
RegisterComponentsEventSink(e.Item.VBComponents, projectId);

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

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

private void RegisterComponentsEventSink(DispatcherEventArgs<VBProject> e, VBProjectsEventsSink sink)
private void RegisterComponentsEventSink(VBComponents components, string projectId)
{
var connectionPointContainer = (IConnectionPointContainer) e.Item.VBComponents;
if (_componentsEventsSinks.ContainsKey(projectId))
{
// already registered - this is caused by the initial load+rename of a project in the VBE
Debug.WriteLine("Components sink already registered.");
return;
}

var connectionPointContainer = (IConnectionPointContainer)components;
var interfaceId = typeof (_dispVBComponentsEvents).GUID;

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

int cookie;
connectionPoint.Advise(componentsSink, out cookie);

_componentsEventsConnectionPoints.Add(sink, Tuple.Create(connectionPoint, cookie));
_componentsEventsConnectionPoints.Add(projectId, Tuple.Create(connectionPoint, cookie));
Debug.WriteLine("Components sink registered and advising.");
}

async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent> e)
Expand Down Expand Up @@ -251,7 +265,7 @@ async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent>
}

Debug.WriteLine(string.Format("Component '{0}' was removed.", e.Item.Name));
_parser.State.ClearDeclarations(e.Item);
_parser.State.ClearStateCache(e.Item);
}

async void sink_ComponentReloaded(object sender, DispatcherEventArgs<VBComponent> e)
Expand Down Expand Up @@ -364,7 +378,10 @@ public void Dispose()
{
item.Value.Item1.Unadvise(item.Value.Item2);
}

foreach (var item in _referencesEventsConnectionPoints)
{
item.Value.Item1.Unadvise(item.Value.Item2);
}
_hooks.Dispose();
}
}
Expand Down
8 changes: 4 additions & 4 deletions RetailCoder.VBE/Common/DeclarationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static IEnumerable<Declaration> InScope(this IEnumerable<Declaration> dec

public static IEnumerable<Declaration> FindInterfaces(this IEnumerable<Declaration> declarations)
{
var classes = declarations.Where(item => item.DeclarationType == DeclarationType.Class);
var classes = declarations.Where(item => item.DeclarationType == DeclarationType.ClassModule);
var interfaces = classes.Where(item => item.References.Any(reference =>
reference.Context.Parent is VBAParser.ImplementsStmtContext));

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

var forms = items.Where(item => item.DeclarationType == DeclarationType.Class
var forms = items.Where(item => item.DeclarationType == DeclarationType.ClassModule
&& item.QualifiedName.QualifiedModuleName.Component != null
&& item.QualifiedName.QualifiedModuleName.Component.Type == vbext_ComponentType.vbext_ct_MSForm)
.ToList();
Expand Down Expand Up @@ -318,7 +318,7 @@ public static IEnumerable<Tuple<Declaration,Declaration>> FindHandlersForEvent(t
.Select(item => new
{
WithEventDeclaration = item,
EventProvider = items.SingleOrDefault(type => type.DeclarationType == DeclarationType.Class && type.QualifiedName.QualifiedModuleName == item.QualifiedName.QualifiedModuleName)
EventProvider = items.SingleOrDefault(type => type.DeclarationType == DeclarationType.ClassModule && type.QualifiedName.QualifiedModuleName == item.QualifiedName.QualifiedModuleName)
})
.Select(item => new
{
Expand All @@ -341,7 +341,7 @@ public static IEnumerable<Declaration> FindEventProcedures(this IEnumerable<Decl
}

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

Expand Down
12 changes: 6 additions & 6 deletions RetailCoder.VBE/Common/DeclarationIconCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public static BitmapImage ComponentIcon(vbext_ComponentType componentType)
switch (componentType)
{
case vbext_ComponentType.vbext_ct_StdModule:
key = Tuple.Create(DeclarationType.Module, Accessibility.Public);
key = Tuple.Create(DeclarationType.ProceduralModule, Accessibility.Public);
break;
case vbext_ComponentType.vbext_ct_ClassModule:
key = Tuple.Create(DeclarationType.Class, Accessibility.Public);
key = Tuple.Create(DeclarationType.ClassModule, Accessibility.Public);
break;
case vbext_ComponentType.vbext_ct_Document:
key = Tuple.Create(DeclarationType.Document, Accessibility.Public);
Expand All @@ -61,19 +61,19 @@ private static Uri GetIconUri(DeclarationType declarationType, Accessibility acc
string path;
switch (declarationType)
{
case DeclarationType.Module:
case DeclarationType.ProceduralModule:
path = "VSObject_Module.png";
break;

case DeclarationType.Document | DeclarationType.Class:
case DeclarationType.Document | DeclarationType.ClassModule:
path = "document.png";
break;

case DeclarationType.UserForm | DeclarationType.Class | DeclarationType.Control:
case DeclarationType.UserForm | DeclarationType.ClassModule | DeclarationType.Control:
path = "VSProject_Form.png";
break;

case DeclarationType.Class | DeclarationType.Module:
case DeclarationType.ClassModule | DeclarationType.ProceduralModule:
path = "VSProject_Class.png";
break;

Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/Inspections/ConstantNotUsedInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
declaration.DeclarationType == DeclarationType.Constant && !declaration.References.Any());

return results.Select(issue =>
new IdentifierNotUsedInspectionResult(this, issue, ((dynamic)issue.Context).ambiguousIdentifier(), issue.QualifiedName.QualifiedModuleName)).Cast<InspectionResultBase>();
new IdentifierNotUsedInspectionResult(this, issue, ((dynamic)issue.Context).identifier(), issue.QualifiedName.QualifiedModuleName)).Cast<InspectionResultBase>();
}
}
}
2 changes: 1 addition & 1 deletion RetailCoder.VBE/Inspections/ConvertToProcedureQuickFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void Fix()
: Tokens.Property;

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

string args = context.argList().GetText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
let arg = item.Context as VBAParser.ArgContext
where arg != null && arg.BYREF() == null && arg.BYVAL() == null
select new QualifiedContext<VBAParser.ArgContext>(item.QualifiedName, arg))
.Select(issue => new ImplicitByRefParameterInspectionResult(this, issue.Context.ambiguousIdentifier().GetText(), issue));
.Select(issue => new ImplicitByRefParameterInspectionResult(this, issue.Context.identifier().GetText(), issue));


return issues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private ProcedureNode GetNode(VBAParser.FunctionStmtContext context)
}

var scope = Selection.QualifiedName.ToString();
var localScope = scope + "." + context.ambiguousIdentifier().GetText();
var localScope = scope + "." + context.identifier().GetText();
return new ProcedureNode(context, scope, localScope);
}

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

var scope = Selection.QualifiedName.ToString();
var localScope = scope + "." + context.ambiguousIdentifier().GetText();
var localScope = scope + "." + context.identifier().GetText();
return new ProcedureNode(context, scope, localScope);
}
}
Expand Down
12 changes: 12 additions & 0 deletions RetailCoder.VBE/Inspections/InspectionsUI.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,16 @@
<data name="QualifiedSelectionInspection" xml:space="preserve">
<value>{0}: {1} - {2}.{3}, Zeile {4}</value>
</data>
<data name="SetObjectVariableQuickFix" xml:space="preserve">
<value>Benutze das Schlüsselwort 'Set'</value>
</data>
<data name="ObjectVariableNotSetInspectionResultFormat" xml:space="preserve">
<value>Objektvariable '{0}' wird ohne das 'Set' Schlüsselwort zugewiesen</value>
</data>
<data name="ObjectVariableNotSetInspectionMeta" xml:space="preserve">
<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>
</data>
<data name="ObjectVariableNotSetInspectionName" xml:space="preserve">
<value>Zuweiseung in eine Objektvariable benötigt das 'Set'-Schlüsselwort.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
{
if (declaration.DeclarationType != DeclarationType.Variable ||
!new[] {DeclarationType.Class, DeclarationType.Module}.Contains(declaration.ParentDeclaration.DeclarationType))
!new[] {DeclarationType.ClassModule, DeclarationType.ProceduralModule}.Contains(declaration.ParentDeclaration.DeclarationType))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public MultipleFolderAnnotationsInspection(RubberduckParserState state)
public override IEnumerable<InspectionResultBase> GetInspectionResults()
{
var issues = UserDeclarations.Where(declaration =>
(declaration.DeclarationType == DeclarationType.Class
|| declaration.DeclarationType == DeclarationType.Module)
(declaration.DeclarationType == DeclarationType.ClassModule
|| declaration.DeclarationType == DeclarationType.ProceduralModule)
&& declaration.Annotations.Count(annotation => annotation.AnnotationType == AnnotationType.Folder) > 1);
return issues.Select(issue =>
new MultipleFolderAnnotationsInspectionResult(this, issue));
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/Inspections/OptionExplicitInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public OptionExplicitInspection(RubberduckParserState state)

private static readonly DeclarationType[] ModuleTypes =
{
DeclarationType.Module,
DeclarationType.Class
DeclarationType.ProceduralModule,
DeclarationType.ClassModule
};

public override IEnumerable<InspectionResultBase> GetInspectionResults()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
&& ((VBAParser.ArgContext) declaration.Context).BYVAL() == null
&& !IsUsedAsByRefParam(declarations, declaration)
&& !declaration.References.Any(reference => reference.IsAssignment))
.Select(issue => new ParameterCanBeByValInspectionResult(this, issue, ((dynamic)issue.Context).ambiguousIdentifier(), issue.QualifiedName));
.Select(issue => new ParameterCanBeByValInspectionResult(this, issue, ((dynamic)issue.Context).identifier(), issue.QualifiedName));

return issues;
}
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
&& !builtInHandlers.Contains(parameter.ParentDeclaration))
let isInterfaceImplementationMember = IsInterfaceMemberImplementationParameter(issue, interfaceImplementationMemberScopes)
select new ParameterNotUsedInspectionResult(this, issue,
((dynamic) issue.Context).ambiguousIdentifier(), issue.QualifiedName,
((dynamic) issue.Context).identifier(), issue.QualifiedName,
isInterfaceImplementationMember, quickFixRefactoring, State);

return issues.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
{
var declaration =
UserDeclarations.SingleOrDefault(d => d.DeclarationType == DeclarationType.Procedure &&
d.IdentifierName == c.ambiguousIdentifier().GetText() &&
d.IdentifierName == c.identifier().GetText() &&
d.Context.GetSelection().Equals(c.GetSelection()));
var interfaceImplementation = UserDeclarations.FindInterfaceImplementationMembers().SingleOrDefault(m => m.Equals(declaration));
Expand All @@ -46,7 +46,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
.Where(c =>
{
var declaration = UserDeclarations.SingleOrDefault(d => d.DeclarationType == DeclarationType.Procedure &&
d.IdentifierName == c.ambiguousIdentifier().GetText() &&
d.IdentifierName == c.identifier().GetText() &&
d.Context.GetSelection().Equals(c.GetSelection()));
if (declaration == null) { return false; } // rather be safe than sorry
Expand Down
Loading

0 comments on commit 29f98b9

Please sign in to comment.