Skip to content

Commit 8620f97

Browse files
committed
Convert static readonly fields to const, #662
1 parent d95a40b commit 8620f97

File tree

83 files changed

+372
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+372
-357
lines changed

src/Lucene.Net.Analysis.Common/Analysis/Cjk/CJKBigramFilter.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public enum CJKScript
4949
/// Forms bigrams of CJK terms that are generated from <see cref="StandardTokenizer"/>
5050
/// or ICUTokenizer.
5151
/// <para>
52-
/// CJK types are set by these tokenizers, but you can also use
52+
/// CJK types are set by these tokenizers, but you can also use
5353
/// <see cref="CJKBigramFilter(TokenStream, CJKScript)"/> to explicitly control which
5454
/// of the CJK scripts are turned into bigrams.
5555
/// </para>
@@ -83,8 +83,8 @@ public sealed class CJKBigramFilter : TokenFilter
8383
private static readonly string KATAKANA_TYPE = StandardTokenizer.TOKEN_TYPES[StandardTokenizer.KATAKANA];
8484
private static readonly string HANGUL_TYPE = StandardTokenizer.TOKEN_TYPES[StandardTokenizer.HANGUL];
8585

86-
// sentinel value for ignoring a script
87-
private static readonly string NO = "<NO>";
86+
// sentinel value for ignoring a script
87+
private const string NO = "<NO>";
8888

8989
// these are set to either their type or NO if we want to pass them thru
9090
private readonly string doHan;
@@ -133,7 +133,7 @@ public CJKBigramFilter(TokenStream @in)
133133
/// </summary>
134134
/// <param name="in">
135135
/// Input <see cref="TokenStream"/> </param>
136-
/// <param name="flags"> OR'ed set from <see cref="CJKScript.HAN"/>, <see cref="CJKScript.HIRAGANA"/>,
136+
/// <param name="flags"> OR'ed set from <see cref="CJKScript.HAN"/>, <see cref="CJKScript.HIRAGANA"/>,
137137
/// <see cref="CJKScript.KATAKANA"/>, <see cref="CJKScript.HANGUL"/> </param>
138138
public CJKBigramFilter(TokenStream @in, CJKScript flags)
139139
: this(@in, flags, false)
@@ -145,7 +145,7 @@ public CJKBigramFilter(TokenStream @in, CJKScript flags)
145145
/// and whether or not unigrams should also be output. </summary>
146146
/// <param name="in">
147147
/// Input <see cref="TokenStream"/> </param>
148-
/// <param name="flags"> OR'ed set from <see cref="CJKScript.HAN"/>, <see cref="CJKScript.HIRAGANA"/>,
148+
/// <param name="flags"> OR'ed set from <see cref="CJKScript.HAN"/>, <see cref="CJKScript.HIRAGANA"/>,
149149
/// <see cref="CJKScript.KATAKANA"/>, <see cref="CJKScript.HANGUL"/> </param>
150150
/// <param name="outputUnigrams"> true if unigrams for the selected writing systems should also be output.
151151
/// when this is false, this is only done when there are no adjacent characters to form
@@ -166,8 +166,8 @@ public CJKBigramFilter(TokenStream @in, CJKScript flags, bool outputUnigrams)
166166
}
167167

168168
/*
169-
* much of this complexity revolves around handling the special case of a
170-
* "lone cjk character" where cjktokenizer would output a unigram. this
169+
* much of this complexity revolves around handling the special case of a
170+
* "lone cjk character" where cjktokenizer would output a unigram. this
171171
* is also the only time we ever have to captureState.
172172
*/
173173
public override bool IncrementToken()
@@ -186,7 +186,7 @@ public override bool IncrementToken()
186186
// when also outputting unigrams, we output the unigram first,
187187
// then rewind back to revisit the bigram.
188188
// so an input of ABC is A + (rewind)AB + B + (rewind)BC + C
189-
// the logic in hasBufferedUnigram ensures we output the C,
189+
// the logic in hasBufferedUnigram ensures we output the C,
190190
// even though it did actually have adjacent CJK characters.
191191

