Skip to content

Commit 3247ab5

Browse files
committed
cleanup
1 parent de501be commit 3247ab5

File tree

10 files changed

+39
-58
lines changed

10 files changed

+39
-58
lines changed

Binder.Tests/ParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void Tokenizer( TokenizerConfig config )
1919
AvailableTokens.GetDefault(CommandLineStyle.Windows, LoggerFactory),
2020
LoggerFactory,
2121
new ConsolidateQuotedText(StringComparison.OrdinalIgnoreCase, LoggerFactory()),
22-
new MergeSequentialSeparators(LoggerFactory()) );
22+
new MergeSequentialSeparators() );
2323

2424
var tokens = tokenizer.Tokenize( config.CommandLine );
2525

Binder/J4JCommandLineSource.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using J4JSoftware.Logging;
33
using Microsoft.Extensions.Configuration;
4-
using Serilog.Core;
54

65
namespace J4JSoftware.Configuration.CommandLine
76
{
@@ -20,7 +19,7 @@ public J4JCommandLineSource(
2019
_cmdLine = cmdLine;
2120

2221
var tokenizer = new Tokenizer( options.CommandLineStyle, options.MasterText.TextComparison, loggerFactory );
23-
var parsingTable = new ParsingTable( options, loggerFactory);
22+
var parsingTable = new ParsingTable( options, loggerFactory );
2423

2524
_parser = new Parser( options, tokenizer, parsingTable, loggerFactory?.Invoke() );
2625
}

Binder/grammar/ConsolidateQuotedText.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace J4JSoftware.Configuration.CommandLine
1010
{
1111
public class ConsolidateQuotedText : ICleanupTokens
1212
{
13-
private readonly StringComparison _textComparison;
1413
private readonly IJ4JLogger? _logger;
14+
private readonly StringComparison _textComparison;
1515

1616
public ConsolidateQuotedText(
1717
StringComparison textComparison,
@@ -24,7 +24,7 @@ public ConsolidateQuotedText(
2424
public void Process( List<Token> tokens )
2525
{
2626
var startIdx = 0;
27-
QuoterPair? curPair = null;
27+
QuoterPair? curPair;
2828

2929
// loop through all QuoterPairs (i.e., pairs of quoter tokens defining
3030
// a quoted sequence
@@ -34,7 +34,7 @@ public void Process( List<Token> tokens )
3434
// "quoted" tokens
3535
if( curPair.End == null )
3636
{
37-
_logger?.Error( "Unclosed quoter encountered, command line truncated at token #{0}",
37+
_logger?.Error( "Unclosed quoter encountered, command line truncated at token #{0}",
3838
curPair.Start.Index );
3939

4040
tokens.RemoveFrom( curPair.Start.Index );

Binder/grammar/MergeSequentialSeparators.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ namespace J4JSoftware.Configuration.CommandLine
55
{
66
public class MergeSequentialSeparators : ICleanupTokens
77
{
8-
private readonly IJ4JLogger? _logger;
9-
10-
public MergeSequentialSeparators( IJ4JLogger? logger )
11-
{
12-
_logger = logger;
13-
}
14-
158
public void Process( List<Token> tokens )
169
{
1710
var toRemove = new List<int>();

Binder/grammar/ParsingTable.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ public class ParsingTable : IParsingTable
1212
private readonly Dictionary<TokenType, Dictionary<TokenType, ParsingAction?>> _table =
1313
new();
1414

15-
private readonly IJ4JLogger? _logger;
16-
1715
public ParsingTable( IOptionCollection options, Func<IJ4JLogger>? loggerFactory = null )
1816
{
19-
_logger = loggerFactory?.Invoke();
20-
2117
Entries = new TokenEntry.TokenEntries( options, loggerFactory?.Invoke() );
2218

2319
foreach( var row in Enum.GetValues( typeof(TokenType) )

Binder/grammar/tokenizer/AvailableTokens.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public bool Add( TokenType type, string text )
4141
if( _available.SelectMany( kvp => kvp.Value )
4242
.Any( t => t.Equals( text, TextComparison ) ) )
4343
{
44-
_logger?.Error( "Duplicate token text '{0}' ({1})", text, type);
44+
_logger?.Error( "Duplicate token text '{0}' ({1})", text, type );
4545
return false;
4646
}
4747

Binder/grammar/tokenizer/Tokenizer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ params ICleanupTokens[] cleanupProcessors
2525
_cleanupProcessors = new ICleanupTokens[]
2626
{
2727
new ConsolidateQuotedText( collection.TextComparison, loggerFactory?.Invoke() ),
28-
new MergeSequentialSeparators( loggerFactory?.Invoke() )
28+
new MergeSequentialSeparators()
2929
};
3030
}
3131

@@ -47,7 +47,7 @@ params ICleanupTokens[] cleanupProcessors
4747
_cleanupProcessors = new ICleanupTokens[]
4848
{
4949
new ConsolidateQuotedText( textComparison.Value, loggerFactory?.Invoke() ),
50-
new MergeSequentialSeparators( loggerFactory?.Invoke() )
50+
new MergeSequentialSeparators()
5151
};
5252
}
5353

@@ -108,7 +108,7 @@ public List<Token> Tokenize( string cmdLine )
108108

109109
retVal.Add( firstMatch.token );
110110

111-
cmdLine = cmdLine.Substring( firstMatch.startChar + firstMatch.token.Length );
111+
cmdLine = cmdLine[(firstMatch.startChar + firstMatch.token.Length)..];
112112
}
113113

114114
foreach( var cleanupProc in _cleanupProcessors ) cleanupProc.Process( retVal );

Binder/master-text/MasterTextCollection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.ComponentModel;
43
using System.Linq;
54
using J4JSoftware.Logging;
65

@@ -95,7 +94,7 @@ public bool AddRange( TextUsageType usage, IEnumerable<string> items )
9594

9695
if( usage == TextUsageType.Undefined )
9796
{
98-
_logger?.Information<TextUsageType, string>( "Cannot add {0} items ({1})",
97+
_logger?.Information<TextUsageType, string>( "Cannot add {0} items ({1})",
9998
usage,
10099
string.Join( ",", items ) );
101100

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.ComponentModel;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
73
using J4JSoftware.Logging;
84

95
namespace J4JSoftware.Configuration.CommandLine
@@ -13,40 +9,39 @@ public partial class MasterTextCollection
139
public static MasterTextCollection GetDefault(
1410
CommandLineStyle cmdLineStyle,
1511
Func<IJ4JLogger>? loggerFactory,
16-
StringComparison? comparison = null)
12+
StringComparison? comparison = null )
1713
{
18-
var retVal = new MasterTextCollection(comparison ?? StringComparison.OrdinalIgnoreCase, loggerFactory);
14+
var retVal = new MasterTextCollection( comparison ?? StringComparison.OrdinalIgnoreCase, loggerFactory );
1915

20-
switch (cmdLineStyle)
16+
switch( cmdLineStyle )
2117
{
2218
case CommandLineStyle.Linux:
23-
retVal.AddRange(TextUsageType.Prefix, "-", "--");
24-
retVal.AddRange(TextUsageType.Quote, "\"", "'");
25-
retVal.Add(TextUsageType.ValueEncloser, "=");
26-
retVal.AddRange(TextUsageType.Separator, " ", "\t");
19+
retVal.AddRange( TextUsageType.Prefix, "-", "--" );
20+
retVal.AddRange( TextUsageType.Quote, "\"", "'" );
21+
retVal.Add( TextUsageType.ValueEncloser, "=" );
22+
retVal.AddRange( TextUsageType.Separator, " ", "\t" );
2723

2824
return retVal;
2925

3026
case CommandLineStyle.Universal:
31-
retVal.AddRange(TextUsageType.Prefix, "-", "--", "/");
32-
retVal.AddRange(TextUsageType.Quote, "\"", "'");
33-
retVal.Add(TextUsageType.ValueEncloser, "=");
34-
retVal.AddRange(TextUsageType.Separator, " ", "\t");
27+
retVal.AddRange( TextUsageType.Prefix, "-", "--", "/" );
28+
retVal.AddRange( TextUsageType.Quote, "\"", "'" );
29+
retVal.Add( TextUsageType.ValueEncloser, "=" );
30+
retVal.AddRange( TextUsageType.Separator, " ", "\t" );
3531

3632
return retVal;
3733

3834
case CommandLineStyle.Windows:
39-
retVal.AddRange(TextUsageType.Prefix, "/", "-", "--");
40-
retVal.Add(TextUsageType.Quote, "\"");
41-
retVal.Add(TextUsageType.ValueEncloser, "=");
42-
retVal.AddRange(TextUsageType.Separator, " ", "\t");
35+
retVal.AddRange( TextUsageType.Prefix, "/", "-", "--" );
36+
retVal.Add( TextUsageType.Quote, "\"" );
37+
retVal.Add( TextUsageType.ValueEncloser, "=" );
38+
retVal.AddRange( TextUsageType.Separator, " ", "\t" );
4339

4440
return retVal;
4541

4642
default:
47-
throw new InvalidEnumArgumentException($"Unsupported CommandLineStyle '{cmdLineStyle}'");
43+
throw new InvalidEnumArgumentException( $"Unsupported CommandLineStyle '{cmdLineStyle}'" );
4844
}
4945
}
50-
5146
}
52-
}
47+
}

Binder/options/OptionCollectionNG.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ namespace J4JSoftware.Configuration.CommandLine
1313
public class OptionCollectionNG : IOptionCollection
1414
{
1515
private readonly TypeBoundOptionComparer _comparer = new();
16+
private readonly IJ4JLogger? _logger;
1617
private readonly List<IOption> _options = new();
1718

1819
private readonly Dictionary<Type, string> _typePrefixes = new();
19-
private readonly IJ4JLogger? _logger;
2020

21-
public OptionCollectionNG(
22-
CommandLineStyle cmdLineStyle = CommandLineStyle.Windows,
23-
Func<IJ4JLogger>? loggerFactory = null
24-
)
21+
public OptionCollectionNG(
22+
CommandLineStyle cmdLineStyle = CommandLineStyle.Windows,
23+
Func<IJ4JLogger>? loggerFactory = null
24+
)
2525
{
2626
CommandLineStyle = cmdLineStyle;
2727

@@ -141,7 +141,7 @@ public IOption Add( string contextPath )
141141

142142
break;
143143

144-
case ParameterExpression paramExpr:
144+
case ParameterExpression:
145145
// this is the root/anchor of the expression tree.
146146
// we're done
147147
curExpr = null;
@@ -309,14 +309,14 @@ private IEnumerable<string> ValidateCommandLineKeys( string[] cmdLineKeys )
309309
yield return key;
310310
}
311311

312-
private string GetContextPath( List<PropertyInfo> propElements )
312+
private static string GetContextPath( List<PropertyInfo> propElements )
313313
{
314314
return propElements.Aggregate(
315315
new StringBuilder(),
316316
( sb, pi ) =>
317317
{
318318
if( sb.Length > 0 )
319-
sb.Append( ":" );
319+
sb.Append(':');
320320

321321
sb.Append( pi.Name );
322322

@@ -326,7 +326,7 @@ private string GetContextPath( List<PropertyInfo> propElements )
326326
);
327327
}
328328

329-
private bool HasAttribute<TAttr>( Type toCheck )
329+
private static bool HasAttribute<TAttr>( Type toCheck )
330330
where TAttr : Attribute
331331
{
332332
return toCheck.GetCustomAttribute<TAttr>() != null;
@@ -337,11 +337,10 @@ private class TypeBoundOptionComparer : IEqualityComparer<ITypeBoundOption>
337337
public bool Equals( ITypeBoundOption? x, ITypeBoundOption? y )
338338
{
339339
if( ReferenceEquals( x, y ) ) return true;
340-
if( ReferenceEquals( x, null ) ) return false;
341-
if( ReferenceEquals( y, null ) ) return false;
342-
if( x.GetType() != y.GetType() ) return false;
340+
if( x is null) return false;
341+
if( y is null) return false;
343342

344-
return x.TargetType.Equals( y.TargetType );
343+
return x.GetType() == y.GetType() && x.TargetType == y.TargetType;
345344
}
346345

347346
public int GetHashCode( ITypeBoundOption obj )

0 commit comments

Comments
 (0)