Skip to content

Commit

Permalink
Fix csharpsquid:S1117 SonarCloud warnings about shadowing fields with…
Browse files Browse the repository at this point in the history
… variable names (#1042)

* Fix csharpsquid:S1117 warnings about shadowing fields with variable names, #678
  • Loading branch information
paulirwin authored Nov 21, 2024
1 parent 63f6d5e commit ccff6dd
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ public sealed class HTMLStripCharFilter : BaseCharFilter
"\x000A\x00BC\x0007\x0000\x001A\x0001\x0004\x0000\x0001\x0002\x0001\x0000\x001A\x0001\x000B\x0000\x0059\x0001\x0003\x0000" +
"\x0006\x0001\x0002\x0000\x0006\x0001\x0002\x0000\x0006\x0001\x0002\x0000\x0003\x0001\x0023\x0000";

/**
/**
* Translates characters to character classes
*/
private static readonly char[] ZZ_CMAP = ZzUnpackCMap(ZZ_CMAP_PACKED);

/**
/**
* Translates DFA states to action switch labels.
*/
private static readonly int[] ZZ_ACTION = ZzUnpackAction();
Expand Down Expand Up @@ -348,7 +348,7 @@ private static int ZzUnpackAction(string packed, int offset, int[] result)
}


/**
/**
* Translates a state to a row index in the transition table
*/
private static readonly int[] ZZ_ROWMAP = ZzUnpackRowMap();
Expand Down Expand Up @@ -30693,7 +30693,7 @@ private static readonly IDictionary<string, string> upperCaseVariantsAccepted

private static CharArrayDictionary<char> LoadEntityValues() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
CharArrayDictionary<char> entityValues
CharArrayDictionary<char> result
#pragma warning disable 612, 618
= new CharArrayDictionary<char>(LuceneVersion.LUCENE_CURRENT, 253, false);
#pragma warning restore 612, 618
Expand Down Expand Up @@ -30775,13 +30775,13 @@ CharArrayDictionary<char> entityValues
for (int i = 0; i < entities.Length; i += 2)
{
var value = entities[i + 1][0];
entityValues[entities[i]] = value;
result[entities[i]] = value;
if (upperCaseVariantsAccepted.TryGetValue(entities[i], out string upperCaseVariant) && upperCaseVariant != null)
{
entityValues[upperCaseVariant] = value;
result[upperCaseVariant] = value;
}
}
return entityValues;
return result;
}
private static readonly int INITIAL_INPUT_SEGMENT_SIZE = 1024;
private static readonly char BLOCK_LEVEL_START_TAG_REPLACEMENT = '\n';
Expand Down Expand Up @@ -31024,7 +31024,7 @@ private bool ZzRefill()
zzEndRead += numRead;
return false;
}
// unlikely but not impossible: read 0 characters, but not at end of stream
// unlikely but not impossible: read 0 characters, but not at end of stream
if (numRead == 0)
{
int c = zzReader.Read();
Expand Down Expand Up @@ -31104,7 +31104,7 @@ private void YyBegin(int newState)
//private string YyText => new string(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);

/// <summary>
/// Returns the character at position <tt>pos</tt> from the
/// Returns the character at position <tt>pos</tt> from the
/// matched text. It is equivalent to YyText[pos], but faster
/// </summary>
/// <param name="pos">the position of the character to fetch. A value from 0 to YyLength()-1.</param>
Expand All @@ -31124,7 +31124,7 @@ private char YyCharAt(int pos)
/// Reports an error that occured while scanning.
/// <para/>
/// In a wellformed scanner (no or only correct usage of
/// YyPushBack(int) and a match-all fallback rule) this method
/// YyPushBack(int) and a match-all fallback rule) this method
/// will only be called with things that "Can't Possibly Happen".
/// If this method is called, something is seriously wrong
/// (e.g. a JFlex bug producing a faulty scanner etc.).
Expand All @@ -31151,7 +31151,7 @@ private static void ZzScanError(int errorCode) // LUCENENET: CA1822: Mark member

/// <summary>
/// Pushes the specified amount of characters back into the input stream.
///
///
/// They will be read again by then next call of the scanning method
/// </summary>
/// <param name="number">the number of characters to be read again.
Expand Down Expand Up @@ -32094,4 +32094,4 @@ private int NextChar()
}
}
}
}
}
30 changes: 15 additions & 15 deletions src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Lucene.Net.Analysis.Nl
*/

