Skip to content

Commit

Permalink
Fix csharpsquid:S2223 issues, apache#679
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Jan 19, 2025
1 parent 2505d89 commit 89ccb6c
Show file tree
Hide file tree
Showing 41 changed files with 254 additions and 204 deletions.
6 changes: 4 additions & 2 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemData1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ internal class KStemData1
private KStemData1()
{
}

// LUCENENET specific - made readonly
// KStemData1 ... KStemData8 are created from "head_word_list.txt"
internal static string[] data = new string[] {
internal static readonly string[] data = {
"aback","abacus","abandon","abandoned","abase",
"abash","abate","abattoir","abbess","abbey",
"abbot","abbreviate","abbreviation","abc","abdicate",
Expand Down Expand Up @@ -752,4 +754,4 @@ private KStemData1()
"cascara","case","casebook","casein","casework",
};
}
}
}
6 changes: 4 additions & 2 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemData2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class KStemData2
private KStemData2()
{
}
internal static string[] data = new string[] {

// LUCENENET specific - made readonly
internal static readonly string[] data = {
"cash","cashew","cashier","cashmere","casing",
"casino","cask","casket","casque","cassava",
"casserole","cassette","cassock","cassowary","cast",
Expand Down Expand Up @@ -750,4 +752,4 @@ private KStemData2()
"distal","distance","distant","distantly","distaste",
};
}
}
}
6 changes: 4 additions & 2 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemData3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class KStemData3
private KStemData3()
{
}
internal static string[] data = new string[] {

// LUCENENET specific - made readonly
internal static readonly string[] data = {
"distasteful","distemper","distempered","distend","distension",
"distil","distill","distillation","distiller","distillery",
"distinct","distinction","distinctive","distinguish","distinguishable",
Expand Down Expand Up @@ -750,4 +752,4 @@ private KStemData3()
"grange","granite","grannie","granny","grant",
};
}
}
}
6 changes: 4 additions & 2 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemData4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class KStemData4
private KStemData4()
{
}
internal static string[] data = new string[] {

// LUCENENET specific - made readonly
internal static readonly string[] data = {
"granular","granulate","granule","grape","grapefruit",
"grapeshot","grapevine","graph","graphic","graphical",
"graphically","graphite","graphology","grapnel","grapple",
Expand Down Expand Up @@ -750,4 +752,4 @@ private KStemData4()
"locate","located","location","loch","loci",
};
}
}
}
6 changes: 4 additions & 2 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemData5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class KStemData5
private KStemData5()
{
}
internal static string[] data = new string[] {

// LUCENENET specific - made readonly
internal static readonly string[] data = {
"lock","locker","locket","lockjaw","locknut",
"lockout","locks","locksmith","lockstitch","lockup",
"loco","locomotion","locomotive","locum","locus",
Expand Down Expand Up @@ -750,4 +752,4 @@ private KStemData5()
"peculiarly","pecuniary","pedagogue","pedagogy","pedal",
};
}
}
}
6 changes: 4 additions & 2 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemData6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class KStemData6
private KStemData6()
{
}
internal static string[] data = new string[] {

// LUCENENET specific - made readonly
internal static readonly string[] data = {
"pedant","pedantic","pedantry","peddle","peddler",
"pederast","pederasty","pedestal","pedestrian","pediatrician",
"pediatrics","pedicab","pedicel","pedicure","pedigree",
Expand Down Expand Up @@ -750,4 +752,4 @@ private KStemData6()
"running","runny","runs","runt","runway",
};
}
}
}
6 changes: 4 additions & 2 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemData7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class KStemData7
private KStemData7()
{
}
internal static string[] data = new string[] {

// LUCENENET specific - made readonly
internal static readonly string[] data = {
"rupee","rupture","rural","ruritanian","ruse",
"rush","rushes","rushlight","rusk","russet",
"rust","rustic","rusticate","rustication","rustle",
Expand Down Expand Up @@ -750,4 +752,4 @@ private KStemData7()
"tenement","tenet","tenner","tennis","tenon",
};
}
}
}
6 changes: 4 additions & 2 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemData8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class KStemData8
private KStemData8()
{
}
internal static string[] data = new string[] {

// LUCENENET specific - made readonly
internal static readonly string[] data = {
"tenor","tenpin","tense","tensile","tension",
"tent","tentacle","tentative","tenterhooks","tenuity",
"tenuous","tenure","tepee","tepid","tequila",
Expand Down Expand Up @@ -649,4 +651,4 @@ private KStemData8()
"zoom","zoophyte","zouave","zucchini","zulu",
};
}
}
}
3 changes: 2 additions & 1 deletion src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace Lucene.Net.Analysis.OpenNlp
/// </summary>
public sealed class OpenNLPTokenizer : SegmentingTokenizerBase
{
public static int EOS_FLAG_BIT = 1;
// LUCENENET specific - made const, since it is never modified. Removed in Lucene 9.5.0.
public const int EOS_FLAG_BIT = 1;

private readonly ICharTermAttribute termAtt;
private readonly IFlagsAttribute flagsAtt;
Expand Down
8 changes: 4 additions & 4 deletions src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Lucene.Net.Analysis.Cn.Smart
/// To place the files in an alternate location, set an environment variable named "smartcn.data.dir"
/// with the name of the directory the "bigramdict.dct" and "coredict.dct" files can be located within.
/// <para/>
/// The default "bigramdict.dct" and "coredict.dct" files can be found at:
/// The default "bigramdict.dct" and "coredict.dct" files can be found at:
/// <a href="https://issues.apache.org/jira/browse/LUCENE-1629">https://issues.apache.org/jira/browse/LUCENE-1629</a>.
/// <para/>
/// @lucene.experimental
Expand All @@ -44,14 +44,15 @@ public static class AnalyzerProfile // LUCENENET specific: CA1052 Static holder
/// <summary>
/// Global indicating the configured analysis data directory
/// </summary>
public static string ANALYSIS_DATA_DIR = "";
// LUCENENET specific - changed from a mutable static field to a property.
public static string ANALYSIS_DATA_DIR { get; set; } = "";

static AnalyzerProfile()
{
Init();
}

// LUCENENET specific - changed the logic here to leave the
// LUCENENET specific - changed the logic here to leave the
// ANALYSIS_DATA_DIR an empty string if it is not found. This
// allows us to skip loading files from disk if there are no files
// to load (and fixes LUCENE-1817 that prevents the on-disk files
Expand Down Expand Up @@ -79,7 +80,6 @@ private static void Init()
ANALYSIS_DATA_DIR = candidatePath;
return;
}


