Skip to content

Commit 53cf888

Browse files
paulirwinclaudeNightOwl888
authored
Scan TestFramework assembly in analysis discovery tests, #1126 (#1333)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Shad Storhaug <shad@shadstorhaug.com>
1 parent 80b2a66 commit 53cf888

31 files changed

Lines changed: 307 additions & 108 deletions

src/Lucene.Net.Analysis.Common/Analysis/Util/AnalysisSPILoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ public Type LookupClass(string name)
128128
}
129129
else
130130
{
131+
// LUCENENET Specific: Sort the keys for better error message readability
131132
throw new ArgumentException("A SPI class of type " + clazz.Name + " with name '" + name + "' does not exist. " +
132133
"You need to add the corresponding reference supporting this SPI to your project or AppDomain. " +
133-
"The current classpath supports the following names: " + string.Format(J2N.Text.StringFormatter.InvariantCulture, "{0}", AvailableServices));
134+
"The current classpath supports the following names: " + new JCG.SortedSet<string>(AvailableServices));
134135
}
135136
}
136137

src/Lucene.Net.Analysis.Kuromoji/GraphvizFormatter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Text;
66
using JCG = J2N.Collections.Generic;
7+
#nullable enable
78

89
namespace Lucene.Net.Analysis.Ja
910
{
@@ -46,7 +47,7 @@ public class GraphvizFormatter
4647

4748
public GraphvizFormatter(ConnectionCosts costs)
4849
{
49-
this.costs = costs;
50+
this.costs = costs ?? throw new ArgumentNullException(nameof(costs)); // LUCENENET: Added guard clause
5051
this.bestPathMap = new JCG.Dictionary<string, string>();
5152
sb.Append(FormatHeader());
5253
sb.Append(" init [style=invis]\n");
@@ -136,7 +137,7 @@ private string FormatNodes(JapaneseTokenizer tok, WrappedPositionArray positions
136137
sb.Append(toNodeID);
137138

138139
string attrs;
139-
bestPathMap.TryGetValue(fromNodeID, out string path);
140+
bestPathMap.TryGetValue(fromNodeID, out string? path);
140141
if (toNodeID.Equals(path, StringComparison.Ordinal))
141142
{
142143
// This arc is on best path

src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using J2N.Collections.Generic.Extensions;
21
using Lucene.Net.Analysis.Cjk;
32
using Lucene.Net.Analysis.Core;
43
using Lucene.Net.Analysis.Ja.Dict;
@@ -8,6 +7,7 @@
87
using System.Collections.Generic;
98
using System.IO;
109
using JCG = J2N.Collections.Generic;
10+
#nullable enable
1111

1212
namespace Lucene.Net.Analysis.Ja
1313
{
@@ -36,19 +36,19 @@ public class JapaneseAnalyzer : StopwordAnalyzerBase
3636
{
3737
private readonly JapaneseTokenizerMode mode;
3838
private readonly ISet<string> stoptags;
39-
private readonly UserDictionary userDict;
39+
private readonly UserDictionary? userDict;
4040

4141
public JapaneseAnalyzer(LuceneVersion matchVersion)
4242
: this(matchVersion, null, JapaneseTokenizer.DEFAULT_MODE, DefaultSetHolder.DEFAULT_STOP_SET, DefaultSetHolder.DEFAULT_STOP_TAGS)
4343
{
4444
}
4545

46-
public JapaneseAnalyzer(LuceneVersion matchVersion, UserDictionary userDict, JapaneseTokenizerMode mode, CharArraySet stopwords, ISet<string> stoptags)
46+
public JapaneseAnalyzer(LuceneVersion matchVersion, UserDictionary? userDict, JapaneseTokenizerMode mode, CharArraySet stopwords, ISet<string> stoptags)
4747
: base(matchVersion, stopwords)
4848
{
4949
this.userDict = userDict;
5050
this.mode = mode;
51-
this.stoptags = stoptags;
51+
this.stoptags = stoptags ?? throw new ArgumentNullException(nameof(stoptags));
5252
}
5353

5454
[Obsolete("Use DefaultStopSet instead. This method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]

src/Lucene.Net.Analysis.Kuromoji/JapaneseBaseFormFilter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Lucene.Net.Analysis.Ja.TokenAttributes;
22
using Lucene.Net.Analysis.TokenAttributes;
33
using Lucene.Net.Analysis.TokenAttributes.Extensions;
4+
#nullable enable
45

56
namespace Lucene.Net.Analysis.Ja
67
{
@@ -49,7 +50,7 @@ public override bool IncrementToken()
4950
{
5051
if (!keywordAtt.IsKeyword)
5152
{
52-
string baseForm = basicFormAtt.GetBaseForm();
53+
string? baseForm = basicFormAtt.GetBaseForm();
5354
if (baseForm != null)
5455
{
5556
termAtt.SetEmpty().Append(baseForm);

src/Lucene.Net.Analysis.Kuromoji/JapaneseBaseFormFilterFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Lucene.Net.Analysis.Util;
22
using System;
33
using System.Collections.Generic;
4+
#nullable enable
45

56
namespace Lucene.Net.Analysis.Ja
67
{

src/Lucene.Net.Analysis.Kuromoji/JapaneseIterationMarkCharFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Lucene.Net.Analysis.Util;
22
using Lucene.Net.Diagnostics;
33
using System.IO;
4+
#nullable enable
45

56
namespace Lucene.Net.Analysis.Ja
67
{

src/Lucene.Net.Analysis.Kuromoji/JapaneseIterationMarkCharFilterFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.IO;
5+
#nullable enable
56

67
namespace Lucene.Net.Analysis.Ja
78
{
@@ -58,7 +59,7 @@ public override TextReader Create(TextReader input)
5859
return new JapaneseIterationMarkCharFilter(input, normalizeKanji, normalizeKana);
5960
}
6061

61-
public virtual AbstractAnalysisFactory GetMultiTermComponent()
62+
public virtual AbstractAnalysisFactory? GetMultiTermComponent()
6263
{
6364
return this;
6465
}

src/Lucene.Net.Analysis.Kuromoji/JapaneseKatakanaStemFilter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Lucene.Net.Analysis.TokenAttributes;
2+
using System;
23
using System.Text.RegularExpressions;
4+
#nullable enable
35

46
namespace Lucene.Net.Analysis.Ja
57
{
@@ -49,6 +51,10 @@ public sealed class JapaneseKatakanaStemFilter : TokenFilter
4951
public JapaneseKatakanaStemFilter(TokenStream input, int minimumLength)
5052
: base(input)
5153
{
54+
// LUCENENET: Added guard clause
55+
if (minimumLength < 0)
56+
throw new ArgumentOutOfRangeException(nameof(minimumLength), "Minimum length must be a non-negative integer.");
57+
5258
this.minimumKatakanaLength = minimumLength;
5359
this.termAttr = AddAttribute<ICharTermAttribute>();
5460
this.keywordAttr = AddAttribute<IKeywordAttribute>();

src/Lucene.Net.Analysis.Kuromoji/JapaneseKatakanaStemFilterFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Lucene.Net.Analysis.Util;
22
using System;
33
using System.Collections.Generic;
4+
#nullable enable
45

56
namespace Lucene.Net.Analysis.Ja
67
{

src/Lucene.Net.Analysis.Kuromoji/JapanesePartOfSpeechStopFilter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Lucene.Net.Util;
44
using System;
55
using System.Collections.Generic;
6+
#nullable enable
67

78
namespace Lucene.Net.Analysis.Ja
89
{
@@ -33,9 +34,9 @@ public sealed class JapanesePartOfSpeechStopFilter : FilteringTokenFilter
3334

3435
[Obsolete("EnablePositionIncrements=false is not supported anymore as of Lucene 4.4.")]
3536
public JapanesePartOfSpeechStopFilter(LuceneVersion version, bool enablePositionIncrements, TokenStream input, ISet<string> stopTags)
36-
: base(version, enablePositionIncrements, input)
37+
: base(version, enablePositionIncrements, input)
3738
{
38-
this.stopTags = stopTags;
39+
this.stopTags = stopTags ?? throw new ArgumentNullException(nameof(stopTags));
3940
this.posAtt = AddAttribute<IPartOfSpeechAttribute>();
4041
}
4142

@@ -48,13 +49,13 @@ public JapanesePartOfSpeechStopFilter(LuceneVersion version, bool enablePosition
4849
public JapanesePartOfSpeechStopFilter(LuceneVersion version, TokenStream input, ISet<string> stopTags)
4950
: base(version, input)
5051
{
51-
this.stopTags = stopTags;
52+
this.stopTags = stopTags ?? throw new ArgumentNullException(nameof(stopTags));
5253
this.posAtt = AddAttribute<IPartOfSpeechAttribute>();
5354
}
5455

5556
protected override bool Accept()
5657
{
57-
string pos = posAtt.GetPartOfSpeech();
58+
string? pos = posAtt.GetPartOfSpeech();
5859
return pos is null || !stopTags.Contains(pos);
5960
}
6061
}

0 commit comments

Comments
 (0)