Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analysis: conditional cleanup #26915

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ public virtual void ProcessEntityTypeAnnotationChanged(
}
}

if (propertyType != typeof(Guid))
{
return null;
}

return base.GetValueGenerated(property);
return propertyType != typeof(Guid)
? null
: base.GetValueGenerated(property);
}
}
9 changes: 1 addition & 8 deletions src/EFCore.Cosmos/Query/Internal/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,7 @@ protected override Expression VisitSelect(SelectExpression selectExpression)

_sqlBuilder.AppendLine();

if (selectExpression.FromExpression is FromSqlExpression)
{
_sqlBuilder.Append("FROM ");
}
else
{
_sqlBuilder.Append("FROM root ");
}
_sqlBuilder.Append(selectExpression.FromExpression is FromSqlExpression ? "FROM " : "FROM root ");

Visit(selectExpression.FromExpression);

Expand Down
4 changes: 1 addition & 3 deletions src/EFCore.Cosmos/Query/Internal/SqlConstantExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ public override bool Equals(object? obj)

private bool Equals(SqlConstantExpression sqlConstantExpression)
=> base.Equals(sqlConstantExpression)
&& (Value == null
? sqlConstantExpression.Value == null
: Value.Equals(sqlConstantExpression.Value));
&& (Value?.Equals(sqlConstantExpression.Value) ?? sqlConstantExpression.Value == null);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
9 changes: 3 additions & 6 deletions src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,8 @@ public virtual Task<bool> CanConnectAsync(CancellationToken cancellationToken =
private static string GetPartitionKeyStoreName(IEntityType entityType)
{
var name = entityType.GetPartitionKeyPropertyName();
if (name != null)
{
return entityType.FindProperty(name)!.GetJsonPropertyName();
}

return CosmosClientWrapper.DefaultPartitionKey;
return name != null
? entityType.FindProperty(name)!.GetJsonPropertyName()
: CosmosClientWrapper.DefaultPartitionKey;
}
}
7 changes: 1 addition & 6 deletions src/EFCore.Design/Design/Internal/CSharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -963,12 +963,7 @@ private bool HandleExpression(Expression expression, StringBuilder builder, bool

builder.Append(" + ");

if (!HandleExpression(binaryExpression.Right, builder))
{
return false;
}

return true;
return HandleExpression(binaryExpression.Right, builder);
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/EFCore.Design/Design/Internal/DbContextOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,10 @@ public virtual void DropDatabase(string? contextType)
using var context = CreateContext(contextType);
var connection = context.Database.GetDbConnection();
_reporter.WriteInformation(DesignStrings.DroppingDatabase(connection.Database, connection.DataSource));
if (context.Database.EnsureDeleted())
{
_reporter.WriteInformation(DesignStrings.DatabaseDropped(connection.Database));
}
else
{
_reporter.WriteInformation(DesignStrings.NotExistDatabase(connection.Database));
}
_reporter.WriteInformation(
context.Database.EnsureDeleted()
? DesignStrings.DatabaseDropped(connection.Database)
: DesignStrings.NotExistDatabase(connection.Database));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,7 @@ private static string GenerateHeader(SortedSet<string> namespaces, string curren
builder.AppendLine()
.AppendLine("#pragma warning disable 219, 612, 618");

if (nullable)
{
builder.AppendLine("#nullable enable");
}
else
{
builder.AppendLine("#nullable disable");
}
builder.AppendLine(nullable ? "#nullable enable" : "#nullable disable");

builder.AppendLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,17 @@ private static string GenerateCandidateIdentifier(string originalIdentifier)

private static string FindCandidateNavigationName(IEnumerable<IReadOnlyProperty> properties)
{
if (!properties.Any())
var count = properties.Count();
if (count == 0)
{
return string.Empty;
}

var candidateName = string.Empty;
var firstProperty = properties.First();
if (properties.Count() == 1)
{
candidateName = firstProperty.Name;
}
else
{
candidateName = FindCommonPrefix(firstProperty.Name, properties.Select(p => p.Name));
}

return StripId(candidateName);
return StripId(
count == 1
? firstProperty.Name
: FindCommonPrefix(firstProperty.Name, properties.Select(p => p.Name)));
}

private static string FindCommonPrefix(string firstName, IEnumerable<string> propertyNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,9 @@ public static bool IsKeyOrIndex(this DatabaseColumn column)
{
var table = column.Table;

if (table.PrimaryKey?.Columns.Contains(column) == true)
{
return true;
}

if (table.UniqueConstraints.Any(uc => uc.Columns.Contains(column)))
{
return true;
}

return table.Indexes.Any(uc => uc.Columns.Contains(column));
return table.PrimaryKey?.Columns.Contains(column) == true
|| (table.UniqueConstraints.Any(uc => uc.Columns.Contains(column))
|| table.Indexes.Any(uc => uc.Columns.Contains(column)));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,9 @@ public virtual Expression Translate(InMemoryQueryExpression queryExpression, Exp
}

var translation = _expressionTranslatingExpressionVisitor.Translate(expression);
if (translation != null)
{
return AddClientProjection(translation, expression.Type.MakeNullable());
}

return base.Visit(expression);
return translation != null
? AddClientProjection(translation, expression.Type.MakeNullable())
: base.Visit(expression);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,7 @@ public override void Generate(ISkipNavigation navigation, CSharpRuntimeAnnotatio
public override void Generate(IIndex index, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
{
var annotations = parameters.Annotations;
if (parameters.IsRuntime)
{
annotations.Remove(RelationalAnnotationNames.TableIndexMappings);
}
else
{
annotations.Remove(RelationalAnnotationNames.Filter);
}
annotations.Remove(parameters.IsRuntime ? RelationalAnnotationNames.TableIndexMappings : RelationalAnnotationNames.Filter);

base.Generate(index, parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,20 +445,10 @@ public static string GetDefaultSqlQueryName(this IReadOnlyEntityType entityType)
/// <param name="entityType">The entity type.</param>
/// <returns>The SQL string used to provide data for the entity type.</returns>
public static string? GetSqlQuery(this IReadOnlyEntityType entityType)
{
var queryAnnotation = (string?)entityType[RelationalAnnotationNames.SqlQuery];
if (queryAnnotation != null)
{
return queryAnnotation;
}

if (entityType.BaseType != null)
{
return entityType.GetRootType().GetSqlQuery();
}

return null;
}
=> (string?)entityType[RelationalAnnotationNames.SqlQuery]
?? (entityType.BaseType != null
? entityType.GetRootType().GetSqlQuery()
: null);

/// <summary>
/// Sets the SQL string used to provide data for the entity type.
Expand Down Expand Up @@ -511,20 +501,10 @@ public static IEnumerable<ISqlQueryMapping> GetSqlQueryMappings(this IEntityType
/// <param name="entityType">The entity type to get the function name for.</param>
/// <returns>The name of the function to which the entity type is mapped.</returns>
public static string? GetFunctionName(this IReadOnlyEntityType entityType)
{
var nameAnnotation = (string?)entityType[RelationalAnnotationNames.FunctionName];
if (nameAnnotation != null)
{
return nameAnnotation;
}

if (entityType.BaseType != null)
{
return entityType.GetRootType().GetFunctionName();
}

return null;
}
=> (string?)entityType[RelationalAnnotationNames.FunctionName]
?? (entityType.BaseType != null
? entityType.GetRootType().GetFunctionName()
: null);

/// <summary>
/// Sets the name of the function to which the entity type is mapped.
Expand Down
69 changes: 21 additions & 48 deletions src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,9 @@ public static void SetColumnName(
}

var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject);
if (sharedTableRootProperty != null)
{
return GetColumnOrder(sharedTableRootProperty, storeObject);
}

return null;
return sharedTableRootProperty != null
? GetColumnOrder(sharedTableRootProperty, storeObject)
: null;
}

/// <summary>
Expand Down Expand Up @@ -541,12 +538,9 @@ public static IEnumerable<IFunctionColumnMapping> GetFunctionColumnMappings(this
}

var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject);
if (sharedTableRootProperty != null)
{
return GetDefaultValueSql(sharedTableRootProperty, storeObject);
}

return null;
return sharedTableRootProperty != null
? GetDefaultValueSql(sharedTableRootProperty, storeObject)
: null;
}

/// <summary>
Expand Down Expand Up @@ -610,12 +604,9 @@ public static void SetDefaultValueSql(this IMutableProperty property, string? va
}

var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject);
if (sharedTableRootProperty != null)
{
return GetComputedColumnSql(sharedTableRootProperty, storeObject);
}

return null;
return sharedTableRootProperty != null
? GetComputedColumnSql(sharedTableRootProperty, storeObject)
: null;
}

/// <summary>
Expand Down Expand Up @@ -687,12 +678,9 @@ public static void SetComputedColumnSql(this IMutableProperty property, string?
}

var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject);
if (sharedTableRootProperty != null)
{
return GetIsStored(sharedTableRootProperty, storeObject);
}

return null;
return sharedTableRootProperty != null
? GetIsStored(sharedTableRootProperty, storeObject)
: null;
}

/// <summary>
Expand Down Expand Up @@ -960,12 +948,9 @@ public static void SetDefaultValue(this IMutableProperty property, object? value
}

var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject);
if (sharedTableRootProperty != null)
{
return IsFixedLength(sharedTableRootProperty, storeObject);
}