try
{
Expand Down
5 changes: 3 additions & 2 deletions src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ namespace Egothor.Stemmer
/// </summary>
public class MultiTrie : Trie
{
internal static char EOM = '*';
internal static string EOM_NODE = "" + EOM;
// LUCENENET specific - made const
internal const char EOM = '*';
internal const string EOM_NODE = "*"; // was `= "" + EOM;` but that is not a compile-time constant

protected IList<Trie> m_tries = new JCG.List<Trie>();

Expand Down
16 changes: 10 additions & 6 deletions src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
/// </summary>
public class TaskSequence : PerfTask
{
public static int REPEAT_EXHAUST = -2;
// LUCENENET specific - changed from a mutable static field to a constant.
// While the original Java code uses a mutable static field, it is only
// intended to be used as a sentinel value, so we are changing it to a
// constant to prevent accidental modification.
public const int REPEAT_EXHAUST = -2;
private IList<PerfTask> tasks;
private int repetitions = 1;
private readonly bool parallel;
Expand All @@ -46,7 +50,7 @@ public class TaskSequence : PerfTask
private bool resetExhausted = false;
private PerfTask[] tasksArray;
private bool anyExhaustibleTasks;
private readonly bool collapsable = false; // to not collapse external sequence named in alg.
private readonly bool collapsable = false; // to not collapse external sequence named in alg.

private bool fixedTime; // true if we run for fixed time
private double runTimeSec; // how long to run for
Expand Down Expand Up @@ -299,7 +303,7 @@ private int DoSerialTasksWithRate()
{
break;
}
nextStartTime += delayStep; // this aims at avarage rate.
nextStartTime += delayStep; // this aims at avarage rate.
try
{
int inc = task.RunAndMaybeStats(letChildReport);
Expand Down Expand Up @@ -494,7 +498,7 @@ private void StartlThreadsWithRate(ParallelTask[] t)
{
Thread.Sleep((int)waitMore);
}
nextStartTime += delayStep; // this aims at average rate of starting threads.
nextStartTime += delayStep; // this aims at average rate of starting threads.
t[i].Start();
}
}
Expand Down Expand Up @@ -573,7 +577,7 @@ public virtual int GetRate()
}

/// <summary>
///
///
/// </summary>
/// <param name="rate">The rate to set.</param>
/// <param name="perMin"></param>
Expand Down Expand Up @@ -607,7 +611,7 @@ private void SetSequenceName()

public override string GetName()
{
return seqName; // override to include more info
return seqName; // override to include more info
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Lucene.Net.Benchmark/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static class Constants // LUCENENET specific: CA1052 Static holder types
public const int DEFAULT_SCALE_UP = 5;
public const int DEFAULT_LOG_STEP = 1000;

public static bool[] BOOLEANS = new bool[] { false, true };
// LUCENENET specific - made readonly
public static readonly bool[] BOOLEANS = new bool[] { false, true };

public const int DEFAULT_MAXIMUM_DOCUMENTS = int.MaxValue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ExtractWikipedia
{
private readonly DirectoryInfo outputDir; // LUCENENET: marked readonly

public static int count = 0;
public static int Count { get; set; } // LUCENENET: changed mutable static field into a property

internal const int BASE = 10;
protected DocMaker m_docMaker;
Expand Down Expand Up @@ -74,7 +74,7 @@ public virtual DirectoryInfo Directory(int count, DirectoryInfo directory)

public virtual void Create(string id, string title, string time, string body)
{
DirectoryInfo d = Directory(count++, null);
DirectoryInfo d = Directory(Count++, null);
d.Create();
FileInfo f = new FileInfo(System.IO.Path.Combine(d.FullName, id + ".txt"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Lucene.Net.Search.Highlight
*/

/// <summary>
/// Class used to extract <see cref="WeightedSpanTerm"/>s from a <see cref="Query"/> based on whether
/// Class used to extract <see cref="WeightedSpanTerm"/>s from a <see cref="Query"/> based on whether
/// <see cref="Term"/>s from the <see cref="Query"/> are contained in a supplied <see cref="Analysis.TokenStream"/>.
/// </summary>
public class WeightedSpanTermExtractor
Expand Down Expand Up @@ -137,10 +137,10 @@ protected virtual void Extract(Query query, IDictionary<string, WeightedSpanTerm
}
else if (query is CommonTermsQuery)
{
// specialized since rewriting would change the result query
// specialized since rewriting would change the result query
// this query is TermContext sensitive.
ExtractWeightedTerms(terms, query);
}
}
else if (query is DisjunctionMaxQuery disjunctionMaxQuery)
{
foreach (var q in disjunctionMaxQuery)
Expand Down Expand Up @@ -336,7 +336,7 @@ protected virtual void ExtractWeightedSpanTerms(IDictionary<string, WeightedSpan
}

/// <summary>
/// Fills a <see cref="T:IDictionary{string,WeightedSpanTerm}"/> with <see cref="WeightedSpanTerm"/>s using the terms from
/// Fills a <see cref="T:IDictionary{string,WeightedSpanTerm}"/> with <see cref="WeightedSpanTerm"/>s using the terms from
/// the supplied <see cref="Search.Spans.SpanQuery"/>.
/// </summary>
/// <param name="terms"><see cref="T:IDictionary{string,WeightedSpanTerm}"/> to place created <see cref="WeightedSpanTerm"/>s in</param>
Expand Down Expand Up @@ -395,7 +395,7 @@ protected virtual AtomicReaderContext GetLeafContext()
/// </summary>
internal sealed class DelegatingAtomicReader : FilterAtomicReader
{
public static string FIELD_NAME = "shadowed_field";
public const string FIELD_NAME = "shadowed_field";

internal DelegatingAtomicReader(AtomicReader reader) : base(reader) { }

Expand Down Expand Up @@ -430,7 +430,7 @@ public override BinaryDocValues GetBinaryDocValues(string field)
{
return base.GetBinaryDocValues(FIELD_NAME);
}

public override SortedDocValues GetSortedDocValues(string field)
{
return base.GetSortedDocValues(FIELD_NAME);
Expand Down Expand Up @@ -742,4 +742,4 @@ protected internal void SetMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
this.maxDocCharsToAnalyze = maxDocCharsToAnalyze;
}
}
}
}
Loading

0 comments on commit 89ccb6c

Please sign in to comment.