/// <summary>
/// <see cref="Analyzer"/> for Dutch language.
/// <see cref="Analyzer"/> for Dutch language.
/// <para>
/// Supports an external list of stopwords (words that
/// will not be indexed at all), an external list of exclusions (word that will
Expand All @@ -38,20 +38,20 @@ namespace Lucene.Net.Analysis.Nl
/// A default set of stopwords is used unless an alternative list is specified, but the
/// exclusion list is empty by default.
/// </para>
///
///
/// <para>You must specify the required <see cref="LuceneVersion"/>
/// compatibility when creating <see cref="DutchAnalyzer"/>:
/// <list type="bullet">
/// <item><description> As of 3.6, <see cref="DutchAnalyzer(LuceneVersion, CharArraySet)"/> and
/// <see cref="DutchAnalyzer(LuceneVersion, CharArraySet, CharArraySet)"/> also populate
/// the default entries for the stem override dictionary</description></item>
/// <item><description> As of 3.1, Snowball stemming is done with SnowballFilter,
/// LowerCaseFilter is used prior to StopFilter, and Snowball
/// <item><description> As of 3.1, Snowball stemming is done with SnowballFilter,
/// LowerCaseFilter is used prior to StopFilter, and Snowball
/// stopwords are used by default.</description></item>
/// <item><description> As of 2.9, StopFilter preserves position
/// increments</description></item>
/// </list>
///
///
/// </para>
/// <para><b>NOTE</b>: This class uses the same <see cref="LuceneVersion"/>
/// dependent settings as <see cref="StandardAnalyzer"/>.</para>
Expand Down Expand Up @@ -93,13 +93,13 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons
private static CharArrayDictionary<string> LoadDefaultStemDict() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
#pragma warning disable 612, 618
var DEFAULT_STEM_DICT = new CharArrayDictionary<string>(LuceneVersion.LUCENE_CURRENT, 4, false);
var result = new CharArrayDictionary<string>(LuceneVersion.LUCENE_CURRENT, 4, false);
#pragma warning restore 612, 618
DEFAULT_STEM_DICT["fiets"] = "fiets"; //otherwise fiet
DEFAULT_STEM_DICT["bromfiets"] = "bromfiets"; //otherwise bromfiet
DEFAULT_STEM_DICT["ei"] = "eier";
DEFAULT_STEM_DICT["kind"] = "kinder";
return DEFAULT_STEM_DICT;
result["fiets"] = "fiets"; //otherwise fiet
result["bromfiets"] = "bromfiets"; //otherwise bromfiet
result["ei"] = "eier";
result["kind"] = "kinder";
return result;
}
}

Expand All @@ -121,7 +121,7 @@ private static CharArrayDictionary<string> LoadDefaultStemDict() // LUCENENET: A
private readonly LuceneVersion matchVersion;

/// <summary>
/// Builds an analyzer with the default stop words (<see cref="DefaultStopSet"/>)
/// Builds an analyzer with the default stop words (<see cref="DefaultStopSet"/>)
/// and a few default entries for the stem exclusion table.
/// </summary>
public DutchAnalyzer(LuceneVersion matchVersion)
Expand Down Expand Up @@ -191,11 +191,11 @@ public DutchAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords, CharArr
}