192192
if (ngramState)
@@ -225,7 +225,7 @@ public override bool IncrementToken()
225225
{
226226

227227
// we have a buffered unigram, and we peeked ahead to see if we could form
228-
// a bigram, but we can't, because the offsets are unaligned. capture the state
228+
// a bigram, but we can't, because the offsets are unaligned. capture the state
229229
// of this peeked data to be revisited next time thru the loop, and dump our unigram.
230230

231231
loneState = CaptureState();
@@ -246,7 +246,7 @@ public override bool IncrementToken()
246246
{
247247

248248
// we have a buffered unigram, and we peeked ahead to see if we could form
249-
// a bigram, but we can't, because its not a CJK type. capture the state
249+
// a bigram, but we can't, because its not a CJK type. capture the state
250250
// of this peeked data to be revisited next time thru the loop, and dump our unigram.
251251

252252
loneState = CaptureState();
@@ -259,7 +259,7 @@ public override bool IncrementToken()
259259
else
260260
{
261261

262-
// case 3: we have only zero or 1 codepoints buffered,
262+
// case 3: we have only zero or 1 codepoints buffered,
263263
// so not enough to form a bigram. But, we also have no
264264
// more input. So if we have a buffered codepoint, emit
265265
// a unigram, otherwise, its end of stream.
@@ -277,7 +277,7 @@ public override bool IncrementToken()
277277
private State loneState; // rarely used: only for "lone cjk characters", where we emit unigrams
278278

279279
/// <summary>
280-
/// looks at next input token, returning false is none is available
280+
/// looks at next input token, returning false is none is available
281281
/// </summary>
282282
private bool DoNext()
283283
{
@@ -359,7 +359,7 @@ private void Refill()
359359
}
360360

361361
/// <summary>
362-
/// Flushes a bigram token to output from our buffer
362+
/// Flushes a bigram token to output from our buffer
363363
/// This is the normal case, e.g. ABC -> AB BC
364364
/// </summary>
365365
private void FlushBigram()
@@ -383,7 +383,7 @@ private void FlushBigram()
383383
/// <summary>
384384
/// Flushes a unigram token to output from our buffer.
385385
/// This happens when we encounter isolated CJK characters, either the whole
386-
/// CJK string is a single character, or we encounter a CJK character surrounded
386+
/// CJK string is a single character, or we encounter a CJK character surrounded
387387
/// by space, punctuation, english, etc, but not beside any other CJK.
388388
/// </summary>
389389
private void FlushUnigram()
@@ -435,4 +435,4 @@ public override void Reset()
435435
ngramState = false;
436436
}
437437
}
438-
}
438+
}

src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/CapitalizationFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace Lucene.Net.Analysis.Miscellaneous
3434
/// </summary>
3535
public sealed class CapitalizationFilter : TokenFilter
3636
{
37-
public static readonly int DEFAULT_MAX_WORD_COUNT = int.MaxValue;
38-
public static readonly int DEFAULT_MAX_TOKEN_LENGTH = int.MaxValue;
37+
public const int DEFAULT_MAX_WORD_COUNT = int.MaxValue;
38+
public const int DEFAULT_MAX_TOKEN_LENGTH = int.MaxValue;
3939

4040
private readonly bool onlyFirstWord;
4141
private readonly CharArraySet keep;
@@ -269,4 +269,4 @@ private void ProcessWord(char[] buffer, int offset, int length, int wordCount)
269269
//return word.toString();
270270
}
271271
}
272-
}
272+
}

src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/DefaultICUTokenizerConfig.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ namespace Lucene.Net.Analysis.Icu.Segmentation
3030
/// to many languages.
3131
/// </summary>
3232
/// <remarks>
33-
/// Generally tokenizes Unicode text according to UAX#29
34-
/// (<see cref="T:BreakIterator.GetWordInstance(ULocale.ROOT)"/>),
33+
/// Generally tokenizes Unicode text according to UAX#29
34+
/// (<see cref="T:BreakIterator.GetWordInstance(ULocale.ROOT)"/>),
3535
/// but with the following tailorings:
3636
/// <list type="bullet">
3737
/// <item><description>Thai, Lao, Myanmar, Khmer, and CJK text is broken into words with a dictionary.</description></item>
@@ -54,6 +54,7 @@ public class DefaultICUTokenizerConfig : ICUTokenizerConfig
5454
/// <summary>Token type for words that appear to be numbers</summary>
5555
public static readonly string WORD_NUMBER = StandardTokenizer.TOKEN_TYPES[StandardTokenizer.NUM];
5656
/// <summary>Token type for words that appear to be emoji sequences</summary>
57+
// ReSharper disable once ConvertToConstant.Global - matches the fields above to keep it static readonly
5758
public static readonly string WORD_EMOJI = "<EMOJI>"; //StandardTokenizer.TOKEN_TYPES[StandardTokenizer.EMOJI]; // LUCENENET: 4.8.1 StandardTokenizer doesn't contain EMOJI
5859

5960
/// <summary>

