Skip to content

Commit ae19b66

Browse files
authored
Merge pull request #3609 from IvenBach/Rubberduck.SmartIndenter_C#6&7_Update
C#6/C#7 technical debt payment
2 parents 51cdfc0 + 86834c0 commit ae19b66

File tree

5 files changed

+50
-85
lines changed

5 files changed

+50
-85
lines changed

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ private void ExtractEndOfLineComment()
9494
EndOfLineComment = match.Groups["comment"].Value.Trim();
9595
}
9696

97-
public AbsoluteCodeLine Previous { get; private set; }
97+
public AbsoluteCodeLine Previous { get; }
9898

99-
public string Original { get; private set; }
99+
public string Original { get; }
100100

101101
public string Escaped
102102
{
@@ -120,58 +120,46 @@ public string Escaped
120120

121121
public string EndOfLineComment { get; private set; }
122122

123-
public IEnumerable<string> Segments
124-
{
125-
get { return _segments; }
126-
}
123+
public IEnumerable<string> Segments => _segments;
127124

128125
public string ContinuationRebuildText
129126
{
130127
get
131128
{
132-
var output = (_code + " " + EndOfLineComment).Trim();
129+
var output = ($"{_code} {EndOfLineComment}").Trim();
133130
return HasContinuation ? output.Substring(0, output.Length - 1) : output;
134131
}
135132
}
136133

137-
public bool ContainsOnlyComment
138-
{
139-
get { return _code.StartsWith("'") || _code.StartsWith("Rem "); }
140-
}
134+
public bool ContainsOnlyComment => _code.StartsWith("'") || _code.StartsWith("Rem ");
141135

142-
public bool IsDeclaration
143-
{
144-
get { return !IsEmpty && (!IsProcedureStart && !ProcedureStartIgnoreRegex.IsMatch(_code)) && DeclarationRegex.IsMatch(_code); }
145-
}
136+
public bool IsDeclaration => !IsEmpty && (!IsProcedureStart && !ProcedureStartIgnoreRegex.IsMatch(_code)) && DeclarationRegex.IsMatch(_code);
146137

147138
public bool IsDeclarationContinuation { get; set; }
148139

149140
public bool HasDeclarationContinuation
150141
{
151142
get
152143
{
153-
return (!IsProcedureStart && !ProcedureStartIgnoreRegex.IsMatch(_code)) &&
154-
!ContainsOnlyComment &&
155-
string.IsNullOrEmpty(EndOfLineComment) &&
156-
HasContinuation &&
157-
((IsDeclarationContinuation && Segments.Count() == 1) || DeclarationRegex.IsMatch(Segments.Last()));
144+
if (!string.IsNullOrEmpty(EndOfLineComment)
145+
|| ContainsOnlyComment
146+
|| IsProcedureStart
147+
|| !HasContinuation
148+
|| ProcedureStartIgnoreRegex.IsMatch(_code))
149+
{
150+
return false;
151+
}
152+
153+
return (IsDeclarationContinuation && Segments.Count() == 1)
154+
|| DeclarationRegex.IsMatch(Segments.Last());
158155
}
159156
}
160157

161-
public bool HasContinuation
162-
{
163-
get { return _code.Equals("_") || _code.EndsWith(" _") || EndOfLineComment.EndsWith(" _"); }
164-
}
158+
public bool HasContinuation => _code.Equals("_") || _code.EndsWith(" _") || EndOfLineComment.EndsWith(" _");
165159

166-
public bool IsPrecompilerDirective
167-
{
168-
get { return _code.TrimStart().StartsWith("#"); }
169-
}
160+
public bool IsPrecompilerDirective => _code.TrimStart().StartsWith("#");
170161

171-
public bool IsBareDebugStatement
172-
{
173-
get { return _code.StartsWith("Debug.") || _code.Equals("Stop"); }
174-
}
162+
public bool IsBareDebugStatement => _code.StartsWith("Debug.") || _code.Equals("Stop");
175163

176164
public int EnumOrTypeStarts
177165
{
@@ -185,19 +173,15 @@ public int EnumOrTypeEnds
185173

186174
public bool IsProcedureStart
187175
{
188-
get
189-
{ return _segments.Any(s => ProcedureStartRegex.IsMatch(s)) && !_segments.Any(s => ProcedureStartIgnoreRegex.IsMatch(s)); }
176+
get { return _segments.Any(s => ProcedureStartRegex.IsMatch(s)) && !_segments.Any(s => ProcedureStartIgnoreRegex.IsMatch(s)); }
190177
}
191178

192179
public bool IsProcedureEnd
193180
{
194181
get { return _segments.Any(s => ProcedureEndRegex.IsMatch(s)); }
195182
}
196183

197-
public bool IsEmpty
198-
{
199-
get { return Original.Trim().Length == 0; }
200-
}
184+
public bool IsEmpty => Original.Trim().Length == 0;
201185

202186
public int NextLineIndents
203187
{
@@ -301,7 +285,7 @@ private void AlignDims(int postition)
301285
{
302286
if (_segments[0].Trim().StartsWith("As "))
303287
{
304-
_segments[0] = string.Format("{0}{1}", new String(' ', _settings.AlignDimColumn - postition - 1), _segments[0].Trim());
288+
_segments[0] = string.Format("{0}{1}", new string(' ', _settings.AlignDimColumn - postition - 1), _segments[0].Trim());
305289
return;
306290
}
307291
var alignTokens = _segments[0].Split(new[] { " As " }, StringSplitOptions.None);

Rubberduck.SmartIndenter/AlignmentToken.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ internal enum AlignmentTokenType
1010

1111
internal class AlignmentToken
1212
{
13-
public AlignmentTokenType Type { get; private set; }
14-
public int Position { get; private set; }
13+
public AlignmentTokenType Type { get; }
14+
public int Position { get; }
1515

1616
public AlignmentToken(AlignmentTokenType type, int position)
1717
{

Rubberduck.SmartIndenter/IndenterProgressEventArgs.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,17 @@ namespace Rubberduck.SmartIndenter
44
{
55
public class IndenterProgressEventArgs : EventArgs
66
{
7-
private readonly int _progress;
8-
private readonly int _max;
9-
private readonly string _componentName;
10-
117
public IndenterProgressEventArgs(string componentName, int progress, int max)
128
{
13-
_progress = progress;
14-
_max = max;
15-
_componentName = componentName;
9+
Progress = progress;
10+
Max = max;
11+
ComponentName = componentName;
1612
}
1713

18-
public int Progress
19-
{
20-
get { return _progress; }
21-
}
14+
public int Progress { get; }
2215

23-
public string ComponentName
24-
{
25-
get { return _componentName; }
26-
}
16+
public string ComponentName { get; }
2717

28-
public int Max
29-
{
30-
get { return _max; }
31-
}
18+
public int Max { get; }
3219
}
3320
}

Rubberduck.SmartIndenter/IndenterSettings.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,35 @@ public class IndenterSettings : IIndenterSettings, IEquatable<IndenterSettings>
2929
private int _dimAlignment;
3030
public virtual int AlignDimColumn
3131
{
32-
get { return _dimAlignment; }
33-
set
34-
{
35-
_dimAlignment = value > MaximumAlignDimColumn ? MaximumAlignDimColumn : Math.Max(value, 0);
36-
}
32+
get => _dimAlignment;
33+
set => _dimAlignment = value > MaximumAlignDimColumn ? MaximumAlignDimColumn : Math.Max(value, 0);
3734
}
3835

3936
public virtual EndOfLineCommentStyle EndOfLineCommentStyle { get; set; }
4037

4138
private int _commentAlignment;
4239
public virtual int EndOfLineCommentColumnSpaceAlignment
4340
{
44-
get { return _commentAlignment; }
45-
set
46-
{
47-
_commentAlignment = value > MaximumEndOfLineCommentColumnSpaceAlignment
48-
? MaximumEndOfLineCommentColumnSpaceAlignment
49-
: value;
50-
}
41+
get => _commentAlignment;
42+
set => _commentAlignment = value > MaximumEndOfLineCommentColumnSpaceAlignment
43+
? MaximumEndOfLineCommentColumnSpaceAlignment
44+
: value;
5145
}
5246

5347
private int _indentSpaces;
5448
public virtual int IndentSpaces
5549
{
56-
get { return _indentSpaces; }
57-
set { _indentSpaces = value > MaximumIndentSpaces ? MaximumIndentSpaces : Math.Max(value, 0); }
50+
get => _indentSpaces;
51+
set => _indentSpaces = value > MaximumIndentSpaces ? MaximumIndentSpaces : Math.Max(value, 0);
5852
}
5953

6054
public virtual bool VerticallySpaceProcedures { get; set; }
6155

6256
private int _procedureSpacing;
6357
public virtual int LinesBetweenProcedures
6458
{
65-
get { return _procedureSpacing; }
66-
set { _procedureSpacing = value > MaximumVerticalSpacing ? MaximumVerticalSpacing : Math.Max(value, 0); }
59+
get => _procedureSpacing;
60+
set => _procedureSpacing = value > MaximumVerticalSpacing ? MaximumVerticalSpacing : Math.Max(value, 0);
6761
}
6862

6963
public IndenterSettings()

Rubberduck.SmartIndenter/StringLiteralAndBracketEscaper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ internal class StringLiteralAndBracketEscaper
1414

1515
private readonly List<string> _strings = new List<string>();
1616
private readonly List<string> _brackets = new List<string>();
17-
private readonly string _unescaped;
18-
private readonly string _escaped;
1917

20-
public string EscapedString { get { return _escaped; } }
21-
public string OriginalString { get { return _unescaped; } }
22-
public IEnumerable<string> EscapedStrings { get { return _strings; } }
23-
public IEnumerable<string> EscapedBrackets { get { return _brackets; } }
18+
public string EscapedString { get; }
19+
20+
public string OriginalString { get; }
21+
22+
public IEnumerable<string> EscapedStrings => _strings;
23+
public IEnumerable<string> EscapedBrackets => _brackets;
2424

2525
public string UnescapeIndented(string indented)
2626
{
@@ -38,9 +38,9 @@ public string UnescapeIndented(string indented)
3838

3939
public StringLiteralAndBracketEscaper(string code)
4040
{
41-
_unescaped = code;
41+
OriginalString = code;
4242

43-
var chars = _unescaped.ToCharArray();
43+
var chars = OriginalString.ToCharArray();
4444
var quoted = false;
4545
var bracketed = false;
4646
var ins = 0;
@@ -88,7 +88,7 @@ public StringLiteralAndBracketEscaper(string code)
8888
}
8989
}
9090
}
91-
_escaped = new string(chars);
91+
EscapedString = new string(chars);
9292
}
9393
}
9494
}

0 commit comments

Comments
 (0)