Skip to content

Commit 5582c1c

Browse files
committed
Merge Main and rename one more variable
2 parents 56bfdbb + 40690b6 commit 5582c1c

File tree

60 files changed

+579
-693
lines changed

Some content is hidden

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

60 files changed

+579
-693
lines changed

RetailCoder.VBE/API/VBA/Declaration.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,18 @@ public interface IDeclaration
3232
[EditorBrowsable(EditorBrowsableState.Always)]
3333
public class Declaration : IDeclaration
3434
{
35-
private readonly RubberduckDeclaration _declaration;
36-
3735
internal Declaration(RubberduckDeclaration declaration)
3836
{
39-
_declaration = declaration;
37+
Instance = declaration;
4038
}
4139

42-
protected RubberduckDeclaration Instance { get { return _declaration; } }
40+
protected RubberduckDeclaration Instance { get; }
4341

44-
public bool IsArray { get { return _declaration.IsArray; } }
45-
public string Name { get { return _declaration.IdentifierName; } }
46-
public Accessibility Accessibility { get { return (Accessibility)_declaration.Accessibility; } }
47-
public DeclarationType DeclarationType {get { return TypeMappings[_declaration.DeclarationType]; }}
48-
public string TypeName { get { return _declaration.AsTypeName; } }
42+
public bool IsArray => Instance.IsArray;
43+
public string Name => Instance.IdentifierName;
44+
public Accessibility Accessibility => (Accessibility)Instance.Accessibility;
45+
public DeclarationType DeclarationType => TypeMappings[Instance.DeclarationType];
46+
public string TypeName => Instance.AsTypeName;
4947

5048
private static readonly IDictionary<Parsing.Symbols.DeclarationType,DeclarationType> TypeMappings =
5149
new Dictionary<Parsing.Symbols.DeclarationType, DeclarationType>
@@ -75,20 +73,14 @@ internal Declaration(RubberduckDeclaration declaration)
7573
};
7674

7775
private Declaration _parentDeclaration;
78-
public Declaration ParentDeclaration
79-
{
80-
get
81-
{
82-
return _parentDeclaration ?? (_parentDeclaration = new Declaration(Instance.ParentDeclaration));
83-
}
84-
}
76+
public Declaration ParentDeclaration => _parentDeclaration ?? (_parentDeclaration = new Declaration(Instance.ParentDeclaration));
8577

8678
private IdentifierReference[] _references;
8779
public IdentifierReference[] References
8880
{
8981
get
9082
{
91-
return _references ?? (_references = _declaration.References.Select(item => new IdentifierReference(item)).ToArray());
83+
return _references ?? (_references = Instance.References.Select(item => new IdentifierReference(item)).ToArray());
9284
}
9385
}
9486
}

RetailCoder.VBE/API/VBA/IdentifierReference.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,19 @@ public IdentifierReference(Parsing.Symbols.IdentifierReference reference)
3131
}
3232

3333
private Declaration _declaration;
34-
public Declaration Declaration
35-
{
36-
get { return _declaration ?? (_declaration = new Declaration(_reference.Declaration)); }
37-
}
34+
public Declaration Declaration => _declaration ?? (_declaration = new Declaration(_reference.Declaration));
3835

3936
private Declaration _parentScoping;
40-
public Declaration ParentScope
41-
{
42-
get { return _parentScoping ?? (_parentScoping = new Declaration(_reference.ParentScoping)); }
43-
}
37+
public Declaration ParentScope => _parentScoping ?? (_parentScoping = new Declaration(_reference.ParentScoping));
4438

4539
private Declaration _parentNonScoping;
46-
public Declaration ParentNonScoping
47-
{
48-
get { return _parentNonScoping ?? (_parentNonScoping = new Declaration(_reference.ParentNonScoping)); }
49-
}
40+
public Declaration ParentNonScoping => _parentNonScoping ?? (_parentNonScoping = new Declaration(_reference.ParentNonScoping));
5041

51-
public bool IsAssignment { get { return _reference.IsAssignment; } }
42+
public bool IsAssignment => _reference.IsAssignment;
5243

