diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity.cs index 2002fe0f1d7..39d0f886b81 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity.cs @@ -54,22 +54,6 @@ namespace Semmle.Extraction.CSharp.Entities } } - protected static void WriteLocationToTrap(Action writeAction, T1 entity, Location l) - { - if (l is not EmptyLocation) - { - writeAction(entity, l); - } - } - - protected static void WriteLocationsToTrap(Action writeAction, T1 entity, IEnumerable locations) - { - foreach (var loc in locations) - { - WriteLocationToTrap(writeAction, entity, loc); - } - } - public override bool NeedsPopulation { get; } public override int GetHashCode() => Symbol is null ? 0 : Symbol.GetHashCode(); diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs index 92861e97fdd..1a69b0e08b2 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs @@ -32,32 +32,6 @@ namespace Semmle.Extraction.CSharp.Entities Attribute.ExtractAttributes(Context, Symbol, this); } - protected void PopulateNullability(TextWriter trapFile, AnnotatedTypeSymbol type) - { - var n = NullabilityEntity.Create(Context, Nullability.Create(type)); - if (!type.HasObliviousNullability()) - { - trapFile.type_nullability(this, n); - } - } - - protected void PopulateRefKind(TextWriter trapFile, RefKind kind) - { - switch (kind) - { - case RefKind.Out: - trapFile.type_annotation(this, Kinds.TypeAnnotation.Out); - break; - case RefKind.Ref: - trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref); - break; - case RefKind.RefReadOnly: - case RefKind.RefReadOnlyParameter: - trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef); - break; - } - } - protected void PopulateScopedKind(TextWriter trapFile, ScopedKind kind) { switch (kind) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs index ca1887b3be9..94b2e16e9e6 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; using Microsoft.CodeAnalysis; +using Semmle.Extraction.CSharp.Entities; namespace Semmle.Extraction.CSharp { @@ -24,7 +26,7 @@ namespace Semmle.Extraction.CSharp trapFile.WriteUnescaped('\"'); } - public abstract Location? ReportingLocation { get; } + public abstract Microsoft.CodeAnalysis.Location? ReportingLocation { get; } public abstract TrapStackBehaviour TrapStackBehaviour { get; } @@ -65,6 +67,48 @@ namespace Semmle.Extraction.CSharp } #endif + protected void PopulateRefKind(TextWriter trapFile, RefKind kind) + { + switch (kind) + { + case RefKind.Out: + trapFile.type_annotation(this, Kinds.TypeAnnotation.Out); + break; + case RefKind.Ref: + trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref); + break; + case RefKind.RefReadOnly: + case RefKind.RefReadOnlyParameter: + trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef); + break; + } + } + + protected void PopulateNullability(TextWriter trapFile, AnnotatedTypeSymbol type) + { + var n = NullabilityEntity.Create(Context, Nullability.Create(type)); + if (!type.HasObliviousNullability()) + { + trapFile.type_nullability(this, n); + } + } + + protected static void WriteLocationToTrap(Action writeAction, T1 entity, Entities.Location l) + { + if (l is not EmptyLocation) + { + writeAction(entity, l); + } + } + + protected static void WriteLocationsToTrap(Action writeAction, T1 entity, IEnumerable locations) + { + foreach (var loc in locations) + { + WriteLocationToTrap(writeAction, entity, loc); + } + } + public override string ToString() => Label.ToString(); } }