Skip to content

Commit b7098b7

Browse files
committed
Move location-like entities to the Semmle.Extraction.CSharp namespace
1 parent e7844e2 commit b7098b7

Some content is hidden

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

50 files changed

+122
-138
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class CommentBlock
1212

1313
public IEnumerable<CommentLine> CommentLines => lines;
1414

15-
public Location Location { get; private set; }
15+
public Microsoft.CodeAnalysis.Location Location { get; private set; }
1616

1717
public CommentBlock(CommentLine firstLine)
1818
{
@@ -49,7 +49,7 @@ public void AddCommentLine(CommentLine line)
4949
{
5050
Location = !lines.Any()
5151
? line.Location
52-
: Location.Create(
52+
: Microsoft.CodeAnalysis.Location.Create(
5353
line.Location.SourceTree!,
5454
new TextSpan(Location.SourceSpan.Start, line.Location.SourceSpan.End - Location.SourceSpan.Start));
5555

csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentProcessor.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public void AddComment(CommentLine comment)
1919
}
2020

2121
// Comments sorted by location.
22-
private readonly SortedDictionary<Location, CommentLine> comments = new SortedDictionary<Location, CommentLine>(new LocationComparer());
22+
private readonly SortedDictionary<Microsoft.CodeAnalysis.Location, CommentLine> comments = new SortedDictionary<Microsoft.CodeAnalysis.Location, CommentLine>(new LocationComparer());
2323

2424
// Program elements sorted by location.
25-
private readonly SortedDictionary<Location, Label> elements = new SortedDictionary<Location, Label>(new LocationComparer());
25+
private readonly SortedDictionary<Microsoft.CodeAnalysis.Location, Label> elements = new SortedDictionary<Microsoft.CodeAnalysis.Location, Label>(new LocationComparer());
2626

2727
private readonly Dictionary<Label, Key> duplicationGuardKeys = new Dictionary<Label, Key>();
2828

@@ -33,9 +33,9 @@ public void AddComment(CommentLine comment)
3333
return null;
3434
}
3535

36-
private class LocationComparer : IComparer<Location>
36+
private class LocationComparer : IComparer<Microsoft.CodeAnalysis.Location>
3737
{
38-
public int Compare(Location? l1, Location? l2) => CommentProcessor.Compare(l1, l2);
38+
public int Compare(Microsoft.CodeAnalysis.Location? l1, Microsoft.CodeAnalysis.Location? l2) => CommentProcessor.Compare(l1, l2);
3939
}
4040

4141
/// <summary>
@@ -44,7 +44,7 @@ private class LocationComparer : IComparer<Location>
4444
/// <param name="l1">First location</param>
4545
/// <param name="l2">Second location</param>
4646
/// <returns>&lt;0 if l1 before l2, &gt;0 if l1 after l2, else 0.</returns>
47-
private static int Compare(Location? l1, Location? l2)
47+
private static int Compare(Microsoft.CodeAnalysis.Location? l1, Microsoft.CodeAnalysis.Location? l2)
4848
{
4949
if (object.ReferenceEquals(l1, l2))
5050
return 0;
@@ -68,7 +68,7 @@ private static int Compare(Location? l1, Location? l2)
6868
/// <param name="elementLabel">The label of the element in the trap file.</param>
6969
/// <param name="duplicationGuardKey">The duplication guard key of the element, if any.</param>
7070
/// <param name="loc">The location of the element.</param>
71-
public void AddElement(Label elementLabel, Key? duplicationGuardKey, Location? loc)
71+
public void AddElement(Label elementLabel, Key? duplicationGuardKey, Microsoft.CodeAnalysis.Location? loc)
7272
{
7373
if (loc is not null && loc.IsInSource)
7474
elements[loc] = elementLabel;
@@ -78,7 +78,7 @@ public void AddElement(Label elementLabel, Key? duplicationGuardKey, Location? l
7878

7979
// Ensure that commentBlock and element refer to the same file
8080
// which can happen when processing multiple files.
81-
private static void EnsureSameFile(Comments.CommentBlock commentBlock, ref KeyValuePair<Location, Label>? element)
81+
private static void EnsureSameFile(Comments.CommentBlock commentBlock, ref KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? element)
8282
{
8383
if (element is not null && element.Value.Key.SourceTree != commentBlock.Location.SourceTree)
8484
element = null;
@@ -96,9 +96,9 @@ private static void EnsureSameFile(Comments.CommentBlock commentBlock, ref KeyVa
9696
/// <param name="callback">Output binding information.</param>
9797
private void GenerateBindings(
9898
Comments.CommentBlock commentBlock,
99-
KeyValuePair<Location, Label>? previousElement,
100-
KeyValuePair<Location, Label>? nextElement,
101-
KeyValuePair<Location, Label>? parentElement,
99+
KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? previousElement,
100+
KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? nextElement,
101+
KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? parentElement,
102102
CommentBindingCallback callback
103103
)
104104
{
@@ -125,7 +125,7 @@ CommentBindingCallback callback
125125
}
126126

127127
// Heuristic to decide which is the "best" element associated with the comment.
128-
KeyValuePair<Location, Label>? bestElement;
128+
KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? bestElement;
129129

130130
if (previousElement is not null && previousElement.Value.Key.EndLine() == commentBlock.Location.StartLine())
131131
{
@@ -180,14 +180,14 @@ CommentBindingCallback callback
180180
private class ElementStack
181181
{
182182
// Invariant: the top of the stack must be contained by items below it.
183-
private readonly Stack<KeyValuePair<Location, Label>> elementStack = new Stack<KeyValuePair<Location, Label>>();
183+
private readonly Stack<KeyValuePair<Microsoft.CodeAnalysis.Location, Label>> elementStack = new();
184184

185185
/// <summary>
186186
/// Add a new element to the stack.
187187
/// </summary>
188188
/// The stack is maintained.
189189
/// <param name="value">The new element to push.</param>
190-
public void Push(KeyValuePair<Location, Label> value)
190+
public void Push(KeyValuePair<Microsoft.CodeAnalysis.Location, Label> value)
191191
{
192192
// Maintain the invariant by popping existing elements
193193
while (elementStack.Count > 0 && !elementStack.Peek().Key.Contains(value.Key))
@@ -201,15 +201,15 @@ public void Push(KeyValuePair<Location, Label> value)
201201
/// </summary>
202202
/// <param name="l">The location of the comment.</param>
203203
/// <returns>An element completely containing l, or null if none found.</returns>
204-
public KeyValuePair<Location, Label>? FindParent(Location l) =>
204+
public KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? FindParent(Microsoft.CodeAnalysis.Location l) =>
205205
elementStack.Where(v => v.Key.Contains(l)).FirstOrNull();
206206

207207
/// <summary>
208208
/// Finds the element on the stack immediately preceding the comment at l.
209209
/// </summary>
210210
/// <param name="l">The location of the comment.</param>
211211
/// <returns>The element before l, or null.</returns>
212-
public KeyValuePair<Location, Label>? FindBefore(Location l)
212+
public KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? FindBefore(Microsoft.CodeAnalysis.Location l)
213213
{
214214
return elementStack
215215
.Where(v => v.Key.SourceSpan.End < l.SourceSpan.Start)
@@ -222,7 +222,7 @@ public void Push(KeyValuePair<Location, Label> value)
222222
/// <param name="comment">The location of the comment.</param>
223223
/// <param name="next">The next element.</param>
224224
/// <returns>The next element.</returns>
225-
public KeyValuePair<Location, Label>? FindAfter(Location comment, KeyValuePair<Location, Label>? next)
225+
public KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? FindAfter(Microsoft.CodeAnalysis.Location comment, KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? next)
226226
{
227227
var p = FindParent(comment);
228228
return next.HasValue && p.HasValue && p.Value.Key.Before(next.Value.Key) ? null : next;
@@ -233,7 +233,7 @@ public void Push(KeyValuePair<Location, Label> value)
233233
private void GenerateBindings(
234234
Comments.CommentBlock block,
235235
ElementStack elementStack,
236-
KeyValuePair<Location, Label>? nextElement,
236+
KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? nextElement,
237237
CommentBindingCallback cb
238238
)
239239
{
@@ -259,8 +259,8 @@ CommentBindingCallback cb
259259
/// <param name="cb">Where to send the results.</param>
260260
/// <returns>true if there are more comments to process, false otherwise.</returns>
261261
private bool GenerateBindings(
262-
IEnumerator<KeyValuePair<Location, CommentLine>> commentEnumerator,
263-
KeyValuePair<Location, Label>? nextElement,
262+
IEnumerator<KeyValuePair<Microsoft.CodeAnalysis.Location, CommentLine>> commentEnumerator,
263+
KeyValuePair<Microsoft.CodeAnalysis.Location, Label>? nextElement,
264264
ElementStack elementStack,
265265
CommentBindingCallback cb
266266
)
@@ -319,8 +319,8 @@ public void GenerateBindings(CommentBindingCallback cb)
319319

320320
var elementStack = new ElementStack();
321321

322-
using IEnumerator<KeyValuePair<Location, Label>> elementEnumerator = elements.GetEnumerator();
323-
using IEnumerator<KeyValuePair<Location, CommentLine>> commentEnumerator = comments.GetEnumerator();
322+
using IEnumerator<KeyValuePair<Microsoft.CodeAnalysis.Location, Label>> elementEnumerator = elements.GetEnumerator();
323+
using IEnumerator<KeyValuePair<Microsoft.CodeAnalysis.Location, CommentLine>> commentEnumerator = comments.GetEnumerator();
324324
if (!commentEnumerator.MoveNext())
325325
{
326326
// There are no comments to process.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Semmle.Extraction.CSharp.Entities
55
{
6-
internal class Assembly : Extraction.Entities.Location
6+
internal class Assembly : Location
77
{
88
public override Context Context => (Context)base.Context;
99

@@ -56,7 +56,7 @@ public override bool Equals(object? obj)
5656
return false;
5757
}
5858

59-
public static Extraction.Entities.Location Create(Context cx, Microsoft.CodeAnalysis.Location loc) => AssemblyConstructorFactory.Instance.CreateEntity(cx, loc, loc);
59+
public static Location Create(Context cx, Microsoft.CodeAnalysis.Location loc) => AssemblyConstructorFactory.Instance.CreateEntity(cx, loc, loc);
6060

6161
private class AssemblyConstructorFactory : CachedEntityFactory<Microsoft.CodeAnalysis.Location?, Assembly>
6262
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ private void ExtractArguments(TextWriter trapFile)
151151

152152
public override Microsoft.CodeAnalysis.Location? ReportingLocation => attributeSyntax?.Name.GetLocation();
153153

154-
private Semmle.Extraction.Entities.Location? location;
154+
private Location? location;
155155

156-
private Semmle.Extraction.Entities.Location Location =>
156+
private Location Location =>
157157
location ??= Context.CreateLocation(attributeSyntax is null
158158
? entity.ReportingLocation
159159
: attributeSyntax.Name.GetLocation());

0 commit comments

Comments
 (0)