Skip to content

Commit 8cb54eb

Browse files
committed
Merge branch 'next' into RestoreReplaceReferences
2 parents ab5b019 + 0cac5e6 commit 8cb54eb

File tree

47 files changed

+483
-288
lines changed

Some content is hidden

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

47 files changed

+483
-288
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyStringLiteralInspection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
99
/// <summary>
1010
/// Flags uses of an empty string literal ("").
1111
/// </summary>
12+
/// <remarks>
13+
/// Treating an empty string literal as equal to the 'vbNullString' constant
14+
/// requires using the PermissiveAssertClass. The default AssertClass is more strict about data types, and tells them apart.
15+
/// </remarks>
1216
/// <why>
1317
/// Standard library constant 'vbNullString' is more explicit about its intent, and should be preferred to a string literal.
1418
/// While the memory gain is meaningless, an empty string literal still takes up 2 bytes of memory,
15-
/// but 'vbNullString' is a null string pointer, and doesn't.
19+
/// but 'vbNullString' is a null string pointer, and doesn't. In VB6 and VBA this makes little to no difference however,
20+
/// but in earlier versions each instance of an empty string literal in source code resulted in the allocation of these 2 bytes every time.
1621
/// </why>
1722
/// <example hasResult="true">
1823
/// <module name="MyModule" type="Standard Module">

Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueAlwaysDiscardedInspection.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,23 @@ private static bool IsCalledAsProcedure(ParserRuleContext context)
141141
}
142142

143143
//Member accesses are parsed right-to-left, e.g. 'foo.Bar' is the parent of 'foo'.
144-
//Thus, having a member access parent means that the return value is used somehow.
145-
var ownFunctionCallExpression = context.Parent is VBAParser.MemberAccessExprContext methodCall
146-
? methodCall
147-
: context;
148-
var memberAccessParent = ownFunctionCallExpression.GetAncestor<VBAParser.MemberAccessExprContext>();
144+
//Thus, having a member access parent and being contained in its lExpression on the left of the dot
145+
//or having a further member access parent means that the return value is used somehow.
146+
var memberAccessParent = context.GetAncestor<VBAParser.MemberAccessExprContext>();
149147
if (memberAccessParent != null)
150148
{
151-
return false;
149+
//This case is necessary for member accesses in particular on simple name expressions since the context is the simpleNameExpression there and not the identifier.
150+
if (memberAccessParent.lExpression().Contains(context))
151+
{
152+
return false;
153+
}
154+
155+
//This case is necessary if the context is itself the unrestricted identifier in a member access.
156+
var furtherMemberAccessParent = memberAccessParent.GetAncestor<VBAParser.MemberAccessExprContext>();
157+
if (furtherMemberAccessParent != null)
158+
{
159+
return false;
160+
}
152161
}
153162

154163
//If we are in an output list, the value is used somewhere in defining the argument.

Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueDiscardedInspection.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,23 @@ private static bool IsCalledAsProcedure(ParserRuleContext context)
7777
}
7878

7979
//Member accesses are parsed right-to-left, e.g. 'foo.Bar' is the parent of 'foo'.
80-
//Thus, having a member access parent means that the return value is used somehow.
81-
var ownFunctionCallExpression = context.Parent is VBAParser.MemberAccessExprContext methodCall
82-
? methodCall
83-
: context;
84-
var memberAccessParent = ownFunctionCallExpression.GetAncestor<VBAParser.MemberAccessExprContext>();
80+
//Thus, having a member access parent and being contained in its lExpression on the left of the dot
81+
//or having a further member access parent means that the return value is used somehow.
82+
var memberAccessParent = context.GetAncestor<VBAParser.MemberAccessExprContext>();
8583
if (memberAccessParent != null)
8684
{
87-
return false;
85+
//This case is necessary for member accesses in particular on simple name expressions since the context is the simpleNameExpression there and not the identifier.
86+
if (memberAccessParent.lExpression().Contains(context))
87+
{
88+
return false;
89+
}
90+
91+
//This case is necessary if the context is itself the unrestricted identifier in a member access.
92+
var furtherMemberAccessParent = memberAccessParent.GetAncestor<VBAParser.MemberAccessExprContext>();
93+
if (furtherMemberAccessParent != null)
94+
{
95+
return false;
96+
}
8897
}
8998

