Skip to content

Commit 5d7369a

Browse files
authored
Merge pull request #5327 from BZngr/4805_EncapsulateFieldTypeMember
Rewrite of EncapsulateField refactoring, introduces "wrap with private type" functionality
2 parents 9b3bd2d + 93156c5 commit 5d7369a

File tree

49 files changed

+7201
-1193
lines changed

Some content is hidden

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

49 files changed

+7201
-1193
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/HungarianNotationInspection.cs

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text.RegularExpressions;
55
using Rubberduck.CodeAnalysis.Settings;
6+
using Rubberduck.Common;
67
using Rubberduck.Inspections.Abstract;
78
using Rubberduck.Inspections.Inspections.Extensions;
89
using Rubberduck.Inspections.Results;
@@ -49,69 +50,6 @@ namespace Rubberduck.Inspections.Concrete
4950
public sealed class HungarianNotationInspection : InspectionBase
5051
{
5152
#region statics
52-
private static readonly List<string> HungarianPrefixes = new List<string>
53-
{
54-
"chk",
55-
"cbo",
56-
"cmd",
57-
"btn",
58-
"fra",
59-
"img",
60-
"lbl",
61-
"lst",
62-
"mnu",
63-
"opt",
64-
"pic",
65-
"shp",
66-
"txt",
67-
"tmr",
68-
"chk",
69-
"dlg",
70-
"drv",
71-
"frm",
72-
"grd",
73-
"obj",
74-
"rpt",
75-
"fld",
76-
"idx",
77-
"tbl",
78-
"tbd",
79-
"bas",
80-
"cls",
81-
"g",
82-
"m",
83-
"bln",
84-
"byt",
85-
"col",
86-
"dtm",
87-
"dbl",
88-
"cur",
89-
"int",
90-
"lng",
91-
"sng",
92-
"str",
93-
"udt",
94-
"vnt",
95-
"var",
96-
"pgr",
97-
"dao",
98-
"b",
99-
"by",
100-
"c",
101-
"chr",
102-
"i",
103-
"l",
104-
"s",
105-
"o",
106-
"n",
107-
"dt",
108-
"dat",
109-
"a",
110-
"arr"
111-
};
112-
113-
private static readonly Regex HungarianIdentifierRegex = new Regex($"^({string.Join("|", HungarianPrefixes)})[A-Z0-9].*$");
114-
11553
private static readonly List<DeclarationType> TargetDeclarationTypes = new List<DeclarationType>
11654
{
11755
DeclarationType.Parameter,
@@ -154,7 +92,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
15492
&& TargetDeclarationTypes.Contains(declaration.DeclarationType)
15593
&& !IgnoredProcedureTypes.Contains(declaration.DeclarationType)
15694
&& !IgnoredProcedureTypes.Contains(declaration.ParentDeclaration.DeclarationType)
157-
&& HungarianIdentifierRegex.IsMatch(declaration.IdentifierName))
95+
&& declaration.IdentifierName.TryMatchHungarianNotationCriteria(out _))
15896
.Select(issue => new DeclarationInspectionResult(this,
15997
string.Format(Resources.Inspections.InspectionResults.IdentifierNameInspection,
16098
RubberduckUI.ResourceManager.GetString($"DeclarationType_{issue.DeclarationType}", CultureInfo.CurrentUICulture),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Data;
9+
10+
namespace Rubberduck.UI.Converters
11+
{
12+
public class BoolToVisibleVisibilityConverter : IValueConverter
13+
{
14+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
15+
{
16+
var typedValue = (bool)value;
17+
return typedValue ? Visibility.Visible : Visibility.Collapsed;
18+
}
19+
20+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
21+
{
22+
var typedValue = (Visibility)value;
23+
return typedValue != Visibility.Collapsed;
24+
}
25+
}
26+
}

Rubberduck.Core/UI/Refactorings/EncapsulateField/EncapsulateFieldDialog.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,8 @@ namespace Rubberduck.UI.Refactorings.EncapsulateField
44
{
55
public sealed class EncapsulateFieldDialog : RefactoringDialogBase<EncapsulateFieldModel, EncapsulateFieldView, EncapsulateFieldViewModel>
66
{
7-
private bool _isExpanded;
8-
private new int MinHeight => _isExpanded ? 560 : 305;
9-
107
public EncapsulateFieldDialog(DialogData dialogData, EncapsulateFieldModel model, EncapsulateFieldView view, EncapsulateFieldViewModel viewModel) : base(dialogData, model, view, viewModel)
118
{
12-
ViewModel.ExpansionStateChanged += Vm_ExpansionStateChanged;
13-
}
14-
15-
private void Vm_ExpansionStateChanged(object sender, bool isExpanded)
16-
{
17-
_isExpanded = isExpanded;
18-
Height = MinHeight;
199
}
2010
}
2111
}

Rubberduck.Core/UI/Refactorings/EncapsulateField/EncapsulateFieldPresenter.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ namespace Rubberduck.UI.Refactorings.EncapsulateField
66
internal class EncapsulateFieldPresenter : RefactoringPresenterBase<EncapsulateFieldModel>, IEncapsulateFieldPresenter
77
{
88
private static readonly DialogData DialogData =
9-
DialogData.Create(RubberduckUI.EncapsulateField_Caption, 305, 667);
9+
DialogData.Create(RubberduckUI.EncapsulateField_Caption, 800, 900);
1010

1111
public EncapsulateFieldPresenter(EncapsulateFieldModel model,
1212
IRefactoringDialogFactory dialogFactory) : base(DialogData, model, dialogFactory) { }
13-
14-
public override EncapsulateFieldModel Show()
15-
{
16-
return Model.TargetDeclaration == null ? null : base.Show();
17-
}
1813
}
1914
}

0 commit comments

Comments
 (0)