Files
codeql/powershell/extractor/Semmle.Extraction.PowerShell/Entities/UsingExpressionEntity.cs

46 lines
1.9 KiB
C#

using System.IO;
using System.Management.Automation.Language;
namespace Semmle.Extraction.PowerShell.Entities
{
internal class UsingExpressionEntity : CachedEntity<(UsingExpressionAst, UsingExpressionAst)>
{
private UsingExpressionEntity(PowerShellContext cx, UsingExpressionAst fragment)
: base(cx, (fragment, fragment))
{
}
public override Microsoft.CodeAnalysis.Location ReportingLocation => PowerShellContext.CreateAnalysisLocation(Fragment);
public UsingExpressionAst Fragment => Symbol.Item1;
public override void Populate(TextWriter trapFile)
{
trapFile.using_expression(this, EntityConstructor.ConstructAppropriateEntity(PowerShellContext, Fragment.SubExpression));
trapFile.using_expression_location(this, TrapSuitableLocation);
trapFile.parent(PowerShellContext, this, Fragment.Parent);
}
public override bool NeedsPopulation => true;
public override void WriteId(EscapingTextWriter trapFile)
{
trapFile.WriteSubId(TrapSuitableLocation);
trapFile.Write(";using_expression");
}
internal static UsingExpressionEntity Create(PowerShellContext cx, UsingExpressionAst fragment)
{
var init = (fragment, fragment);
return UsingExpressionEntityFactory.Instance.CreateEntity(cx, init, init);
}
private class UsingExpressionEntityFactory : CachedEntityFactory<(UsingExpressionAst, UsingExpressionAst), UsingExpressionEntity>
{
public static UsingExpressionEntityFactory Instance { get; } = new UsingExpressionEntityFactory();
public override UsingExpressionEntity Create(PowerShellContext cx, (UsingExpressionAst, UsingExpressionAst) init) =>
new UsingExpressionEntity(cx, init.Item1);
}
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.OptionalLabel;
}
}