return null;
return sharedTableRootProperty != null
? IsFixedLength(sharedTableRootProperty, storeObject)
: null;
}

/// <summary>
Expand Down Expand Up @@ -1097,12 +1082,9 @@ private static bool IsOptionalSharingDependent(
}

var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject);
if (sharedTableRootProperty != null)
{
return GetComment(sharedTableRootProperty, storeObject);
}

return null;
return sharedTableRootProperty != null
? GetComment(sharedTableRootProperty, storeObject)
: null;
}

/// <summary>
Expand Down Expand Up @@ -1162,18 +1144,9 @@ public static void SetComment(this IMutableProperty property, string? comment)
}

var annotation = property.FindAnnotation(RelationalAnnotationNames.Collation);
if (annotation != null)
{
return (string?)annotation.Value;
}

var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject);
if (sharedTableRootProperty != null)
{
return sharedTableRootProperty.GetCollation(storeObject);
}

return null;
return annotation != null
? (string?)annotation.Value
: property.FindSharedStoreObjectRootProperty(storeObject)?.GetCollation(storeObject);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,7 @@ protected override void ProcessIndexAnnotations(
{
base.ProcessIndexAnnotations(annotations, index, runtimeIndex, runtime);

if (runtime)
{
annotations.Remove(RelationalAnnotationNames.TableIndexMappings);
}
else
{
annotations.Remove(RelationalAnnotationNames.Filter);
}
annotations.Remove(runtime ? RelationalAnnotationNames.TableIndexMappings : RelationalAnnotationNames.Filter);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ private void ProcessTableChanged(
protected override ValueGenerated? GetValueGenerated(IConventionProperty property)
{
var tableName = property.DeclaringEntityType.GetTableName();
if (tableName == null)
{
return null;
}

return GetValueGenerated(property, StoreObjectIdentifier.Table(tableName, property.DeclaringEntityType.GetSchema()));
return tableName == null
? null
: GetValueGenerated(property, StoreObjectIdentifier.Table(tableName, property.DeclaringEntityType.GetSchema()));
}

/// <summary>
Expand Down
Loading