Skip to content

Commit 584a484

Browse files
committed
Refactor some inconsistent code styles
1 parent 14aa405 commit 584a484

9 files changed

+64
-60
lines changed

AutoItSyntaxHighlight/AutoItEditorClassifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace AutoItSyntaxHighlight
2222
{
2323
internal class AutoItEditorClassifier : IClassifier
2424
{
25-
private AutoItLexer m_Lexer;
25+
private readonly AutoItLexer m_Lexer;
2626

2727
internal AutoItEditorClassifier(IClassificationTypeRegistryService registry)
2828
{

AutoItSyntaxHighlight/AutoItEditorClassifierClassificationDefinition.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@ internal static class AutoItEditorClassifierClassificationDefinition
2626
#pragma warning disable CS0414
2727
[Export(typeof(ClassificationTypeDefinition))]
2828
[Name("AutoItEditorClassifier")]
29-
private static ClassificationTypeDefinition typeDefinition = null;
29+
private static ClassificationTypeDefinition m_TypeDefinition = null;
3030

3131
[Export(typeof(ClassificationTypeDefinition))]
3232
[Name("AutoItEditorCommentClassifier")]
33-
private static ClassificationTypeDefinition typeCommentDefinition = null;
33+
private static ClassificationTypeDefinition m_TypeCommentDefinition = null;
3434

3535
[Export(typeof(ClassificationTypeDefinition))]
3636
[Name("AutoItEditorStringClassifier")]
37-
private static ClassificationTypeDefinition typeStringDefinition = null;
37+
private static ClassificationTypeDefinition m_TypeStringDefinition = null;
3838

3939
[Export(typeof(ClassificationTypeDefinition))]
4040
[Name("AutoItEditorFunctionsClassifier")]
41-
private static ClassificationTypeDefinition typeFunctionDefinition = null;
41+
private static ClassificationTypeDefinition m_TypeFunctionDefinition = null;
4242

4343
[Export(typeof(ClassificationTypeDefinition))]
4444
[Name("AutoItEditorKeywordClassifier")]
45-
private static ClassificationTypeDefinition typeKeywordDefinition = null;
45+
private static ClassificationTypeDefinition m_TypeKeywordDefinition = null;
4646

4747
[Export]
4848
[Name("au3")]
4949
[BaseDefinition("code")]
50-
internal static ContentTypeDefinition AutoItContentDefinition = null;
50+
internal static ContentTypeDefinition ItContentDefinition = null;
5151

5252
[Export]
5353
[FileExtension(".au3")]
5454
[ContentType("au3")]
55-
internal static FileExtensionToContentTypeDefinition AutoItFileExtensionDefinition = null;
55+
internal static FileExtensionToContentTypeDefinition ItFileExtensionDefinition = null;
5656

5757
#pragma warning restore 169
5858
#pragma warning restore CS0414

AutoItSyntaxHighlight/AutoItEditorClassifierProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ internal class AutoItEditorClassifierProvider : IClassifierProvider
2727
// Disable "Field is never assigned to..." compiler's warning. Justification: the field is assigned by MEF.
2828
#pragma warning disable 649
2929
[Import]
30-
private readonly IClassificationTypeRegistryService classificationRegistry;
30+
private readonly IClassificationTypeRegistryService m_ClassificationRegistry;
3131

3232
#pragma warning restore 649
3333

3434
#region IClassifierProvider
3535
public IClassifier GetClassifier(ITextBuffer buffer)
3636
{
37-
return buffer.Properties.GetOrCreateSingletonProperty<AutoItEditorClassifier>(creator: () => new AutoItEditorClassifier(this.classificationRegistry));
37+
return buffer.Properties.GetOrCreateSingletonProperty(creator: () => new AutoItEditorClassifier(this.m_ClassificationRegistry));
3838
}
3939
#endregion
4040
}

AutoItSyntaxHighlight/AutoItLexer.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ namespace AutoItSyntaxHighlight
2525
internal sealed class AutoItLexer
2626
{
2727
private readonly List<IAutoItLexer> m_Lexer;
28-
private readonly IClassificationType classificationType;
28+
2929
public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
30+
31+
public IClassificationType ClassificationType { get; }
3032

3133
public AutoItLexer(IClassificationTypeRegistryService registry)
3234
{
33-
this.classificationType = registry.GetClassificationType("AutoItEditorClassifier");
35+
this.ClassificationType = registry.GetClassificationType("AutoItEditorClassifier");
3436

3537
m_Lexer = new List<IAutoItLexer>
3638
{
@@ -55,7 +57,7 @@ public List<ClassificationSpan> FlattenSpanList(List<PrioritiesClassificationSpa
5557
List<ClassificationSpan> classifications = new List<ClassificationSpan>();
5658
foreach (var one in spanList)
5759
{
58-
bool hasntHighestPriority = true;
60+
bool hasNotHighestPriority = true;
5961
foreach (var two in spanList)
6062
{
6163
if (one == two || one.Span.Span.OverlapsWith(two.Span.Span) == false)
@@ -65,12 +67,12 @@ public List<ClassificationSpan> FlattenSpanList(List<PrioritiesClassificationSpa
6567

6668
if (one.Priority < two.Priority)
6769
{
68-
hasntHighestPriority = false;
70+
hasNotHighestPriority = false;
6971
break;
7072
}
7173
}
7274

73-
if(hasntHighestPriority)
75+
if(hasNotHighestPriority)
7476
{
7577
classifications.Add(one.Span);
7678
}
@@ -80,12 +82,12 @@ public List<ClassificationSpan> FlattenSpanList(List<PrioritiesClassificationSpa
8082

8183
public List<ClassificationSpan> Parse(SnapshotSpan span)
8284
{
83-
List<PrioritiesClassificationSpan> prioClassi = new List<PrioritiesClassificationSpan>();
85+
List<PrioritiesClassificationSpan> priorClassification = new List<PrioritiesClassificationSpan>();
8486
foreach (var lexer in m_Lexer)
8587
{
86-
prioClassi.AddRange(lexer.Parse(span));
88+
priorClassification.AddRange(lexer.Parse(span));
8789
}
88-
return FlattenSpanList(prioClassi);
90+
return FlattenSpanList(priorClassification);
8991
}
9092
}
9193
}

AutoItSyntaxHighlight/Helper/MultiLineComment.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// limitations under the License.
1515
//
1616
using Microsoft.VisualStudio.Text;
17-
using Microsoft.VisualStudio.Text.Classification;
1817

1918
namespace AutoItSyntaxHighlight.Helper
2019
{

AutoItSyntaxHighlight/Lexer/AutoItLexerComments.cs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ namespace AutoItSyntaxHighlight.Lexer
2525
{
2626
internal sealed class AutoItLexerComments : IAutoItLexer
2727
{
28-
private Regex m_Regex;
28+
private readonly Regex m_Regex;
2929
private readonly IClassificationType m_Type;
30-
private List<MultiLineComment> m_MultiLineComments;
31-
private IClassificationTypeRegistryService m_Registry;
30+
private readonly List<MultiLineComment> m_MultiLineComments;
31+
private readonly IClassificationTypeRegistryService m_Registry;
3232
public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
3333

3434
public AutoItLexerComments(IClassificationTypeRegistryService registry)
@@ -56,13 +56,13 @@ private List<PrioritiesClassificationSpan> ParseMultiLine(SnapshotSpan span)
5656

5757
try
5858
{
59-
string codeSegement = span.Snapshot.GetLineFromLineNumber(lineNumber).GetText();
60-
int endPosition = IndexOfCommentEnd(codeSegement);
59+
string codeSegment = span.Snapshot.GetLineFromLineNumber(lineNumber).GetText();
60+
int endPosition = IndexOfCommentEnd(codeSegment);
6161
while (endPosition < 0)
6262
{
6363
++lineNumber;
64-
codeSegement = span.Snapshot.GetLineFromLineNumber(lineNumber).GetText();
65-
endPosition = IndexOfCommentEnd(codeSegement);
64+
codeSegment = span.Snapshot.GetLineFromLineNumber(lineNumber).GetText();
65+
endPosition = IndexOfCommentEnd(codeSegment);
6666
}
6767
}
6868
catch (ArgumentOutOfRangeException)
@@ -80,10 +80,11 @@ private List<PrioritiesClassificationSpan> ParseMultiLine(SnapshotSpan span)
8080
new ClassificationChangedEventArgs(new SnapshotSpan(span.End + 1, multiSpan.End)));
8181
}
8282

83-
var prioSpan = new PrioritiesClassificationSpan();
84-
prioSpan.Span = new ClassificationSpan(multiSpan, m_Type);
85-
prioSpan.Priority = 400;
86-
classifications.Add(prioSpan);
83+
var priorClassification = new PrioritiesClassificationSpan
84+
{
85+
Span = new ClassificationSpan(multiSpan, m_Type), Priority = 400
86+
};
87+
classifications.Add(priorClassification);
8788

8889
if (m_MultiLineComments.Any(a => a.Tracking.GetSpan(span.Snapshot).Span == multiSpan.Span) == false)
8990
{
@@ -120,16 +121,16 @@ public List<PrioritiesClassificationSpan> Parse(SnapshotSpan span)
120121
isInsideOfComment = true;
121122
if (span.Snapshot.Version == comment.Version)
122123
{
123-
var prioSpan = new PrioritiesClassificationSpan();
124-
prioSpan.Span = new ClassificationSpan(multiSpan, m_Type);
125-
prioSpan.Priority = 400;
126-
classifications.Add(prioSpan);
124+
var priorClassification = new PrioritiesClassificationSpan
125+
{
126+
Span = new ClassificationSpan(multiSpan, m_Type), Priority = 400
127+
};
128+
classifications.Add(priorClassification);
127129
}
128130
else
129131
{
130132
m_MultiLineComments.RemoveAt(i);
131133
ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(multiSpan));
132-
continue;
133134
}
134135
}
135136

@@ -157,10 +158,11 @@ public List<PrioritiesClassificationSpan> Parse(SnapshotSpan span)
157158
span.GetText().Length - match.Index);
158159
SnapshotSpan snapshot = new SnapshotSpan(span.Snapshot, spanWord);
159160

160-
var prioSpan = new PrioritiesClassificationSpan();
161-
prioSpan.Span = new ClassificationSpan(snapshot, m_Type);
162-
prioSpan.Priority = 400;
163-
classifications.Add(prioSpan);
161+
var priorClassification = new PrioritiesClassificationSpan
162+
{
163+
Span = new ClassificationSpan(snapshot, m_Type), Priority = 400
164+
};
165+
classifications.Add(priorClassification);
164166
}
165167
return classifications;
166168
}
@@ -184,12 +186,12 @@ private int IndexOfCommentStart(string code)
184186
{
185187
if (code.Contains("#cs"))
186188
{
187-
return code.IndexOf("#cs");
189+
return code.IndexOf("#cs", StringComparison.Ordinal);
188190
}
189191

190192
if (code.Contains("#comment-start"))
191193
{
192-
return code.IndexOf("#comment-start");
194+
return code.IndexOf("#comment-start", StringComparison.Ordinal);
193195
}
194196
return -1;
195197
}
@@ -198,12 +200,12 @@ private int IndexOfCommentEnd(string code)
198200
{
199201
if (code.Contains("#ce"))
200202
{
201-
return code.IndexOf("#ce");
203+
return code.IndexOf("#ce", StringComparison.Ordinal);
202204
}
203205

204206
if (code.Contains("#comment-end"))
205207
{
206-
return code.IndexOf("#comment-end");
208+
return code.IndexOf("#comment-end", StringComparison.Ordinal);
207209
}
208210
return -1;
209211
}

AutoItSyntaxHighlight/Lexer/AutoItLexerFunctions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace AutoItSyntaxHighlight.Lexer
2424
{
2525
internal sealed class AutoItLexerFunctions : IAutoItLexer
2626
{
27-
private Regex m_Regex;
27+
private readonly Regex m_Regex;
2828
private readonly IClassificationType m_Type;
2929

3030
#pragma warning disable CS0067
@@ -58,9 +58,9 @@ public List<PrioritiesClassificationSpan> Parse(SnapshotSpan span)
5858
Span spanWord = new Span(span.Start.Position + group.Index, group.Length);
5959
SnapshotSpan snapshot = new SnapshotSpan(span.Snapshot, spanWord);
6060

61-
var prioSpan = new PrioritiesClassificationSpan();
62-
prioSpan.Span = new ClassificationSpan(snapshot, m_Type);
63-
classifications.Add(prioSpan);
61+
var priorClassification = new PrioritiesClassificationSpan();
62+
priorClassification.Span = new ClassificationSpan(snapshot, m_Type);
63+
classifications.Add(priorClassification);
6464
}
6565
return classifications;
6666
}

AutoItSyntaxHighlight/Lexer/AutoItLexerKeywords.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace AutoItSyntaxHighlight.Lexer
2525
internal sealed class AutoItLexerKeywords : IAutoItLexer
2626
{
2727
private readonly IClassificationType m_Type;
28-
private List<string> m_Keywords;
28+
private readonly List<string> m_Keywords;
2929

3030
#pragma warning disable CS0067
3131
public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
@@ -36,7 +36,7 @@ public AutoItLexerKeywords(IClassificationTypeRegistryService registry)
3636
m_Type = registry.GetClassificationType("AutoItEditorKeywordClassifier");
3737

3838
// https://www.autoitscript.com/autoit3/docs/keywords.htm
39-
m_Keywords = new List<string>(new string[] { "True", "False",
39+
m_Keywords = new List<string>(new[] { "True", "False",
4040
"ContinueCase", "ContinueLoop", "#Region", "#EndRegion",
4141
"Default", "Dim", "Global", "Local", "Const", "Do", "Until", "Enum",
4242
"Exit", "ExitLoop", "For", "To", "Step", "Next", "In", "Next",
@@ -70,9 +70,9 @@ public List<PrioritiesClassificationSpan> Parse(SnapshotSpan span)
7070
Group group = match.Groups[1];
7171
if (group.Index > 0)
7272
{
73-
Regex regWhitspace = new Regex(@"\s+", RegexOptions.IgnoreCase);
73+
Regex regWhitespace = new Regex(@"\s+", RegexOptions.IgnoreCase);
7474
string code = "" + span.GetText()[group.Index - 1];
75-
if (regWhitspace.IsMatch(code) == false)
75+
if (regWhitespace.IsMatch(code) == false)
7676
{
7777
continue;
7878
}
@@ -81,10 +81,10 @@ public List<PrioritiesClassificationSpan> Parse(SnapshotSpan span)
8181
Span spanWord = new Span(span.Start.Position + group.Index, group.Length);
8282
SnapshotSpan snapshot = new SnapshotSpan(span.Snapshot, spanWord);
8383

84-
var prioSpan = new PrioritiesClassificationSpan();
85-
prioSpan.Span = new ClassificationSpan(snapshot, m_Type);
86-
prioSpan.Priority = 200;
87-
classifications.Add(prioSpan);
84+
var priorClassification = new PrioritiesClassificationSpan();
85+
priorClassification.Span = new ClassificationSpan(snapshot, m_Type);
86+
priorClassification.Priority = 200;
87+
classifications.Add(priorClassification);
8888
}
8989
}
9090
return classifications;

AutoItSyntaxHighlight/Lexer/AutoItLexerStrings.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace AutoItSyntaxHighlight.Lexer
2424
{
2525
internal sealed class AutoItLexerStrings : IAutoItLexer
2626
{
27-
private Regex m_Regex;
27+
private readonly Regex m_Regex;
2828
private readonly IClassificationType m_Type;
2929

3030
#pragma warning disable CS0067
@@ -51,10 +51,11 @@ public List<PrioritiesClassificationSpan> Parse(SnapshotSpan span)
5151
Span spanWord = new Span(span.Start.Position + match.Index, match.Length);
5252
SnapshotSpan snapshot = new SnapshotSpan(span.Snapshot, spanWord);
5353

54-
var prioSpan = new PrioritiesClassificationSpan();
55-
prioSpan.Span = new ClassificationSpan(snapshot, m_Type);
56-
prioSpan.Priority = 300;
57-
classifications.Add(prioSpan);
54+
var priorClassification = new PrioritiesClassificationSpan
55+
{
56+
Span = new ClassificationSpan(snapshot, m_Type), Priority = 300
57+
};
58+
classifications.Add(priorClassification);
5859
}
5960
return classifications;
6061
}

0 commit comments

Comments
 (0)