Skip to content

Commit

Permalink
Refactor code: Replace string concatenation with string interpolation…
Browse files Browse the repository at this point in the history
… and change static readonly to const, #1077
  • Loading branch information
manognya-b committed Jan 7, 2025
1 parent 6435a2c commit a864889
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override Tokenizer Create(AttributeSource.AttributeFactory factory, TextR
EdgeNGramTokenFilter.Side sideEnum;
if (!Enum.TryParse(this.side, true, out sideEnum))
{
throw new ArgumentException(nameof(EdgeNGramTokenizer) + " does not support backward n-grams as of Lucene 4.4");
throw new ArgumentException($"{nameof(EdgeNGramTokenizer)} does not support backward n-grams as of Lucene 4.4");
}
return new EdgeNGramTokenizer(m_luceneMatchVersion, input, minGramSize, maxGramSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal sealed class AnalysisSPILoader<S> where S : AbstractAnalysisFactory
private readonly string[] suffixes;

public AnalysisSPILoader()
: this(new string[] { nameof(S) })
: this(new string[] { typeof(S).Name })
{
}

Expand Down
10 changes: 5 additions & 5 deletions src/Lucene.Net/Codecs/Lucene3x/Lucene3xSegmentInfoFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public class Lucene3xSegmentInfoFormat : SegmentInfoFormat
public override SegmentInfoWriter SegmentInfoWriter => throw UnsupportedOperationException.Create("this codec can only be used for reading");

// only for backwards compat
public static readonly string DS_OFFSET_KEY = nameof(Lucene3xSegmentInfoFormat) + ".dsoffset";
public const string DS_OFFSET_KEY = nameof(Lucene3xSegmentInfoFormat) + ".dsoffset";

public static readonly string DS_NAME_KEY = nameof(Lucene3xSegmentInfoFormat) + ".dsname";
public static readonly string DS_COMPOUND_KEY = nameof(Lucene3xSegmentInfoFormat) + ".dscompound";
public static readonly string NORMGEN_KEY = nameof(Lucene3xSegmentInfoFormat) + ".normgen";
public static readonly string NORMGEN_PREFIX = nameof(Lucene3xSegmentInfoFormat) + ".normfield";
public const string DS_NAME_KEY = nameof(Lucene3xSegmentInfoFormat) + ".dsname";
public const string DS_COMPOUND_KEY = nameof(Lucene3xSegmentInfoFormat) + ".dscompound";
public const string NORMGEN_KEY = nameof(Lucene3xSegmentInfoFormat) + ".normgen";
public const string NORMGEN_PREFIX = nameof(Lucene3xSegmentInfoFormat) + ".normfield";

/// <returns> If this segment shares stored fields &amp; vectors, this
/// offset is where in that file this segment's docs begin. </returns>
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public override FieldInfos Read(Directory directory, string segmentName, string
}
}

internal static readonly string LEGACY_DV_TYPE_KEY = nameof(Lucene40FieldInfosReader) + ".dvtype";
internal static readonly string LEGACY_NORM_TYPE_KEY = nameof(Lucene40FieldInfosReader) + ".normtype";
internal const string LEGACY_DV_TYPE_KEY = nameof(Lucene40FieldInfosReader) + ".dvtype";
internal const string LEGACY_NORM_TYPE_KEY = nameof(Lucene40FieldInfosReader) + ".normtype";

// mapping of 4.0 types -> 4.2 types
/*internal enum LegacyDocValuesType
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public abstract class PerFieldDocValuesFormat : DocValuesFormat
/// <see cref="FieldInfo"/> attribute name used to store the
/// format name for each field.
/// </summary>
public static readonly string PER_FIELD_FORMAT_KEY = nameof(PerFieldDocValuesFormat) + ".format";
public const string PER_FIELD_FORMAT_KEY = nameof(PerFieldDocValuesFormat) + ".format";

/// <summary>
/// <see cref="FieldInfo"/> attribute name used to store the
/// segment suffix name for each field.
/// </summary>
public static readonly string PER_FIELD_SUFFIX_KEY = nameof(PerFieldDocValuesFormat) + ".suffix";
public const string PER_FIELD_SUFFIX_KEY = nameof(PerFieldDocValuesFormat) + ".suffix";

/// <summary>
/// Sole constructor. </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public abstract class PerFieldPostingsFormat : PostingsFormat
/// <see cref="FieldInfo"/> attribute name used to store the
/// format name for each field.
/// </summary>
public static readonly string PER_FIELD_FORMAT_KEY = nameof(PerFieldPostingsFormat) + ".format";
public const string PER_FIELD_FORMAT_KEY = nameof(PerFieldPostingsFormat) + ".format";

/// <summary>
/// <see cref="FieldInfo"/> attribute name used to store the
/// segment suffix name for each field.
/// </summary>
public static readonly string PER_FIELD_SUFFIX_KEY = nameof(PerFieldPostingsFormat) + ".suffix";
public const string PER_FIELD_SUFFIX_KEY = nameof(PerFieldPostingsFormat) + ".suffix";

/// <summary>
/// Sole constructor. </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net/Support/Util/NamedServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected static string GetCanonicalName(Type type)
genericSuffix = "Generic" + name.Substring(genericIndex + 1);
name = name.Substring(0, genericIndex);
}
string serviceName = nameof(TService);
string serviceName = typeof(TService).Name;
if (name.EndsWith(serviceName, StringComparison.Ordinal))
{
name = name.Substring(0, name.Length - serviceName.Length);
Expand Down
8 changes: 4 additions & 4 deletions src/Lucene.Net/Util/CommandLineUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ public static FSDirectory NewFSDirectory(string clazzName, DirectoryInfo dir)

// LUCENENET: In .NET, we get a null when the class is not found, so we need to throw here for compatibility
if (clazz is null)
throw new ArgumentException(nameof(FSDirectory) + " implementation not found: " + clazzName);
throw new ArgumentException($"{nameof(FSDirectory)} implementation not found: {clazzName}");

return NewFSDirectory(clazz, dir);
}
catch (Exception e) when (e.IsClassNotFoundException())
{
throw new ArgumentException(nameof(FSDirectory) + " implementation not found: " + clazzName, e);
throw new ArgumentException($"{nameof(FSDirectory)} implementation not found: {clazzName}", e);
}
catch (Exception e) when (e.IsClassCastException())
{
throw new ArgumentException(clazzName + " is not a " + nameof(FSDirectory) + " implementation", e);
throw new ArgumentException($"{clazzName} is not a {nameof(FSDirectory)} implementation", e);
}
catch (Exception e) when (e.IsNoSuchMethodException())
{
throw new ArgumentException(clazzName + " constructor with " + nameof(FileInfo) + " as parameter not found", e);
throw new ArgumentException($"{clazzName} constructor with {nameof(FileInfo)} as parameter not found", e);
}
catch (Exception e)
{
Expand Down

0 comments on commit a864889

Please sign in to comment.