53-
public int StartLine { get { return _reference.Selection.StartLine; } }
54-
public int EndLine { get { return _reference.Selection.EndLine; } }
55-
public int StartColumn { get { return _reference.Selection.StartColumn; } }
56-
public int EndColumn { get { return _reference.Selection.EndColumn; } }
44+
public int StartLine => _reference.Selection.StartLine;
45+
public int EndLine => _reference.Selection.EndLine;
46+
public int StartColumn => _reference.Selection.StartColumn;
47+
public int EndColumn => _reference.Selection.EndColumn;
5748
}
5849
}

RetailCoder.VBE/API/VBA/ParserState.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ public void BeginParse()
150150

151151
private void _state_StateChanged(object sender, EventArgs e)
152152
{
153-
_allDeclarations = _state.AllDeclarations
153+
AllDeclarations = _state.AllDeclarations
154154
.Select(item => new Declaration(item))
155155
.ToArray();
156156

157-
_userDeclarations = _state.AllUserDeclarations
157+
UserDeclarations = _state.AllUserDeclarations
158158
.Select(item => new Declaration(item))
159159
.ToArray();
160160

@@ -177,20 +177,9 @@ private void _state_StateChanged(object sender, EventArgs e)
177177
}
178178
}
179179

180-
private Declaration[] _allDeclarations;
180+
public Declaration[] AllDeclarations { get; private set; }
181181

182-
public Declaration[] AllDeclarations
183-
{
184-
//[return: MarshalAs(UnmanagedType.SafeArray/*, SafeArraySubType = VarEnum.VT_VARIANT*/)]
185-
get { return _allDeclarations; }
186-
}
187-
188-
private Declaration[] _userDeclarations;
189-
public Declaration[] UserDeclarations
190-
{
191-
//[return: MarshalAs(UnmanagedType.SafeArray/*, SafeArraySubType = VarEnum.VT_VARIANT*/)]
192-
get { return _userDeclarations; }
193-
}
182+
public Declaration[] UserDeclarations { get; private set; }
194183

195184
private bool _disposed;
196185
public void Dispose()

RetailCoder.VBE/App.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void Startup()
120120
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
121121
_appMenus.Localize();
122122

