Skip to content

Commit

Permalink
Static analysis: minor small changes (#26946)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Dec 9, 2021
1 parent c918248 commit 8f7f790
Show file tree
Hide file tree
Showing 33 changed files with 118 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public override Expression Visit(Expression expression)
{
switch (expression)
{
case ConstantExpression _:
case ConstantExpression:
return expression;

case ParameterExpression parameterExpression:
Expand All @@ -130,7 +130,7 @@ public override Expression Visit(Expression expression)

throw new InvalidOperationException(CoreStrings.TranslationFailed(parameterExpression.Print()));

case MaterializeCollectionNavigationExpression _:
case MaterializeCollectionNavigationExpression:
return base.Visit(expression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
_ownerMappings[accessExpression] =
(innerObjectAccessExpression.Navigation.DeclaringEntityType, innerAccessExpression);
break;
case RootReferenceExpression _:
case RootReferenceExpression:
innerAccessExpression = _jObjectParameter;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ protected override Expression VisitExtension(Expression extensionExpression)
{
switch (extensionExpression)
{
case EntityProjectionExpression _:
case EntityReferenceExpression _:
case SqlExpression _:
case EntityProjectionExpression:
case EntityReferenceExpression:
case SqlExpression:
return extensionExpression;

case EntityShaperExpression entityShaperExpression:
Expand Down Expand Up @@ -380,7 +380,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& right is SqlExpression rightSql)
{
sqlObject = leftSql;
arguments = new SqlExpression[1] { rightSql };
arguments = new[] { rightSql };
}
else
{
Expand All @@ -407,7 +407,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (left is SqlExpression leftSql
&& right is SqlExpression rightSql)
{
arguments = new SqlExpression[2] { leftSql, rightSql };
arguments = new[] { leftSql, rightSql };
}
else
{
Expand All @@ -428,7 +428,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (enumerable is SqlExpression sqlEnumerable
&& item is SqlExpression sqlItem)
{
arguments = new SqlExpression[2] { sqlEnumerable, sqlItem };
arguments = new[] { sqlEnumerable, sqlItem };
}
else
{
Expand All @@ -450,7 +450,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& item is SqlExpression sqlItem)
{
sqlObject = sqlEnumerable;
arguments = new SqlExpression[1] { sqlItem };
arguments = new[] { sqlItem };
}
else
{
Expand Down
7 changes: 3 additions & 4 deletions src/EFCore.Design/Design/Internal/MigrationsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class MigrationsOperations
private readonly string? _language;
private readonly DesignTimeServicesBuilder _servicesBuilder;
private readonly DbContextOperations _contextOperations;
private readonly string[] _args;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -43,7 +42,7 @@ public MigrationsOperations(
_projectDir = projectDir;
_rootNamespace = rootNamespace;
_language = language;
_args = args ?? Array.Empty<string>();
args ??= Array.Empty<string>();
_contextOperations = new DbContextOperations(
reporter,
assembly,
Expand All @@ -52,9 +51,9 @@ public MigrationsOperations(
rootNamespace,
language,
nullable,
_args);
args);

_servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, _args);
_servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, args);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,6 @@ protected virtual void Generate(AlterDatabaseOperation operation, IndentedString
.AppendLine()
.Append("oldCollation: ")
.Append(Code.Literal(operation.OldDatabase.Collation));

needComma = true;
}

builder.Append(")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ private void CreateForeignKey(

using (mainBuilder.Indent())
{
var foreignKeyVariable = "runtimeForeignKey";
const string foreignKeyVariable = "runtimeForeignKey";
var variables = new HashSet<string>
{
declaringEntityType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ protected override Expression VisitExtension(Expression extensionExpression)
{
switch (extensionExpression)
{
case EntityProjectionExpression _:
case EntityReferenceExpression _:
case EntityProjectionExpression:
case EntityReferenceExpression:
return extensionExpression;

case EntityShaperExpression entityShaperExpression:
Expand Down Expand Up @@ -527,7 +527,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
}

@object = left;
arguments = new Expression[1] { right };
arguments = new[] { right };
}
else if (method.Name == nameof(object.Equals)
&& methodCallExpression.Object == null
Expand Down Expand Up @@ -560,7 +560,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
return QueryCompilationContext.NotTranslatedExpression;
}

arguments = new Expression[2] { left, right };
arguments = new[] { left, right };
}
else if (method.IsGenericMethod
&& method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains))
Expand All @@ -582,7 +582,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
return QueryCompilationContext.NotTranslatedExpression;
}

arguments = new Expression[2] { enumerable, item };
arguments = new[] { enumerable, item };
}
else if (methodCallExpression.Arguments.Count == 1
&& method.IsContainsMethod())
Expand All @@ -605,7 +605,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
}

@object = enumerable;
arguments = new Expression[1] { item };
arguments = new[] { item };
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public virtual Expression Translate(InMemoryQueryExpression queryExpression, Exp
{
switch (expression)
{
case ConstantExpression _:
case ConstantExpression:
return expression;

case ProjectionBindingExpression projectionBindingExpression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public virtual GroupByShaperExpression ApplyGrouping(
bool defaultElementSelector)
{
var source = ServerQueryExpression;
Expression? selector = null;
Expression? selector;
if (defaultElementSelector)
{
selector = Lambda(
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore.Relational/Metadata/Internal/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,13 @@ public static SequenceData Deserialize(string value)
=> value == null ? null : long.Parse(value, CultureInfo.InvariantCulture);

private static Type AsType(string value)
=> value == typeof(long).Name
=> value == nameof(Int64)
? typeof(long)
: value == typeof(int).Name
: value == nameof(Int32)
? typeof(int)
: value == typeof(short).Name
: value == nameof(Int16)
? typeof(short)
: value == typeof(decimal).Name
: value == nameof(Decimal)
? typeof(decimal)
: typeof(byte);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ protected virtual void TrackData(
}

var targetTable = diffContext.FindTarget(sourceTable);
bool removedMapping = !(targetTable != null
var removedMapping = !(targetTable != null
&& targetKeyMap.Keys.Any(
k => k.Item2 == targetTable
&& k.Item1.DeclaringEntityType.GetTableMappings().First().Table == firstTargetTable));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
{
switch (expression)
{
case ConstantExpression _:
case ConstantExpression:
return expression;

case ParameterExpression parameterExpression:
Expand Down Expand Up @@ -306,7 +306,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
new ProjectionBindingExpression(_selectExpression, _projectionMembers.Peek(), typeof(ValueBuffer)));
}

case IncludeExpression _:
case IncludeExpression:
return _indexBasedBinding ? base.VisitExtension(extensionExpression) : QueryCompilationContext.NotTranslatedExpression;

case CollectionResultExpression collectionResultExpression:
Expand Down Expand Up @@ -544,7 +544,7 @@ protected override Expression VisitNewArray(NewArrayExpression newArrayExpressio
/// </summary>
protected override Expression VisitUnary(UnaryExpression unaryExpression)
{
var operand = Visit(unaryExpression.Operand)!;
var operand = Visit(unaryExpression.Operand);

return (unaryExpression.NodeType == ExpressionType.Convert
|| unaryExpression.NodeType == ExpressionType.ConvertChecked)
Expand Down
11 changes: 6 additions & 5 deletions src/EFCore.Relational/Query/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public virtual IRelationalCommand GetCommand(SelectExpression selectExpression)
/// <summary>
/// The default alias separator.
/// </summary>
protected virtual string AliasSeparator { get; } = " AS ";
protected virtual string AliasSeparator
=> " AS ";

/// <summary>
/// The current SQL command builder.
Expand Down Expand Up @@ -838,7 +839,7 @@ protected virtual bool RequiresParentheses(SqlExpression outerExpression, SqlExp
{
switch (innerExpression)
{
case LikeExpression _:
case LikeExpression:
return true;

case SqlUnaryExpression sqlUnaryExpression:
Expand Down Expand Up @@ -1069,9 +1070,9 @@ protected virtual void GenerateSetOperation(SetOperationBase setOperation)
static string GetSetOperation(SetOperationBase operation)
=> operation switch
{
ExceptExpression _ => "EXCEPT",
IntersectExpression _ => "INTERSECT",
UnionExpression _ => "UNION",
ExceptExpression => "EXCEPT",
IntersectExpression => "INTERSECT",
UnionExpression => "UNION",
_ => throw new InvalidOperationException(CoreStrings.UnknownEntity("SetOperationType"))
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public RelationalQueryCompilationContext(

/// <summary>
/// A value indicating the <see cref="EntityFrameworkCore.QuerySplittingBehavior" /> configured for the query.
/// If no value has been configured then <see cref="QuerySplittingBehavior.SingleQuery" /> will be used.
/// If no value has been configured then <see cref="Microsoft.EntityFrameworkCore.QuerySplittingBehavior.SingleQuery" />
/// will be used.
/// </summary>
public virtual QuerySplittingBehavior? QuerySplittingBehavior { get; internal set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ public DeferredOwnedExpansionRemovingVisitor(SelectExpression selectExpression)
{
DeferredOwnedExpansionExpression doee => UnwrapDeferredEntityProjectionExpression(doee),
// For the source entity shaper or owned collection expansion
EntityShaperExpression _ or ShapedQueryExpression _ => expression,
EntityShaperExpression or ShapedQueryExpression => expression,
_ => base.Visit(expression)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
return accessor;
}

case GroupByShaperExpression _:
case GroupByShaperExpression:
throw new InvalidOperationException(RelationalStrings.ClientGroupByNotSupported);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ protected override Expression VisitExtension(Expression extensionExpression)
{
switch (extensionExpression)
{
case EntityProjectionExpression _:
case EntityReferenceExpression _:
case SqlExpression _:
case EntityProjectionExpression:
case EntityReferenceExpression:
case SqlExpression:
return extensionExpression;

case EntityShaperExpression entityShaperExpression:
Expand Down Expand Up @@ -530,7 +530,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& right is SqlExpression rightSql)
{
sqlObject = leftSql;
arguments = new SqlExpression[1] { rightSql };
arguments = new[] { rightSql };
}
else
{
Expand Down Expand Up @@ -565,7 +565,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (left is SqlExpression leftSql
&& right is SqlExpression rightSql)
{
arguments = new SqlExpression[2] { leftSql, rightSql };
arguments = new[] { leftSql, rightSql };
}
else
{
Expand All @@ -588,7 +588,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (enumerable is SqlExpression sqlEnumerable
&& item is SqlExpression sqlItem)
{
arguments = new SqlExpression[2] { sqlEnumerable, sqlItem };
arguments = new[] { sqlEnumerable, sqlItem };
}
else
{
Expand All @@ -612,7 +612,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& item is SqlExpression sqlItem)
{
sqlObject = sqlEnumerable;
arguments = new SqlExpression[1] { sqlItem };
arguments = new[] { sqlItem };
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ internal SelectExpression(IEntityType entityType, TableExpressionBase tableExpre
{
TableExpression tableExpression => tableExpression.Table,
TableValuedFunctionExpression tableValuedFunctionExpression => tableValuedFunctionExpression.StoreFunction,
_ => entityType.GetDefaultMappings().Single().Table,
_ => entityType.GetDefaultMappings().Single().Table
};

var tableReferenceExpression = new TableReferenceExpression(this, tableExpressionBase.Alias!);
Expand Down Expand Up @@ -1158,7 +1158,7 @@ public void ApplyGrouping(Expression keySelector)
newGroupByTerms.Add(newItem);
}

keySelector = new ReplacingExpressionVisitor(groupByTerms, newGroupByTerms).Visit(keySelector);
new ReplacingExpressionVisitor(groupByTerms, newGroupByTerms).Visit(keySelector);
groupByTerms = newGroupByTerms;
}

Expand Down Expand Up @@ -1706,7 +1706,7 @@ static bool IsNullableProjection(ProjectionExpression projectionExpression)
{
ColumnExpression columnExpression => columnExpression.IsNullable,
SqlConstantExpression sqlConstantExpression => sqlConstantExpression.Value == null,
_ => true,
_ => true
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Storage/RelationalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ await Dependencies.ConnectionLogger.ConnectionErrorAsync(
}

/// <summary>
/// Template method that by default calls <see cref="DbConnection.CloseAsync" /> but can be overridden
/// Template method that by default calls <see cref="System.Data.Common.DbConnection.CloseAsync" /> but can be overridden
/// by providers to make a different call instead.
/// </summary>
protected virtual Task CloseDbConnectionAsync()
Expand Down Expand Up @@ -1073,7 +1073,7 @@ protected virtual void DisposeDbConnection()
=> DbConnection.Dispose();

/// <summary>
/// Template method that by default calls <see cref="DbConnection.DisposeAsync" /> but can be overridden by
/// Template method that by default calls <see cref="System.Data.Common.DbConnection.DisposeAsync" /> but can be overridden by
/// providers to make a different call instead.
/// </summary>
protected virtual ValueTask DisposeDbConnectionAsync()
Expand Down
Loading

0 comments on commit 8f7f790

Please sign in to comment.