Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Code Quality (originally submitted by @iamcarbon in #754) #756

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Lucene.Net/Analysis/TokenStreamToAutomaton.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using J2N;
using J2N;
using Lucene.Net.Analysis.TokenAttributes;
using Lucene.Net.Diagnostics;
using Lucene.Net.Util;
using System;
using System.Diagnostics;

namespace Lucene.Net.Analysis
{
Expand Down
3 changes: 1 addition & 2 deletions src/Lucene.Net/Codecs/MappingMultiDocsAndPositionsEnum.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Lucene.Net.Support;
using System;
using Lucene.Net.Support;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

Expand Down
3 changes: 1 addition & 2 deletions src/Lucene.Net/Codecs/MappingMultiDocsEnum.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lucene.Net.Diagnostics;
using Lucene.Net.Diagnostics;
using Lucene.Net.Support;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

Expand Down
1 change: 0 additions & 1 deletion src/Lucene.Net/Codecs/TermsConsumer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lucene.Net.Diagnostics;
using Lucene.Net.Index;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace Lucene.Net.Codecs
Expand Down
202 changes: 78 additions & 124 deletions src/Lucene.Net/Index/CheckIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,7 @@ public virtual void FlushInfoStream() // LUCENENET specific

private static void Msg(TextWriter @out, string msg)
{
if (@out != null)
{
@out.WriteLine(msg);
}
@out?.WriteLine(msg);
}

/// <summary>
Expand Down Expand Up @@ -522,14 +519,13 @@ public virtual Status DoCheckIndex(IList<string> onlySegments)
{
Msg(infoStream, "ERROR: could not read any segments file in directory");
result.MissingSegments = true;
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(t.ToString());
//infoStream.WriteLine(t.StackTrace);
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(t.ToString());
//infoStream.WriteLine(t.StackTrace);

return result;
}

Expand Down Expand Up @@ -571,14 +567,13 @@ public virtual Status DoCheckIndex(IList<string> onlySegments)
catch (Exception t) when (t.IsThrowable())
{
Msg(infoStream, "ERROR: could not open segments file in directory");
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(t.ToString());
//infoStream.WriteLine(t.StackTrace);
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(t.ToString());
//infoStream.WriteLine(t.StackTrace);

result.CantOpenSegments = true;
return result;
}
Expand All @@ -590,23 +585,19 @@ public virtual Status DoCheckIndex(IList<string> onlySegments)
catch (Exception t) when (t.IsThrowable())
{
Msg(infoStream, "ERROR: could not read segment file version in directory");
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(t.ToString());
//infoStream.WriteLine(t.StackTrace);
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(t.ToString());
//infoStream.WriteLine(t.StackTrace);

result.MissingSegmentVersion = true;
return result;
}
finally
{
if (input != null)
{
input.Dispose();
}
input?.Dispose();
}

string sFormat = "";
Expand Down Expand Up @@ -745,26 +736,21 @@ public virtual Status DoCheckIndex(IList<string> onlySegments)
segInfoStat.HasDeletions = true;
segInfoStat.DeletionsGen = info.DelGen;
}
if (infoStream != null)
{
infoStream.Write(" test: open reader.........");
}

infoStream?.Write(" test: open reader.........");

reader = new SegmentReader(info, DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR, IOContext.DEFAULT);
Msg(infoStream, "OK");

segInfoStat.OpenReaderPassed = true;

if (infoStream != null)
{
infoStream.Write(" test: check integrity.....");
}
infoStream?.Write(" test: check integrity.....");

reader.CheckIntegrity();
Msg(infoStream, "OK");

if (infoStream != null)
{
infoStream.Write(" test: check live docs.....");
}
infoStream?.Write(" test: check live docs.....");

int numDocs = reader.NumDocs;
toLoseDocCount = numDocs;
if (reader.HasDeletions)
Expand Down Expand Up @@ -831,10 +817,8 @@ public virtual Status DoCheckIndex(IList<string> onlySegments)
}

// Test getFieldInfos()
if (infoStream != null)
{
infoStream.Write(" test: fields..............");
}
infoStream?.Write(" test: fields..............");

FieldInfos fieldInfos = reader.FieldInfos;
Msg(infoStream, "OK [" + fieldInfos.Count + " fields]");
segInfoStat.NumFields = fieldInfos.Count;
Expand Down Expand Up @@ -884,24 +868,20 @@ public virtual Status DoCheckIndex(IList<string> onlySegments)
string comment;
comment = "fixIndex() would remove reference to this segment";
Msg(infoStream, " WARNING: " + comment + "; full exception:");
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(t.ToString());
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(t.ToString());

Msg(infoStream, "");
result.TotLoseDocCount += toLoseDocCount;
result.NumBadSegments++;
continue;
}
finally
{
if (reader != null)
{
reader.Dispose();
}
reader?.Dispose();
}

