Skip to content

Commit 60bb9a9

Browse files
committed
C#: Move some populate methods and location writing methods.
1 parent c68cd58 commit 60bb9a9

File tree

3 files changed

+45
-43
lines changed

3 files changed

+45
-43
lines changed

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ public string DebugContents
5454
}
5555
}
5656

57-
protected static void WriteLocationToTrap<T1>(Action<T1, Location> writeAction, T1 entity, Location l)
58-
{
59-
if (l is not EmptyLocation)
60-
{
61-
writeAction(entity, l);
62-
}
63-
}
64-
65-
protected static void WriteLocationsToTrap<T1>(Action<T1, Location> writeAction, T1 entity, IEnumerable<Location> locations)
66-
{
67-
foreach (var loc in locations)
68-
{
69-
WriteLocationToTrap(writeAction, entity, loc);
70-
}
71-
}
72-
7357
public override bool NeedsPopulation { get; }
7458

7559
public override int GetHashCode() => Symbol is null ? 0 : Symbol.GetHashCode();

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,6 @@ protected void PopulateAttributes()
3232
Attribute.ExtractAttributes(Context, Symbol, this);
3333
}
3434

35-
protected void PopulateNullability(TextWriter trapFile, AnnotatedTypeSymbol type)
36-
{
37-
var n = NullabilityEntity.Create(Context, Nullability.Create(type));
38-
if (!type.HasObliviousNullability())
39-
{
40-
trapFile.type_nullability(this, n);
41-
}
42-
}
43-
44-
protected void PopulateRefKind(TextWriter trapFile, RefKind kind)
45-
{
46-
switch (kind)
47-
{
48-
case RefKind.Out:
49-
trapFile.type_annotation(this, Kinds.TypeAnnotation.Out);
50-
break;
51-
case RefKind.Ref:
52-
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
53-
break;
54-
case RefKind.RefReadOnly:
55-
case RefKind.RefReadOnlyParameter:
56-
trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef);
57-
break;
58-
}
59-
}
60-
6135
protected void PopulateScopedKind(TextWriter trapFile, ScopedKind kind)
6236
{
6337
switch (kind)

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using Microsoft.CodeAnalysis;
5+
using Semmle.Extraction.CSharp.Entities;
46

57
namespace Semmle.Extraction.CSharp
68
{
@@ -24,7 +26,7 @@ public virtual void WriteQuotedId(EscapingTextWriter trapFile)
2426
trapFile.WriteUnescaped('\"');
2527
}
2628

27-
public abstract Location? ReportingLocation { get; }
29+
public abstract Microsoft.CodeAnalysis.Location? ReportingLocation { get; }
2830

2931
public abstract TrapStackBehaviour TrapStackBehaviour { get; }
3032

@@ -65,6 +67,48 @@ public string GetDebugLabel()
6567
}
6668
#endif
6769

70+
protected void PopulateRefKind(TextWriter trapFile, RefKind kind)
71+
{
72+
switch (kind)
73+
{
74+
case RefKind.Out:
75+
trapFile.type_annotation(this, Kinds.TypeAnnotation.Out);
76+
break;
77+
case RefKind.Ref:
78+
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
79+
break;
80+
case RefKind.RefReadOnly:
81+
case RefKind.RefReadOnlyParameter:
82+
trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef);
83+
break;
84+
}
85+
}
86+
87+
protected void PopulateNullability(TextWriter trapFile, AnnotatedTypeSymbol type)
88+
{
89+
var n = NullabilityEntity.Create(Context, Nullability.Create(type));
90+
if (!type.HasObliviousNullability())
91+
{
92+
trapFile.type_nullability(this, n);
93+
}
94+
}
95+
96+
protected static void WriteLocationToTrap<T1>(Action<T1, Entities.Location> writeAction, T1 entity, Entities.Location l)
97+
{
98+
if (l is not EmptyLocation)
99+
{
100+
writeAction(entity, l);
101+
}
102+
}
103+
104+
protected static void WriteLocationsToTrap<T1>(Action<T1, Entities.Location> writeAction, T1 entity, IEnumerable<Entities.Location> locations)
105+
{
106+
foreach (var loc in locations)
107+
{
108+
WriteLocationToTrap(writeAction, entity, loc);
109+
}
110+
}
111+
68112
public override string ToString() => Label.ToString();
69113
}
70114
}

0 commit comments

Comments
 (0)