9099
//If we are in an output list, the value is used somewhere in defining the argument.

Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotAssignedInspection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration
5151
&& !declaration.IsWithEvents
5252
&& !declaration.IsSelfAssigned
5353
&& !HasUdtType(declaration, finder) // UDT variables don't need to be assigned
54-
&& !declaration.References.Any(reference => reference.IsAssignment || IsAssignedByRefArgument(reference.ParentScoping, reference, finder));
54+
&& !declaration.References.Any(reference => reference.IsAssignment
55+
|| reference.IsReDim //Ignores Variants used as arrays without assignment of an existing one.
56+
|| IsAssignedByRefArgument(reference.ParentScoping, reference, finder));
5557
}
5658

5759
private static bool HasUdtType(Declaration declaration, DeclarationFinder finder)

Rubberduck.Core/Common/RubberduckHooks.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,18 @@ public void Detach()
121121

122122
private void hook_MessageReceived(object sender, HookEventArgs e)
123123
{
124-
if (sender is IHotkey hotkey
125-
&& hotkey.Command.CanExecute(null))
124+
if (sender is IHotkey hotkey)
126125
{
127-
hotkey.Command.Execute(null);
128-
return;
126+
if (hotkey.Command.CanExecute(null))
127+
{
128+
hotkey.Command.Execute(null);
129+
return;
130+
}
131+
else
132+
{
133+
Console.Beep();
134+
}
129135
}
130-
131136
OnMessageReceived(sender, e);
132137
}
133138