/// <summary>
/// Returns a (possibly reused) <see cref="TokenStream"/> which tokenizes all the
/// Returns a (possibly reused) <see cref="TokenStream"/> which tokenizes all the
/// text in the provided <see cref="TextReader"/>.
/// </summary>
/// <returns> A <see cref="TokenStream"/> built from a <see cref="StandardTokenizer"/>
/// filtered with <see cref="StandardFilter"/>, <see cref="LowerCaseFilter"/>,
/// filtered with <see cref="StandardFilter"/>, <see cref="LowerCaseFilter"/>,
/// <see cref="StopFilter"/>, <see cref="SetKeywordMarkerFilter"/> if a stem exclusion set is provided,
/// <see cref="StemmerOverrideFilter"/>, and <see cref="SnowballFilter"/> </returns>
protected internal override TokenStreamComponents CreateComponents(string fieldName, TextReader aReader)
Expand Down Expand Up @@ -235,4 +235,4 @@ protected internal override TokenStreamComponents CreateComponents(string fieldN
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace Lucene.Net.Analysis.Icu.Segmentation
*/

/// <summary>
/// An iterator that locates ISO 15924 script boundaries in text.
/// An iterator that locates ISO 15924 script boundaries in text.
/// </summary>
/// <remarks>
/// This is not the same as simply looking at the Unicode block, or even the
/// This is not the same as simply looking at the Unicode block, or even the
/// Script property. Some characters are 'common' across multiple scripts, and
/// some 'inherit' the script value of text surrounding them.
/// <para/>
Expand All @@ -36,10 +36,10 @@ namespace Lucene.Net.Analysis.Icu.Segmentation
/// <list type="bullet">
/// <item><description>
/// Doesn't attempt to match paired punctuation. For tokenization purposes, this
/// is not necessary. Its also quite expensive.
/// is not necessary. Its also quite expensive.
/// </description></item>
/// <item><description>
/// Non-spacing marks inherit the script of their base character, following
/// Non-spacing marks inherit the script of their base character, following
/// recommendations from UTR #24.
/// </description></item>
/// </list>
Expand Down Expand Up @@ -157,10 +157,10 @@ public void SetText(char[] text, int start, int length)

private static int[] LoadBasicLatin() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
var basicLatin = new int[128];
for (int i = 0; i < basicLatin.Length; i++)
basicLatin[i] = UScript.GetScript(i);
return basicLatin;
var result = new int[128];
for (int i = 0; i < result.Length; i++)
result[i] = UScript.GetScript(i);
return result;
}

/// <summary>Fast version of <see cref="UScript.GetScript(int)"/>. Basic Latin is an array lookup.</summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public JapaneseAnalyzer(LuceneVersion matchVersion, UserDictionary userDict, Jap
public static ISet<string> DefaultStopTags => DefaultSetHolder.DEFAULT_STOP_TAGS;

/// <summary>
/// Atomically loads DEFAULT_STOP_SET, DEFAULT_STOP_TAGS in a lazy fashion once the
/// Atomically loads DEFAULT_STOP_SET, DEFAULT_STOP_TAGS in a lazy fashion once the
/// outer class accesses the static final set the first time.
/// </summary>
private static class DefaultSetHolder
Expand All @@ -88,12 +88,12 @@ private static ISet<string> LoadDefaultStopTagSet() // LUCENENET: Avoid static c
try
{
CharArraySet tagset = LoadStopwordSet(false, typeof(JapaneseAnalyzer), "stoptags.txt", "#");
var DEFAULT_STOP_TAGS = new JCG.HashSet<string>();
var result = new JCG.HashSet<string>();
foreach (string element in tagset)
{
DEFAULT_STOP_TAGS.Add(element);
result.Add(element);
}
return DEFAULT_STOP_TAGS.AsReadOnly(); // LUCENENET: Made readonly as stated in the docs: https://github.com/apache/lucene/issues/11866
return result.AsReadOnly(); // LUCENENET: Made readonly as stated in the docs: https://github.com/apache/lucene/issues/11866
}
catch (Exception ex) when (ex.IsIOException())
{
Expand Down
6 changes: 3 additions & 3 deletions src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ public bool Matches(string txt)

private static IDictionary<NameType, Lang> LoadLangs() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
IDictionary<NameType, Lang> langs = new Dictionary<NameType, Lang>();
IDictionary<NameType, Lang> result = new Dictionary<NameType, Lang>();
foreach (NameType s in Enum.GetValues(typeof(NameType)))
{
langs[s] = LoadFromResource(LANGUAGE_RULES_RN, Languages.GetInstance(s));
result[s] = LoadFromResource(LANGUAGE_RULES_RN, Languages.GetInstance(s));
}
return langs;
return result;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Lucene.Net.Analysis.Phonetic/Language/Bm/Languages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public class Languages

private static IDictionary<NameType, Languages> LoadLanguages() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
IDictionary<NameType, Languages> LANGUAGES = new Dictionary<NameType, Languages>();
IDictionary<NameType, Languages> result = new Dictionary<NameType, Languages>();
foreach (NameType s in Enum.GetValues(typeof(NameType)))
{
LANGUAGES[s] = GetInstance(LangResourceName(s));
result[s] = GetInstance(LangResourceName(s));
}
return LANGUAGES;
return result;
}