src/Lucene.Net.Analysis.Kuromoji/Dict/BinaryDictionary.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ namespace Lucene.Net.Analysis.Ja.Dict
3838
/// </summary>
3939
public abstract class BinaryDictionary : IDictionary
4040
{
41-
public static readonly string DICT_FILENAME_SUFFIX = "$buffer.dat";
42-
public static readonly string TARGETMAP_FILENAME_SUFFIX = "$targetMap.dat";
43-
public static readonly string POSDICT_FILENAME_SUFFIX = "$posDict.dat";
44-
45-
public static readonly string DICT_HEADER = "kuromoji_dict";
46-
public static readonly string TARGETMAP_HEADER = "kuromoji_dict_map";
47-
public static readonly string POSDICT_HEADER = "kuromoji_dict_pos";
41+
public const string DICT_FILENAME_SUFFIX = "$buffer.dat";
42+
public const string TARGETMAP_FILENAME_SUFFIX = "$targetMap.dat";
43+
public const string POSDICT_FILENAME_SUFFIX = "$posDict.dat";
44+
45+
public const string DICT_HEADER = "kuromoji_dict";
46+
public const string TARGETMAP_HEADER = "kuromoji_dict_map";
47+
public const string POSDICT_HEADER = "kuromoji_dict_pos";
48+
// ReSharper disable once ConvertToConstant.Global - VERSION should be a field
4849
public static readonly int VERSION = 1;
4950

5051
private readonly ByteBuffer buffer;
@@ -387,10 +388,12 @@ private string ReadString(int offset, int length, bool kana)
387388
}
388389

389390
/// <summary>flag that the entry has baseform data. otherwise its not inflected (same as surface form)</summary>
390-
public static readonly int HAS_BASEFORM = 1;
391+
public const int HAS_BASEFORM = 1;
392+
391393
/// <summary>flag that the entry has reading data. otherwise reading is surface form converted to katakana</summary>
392-
public static readonly int HAS_READING = 2;
394+
public const int HAS_READING = 2;
395+
393396
/// <summary>flag that the entry has pronunciation data. otherwise pronunciation is the reading</summary>
394-
public static readonly int HAS_PRONUNCIATION = 4;
397+
public const int HAS_PRONUNCIATION = 4;
395398
}
396399
}