Lines changed: 6 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Sdk="Sunburst.NET.Sdk.WPF.Patched/1.0.49">
2+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
33
<PropertyGroup>
44
<RootNamespace>Rubberduck</RootNamespace>
55
<AssemblyName>Rubberduck.Core</AssemblyName>
66
<Title>Rubberduck.Core</Title>
77
<Product>Rubberduck.Core</Product>
8-
<Copyright>Copyright © 2014-2019</Copyright>
8+
<Copyright>Copyright © 2014-2021</Copyright>
99
<ProjectGuid>{A1587EAC-7B54-407E-853F-4C7493D0323E}</ProjectGuid>
1010
<DocumentationFile>bin\Debug\Rubberduck.Core.xml</DocumentationFile>
1111
<!-- Disable "Missing XML documentation" warning (CS1591) -->
1212
<DisabledWarnings>$(DisabledWarnings);1591</DisabledWarnings>
1313
<ApplicationIcon>Ducky.ico</ApplicationIcon>
14-
<!-- Give a fixed version to not blow XAML generated code to smithereens -->
15-
<!-- This also fixes "Input string was not in the correct format" error message when referring to the current assembly in an XAML-Namespace -->
16-
<AssemblyVersion>2.5.1</AssemblyVersion>
14+
<UseWpf>true</UseWpf>
15+
<UseWindowsForms>true</UseWindowsForms>
1716
</PropertyGroup>
1817
<Import Project="..\RubberduckBaseProject.csproj" />
1918
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugAccess|AnyCPU'">
@@ -45,6 +44,7 @@
4544
<ItemGroup>
4645
<ProjectReference Include="..\Rubberduck.CodeAnalysis\Rubberduck.CodeAnalysis.csproj" />
4746
<ProjectReference Include="..\Rubberduck.Interaction\Rubberduck.Interaction.csproj" />
47+
<ProjectReference Include="..\Rubberduck.InternalApi\Rubberduck.InternalApi.csproj" />
4848
<ProjectReference Include="..\Rubberduck.Parsing\Rubberduck.Parsing.csproj" />
4949
<ProjectReference Include="..\Rubberduck.Refactorings\Rubberduck.Refactorings.csproj" />
5050
<ProjectReference Include="..\Rubberduck.RegexAssistant\Rubberduck.RegexAssistant.csproj" />
@@ -83,107 +83,12 @@
8383
<PackageReference Include="NLog.Schema">
8484
<Version>4.5.10</Version>
8585
</PackageReference>
86+
<PackageReference Include="System.IO.Abstractions" Version="12.2.1" />
8687
<PackageReference Include="System.ValueTuple">
8788
<Version>4.5.0</Version>
8889
</PackageReference>
8990
<PackageReference Include="System.Windows.Interactivity.WPF">
9091
<Version>2.0.20525</Version>
9192
</PackageReference>
9293
</ItemGroup>
93-
94-
<!-- BEGIN WINDOWS FORMS WORKAROUND SECTION -->
95-
<ItemGroup>
96-
<Compile Update="**\*Window.cs" SubType="Form" />
97-
<Compile Update="**\*Dialog.cs" SubType="Form" />
98-
<Compile Update="**\SettingsForm.cs" SubType="Form" />
99-
<Compile Update="**\SimpleListControl.cs" SubType="Form" />
100-
<Compile Update="**\Splash.cs" SubType="Form" />
101-
<Compile Update="**\*.Designer.cs">
102-
<DependentUpon>$([System.String]::Copy('%(Filename)').Replace('.Designer', '')).cs</DependentUpon>
103-
</Compile>
104-
<!--<EmbeddedResource Update="UI\**\*.resx">
105-
<DependentUpon>%(Filename).cs</DependentUpon>
106-
</EmbeddedResource>-->
107-
</ItemGroup>
108-
<ItemGroup>
109-
<Compile Update="Properties\Resources.Designer.cs">
110-
<DesignTime>True</DesignTime>
111-
<AutoGen>True</AutoGen>
112-
<DependentUpon>Resources.resx</DependentUpon>
113-
</Compile>
114-
<Compile Update="Properties\Settings.Designer.cs">
115-
<DependentUpon>Settings.settings</DependentUpon>
116-
<DesignTime>True</DesignTime>
117-
<AutoGen>True</AutoGen>
118-
<DesignTimeSharedInput>True</DesignTimeSharedInput>
119-
</Compile>
120-
<Compile Update="UI\AddRemoveReferences\AddRemoveReferencesUI.Designer.cs">
121-
<DesignTime>True</DesignTime>
122-
<AutoGen>True</AutoGen>
123-
<DependentUpon>AddRemoveReferencesUI.resx</DependentUpon>
124-
</Compile>
125-
<Compile Update="UI\Inspections\InspectionResultsUI.Designer.cs">
126-
<DesignTime>True</DesignTime>
127-
<AutoGen>True</AutoGen>
128-
<DependentUpon>InspectionResultsUI.resx</DependentUpon>
129-
</Compile>
130-
<Compile Update="UI\Refactorings\AnnotateDeclaration\AnnotateDeclarationView.xaml.cs">
131-
<DependentUpon>AnnotateDeclarationView.xaml</DependentUpon>
132-
</Compile>
133-
<Compile Update="UI\Refactorings\MoveFolder\MoveMultipleFoldersView.xaml.cs">
134-
<DependentUpon>MoveMultipleFoldersView.xaml</DependentUpon>
135-
</Compile>
136-
<Compile Update="UI\Refactorings\MoveToFolder\MoveMultipleToFolderView.xaml.cs">
137-
<DependentUpon>MoveMultipleToFolderView.xaml</DependentUpon>
138-
</Compile>
139-
<Compile Update="UI\Refactorings\RenameFolder\RenameFolderView.xaml.cs">
140-
<DependentUpon>RenameFolderView.xaml</DependentUpon>
141-
</Compile>
142-
<Compile Update="UI\Settings\GeneralSettingsUI.Designer.cs">
143-
<DesignTime>True</DesignTime>
144-
<AutoGen>True</AutoGen>
145-
<DependentUpon>GeneralSettingsUI.resx</DependentUpon>
146-
</Compile>
147-
<Compile Update="UI\ToDoItems\ToDoExplorerUI.Designer.cs">
148-
<DesignTime>True</DesignTime>
149-
<AutoGen>True</AutoGen>
150-
<DependentUpon>ToDoExplorerUI.resx</DependentUpon>
151-
</Compile>
152-
<Compile Update="UI\Settings\IgnoredProjectsSettingsView.xaml.cs">
153-
<DependentUpon>IgnoredProjectsSettingsView.xaml</DependentUpon>
154-
</Compile>
155-
</ItemGroup>
156-
<ItemGroup>
157-
<EmbeddedResource Update="Properties\Resources.resx">
158-
<Generator>ResXFileCodeGenerator</Generator>
159-
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
160-
</EmbeddedResource>
161-
<EmbeddedResource Update="UI\AddRemoveReferences\AddRemoveReferencesUI.resx">
162-
<Generator>PublicResXFileCodeGenerator</Generator>
163-
<LastGenOutput>AddRemoveReferencesUI.Designer.cs</LastGenOutput>
164-
</EmbeddedResource>
165-
<EmbeddedResource Update="UI\Inspections\InspectionResultsUI.resx">
166-
<Generator>PublicResXFileCodeGenerator</Generator>
167-
<LastGenOutput>InspectionResultsUI.Designer.cs</LastGenOutput>
168-
</EmbeddedResource>
169-
<EmbeddedResource Update="UI\Settings\GeneralSettingsUI.resx">
170-
<Generator>PublicResXFileCodeGenerator</Generator>
171-
<LastGenOutput>GeneralSettingsUI.Designer.cs</LastGenOutput>
172-
</EmbeddedResource>
173-
<EmbeddedResource Update="UI\ToDoItems\ToDoExplorerUI.resx">
174-
<Generator>PublicResXFileCodeGenerator</Generator>
175-
<LastGenOutput>ToDoExplorerUI.Designer.cs</LastGenOutput>
176-
</EmbeddedResource>
177-
</ItemGroup>
178-
<ItemGroup>
179-
<None Update="Properties\Settings.settings">
180-
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
181-
<Generator>SettingsSingleFileGenerator</Generator>
182-
</None>
183-
</ItemGroup>
184-
<ItemGroup>
185-
<Folder Include="UI\IgnoredProjects\" />
186-
</ItemGroup>
187-
<!-- END WINDOWS FORMS WORKAROUND SECTION -->
188-
18994
</Project>

Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesWindow.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
ItemsSource="{Binding AvailableReferences}"
189189
HorizontalContentAlignment="Stretch"
190190
ScrollViewer.HorizontalScrollBarVisibility="Auto"
191-
GotFocus="ListView_SynchronizeCurrentSelection_OnGotFocus">
191+
SelectionChanged="ListView_SynchronizeCurrentSelection_OnSelectionChanged">
192192
<ListView.ItemContainerStyle>
193193
<Style TargetType="ListViewItem">
194194
<Setter Property="Height" Value="20" />
@@ -246,8 +246,7 @@
246246
SelectionMode="Single"
247247
ItemsSource="{Binding ProjectReferences, NotifyOnTargetUpdated=True}"
248248
ScrollViewer.HorizontalScrollBarVisibility="Auto"
249-
HorizontalContentAlignment="Stretch"
250-
GotFocus="ListView_SynchronizeCurrentSelection_OnGotFocus">
249+
HorizontalContentAlignment="Stretch" SelectionChanged="ListView_SynchronizeCurrentSelection_OnSelectionChanged">
251250
<ListView.ItemContainerStyle>
252251
<Style TargetType="ListViewItem">
253252
<Setter Property="Height" Value="20" />

Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public AddRemoveReferencesWindow()
1616

