C#: Add braces to multiline block statements

This commit is contained in:
Tamas Vajk
2020-10-02 14:27:27 +02:00
parent 28694513a1
commit baf6f59bfc
13 changed files with 44 additions and 11 deletions

View File

@@ -50,12 +50,15 @@ namespace Semmle.Autobuild.CSharp
BuildScript.Create(actions =>
{
foreach (var file in Extractor.GetCSharpArgsLogs())
{
try
{
actions.FileDelete(file);
}
catch // lgtm[cs/catch-of-all-exceptions] lgtm[cs/empty-catch-block]
{ }
}
return 0;
});
var attemptExtractorCleanup =
@@ -104,7 +107,9 @@ namespace Semmle.Autobuild.CSharp
|| Options.MsBuildConfiguration != null
|| Options.MsBuildPlatform != null
|| Options.MsBuildTarget != null)
{
return CSharpBuildStrategy.MSBuild;
}
if (Options.DotNetArguments != null || Options.DotNetVersion != null)
return CSharpBuildStrategy.DotNet;

View File

@@ -62,7 +62,9 @@ namespace Semmle.Autobuild.Shared
QuoteArgument(projectOrSolution.FullPath);
if (nugetDownloaded)
{
ret &= BuildScript.Try(nugetRestore | msbuildRestoreCommand.Script);
}
else
{
// If `nuget restore` fails, and we have not already attempted to download `nuget.exe`,

View File

@@ -111,9 +111,10 @@ namespace Semmle.Extraction.CIL.Entities
get
{
if (ContainingType != null)
{
foreach (var t in ContainingType.TypeArguments)
yield return t;
}
foreach (var t in ThisTypeArguments)
yield return t;
@@ -211,8 +212,10 @@ namespace Semmle.Extraction.CIL.Entities
get
{
if (ContainingType != null)
{
foreach (var t in ContainingType.GenericArguments)
yield return t;
}
foreach (var t in ThisGenericArguments)
yield return t;
}

View File

@@ -15,8 +15,9 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
Create(cx, Syntax.Expression, this, 0);
if (Kind == ExprKind.CAST)
// Type cast
{ // Type cast
TypeAccess.Create(new ExpressionNodeInfo(cx, Syntax.Type, this, 1));
}
else
{
// Type conversion

View File

@@ -139,7 +139,9 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
if (si.CandidateReason == CandidateReason.OverloadResolutionFailure &&
si.CandidateSymbols.OfType<IMethodSymbol>().All(s => s.MethodKind == MethodKind.DelegateInvoke))
{
return true;
}
// Delegate variable is a dynamic
var node = (InvocationExpressionSyntax)info.Node;
@@ -147,7 +149,9 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
node.Expression is IdentifierNameSyntax &&
IsDynamic(info.Context, node.Expression) &&
si.Symbol == null)
{
return true;
}
return si.Symbol != null &&
si.Symbol.Kind == SymbolKind.Method &&

View File

@@ -81,7 +81,9 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
}
}
else
{
declType = type;
}
var decl = VariableDeclaration.Create(cx,
variableSymbol,

View File

@@ -71,6 +71,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
{
var child0 = 0;
foreach (var variable in designation.Variables)
{
switch (variable)
{
case ParenthesizedVariableDesignationSyntax paren:
@@ -94,6 +95,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
default:
throw new InternalError(variable, "Unhandled designation type");
}
}
});
return tuple;

View File

@@ -71,17 +71,19 @@ namespace Semmle.Extraction.CSharp.Entities
var expr = ExpressionBody;
if (block != null || expr != null)
{
Context.PopulateLater(
() =>
{
ExtractInitializers(trapFile);
if (block != null)
Statements.Block.Create(Context, block, this, 0);
else
Expression.Create(Context, expr, this, 0);
() =>
{
ExtractInitializers(trapFile);
if (block != null)
Statements.Block.Create(Context, block, this, 0);
else
Expression.Create(Context, expr, this, 0);
Context.NumberOfLines(trapFile, BodyDeclaringSymbol, this);
});
Context.NumberOfLines(trapFile, BodyDeclaringSymbol, this);
});
}
}
public void Overrides(TextWriter trapFile)
@@ -93,8 +95,10 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.explicitly_implements(this, explicitInterface.TypeRef);
if (IsSourceDeclaration)
{
foreach (var syntax in symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).OfType<MethodDeclarationSyntax>())
TypeMention.Create(Context, syntax.ExplicitInterfaceSpecifier.Name, this, explicitInterface);
}
}
if (symbol.OverriddenMethod != null)

View File

@@ -36,11 +36,13 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.methods(this, Name, ContainingType, returnType.TypeRef, OriginalDefinition);
if (IsSourceDeclaration)
{
foreach (var declaration in symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax()).OfType<MethodDeclarationSyntax>())
{
Context.BindComments(this, declaration.Identifier.GetLocation());
TypeMention.Create(Context, declaration.ReturnType, this, returnType);
}
}
foreach (var l in Locations)
trapFile.method_location(this, l);

View File

@@ -126,7 +126,9 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
if (IsAnonymousType())
{
trapFile.Write('*');
}
else
{
symbol.BuildTypeId(Context, trapFile, symbol, constructUnderlyingTupleType);

View File

@@ -193,7 +193,9 @@ namespace Semmle.Extraction
populateQueue.Enqueue(() => WithDuplicationGuard(key, a));
}
else
{
populateQueue.Enqueue(a);
}
}
/// <summary>

View File

@@ -86,7 +86,9 @@ namespace Semmle.Extraction
}
}
else
{
sb.Append(Regex.Escape(pattern[i++].ToString()));
}
}
return sb.Append(".*");
}

View File

@@ -66,7 +66,9 @@ namespace Semmle.Extraction
TrapBuilder.Write("}");
}
else
{
TrapBuilder.Write(arg.ToString());
}
}
}