mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
C#: Adjust 'fromSource' to hold only on files passed to the compiler as a source file
This commit is contained in:
@@ -17,14 +17,15 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.files(this, TransformedPath.Value, TransformedPath.NameWithoutExtension, TransformedPath.Extension);
|
||||
var trees = Context.Compilation.SyntaxTrees.Where(t => t.FilePath == originalPath);
|
||||
var isSource = trees.Any();
|
||||
|
||||
trapFile.files(this, TransformedPath.Value, TransformedPath.NameWithoutExtension, TransformedPath.Extension, isSource ? FileSourceKind.FromSource : FileSourceKind.Unknown);
|
||||
|
||||
if (TransformedPath.ParentDirectory is PathTransformer.ITransformedPath dir)
|
||||
trapFile.containerparent(Extraction.Entities.Folder.Create(Context, dir), this);
|
||||
|
||||
var trees = Context.Compilation.SyntaxTrees.Where(t => t.FilePath == originalPath);
|
||||
|
||||
if (trees.Any())
|
||||
if (isSource)
|
||||
{
|
||||
foreach (var text in trees.Select(tree => tree.GetText()))
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Semmle.Extraction.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.files(this, "", "", "");
|
||||
trapFile.files(this, "", "", "", FileSourceKind.Unknown);
|
||||
}
|
||||
|
||||
public override void WriteId(TextWriter trapFile)
|
||||
|
||||
9
csharp/extractor/Semmle.Extraction/FileSourceKind.cs
Normal file
9
csharp/extractor/Semmle.Extraction/FileSourceKind.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Semmle.Extraction
|
||||
{
|
||||
public enum FileSourceKind
|
||||
{
|
||||
Unknown = 0,
|
||||
FromSource = 1,
|
||||
FromLibrary = 2
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ namespace Semmle.Extraction
|
||||
trapFile.WriteTuple("extractor_messages", error, (int)severity, origin, errorMessage, entityText, location, stackTrace);
|
||||
}
|
||||
|
||||
public static void files(this System.IO.TextWriter trapFile, File file, string fullName, string name, string extension)
|
||||
public static void files(this System.IO.TextWriter trapFile, File file, string fullName, string name, string extension, FileSourceKind kind)
|
||||
{
|
||||
trapFile.WriteTuple("files", file, fullName, name, extension, 0);
|
||||
trapFile.WriteTuple("files", file, fullName, name, extension, (int)kind);
|
||||
}
|
||||
|
||||
internal static void folders(this System.IO.TextWriter trapFile, Folder folder, string path, string name)
|
||||
|
||||
@@ -192,7 +192,7 @@ class File extends Container, @file {
|
||||
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
|
||||
|
||||
/** Holds if this file contains source code. */
|
||||
predicate fromSource() { this.getNumberOfLinesOfCode() > 0 }
|
||||
predicate fromSource() { files(this, _, _, _, 1) }
|
||||
|
||||
/** Holds if this file is a library. */
|
||||
predicate fromLibrary() {
|
||||
|
||||
Reference in New Issue
Block a user