Skip to content

Commit 2067df7

Browse files
authored
Added Lucene.Net.CodeAnalysis.Dev package reference (#1190)
* Directory.Build.targets: Added global reference to Lucene.Net.CodeAnalysis.Dev to enable development analyzers * SWEEP: Fixed LuceneDev1001 build warnings
1 parent fbd608e commit 2067df7

12 files changed

Lines changed: 27 additions & 16 deletions

File tree

.build/dependencies.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<!-- J2N will break binary compatibility in 3.0.0 to fix the APIs of collection types -->
4141
<J2NPackageVersion>[2.2.0-alpha-0021, 3.0.0)</J2NPackageVersion>
4242
<LiquidTestReportsMarkdownPackageVersion>1.0.9</LiquidTestReportsMarkdownPackageVersion>
43+
<LuceneNetCodeAnalysisDevPackageVersion>1.0.0-alpha.6</LuceneNetCodeAnalysisDevPackageVersion>
4344
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.3.0</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
4445
<MicrosoftAspNetCoreTestHostPackageVersion>8.0.19</MicrosoftAspNetCoreTestHostPackageVersion>
4546
<MicrosoftCodeAnalysisAnalyzersPackageVersion>2.9.8</MicrosoftCodeAnalysisAnalyzersPackageVersion>

Directory.Build.targets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424

2525
<PropertyGroup Label="Warnings to be Disabled in Solution">
2626
<NoWarn Label="Legacy serialization support APIs are obsolete">$(NoWarn);SYSLIB0051</NoWarn>
27+
28+
<!-- These are noisy, but may be helpful during Lucene upgrades or optimization -->
29+
<NoWarn Label="Floating point types should not be compared for exact equality">$(NoWarn);LuceneDev1000</NoWarn>
30+
<NoWarn Label="Floating point type arithmetic needs to be checked on x86 in .NET Framework and may require extra casting">$(NoWarn);LuceneDev1002</NoWarn>
31+
<NoWarn Label="Java array parameters can sometimes be replaced with .NET out or ref parameters">$(NoWarn);LuceneDev1003</NoWarn>
32+
<NoWarn Label="Return array may be able to be replaced with out values">$(NoWarn);LuceneDev1004</NoWarn>
2733
</PropertyGroup>
2834

2935
<PropertyGroup Label="Solution-level Publish to Project-specific Directory">
@@ -222,6 +228,10 @@
222228
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="$(MicrosoftSourceLinkGitHubPackageReferenceVersion)" PrivateAssets="All"/>
223229
</ItemGroup>
224230

231+
<ItemGroup>
232+
<PackageReference Include="Lucene.Net.CodeAnalysis.Dev" Version="$(LuceneNetCodeAnalysisDevPackageVersion)" PrivateAssets="All" />
233+
</ItemGroup>
234+
225235
<Import Project=".build/release.targets" Condition="Exists('.build/release.targets')" />
226236

227237
</Project>

src/Lucene.Net.Benchmark/ByTask/Tasks/AnalyzerFactoryTask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public override void SetParams(string @params)
155155
{
156156
case StreamTokenizer.TokenType_Number:
157157
{
158-
argValue = stok.NumberValue.ToString(CultureInfo.InvariantCulture);
158+
argValue = J2N.Numerics.Double.ToString(stok.NumberValue, CultureInfo.InvariantCulture);
159159
// Drop the ".0" from numbers, for integer arguments
160160
argValue = TRAILING_DOT_ZERO_PATTERN.Replace(argValue, "", 1);
161161
// Intentional fallthrough
@@ -440,7 +440,7 @@ private void CreateAnalysisPipelineComponent(StreamTokenizer stok, Type clazz)
440440
{
441441
case StreamTokenizer.TokenType_Number:
442442
{
443-
argValue = stok.NumberValue.ToString(CultureInfo.InvariantCulture);
443+
argValue = J2N.Numerics.Double.ToString(stok.NumberValue, CultureInfo.InvariantCulture);
444444
// Drop the ".0" from numbers, for integer arguments
445445
argValue = TRAILING_DOT_ZERO_PATTERN.Replace(argValue, "", 1);
446446
// Intentional fall-through

src/Lucene.Net.Benchmark/ByTask/Utils/Algorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public Algorithm(PerfRunData runData)
116116
{
117117
case StreamTokenizer.TokenType_Number:
118118
{
119-
@params.Append(stok.NumberValue.ToString(CultureInfo.InvariantCulture));
119+
@params.Append(J2N.Numerics.Double.ToString(stok.NumberValue, CultureInfo.InvariantCulture));
120120
break;
121121
}
122122
case StreamTokenizer.TokenType_Word:

src/Lucene.Net.Benchmark/ByTask/Utils/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public virtual double Get(string name, double dflt)
269269
// done if not by round
270270
if (!props.TryGetValue(name, out string sval))
271271
{
272-
sval = dflt.ToString(CultureInfo.InvariantCulture);
272+
sval = J2N.Numerics.Double.ToString(dflt, CultureInfo.InvariantCulture);
273273
}
274274
if (sval.IndexOf(':') < 0)
275275
{

src/Lucene.Net.QueryParser/Flexible/Core/Nodes/BoostQueryNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private string GetValueString()
8383
if (f == (long)f)
8484
return "" + (long)f;
8585
else
86-
return "" + f.ToString("0.0#######"); // LUCENENET TODO: Culture
86+
return "" + J2N.Numerics.Single.ToString(f, "0.0#######"); // LUCENENET TODO: Culture
8787
}
8888

8989
public override string ToString()

src/Lucene.Net/Index/CheckIndex.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ public virtual Status DoCheckIndex(IList<string> onlySegments)
717717
#pragma warning restore 612, 618
718718
{
719719
// don't print size in bytes if its a 3.0 segment with shared docstores
720-
Msg(infoStream, " size (MB)=" + segInfoStat.SizeMB.ToString(nf));
720+
Msg(infoStream, " size (MB)=" + J2N.Numerics.Double.ToString(segInfoStat.SizeMB, nf));
721721
}
722722
IDictionary<string, string> diagnostics = info.Info.Diagnostics;
723723
segInfoStat.Diagnostics = diagnostics;
@@ -2269,7 +2269,7 @@ public static Status.TermVectorStatus TestTermVectors(AtomicReader reader, TextW
22692269
}
22702270
}
22712271
float vectorAvg = status.DocCount == 0 ? 0 : status.TotVectors / (float)status.DocCount;
2272-
Msg(infoStream, "OK [" + status.TotVectors + " total vector count; avg " + vectorAvg.ToString(CultureInfo.InvariantCulture.NumberFormat) + " term/freq vector fields per doc]");
2272+
Msg(infoStream, "OK [" + status.TotVectors + " total vector count; avg " + J2N.Numerics.Single.ToString(vectorAvg, NumberFormatInfo.InvariantInfo) + " term/freq vector fields per doc]");
22732273
}
22742274
catch (Exception e) when (e.IsThrowable())
22752275
{

src/Lucene.Net/Index/DocumentsWriterPerThread.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ internal virtual FlushedSegment Flush()
571571
if (infoStream.IsEnabled("DWPT"))
572572
{
573573
double newSegmentSize = segmentInfoPerCommit.GetSizeInBytes() / 1024.0 / 1024.0;
574-
infoStream.Message("DWPT", "flushed: segment=" + segmentInfo.Name + " ramUsed=" + startMBUsed.ToString(nf) + " MB" + " newFlushedSize(includes docstores)=" + newSegmentSize.ToString(nf) + " MB" + " docs/MB=" + (flushState.SegmentInfo.DocCount / newSegmentSize).ToString(nf));
574+
infoStream.Message("DWPT", "flushed: segment=" + segmentInfo.Name + " ramUsed=" + J2N.Numerics.Double.ToString(startMBUsed, nf) + " MB" + " newFlushedSize(includes docstores)=" + J2N.Numerics.Double.ToString(newSegmentSize, nf) + " MB" + " docs/MB=" + J2N.Numerics.Double.ToString((flushState.SegmentInfo.DocCount / newSegmentSize), nf));
575575
}
576576

577577
if (Debugging.AssertsEnabled) Debugging.Assert(segmentInfo != null);

src/Lucene.Net/Index/LogMergePolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ public override MergeSpecification FindMerges(MergeTrigger mergeTrigger, Segment
660660
}
661661
if (IsVerbose)
662662
{
663-
Message(" level " + levelBottom.ToString("0.0") + " to " + maxLevel.ToString("0.0") + ": " + (1 + upto - start) + " segments");
663+
Message(" level " + J2N.Numerics.Single.ToString(levelBottom) + " to " + J2N.Numerics.Single.ToString(maxLevel) + ": " + (1 + upto - start) + " segments");
664664
}
665665

666666
// Finally, record all merges that are viable at this level:

src/Lucene.Net/Index/TieredMergePolicy.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public virtual double MaxMergedSegmentMB
152152
{
153153
if (value < 0.0)
154154
{
155-
throw new ArgumentOutOfRangeException(nameof(MaxMergedSegmentMB), "maxMergedSegmentMB must be >=0 (got " + value.ToString("0.0") + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
155+
throw new ArgumentOutOfRangeException(nameof(MaxMergedSegmentMB), "maxMergedSegmentMB must be >=0 (got " + J2N.Numerics.Double.ToString(value) + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
156156
}
157157
value *= 1024 * 1024;
158158
maxMergedSegmentBytes = (value > long.MaxValue) ? long.MaxValue : (long)value;
@@ -175,7 +175,7 @@ public virtual double ReclaimDeletesWeight
175175
{
176176
if (value < 0.0)
177177
{
178-
throw new ArgumentOutOfRangeException(nameof(ReclaimDeletesWeight), "reclaimDeletesWeight must be >= 0.0 (got " + value.ToString("0.0") + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
178+
throw new ArgumentOutOfRangeException(nameof(ReclaimDeletesWeight), "reclaimDeletesWeight must be >= 0.0 (got " + J2N.Numerics.Double.ToString(value) + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
179179
}
180180
reclaimDeletesWeight = value;
181181
}
@@ -195,7 +195,7 @@ public virtual double FloorSegmentMB
195195
{
196196
if (value <= 0.0)
197197
{
198-
throw new ArgumentOutOfRangeException(nameof(FloorSegmentMB), "floorSegmentMB must be >= 0.0 (got " + value.ToString("0.0") + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
198+
throw new ArgumentOutOfRangeException(nameof(FloorSegmentMB), "floorSegmentMB must be >= 0.0 (got " + J2N.Numerics.Double.ToString(value) + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
199199
}
200200
value *= 1024 * 1024;
201201
floorSegmentBytes = (value > long.MaxValue) ? long.MaxValue : (long)value;
@@ -214,7 +214,7 @@ public virtual double ForceMergeDeletesPctAllowed
214214
{
215215
if (value < 0.0 || value > 100.0)
216216
{
217-
throw new ArgumentOutOfRangeException(nameof(ForceMergeDeletesPctAllowed), "forceMergeDeletesPctAllowed must be between 0.0 and 100.0 inclusive (got " + value.ToString("0.0") + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
217+
throw new ArgumentOutOfRangeException(nameof(ForceMergeDeletesPctAllowed), "forceMergeDeletesPctAllowed must be between 0.0 and 100.0 inclusive (got " + J2N.Numerics.Double.ToString(value) + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
218218
}
219219
forceMergeDeletesPctAllowed = value;
220220
}
@@ -237,7 +237,7 @@ public virtual double SegmentsPerTier
237237
{
238238
if (value < 2.0)
239239
{
240-
throw new ArgumentOutOfRangeException(nameof(SegmentsPerTier), "segmentsPerTier must be >= 2.0 (got " + value.ToString("0.0") + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
240+
throw new ArgumentOutOfRangeException(nameof(SegmentsPerTier), "segmentsPerTier must be >= 2.0 (got " + J2N.Numerics.Double.ToString(value) + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
241241
}
242242
segsPerTier = value;
243243
}

0 commit comments

Comments
 (0)