// Keeper
Expand Down Expand Up @@ -944,10 +924,8 @@ public static Status.FieldNormStatus TestFieldNorms(AtomicReader reader, TextWri
try
{
// Test Field Norms
if (infoStream != null)
{
infoStream.Write(" test: field norms.........");
}
infoStream?.Write(" test: field norms.........");

foreach (FieldInfo info in reader.FieldInfos)
{
if (info.HasNorms)
Expand Down Expand Up @@ -976,14 +954,12 @@ public static Status.FieldNormStatus TestFieldNorms(AtomicReader reader, TextWri
{
Msg(infoStream, "ERROR [" + e.Message + "]");
status.Error = e;
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

return status;
Expand Down Expand Up @@ -1668,20 +1644,14 @@ public static Status.TermIndexStatus TestPostings(AtomicReader reader, TextWrite

try
{
if (infoStream != null)
{
infoStream.Write(" test: terms, freq, prox...");
}

infoStream?.Write(" test: terms, freq, prox...");

Fields fields = reader.Fields;
FieldInfos fieldInfos = reader.FieldInfos;
status = CheckFields(fields, liveDocs, maxDoc, fieldInfos, true, false, infoStream, verbose);
if (liveDocs != null)
{
if (infoStream != null)
{
infoStream.Write(" test (ignoring deletes): terms, freq, prox...");
}
infoStream?.Write(" test (ignoring deletes): terms, freq, prox...");
CheckFields(fields, null, maxDoc, fieldInfos, true, false, infoStream, verbose);
}
}
Expand All @@ -1690,14 +1660,12 @@ public static Status.TermIndexStatus TestPostings(AtomicReader reader, TextWrite
Msg(infoStream, "ERROR: " + e);
status = new Status.TermIndexStatus();
status.Error = e;
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

return status;
Expand All @@ -1714,10 +1682,7 @@ public static Status.StoredFieldStatus TestStoredFields(AtomicReader reader, Tex

try
{
if (infoStream != null)
{
infoStream.Write(" test: stored fields.......");
}
infoStream?.Write(" test: stored fields.......");

// Scan stored fields for all documents
IBits liveDocs = reader.LiveDocs;
Expand Down Expand Up @@ -1745,14 +1710,12 @@ public static Status.StoredFieldStatus TestStoredFields(AtomicReader reader, Tex
{
Msg(infoStream, "ERROR [" + e.Message + "]");
status.Error = e;
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

return status;
Expand All @@ -1768,10 +1731,8 @@ public static Status.DocValuesStatus TestDocValues(AtomicReader reader, TextWrit
Status.DocValuesStatus status = new Status.DocValuesStatus();
try
{
if (infoStream != null)
{
infoStream.Write(" test: docvalues...........");
}
infoStream?.Write(" test: docvalues...........");

foreach (FieldInfo fieldInfo in reader.FieldInfos)
{
if (fieldInfo.HasDocValues)
Expand All @@ -1794,14 +1755,12 @@ public static Status.DocValuesStatus TestDocValues(AtomicReader reader, TextWrit
{
Msg(infoStream, "ERROR [" + e.Message + "]");
status.Error = e;
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}
return status;
}
Expand Down Expand Up @@ -2069,10 +2028,7 @@ public static Status.TermVectorStatus TestTermVectors(AtomicReader reader, TextW

try
{
if (infoStream != null)
{
infoStream.Write(" test: term vectors........");
}
infoStream?.Write(" test: term vectors........");

DocsEnum docs = null;
DocsAndPositionsEnum postings = null;
Expand Down Expand Up @@ -2322,14 +2278,12 @@ public static Status.TermVectorStatus TestTermVectors(AtomicReader reader, TextW
{
Msg(infoStream, "ERROR [" + e.Message + "]");
status.Error = e;
if (infoStream != null)
{
// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

// LUCENENET NOTE: Some tests rely on the error type being in
// the message. We can't get the error type with StackTrace, we
// need ToString() for that.
infoStream?.WriteLine(e.ToString());
//infoStream.WriteLine(e.StackTrace);
}

return status;
Expand Down
5 changes: 1 addition & 4 deletions src/Lucene.Net/Store/BaseDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public override Lock MakeLock(string name)

public override void ClearLock(string name)
{
if (m_lockFactory != null)
{
m_lockFactory.ClearLock(name);
}
m_lockFactory?.ClearLock(name);
}

public override void SetLockFactory(LockFactory lockFactory)
Expand Down
1 change: 0 additions & 1 deletion src/Lucene.Net/Store/BufferedChecksumIndexInput.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Lucene.Net.Support;
using System;

namespace Lucene.Net.Store
{
Expand Down
Loading