1717
private AddRemoveReferencesViewModel ViewModel => DataContext as AddRemoveReferencesViewModel;
1818

19-
private void ListView_SynchronizeCurrentSelection_OnGotFocus(object sender, RoutedEventArgs e)
19+
private void ListView_SynchronizeCurrentSelection_OnSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
2020
{
2121
UpdateCurrentSelection((Selector)sender);
2222

Rubberduck.Core/UI/Command/MenuItems/ParentMenus/RefactoringsParentMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum RefactoringsMenuItemDisplayOrder
2323
ReorderParameters,
2424
MoveCloserToUsage,
2525
EncapsulateField,
26-
IntroduceParameter,
26+
PromoteToParameter,
2727
IntroduceField,
2828
MoveToFolder,
2929
MoveContainingFolder,

Rubberduck.Core/UI/Command/MenuItems/RefactorIntroduceParameterCommandMenuItem.cs renamed to Rubberduck.Core/UI/Command/MenuItems/RefactorPromoteToParameterCommandMenuItem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace Rubberduck.UI.Command.MenuItems
77
{
8-
public class RefactorIntroduceParameterCommandMenuItem : CommandMenuItemBase
8+
public class RefactorPromoteToParameterCommandMenuItem : CommandMenuItemBase
99
{
10-
public RefactorIntroduceParameterCommandMenuItem (RefactorIntroduceParameterCommand command)
10+
public RefactorPromoteToParameterCommandMenuItem (RefactorPromoteToParameterCommand command)
1111
: base(command)
1212
{
1313
}
1414

15-
public override string Key => "RefactorMenu_IntroduceParameter";
16-
public override int DisplayOrder => (int)RefactoringsMenuItemDisplayOrder.IntroduceParameter;
15+
public override string Key => "RefactorMenu_PromoteToParameter";
16+
public override int DisplayOrder => (int)RefactoringsMenuItemDisplayOrder.PromoteToParameter;
1717
public override bool BeginGroup => true;
1818

1919
public override Image Image => Resources.CommandBarIcons.PromoteLocal;

0 commit comments

Comments
 (0)