mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
C#: Re-factor to use ForEach.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
using Semmle.Util;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
@@ -11,12 +11,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.commentblock(this);
|
||||
var child = 0;
|
||||
trapFile.commentblock_location(this, Context.CreateLocation(Symbol.Location));
|
||||
foreach (var l in Symbol.CommentLines)
|
||||
{
|
||||
trapFile.commentblock_child(this, (CommentLine)l, child++);
|
||||
}
|
||||
Symbol.CommentLines.ForEach((l, child) => trapFile.commentblock_child(this, l, child));
|
||||
}
|
||||
|
||||
public override bool NeedsPopulation => true;
|
||||
|
||||
@@ -39,45 +39,29 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
trapFile.compilation_assembly(this, assembly);
|
||||
|
||||
// Arguments
|
||||
var index = 0;
|
||||
foreach (var arg in Compilation.Settings.Args)
|
||||
{
|
||||
trapFile.compilation_args(this, index++, arg);
|
||||
}
|
||||
Compilation.Settings.Args.ForEach((arg, index) => trapFile.compilation_args(this, index, arg));
|
||||
|
||||
// Files
|
||||
index = 0;
|
||||
foreach (var file in Context.Compilation.SyntaxTrees.Select(tree => File.Create(Context, tree.FilePath)))
|
||||
{
|
||||
trapFile.compilation_compiling_files(this, index++, file);
|
||||
}
|
||||
Context.Compilation.SyntaxTrees.Select(tree => File.Create(Context, tree.FilePath)).ForEach((file, index) => trapFile.compilation_compiling_files(this, index, file));
|
||||
|
||||
// References
|
||||
index = 0;
|
||||
foreach (var file in Context.Compilation.References
|
||||
Context.Compilation.References
|
||||
.OfType<PortableExecutableReference>()
|
||||
.Where(r => r.FilePath is not null)
|
||||
.Select(r => File.Create(Context, r.FilePath!)))
|
||||
{
|
||||
trapFile.compilation_referencing_files(this, index++, file);
|
||||
}
|
||||
.Select(r => File.Create(Context, r.FilePath!))
|
||||
.ForEach((file, index) => trapFile.compilation_referencing_files(this, index, file));
|
||||
|
||||
// Diagnostics
|
||||
index = 0;
|
||||
foreach (var diag in Context.Compilation.GetDiagnostics().Select(d => new Diagnostic(Context, d)))
|
||||
{
|
||||
trapFile.diagnostic_for(diag, this, 0, index++);
|
||||
}
|
||||
Context.Compilation
|
||||
.GetDiagnostics()
|
||||
.Select(d => new Diagnostic(Context, d))
|
||||
.ForEach((diag, index) => trapFile.diagnostic_for(diag, this, 0, index));
|
||||
}
|
||||
|
||||
public void PopulatePerformance(PerformanceMetrics p)
|
||||
{
|
||||
var trapFile = Context.TrapWriter.Writer;
|
||||
var index = 0;
|
||||
foreach (var metric in p.Metrics)
|
||||
{
|
||||
trapFile.compilation_time(this, -1, index++, metric);
|
||||
}
|
||||
p.Metrics.ForEach((metric, index) => trapFile.compilation_time(this, -1, index, metric));
|
||||
trapFile.compilation_finished(this, (float)p.Total.Cpu.TotalSeconds, (float)p.Total.Elapsed.TotalSeconds);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using Semmle.Util;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -108,11 +109,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
if (length > 0)
|
||||
{
|
||||
var arrayInit = ArrayInitializer.CreateGenerated(cx, arrayCreation, InitializerIndex, location);
|
||||
var child = 0;
|
||||
foreach (var item in items)
|
||||
{
|
||||
Expression.CreateGenerated(cx, item, arrayInit, child++, location);
|
||||
}
|
||||
items.ForEach((item, child) => Expression.CreateGenerated(cx, item, arrayInit, child, location));
|
||||
}
|
||||
|
||||
return arrayCreation;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using Semmle.Util;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
@@ -146,11 +146,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
var init = (InitializerExpressionSyntax)i;
|
||||
|
||||
var addChild = 0;
|
||||
foreach (var arg in init.Expressions)
|
||||
{
|
||||
Create(Context, arg, invocation, addChild++);
|
||||
}
|
||||
init.Expressions.ForEach((arg, child) => Create(Context, arg, invocation, child));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using Semmle.Util;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
@@ -8,11 +9,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
internal PositionalPattern(Context cx, PositionalPatternClauseSyntax posPc, IExpressionParentEntity parent, int child) :
|
||||
base(new ExpressionInfo(cx, null, cx.CreateLocation(posPc.GetLocation()), ExprKind.POSITIONAL_PATTERN, parent, child, false, null))
|
||||
{
|
||||
child = 0;
|
||||
foreach (var sub in posPc.Subpatterns)
|
||||
{
|
||||
Pattern.Create(cx, sub.Pattern, this, child++);
|
||||
}
|
||||
posPc.Subpatterns.ForEach((p, i) => Pattern.Create(cx, p.Pattern, this, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Util;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
@@ -15,12 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
protected override void PopulatePreprocessor(TextWriter trapFile)
|
||||
{
|
||||
trapFile.pragma_warnings(this, Symbol.DisableOrRestoreKeyword.IsKind(SyntaxKind.DisableKeyword) ? 0 : 1);
|
||||
|
||||
var childIndex = 0;
|
||||
foreach (var code in Symbol.ErrorCodes)
|
||||
{
|
||||
trapFile.pragma_warning_error_codes(this, code.ToString(), childIndex++);
|
||||
}
|
||||
Symbol.ErrorCodes.ForEach((code, child) => trapFile.pragma_warning_error_codes(this, code.ToString(), child));
|
||||
}
|
||||
|
||||
public static PragmaWarningDirective Create(Context cx, PragmaWarningDirectiveTriviaSyntax p) =>
|
||||
|
||||
Reference in New Issue
Block a user