mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace Semmle.Extraction.CIL.Entities
|
|
{
|
|
internal class File : LabelledEntity, IFileOrFolder
|
|
{
|
|
protected string OriginalPath { get; }
|
|
protected PathTransformer.ITransformedPath TransformedPath { get; }
|
|
|
|
public File(Context cx, string path) : base(cx)
|
|
{
|
|
this.OriginalPath = path;
|
|
TransformedPath = Context.Extractor.PathTransformer.Transform(OriginalPath);
|
|
}
|
|
|
|
public override void WriteId(EscapingTextWriter trapFile)
|
|
{
|
|
trapFile.Write(TransformedPath.DatabaseId);
|
|
trapFile.Write(";sourcefile");
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
return GetType() == obj?.GetType() && OriginalPath == ((File)obj).OriginalPath;
|
|
}
|
|
|
|
public override int GetHashCode() => 11 * OriginalPath.GetHashCode();
|
|
|
|
public override IEnumerable<IExtractionProduct> Contents
|
|
{
|
|
get
|
|
{
|
|
if (TransformedPath.ParentDirectory is PathTransformer.ITransformedPath dir)
|
|
{
|
|
var parent = Context.CreateFolder(dir);
|
|
yield return parent;
|
|
yield return Tuples.containerparent(parent, this);
|
|
}
|
|
yield return Tuples.files(this, TransformedPath.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|