src/Lucene.Net.Analysis.Kuromoji/Dict/CharacterDefinition.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ namespace Lucene.Net.Analysis.Ja.Dict
2727
/// </summary>
2828
public sealed class CharacterDefinition
2929
{
30-
public static readonly string FILENAME_SUFFIX = ".dat";
31-
public static readonly string HEADER = "kuromoji_cd";
30+
public const string FILENAME_SUFFIX = ".dat";
31+
public const string HEADER = "kuromoji_cd";
32+
// ReSharper disable once ConvertToConstant.Global - VERSION should be a field
3233
public static readonly int VERSION = 1;
3334

3435
public static readonly int CLASS_COUNT = Enum.GetValues(typeof(CharacterClass)).Length;
@@ -45,18 +46,18 @@ private enum CharacterClass : byte
4546
private readonly bool[] groupMap = new bool[CLASS_COUNT];
4647

4748
// the classes:
48-
public static readonly byte NGRAM = (byte)CharacterClass.NGRAM;
49-
public static readonly byte DEFAULT = (byte)CharacterClass.DEFAULT;
50-
public static readonly byte SPACE = (byte)CharacterClass.SPACE;
51-
public static readonly byte SYMBOL = (byte)CharacterClass.SYMBOL;
52-
public static readonly byte NUMERIC = (byte)CharacterClass.NUMERIC;
53-
public static readonly byte ALPHA = (byte)CharacterClass.ALPHA;
54-
public static readonly byte CYRILLIC = (byte)CharacterClass.CYRILLIC;
55-
public static readonly byte GREEK = (byte)CharacterClass.GREEK;
56-
public static readonly byte HIRAGANA = (byte)CharacterClass.HIRAGANA;
57-
public static readonly byte KATAKANA = (byte)CharacterClass.KATAKANA;
58-
public static readonly byte KANJI = (byte)CharacterClass.KANJI;
59-
public static readonly byte KANJINUMERIC = (byte)CharacterClass.KANJINUMERIC;
49+
public const byte NGRAM = (byte)CharacterClass.NGRAM;
50+
public const byte DEFAULT = (byte)CharacterClass.DEFAULT;
51+
public const byte SPACE = (byte)CharacterClass.SPACE;
52+
public const byte SYMBOL = (byte)CharacterClass.SYMBOL;
53+
public const byte NUMERIC = (byte)CharacterClass.NUMERIC;
54+
public const byte ALPHA = (byte)CharacterClass.ALPHA;
55+
public const byte CYRILLIC = (byte)CharacterClass.CYRILLIC;
56+
public const byte GREEK = (byte)CharacterClass.GREEK;
57+
public const byte HIRAGANA = (byte)CharacterClass.HIRAGANA;
58+
public const byte KATAKANA = (byte)CharacterClass.KATAKANA;
59+
public const byte KANJI = (byte)CharacterClass.KANJI;
60+
public const byte KANJINUMERIC = (byte)CharacterClass.KANJINUMERIC;
6061

6162
private CharacterDefinition()
6263
{

src/Lucene.Net.Analysis.Kuromoji/Dict/ConnectionCosts.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace Lucene.Net.Analysis.Ja.Dict
2828
/// </summary>
2929
public sealed class ConnectionCosts
3030
{
31-
public static readonly string FILENAME_SUFFIX = ".dat";
32-
public static readonly string HEADER = "kuromoji_cc";
31+
public const string FILENAME_SUFFIX = ".dat";
32+
public const string HEADER = "kuromoji_cc";
33+
// ReSharper disable once ConvertToConstant.Global - VERSION should be a field
3334
public static readonly int VERSION = 1;
3435

3536
private readonly short[][] costs; // array is backward IDs first since get is called using the same backward ID consecutively. maybe doesn't matter.

src/Lucene.Net.Analysis.Kuromoji/Dict/Dictionary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public interface IDictionary
9898
// 'getAdditionalData' if other dictionaries like unidic have additional data
9999
}
100100

101-
// LUCENENT TODO: Make this whole thing into an abstact class??
101+
// LUCENENET TODO: Make this whole thing into an abstract class??
102102
public static class Dictionary // LUCENENET specific: CA1052 Static holder types should be Static or NotInheritable
103103
{
104-
public static readonly string INTERNAL_SEPARATOR = "\u0000";
104+
public const string INTERNAL_SEPARATOR = "\0";
105105
}
106106
}

src/Lucene.Net.Analysis.Kuromoji/Dict/TokenInfoDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Lucene.Net.Analysis.Ja.Dict
2929
/// </summary>
3030
public sealed class TokenInfoDictionary : BinaryDictionary
3131
{
32-
public static readonly string FST_FILENAME_SUFFIX = "$fst.dat";
32+
public const string FST_FILENAME_SUFFIX = "$fst.dat";
3333

3434
private readonly TokenInfoFST fst;
3535

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ namespace Lucene.Net.Analysis.Ja
4242
public class JapaneseIterationMarkCharFilter : CharFilter
4343
{
4444
/// <summary>Normalize kanji iteration marks by default</summary>
45-
public static readonly bool NORMALIZE_KANJI_DEFAULT = true;
45+
public const bool NORMALIZE_KANJI_DEFAULT = true;
4646

4747
/// <summary>Normalize kana iteration marks by default</summary>
48-
public static readonly bool NORMALIZE_KANA_DEFAULT = true;
48+
public const bool NORMALIZE_KANA_DEFAULT = true;
4949

5050
private const char KANJI_ITERATION_MARK = '\u3005'; // 々
5151

@@ -167,17 +167,17 @@ public JapaneseIterationMarkCharFilter(TextReader input, bool normalizeKanji, bo
167167
/// Reads a specified maximum number of characters from the current reader and writes the data to a buffer, beginning at the specified index.
168168
/// </summary>
169169
/// <param name="buffer">
170-
/// When this method returns, contains the specified character array with the values between index and (index + count - 1)
170+
/// When this method returns, contains the specified character array with the values between index and (index + count - 1)
171171
/// replaced by the characters read from the current source.</param>
172172
/// <param name="offset">
173173
/// The position in buffer at which to begin writing.
174174
/// </param>
175175
/// <param name="length">
176-
/// The maximum number of characters to read. If the end of the reader is reached before the specified number of characters is
176+
/// The maximum number of characters to read. If the end of the reader is reached before the specified number of characters is
177177
/// read into the buffer, the method returns.
178178
/// </param>
179179
/// <returns>
180-
/// The number of characters that have been read. The number will be less than or equal to count, depending on whether the data is
180+
/// The number of characters that have been read. The number will be less than or equal to count, depending on whether the data is
181181
/// available within the reader. This method returns 0 (zero) if it is called when no more characters are left to read.
182182
/// </returns>
183183
public override int Read(char[] buffer, int offset, int length)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public sealed class JapaneseTokenizer : Tokenizer
6464
/// <summary>
6565
/// Default tokenization mode. Currently this is <see cref="JapaneseTokenizerMode.SEARCH"/>.
6666
/// </summary>
67-
public static readonly JapaneseTokenizerMode DEFAULT_MODE = JapaneseTokenizerMode.SEARCH;
67+
public const JapaneseTokenizerMode DEFAULT_MODE = JapaneseTokenizerMode.SEARCH;
6868

6969
// LUCENENET specific: de-nested Type and renamed JapaneseTokenizerType
7070

0 commit comments

Comments
 (0)