Skip to content

Commit b5bdb03

Browse files
authored
Merge pull request #4515 from retailcoder/bugfix
Misc. bugfixes
2 parents cf1fdbd + 5e9668e commit b5bdb03

File tree

9 files changed

+392
-432
lines changed

9 files changed

+392
-432
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using Rubberduck.Inspections.CodePathAnalysis.Extensions;
88
using System.Linq;
99
using Rubberduck.Inspections.Results;
10+
using Rubberduck.Parsing;
11+
using Rubberduck.Parsing.Grammar;
1012

1113
namespace Rubberduck.Inspections.Concrete
1214
{
@@ -21,7 +23,9 @@ public AssignmentNotUsedInspection(RubberduckParserState state, Walker walker)
2123

2224
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2325
{
24-
var variables = State.DeclarationFinder.UserDeclarations(DeclarationType.Variable);
26+
var variables = State.DeclarationFinder
27+
.UserDeclarations(DeclarationType.Variable)
28+
.Where(d => !d.IsArray);
2529

2630
var nodes = new List<IdentifierReference>();
2731
foreach (var variable in variables)

Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueNotUsedInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2828
var interfaceImplementationMembers = State.DeclarationFinder.FindAllInterfaceImplementingMembers();
2929
var functions = State.DeclarationFinder
3030
.UserDeclarations(DeclarationType.Function)
31-
.Where(item => !IsIgnoringInspectionResultFor(item, AnnotationName))
31+
.Where(item => !IsIgnoringInspectionResultFor(item, AnnotationName) &&
32+
item.References.Any(r => !IsReturnStatement(item, r) && !r.IsAssignment))
3233
.ToList();
3334
var interfaceMemberIssues = GetInterfaceMemberIssues(interfaceMembers);
3435
var nonInterfaceFunctions = functions.Except(interfaceMembers.Union(interfaceImplementationMembers));

Rubberduck.CodeAnalysis/Inspections/Concrete/UnassignedVariableUsageInspection.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Rubberduck.Inspections.Abstract;
66
using Rubberduck.Inspections.Results;
77
using Rubberduck.Parsing;
8+
using Rubberduck.Parsing.Grammar;
89
using Rubberduck.Parsing.Inspections.Abstract;
910
using Rubberduck.Resources.Inspections;
1011
using Rubberduck.Parsing.Symbols;
@@ -30,7 +31,7 @@ public UnassignedVariableUsageInspection(RubberduckParserState state)
3031
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3132
{
3233
var declarations = State.DeclarationFinder.UserDeclarations(DeclarationType.Variable)
33-
.Where(declaration =>
34+
.Where(declaration => !declaration.IsArray &&
3435
State.DeclarationFinder.MatchName(declaration.AsTypeName)
3536
.All(d => d.DeclarationType != DeclarationType.UserDefinedType)
3637
&& !declaration.IsSelfAssigned
@@ -43,12 +44,22 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
4344
.SelectMany(d => d.References)
4445
.Distinct()
4546
.Where(r => !r.IsIgnoringInspectionResultFor(AnnotationName))
47+
.Where(r => !r.Context.TryGetAncestor<VBAParser.RedimStmtContext>(out _) && !IsArraySubscriptAssignment(r))
4648
.Select(r => new IdentifierReferenceInspectionResult(this,
4749
string.Format(InspectionResults.UnassignedVariableUsageInspection, r.IdentifierName),
4850
State,
4951
r)).ToList();
5052
}
5153

54+
private static bool IsArraySubscriptAssignment(IdentifierReference reference)
55+
{
56+
var isLetAssignment = reference.Context.TryGetAncestor<VBAParser.LetStmtContext>(out var letStmt);
57+
var isSetAssignment = reference.Context.TryGetAncestor<VBAParser.SetStmtContext>(out var setStmt);
58+
59+
return isLetAssignment && letStmt.lExpression() is VBAParser.IndexExprContext ||
60+
isSetAssignment && setStmt.lExpression() is VBAParser.IndexExprContext;
61+
}
62+
5263
private static bool DeclarationReferencesContainsReference(Declaration parentDeclaration, Declaration target)
5364
{
5465
foreach (var targetReference in target.References)

Rubberduck.Core/UI/Refactorings/ExtractInterface/ExtractInterfaceView.xaml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,36 @@
5959
<RowDefinition Height="*" />
6060
<RowDefinition Height="40" />
6161
</Grid.RowDefinitions>
62-
<StackPanel Background="White">
62+
<DockPanel Dock="Top" Background="White">
63+
<StackPanel>
64+
6365
<Label Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ExtractInterface_TitleLabel}" FontWeight="Bold" />
6466
<TextBlock Text="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ExtractInterface_InstructionLabel}"
6567
Margin="5,0" />
66-
</StackPanel>
67-
<StackPanel Grid.Row="1" Margin="5,0">
68-
<Grid VerticalAlignment="Top" Margin="0,0,5,0">
69-
<Grid.RowDefinitions>
70-
<RowDefinition Height="auto" />
71-
<RowDefinition Height="auto" />
72-
</Grid.RowDefinitions>
68+
</StackPanel>
69+
</DockPanel>
70+
<Grid Grid.Row="1" Margin="5">
71+
<Grid.RowDefinitions>
72+
<RowDefinition Height="Auto" />
73+
<RowDefinition Height="*" />
74+
</Grid.RowDefinitions>
75+
<StackPanel Grid.Row="0">
7376
<Label Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=NameLabelText}" />
74-
<TextBox Grid.Row="1"
75-
Margin="5,-2,0,0"
77+
<TextBox Margin="5,-2,0,0"
7678
Height="22"
7779
VerticalAlignment="Top"
7880
VerticalContentAlignment="Center"
7981
Text="{Binding InterfaceName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
80-
<Image Grid.Row="1"
81-
Source="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/cross-circle.png"
82+
<Image Source="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/cross-circle.png"
8283
Height="16"
8384
Margin="0,-10,-8,0"
8485
HorizontalAlignment="Right"
8586
VerticalAlignment="Top"
8687
Visibility="{Binding IsValidInterfaceName, Converter={StaticResource BoolToHiddenVisibility}}"/>
87-
</Grid>
88+
</StackPanel>
8889

8990
<GroupBox Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ExtractInterface_MembersGroupBox}"
90-
Margin="5">
91+
Grid.Row="1" Margin="5" Padding="5">
9192
<Grid>
9293
<Grid.ColumnDefinitions>
9394
<ColumnDefinition Width="*" />
@@ -146,7 +147,8 @@
146147
</StackPanel>
147148
</Grid>
148149
</GroupBox>
149-
</StackPanel>
150+
</Grid>
151+
150152
<Grid Grid.Row="2" Background="{x:Static SystemColors.ControlDarkBrush}" Grid.IsSharedSizeScope="True">
151153
<Grid HorizontalAlignment="Right"
152154
Margin="5,0">

Rubberduck.Core/UI/Refactorings/ExtractInterface/InterfaceMemberViewModel.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ namespace Rubberduck.UI.Refactorings.ExtractInterface
44
{
55
internal class InterfaceMemberViewModel : ViewModelBase
66
{
7-
private readonly InterfaceMember _wrapped;
8-
internal InterfaceMember Wrapped { get => _wrapped; }
9-
10-
11-
private bool _isSelected;
12-
private InterfaceMember model;
13-
147
public InterfaceMemberViewModel(InterfaceMember model)
158
{
16-
this.model = model;
9+
Wrapped = model;
1710
}
1811

12+
internal InterfaceMember Wrapped { get; }
13+
14+
private bool _isSelected;
1915
public bool IsSelected
2016
{
2117
get => _isSelected;
@@ -26,7 +22,7 @@ public bool IsSelected
2622
}
2723
}
2824

29-
public string FullMemberSignature { get => _wrapped.FullMemberSignature; }
25+
public string FullMemberSignature => Wrapped?.FullMemberSignature;
3026
}
3127

3228
internal static class ConversionExtensions

0 commit comments

Comments
 (0)