Skip to content

Commit e0d6fdb

Browse files
committed
C#: Provide some higher order methods for writing Locations to TRAP.
1 parent 3672d82 commit e0d6fdb

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
@@ -102,6 +103,22 @@ public virtual IEnumerable<Location> Locations
102103
}
103104
}
104105

106+
protected static void WriteLocationToTrap<T1>(Action<T1, Location> writeAction, T1 entity, Location l)
107+
{
108+
if (l is not EmptyLocation)
109+
{
110+
writeAction(entity, l);
111+
}
112+
}
113+
114+
protected static void WriteLocationsToTrap<T1>(Action<T1, Location> writeAction, T1 entity, IEnumerable<Location> locations)
115+
{
116+
foreach (var loc in locations)
117+
{
118+
WriteLocationToTrap(writeAction, entity, loc);
119+
}
120+
}
121+
105122
/// <summary>
106123
/// Bind comments to this symbol.
107124
/// Comments are only bound to source declarations.

csharp/extractor/Semmle.Extraction.CSharp/Entities/Constructor.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public override void Populate(TextWriter trapFile)
2929
ContainingType!.PopulateGenerics();
3030

3131
trapFile.constructors(this, Symbol.ContainingType.Name, ContainingType, (Constructor)OriginalDefinition);
32-
if (Location is not EmptyLocation)
33-
{
34-
trapFile.constructor_location(this, Location);
35-
}
32+
WriteLocationToTrap(trapFile.constructor_location, this, Location);
3633

3734
if (MakeSynthetic)
3835
{

csharp/extractor/Semmle.Extraction.CSharp/Entities/OrdinaryMethod.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ public override void Populate(TextWriter trapFile)
4545

4646
if (Context.ExtractLocation(Symbol))
4747
{
48-
foreach (var l in Locations)
49-
{
50-
if (l is not EmptyLocation)
51-
{
52-
trapFile.method_location(this, l);
53-
}
54-
}
48+
WriteLocationsToTrap(trapFile.method_location, this, Locations);
5549
}
5650

5751
PopulateGenerics(trapFile);

0 commit comments

Comments
 (0)