123-
if (_config.UserSettings.GeneralSettings.CheckVersion)
123+
if (_config.UserSettings.GeneralSettings.CanCheckVersion)
124124
{
125125
_checkVersionCommand.Execute(null);
126126
}
@@ -165,7 +165,7 @@ private void CheckForLegacyIndenterSettings()
165165
try
166166
{
167167
Logger.Trace("Checking for legacy Smart Indenter settings.");
168-
if (_config.UserSettings.GeneralSettings.SmartIndenterPrompted ||
168+
if (_config.UserSettings.GeneralSettings.IsSmartIndenterPrompted ||
169169
!_config.UserSettings.IndenterSettings.LegacySettingsExist())
170170
{
171171
return;
@@ -177,7 +177,7 @@ private void CheckForLegacyIndenterSettings()
177177
Logger.Trace("Attempting to load legacy Smart Indenter settings.");
178178
_config.UserSettings.IndenterSettings.LoadLegacyFromRegistry();
179179
}
180-
_config.UserSettings.GeneralSettings.SmartIndenterPrompted = true;
180+
_config.UserSettings.GeneralSettings.IsSmartIndenterPrompted = true;
181181
_configService.SaveConfiguration(_config);
182182
}
183183
catch

RetailCoder.VBE/Common/ClipboardWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class ClipboardWriter : IClipboardWriter
1919

2020
public void Write(string text)
2121
{
22-
this.AppendString(DataFormats.UnicodeText, text);
23-
this.Flush();
22+
AppendString(DataFormats.UnicodeText, text);
23+
Flush();
2424
}
2525

2626
public void AppendImage(BitmapSource image)

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static Selection GetVariableStmtContextSelection(this Declaration target)
4242
{
4343
if (target.DeclarationType != DeclarationType.Variable)
4444
{
45-
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
45+
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
4646
}
4747

4848
var statement = GetVariableStmtContext(target) ?? target.Context; // undeclared variables don't have a VariableStmtContext
@@ -59,7 +59,7 @@ public static Selection GetConstStmtContextSelection(this Declaration target)
5959
{
6060
if (target.DeclarationType != DeclarationType.Constant)
6161
{
62-
throw new ArgumentException("Target DeclarationType is not Constant.", "target");
62+
throw new ArgumentException("Target DeclarationType is not Constant.", nameof(target));
6363
}
6464

6565
var statement = GetConstStmtContext(target);
@@ -76,7 +76,7 @@ public static VBAParser.VariableStmtContext GetVariableStmtContext(this Declarat
7676
{
7777
if (target.DeclarationType != DeclarationType.Variable)
7878
{
79-
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
79+
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
8080
}
8181

8282
Debug.Assert(target.IsUndeclared || target.Context is VBAParser.VariableSubStmtContext);
@@ -99,7 +99,7 @@ public static VBAParser.ConstStmtContext GetConstStmtContext(this Declaration ta
9999
{
100100
if (target.DeclarationType != DeclarationType.Constant)
101101
{
102-
throw new ArgumentException("Target DeclarationType is not Constant.", "target");
102+
throw new ArgumentException("Target DeclarationType is not Constant.", nameof(target));
103103
}
104104

105105
var statement = target.Context.Parent as VBAParser.ConstStmtContext;
@@ -121,11 +121,11 @@ public static bool HasMultipleDeclarationsInStatement(this Declaration target)
121121
{
122122
if (target.DeclarationType != DeclarationType.Variable)
123123
{
124-
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
124+
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
125125
}
126126

127-
var statement = target.Context.Parent as VBAParser.VariableListStmtContext;
128-
return statement != null && statement.children.OfType<VBAParser.VariableSubStmtContext>().Count() > 1;
127+
return target.Context.Parent is VBAParser.VariableListStmtContext statement
128+
&& statement.children.OfType<VBAParser.VariableSubStmtContext>().Count() > 1;
129129
}
130130

131131
/// <summary>
@@ -138,17 +138,15 @@ public static int CountOfDeclarationsInStatement(this Declaration target)
138138
{
139139
if (target.DeclarationType != DeclarationType.Variable)
140140
{
141-
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
141+
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
142142
}
143143

144-
var statement = target.Context.Parent as VBAParser.VariableListStmtContext;
145-
146-
if (statement != null)
144+
if (target.Context.Parent is VBAParser.VariableListStmtContext statement)
147145
{
148146
return statement.children.OfType<VBAParser.VariableSubStmtContext>().Count();
149147
}
150148

151-
throw new ArgumentException("'target.Context.Parent' is not type VBAParser.VariabelListStmtContext", "target");
149+
throw new ArgumentException("'target.Context.Parent' is not type VBAParser.VariabelListStmtContext", nameof(target));
152150
}
153151

154152
/// <summary>
@@ -161,20 +159,17 @@ public static int IndexOfVariableDeclarationInStatement(this Declaration target)
161159
{
162160
if (target.DeclarationType != DeclarationType.Variable)
163161
{
164-
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
162+
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
165163
}
166164

167-
var statement = target.Context.Parent as VBAParser.VariableListStmtContext;
168-
169-
if (statement != null)
165+
if (target.Context.Parent is VBAParser.VariableListStmtContext statement)
170166
{
171167
return statement.children.OfType<VBAParser.VariableSubStmtContext>()
172168
.ToList()
173169
.IndexOf((VBAParser.VariableSubStmtContext)target.Context) + 1;
174170
}
175171

176-
// ReSharper disable once LocalizableElement
177-
throw new ArgumentException("'target.Context.Parent' is not type VBAParser.VariabelListStmtContext", "target");
172+
throw new ArgumentException("'target.Context.Parent' is not type VBAParser.VariableListStmtContext", nameof(target));
178173
}
179174

180175
public static readonly DeclarationType[] ProcedureTypes =
@@ -298,9 +293,7 @@ public static Declaration FindSelectedDeclaration(this IEnumerable<Declaration>
298293
&& item.QualifiedName.QualifiedModuleName == selection.QualifiedName).ToList();
299294

300295
var declaration = items.SingleOrDefault(item =>
301-
selector == null
302-
? item.Selection.Contains(selection.Selection)
303-
: selector(item).Contains(selection.Selection));
296+
selector?.Invoke(item).Contains(selection.Selection) ?? item.Selection.Contains(selection.Selection));
304297

305298
if (declaration != null)
306299
{

0 commit comments

Comments
 (0)