public static Languages GetInstance(NameType nameType)
Expand Down Expand Up @@ -130,7 +130,7 @@ public static Languages GetInstance(string languagesResourceName)

private static string LangResourceName(NameType nameType)
{
return string.Format("{0}_languages.txt", nameType.GetName());
return string.Format("{0}_languages.txt", nameType.GetName());
}

private readonly ISet<string> languages;
Expand Down
12 changes: 6 additions & 6 deletions src/Lucene.Net.Benchmark/ByTask/Feeds/TrecDocParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds

/// <summary>
/// Parser for trec doc content, invoked on doc text excluding &lt;DOC&gt; and &lt;DOCNO&gt;
/// which are handled in TrecContentSource. Required to be stateless and hence thread safe.
/// which are handled in TrecContentSource. Required to be stateless and hence thread safe.
/// </summary>
public abstract class TrecDocParser
{
Expand All @@ -48,12 +48,12 @@ public enum ParsePathType { GOV2, FBIS, FT, FR94, LATIMES, UNKNOWN }
internal static readonly IDictionary<string, ParsePathType?> pathName2Type = LoadPathName2Type();
private static IDictionary<string, ParsePathType?> LoadPathName2Type() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
var pathName2Type = new Dictionary<string, ParsePathType?>();
var result = new Dictionary<string, ParsePathType?>();
foreach (ParsePathType ppt in Enum.GetValues(typeof(ParsePathType)))
{
pathName2Type[ppt.ToString().ToUpperInvariant()] = ppt;
result[ppt.ToString().ToUpperInvariant()] = ppt;
}
return pathName2Type;
return result;
}


Expand Down Expand Up @@ -84,14 +84,14 @@ public static ParsePathType PathType(FileInfo f)
}

/// <summary>
/// Parse the text prepared in docBuf into a result DocData,
/// Parse the text prepared in docBuf into a result DocData,
/// no synchronization is required.
/// </summary>
/// <param name="docData">Reusable result.</param>
/// <param name="name">Name that should be set to the result.</param>
/// <param name="trecSrc">Calling trec content source.</param>
/// <param name="docBuf">Text to parse.</param>
/// <param name="pathType">Type of parsed file, or <see cref="ParsePathType.UNKNOWN"/> if unknown - may be used by
/// <param name="pathType">Type of parsed file, or <see cref="ParsePathType.UNKNOWN"/> if unknown - may be used by
/// parsers to alter their behavior according to the file path type. </param>
/// <returns></returns>
public abstract DocData Parse(DocData docData, string name, TrecContentSource trecSrc,
Expand Down
8 changes: 4 additions & 4 deletions src/Lucene.Net.Benchmark/Support/TagSoup/ElementType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ElementType
/// The content model, member-of, and flags vectors are specified as ints.
/// </summary>
/// <param name="name">The element type name</param>
/// <param name="model">ORed-together bits representing the content
/// <param name="model">ORed-together bits representing the content
/// models allowed in the content of this element type</param>
/// <param name="memberOf">ORed-together bits representing the content models
/// to which this element type belongs</param>
Expand Down Expand Up @@ -198,7 +198,7 @@ public virtual void SetAttribute(Attributes atts, string name, string type, stri
}

string ns = GetNamespace(name, true);
string localName = GetLocalName(name);
string ln = GetLocalName(name); // LUCENENET specific - renamed from localName to not shadow field
int i = atts.GetIndex(name);
if (i == -1)
{
Expand All @@ -211,7 +211,7 @@ public virtual void SetAttribute(Attributes atts, string name, string type, stri
{
value = Normalize(value);
}
atts.AddAttribute(ns, localName, name, type, value);
atts.AddAttribute(ns, ln, name, type, value);
}
else
{
Expand All @@ -223,7 +223,7 @@ public virtual void SetAttribute(Attributes atts, string name, string type, stri
{
value = Normalize(value);
}
atts.SetAttribute(i, ns, localName, name, type, value);
atts.SetAttribute(i, ns, ln, name, type, value);
}
}

Expand Down
Loading

0 comments on commit ccff6dd

Please sign in to comment.