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: make members static #26947

Merged
merged 1 commit into from
Dec 9, 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 @@ -94,7 +94,7 @@ public virtual void ProcessEntityTypeAnnotationChanged(
ProcessEntityType(entityTypeBuilder);
}

private void ProcessEntityType(IConventionEntityTypeBuilder entityTypeBuilder)
private static void ProcessEntityType(IConventionEntityTypeBuilder entityTypeBuilder)
{
var entityType = entityTypeBuilder.Metadata;
if (entityType.BaseType != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void ProcessJoinPartitionKey(IConventionSkipNavigation skipNavigation)
}
}

private bool ShouldSharePartitionKey(IConventionSkipNavigation skipNavigation)
private static bool ShouldSharePartitionKey(IConventionSkipNavigation skipNavigation)
=> skipNavigation.DeclaringEntityType.GetContainer() == skipNavigation.TargetEntityType.GetContainer()
&& skipNavigation.DeclaringEntityType.GetPartitionKeyPropertyName() != null
&& skipNavigation.Inverse?.DeclaringEntityType.GetPartitionKeyPropertyName()
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public ContainsTranslator(ISqlExpressionFactory sqlExpressionFactory)
return null;
}

private bool ValidateValues(SqlExpression values)
private static bool ValidateValues(SqlExpression values)
=> values is SqlConstantExpression || values is SqlParameterExpression;
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(IEntityType
return CreateShapedQueryExpression(entityType, selectExpression);
}

private ShapedQueryExpression CreateShapedQueryExpression(IEntityType entityType, Expression queryExpression)
private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType entityType, Expression queryExpression)
=> new(
queryExpression,
new EntityShaperExpression(
Expand Down Expand Up @@ -1050,7 +1050,7 @@ private SqlExpression TranslateLambdaExpression(
private static Expression RemapLambdaBody(Expression shaperBody, LambdaExpression lambdaExpression)
=> ReplacingExpressionVisitor.Replace(lambdaExpression.Parameters.Single(), shaperBody, lambdaExpression.Body);

private ShapedQueryExpression AggregateResultShaper(
private static ShapedQueryExpression AggregateResultShaper(
ShapedQueryExpression source,
Expression projection,
bool throwOnNullResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ var body
return valueExpression;
}

private Expression ConvertJTokenToType(Expression jTokenExpression, Type type)
private static Expression ConvertJTokenToType(Expression jTokenExpression, Type type)
=> type == typeof(JToken)
? jTokenExpression
: Expression.Call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ private static List<TProperty> ParameterListValueExtractor<TEntity, TProperty>(
private static bool IsNullSqlConstantExpression(Expression expression)
=> expression is SqlConstantExpression sqlConstant && sqlConstant.Value == null;

private SqlConstantExpression GetConstantOrNull(Expression expression)
private static SqlConstantExpression GetConstantOrNull(Expression expression)
=> CanEvaluate(expression)
? new SqlConstantExpression(
Expression.Constant(
Expand Down Expand Up @@ -933,7 +933,7 @@ private static bool CanEvaluate(Expression expression)
}

[DebuggerStepThrough]
private bool TranslationFailed(Expression original, Expression translation, out SqlExpression castTranslation)
private static bool TranslationFailed(Expression original, Expression translation, out SqlExpression castTranslation)
{
if (original != null
&& !(translation is SqlExpression))
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Cosmos/Query/Internal/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,14 @@ protected override Expression VisitSqlConstant(SqlConstantExpression sqlConstant
return sqlConstantExpression;
}

private string GenerateConstant(object value, CoreTypeMapping typeMapping)
private static string GenerateConstant(object value, CoreTypeMapping typeMapping)
{
var jToken = GenerateJToken(value, typeMapping);

return jToken is null ? "null" : jToken.ToString(Formatting.None);
}

private JToken GenerateJToken(object value, CoreTypeMapping typeMapping)
private static JToken GenerateJToken(object value, CoreTypeMapping typeMapping)
{
if (value?.GetType().IsInteger() == true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public virtual async Task<bool> EnsureCreatedAsync(CancellationToken cancellatio
return created;
}

private IEnumerable<ContainerProperties> GetContainersToCreate(IModel model)
private static IEnumerable<ContainerProperties> GetContainersToCreate(IModel model)
{
var containers = new Dictionary<string, List<IEntityType>>();
foreach (var entityType in model.GetEntityTypes().Where(et => et.FindPrimaryKey() != null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CosmosTypeMappingSource(TypeMappingSourceDependencies dependencies)
?? base.FindMapping(mappingInfo));
}

private CoreTypeMapping? FindPrimitiveMapping(in TypeMappingInfo mappingInfo)
private static CoreTypeMapping? FindPrimitiveMapping(in TypeMappingInfo mappingInfo)
{
var clrType = mappingInfo.ClrType!;
if ((clrType.IsValueType
Expand All @@ -61,7 +61,7 @@ public CosmosTypeMappingSource(TypeMappingSourceDependencies dependencies)
return null;
}

private CoreTypeMapping? FindCollectionMapping(in TypeMappingInfo mappingInfo)
private static CoreTypeMapping? FindCollectionMapping(in TypeMappingInfo mappingInfo)
{
var clrType = mappingInfo.ClrType!;
var elementType = clrType.TryGetSequenceType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public override Stream ToStream<T>(T input)
return streamPayload;
}

private JsonSerializer GetSerializer()
private static JsonSerializer GetSerializer()
=> CosmosClientWrapper.Serializer;
}
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Update/Internal/DocumentSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public virtual JObject CreateDocument(IUpdateEntry entry, int? ordinal)
return anyPropertyUpdated ? document : null;
}

private IProperty? FindOrdinalKeyProperty(IEntityType entityType)
private static IProperty? FindOrdinalKeyProperty(IEntityType entityType)
=> entityType.FindPrimaryKey()!.Properties.FirstOrDefault(
p =>
p.GetJsonPropertyName().Length == 0 && p.IsOrdinalKeyProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override object NextValue(EntityEntry entry)
return builder.ToString();
}

private void AppendString(StringBuilder builder, object? propertyValue)
private static void AppendString(StringBuilder builder, object? propertyValue)
{
switch (propertyValue)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Design/Design/Internal/DbContextOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public virtual ContextInfo GetContextInfo(string? contextType)
return info;
}

private Func<DbContext>? FindContextFromRuntimeDbContextFactory(IServiceProvider appServices, Type contextType)
private static Func<DbContext>? FindContextFromRuntimeDbContextFactory(IServiceProvider appServices, Type contextType)
{
var factoryInterface = typeof(IDbContextFactory<>).MakeGenericType(contextType);
var service = appServices.GetService(factoryInterface);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void ProcessElement(IReadOnlyAnnotatable? metadata, string version)
}
}

private void UpdateSequences(IReadOnlyModel model, string version)
private static void UpdateSequences(IReadOnlyModel model, string version)
{
if ((!version.StartsWith("1.", StringComparison.Ordinal)
&& !version.StartsWith("2.", StringComparison.Ordinal)
Expand Down Expand Up @@ -157,7 +157,7 @@ private void UpdateSequences(IReadOnlyModel model, string version)
}
}

private void UpdateOwnedTypes(IMutableEntityType entityType)
private static void UpdateOwnedTypes(IMutableEntityType entityType)
{
var ownerships = entityType.GetDeclaredReferencingForeignKeys().Where(fk => fk.IsOwnership && fk.IsUnique)
.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ private void CreateAnnotations(
.AppendLine("static partial void Customize(RuntimeEntityType runtimeEntityType);");
}

private void CreateAnnotations<TAnnotatable>(
private static void CreateAnnotations<TAnnotatable>(
TAnnotatable annotatable,
Action<TAnnotatable, CSharpRuntimeAnnotationCodeGeneratorParameters> process,
CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ private static Expression ConvertToNonNullable(Expression expression)
? Expression.Convert(expression, expression.Type.UnwrapNullableType())
: expression;

private IProperty? FindProperty(Expression expression)
private static IProperty? FindProperty(Expression expression)
{
if (expression.NodeType == ExpressionType.Convert
&& expression.Type.IsNullableType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ private InMemoryQueryExpression Clone()
return (InMemoryQueryExpression)_cloningExpressionVisitor.Visit(this);
}

private Expression GetGroupingKey(Expression key, List<Expression> groupingExpressions, Expression groupingKeyAccessExpression)
private static Expression GetGroupingKey(Expression key, List<Expression> groupingExpressions, Expression groupingKeyAccessExpression)
{
switch (key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ MethodInfo GetMethod()
: source;
}

private ShapedQueryExpression TranslateSetOperation(
private static ShapedQueryExpression TranslateSetOperation(
MethodInfo setOperationMethodInfo,
ShapedQueryExpression source1,
ShapedQueryExpression source2)
Expand All @@ -1446,7 +1446,7 @@ private ShapedQueryExpression TranslateSetOperation(
source1.ShaperExpression, source2.ShaperExpression, makeNullable));
}

private Expression MatchShaperNullabilityForSetOperation(Expression shaper1, Expression shaper2, bool makeNullable)
private static Expression MatchShaperNullabilityForSetOperation(Expression shaper1, Expression shaper2, bool makeNullable)
{
switch (shaper1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private object CreateProxy(
constructorArguments,
GetNotifyChangeInterceptors(options, entityType));

private Type[] GetInterfacesToProxy(
private static Type[] GetInterfacesToProxy(
ProxiesOptionsExtension options,
Type type)
{
Expand All @@ -168,7 +168,7 @@ private Type[] GetInterfacesToProxy(
return interfacesToProxy.ToArray();
}

private IInterceptor[] GetNotifyChangeInterceptors(
private static IInterceptor[] GetNotifyChangeInterceptors(
ProxiesOptionsExtension options,
IEntityType entityType,
LazyLoadingInterceptor? lazyLoadingInterceptor = null)
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Design/AnnotationCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio
protected virtual AttributeCodeFragment? GenerateDataAnnotation(IProperty property, IAnnotation annotation)
=> null;

private IEnumerable<TCodeFragment> GenerateFluentApiCallsHelper<TAnnotatable, TCodeFragment>(
private static IEnumerable<TCodeFragment> GenerateFluentApiCallsHelper<TAnnotatable, TCodeFragment>(
TAnnotatable annotatable,
IDictionary<string, IAnnotation> annotations,
Func<TAnnotatable, IAnnotation, TCodeFragment?> generateCodeFragment)
Expand All @@ -597,7 +597,7 @@ private IEnumerable<TCodeFragment> GenerateFluentApiCallsHelper<TAnnotatable, TC
}
}

private void RemoveConventionalAnnotationsHelper<TAnnotatable>(
private static void RemoveConventionalAnnotationsHelper<TAnnotatable>(
TAnnotatable annotatable,
IDictionary<string, IAnnotation> annotations,
Func<TAnnotatable, IAnnotation, bool> isHandledByConvention)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public override void Generate(IIndex index, CSharpRuntimeAnnotationCodeGenerator
base.Generate(index, parameters);
}

private void CreateAnnotations<TAnnotatable>(
private static void CreateAnnotations<TAnnotatable>(
TAnnotatable annotatable,
Action<TAnnotatable, CSharpRuntimeAnnotationCodeGeneratorParameters> process,
CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
Expand All @@ -484,7 +484,7 @@ parameters with
});
}

private string Capitalize(string @string)
private static string Capitalize(string @string)
{
switch (@string.Length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ protected override void ValidateInheritanceMapping(
}
}

private void ValidateTPTMapping(IEntityType rootEntityType, bool forTables)
private static void ValidateTPTMapping(IEntityType rootEntityType, bool forTables)
{
var derivedTypes = new Dictionary<(string, string?), IEntityType>();
foreach (var entityType in rootEntityType.GetDerivedTypesInclusive())
Expand All @@ -1294,7 +1294,7 @@ private void ValidateTPTMapping(IEntityType rootEntityType, bool forTables)
}
}

private void ValidateTPHMapping(IEntityType rootEntityType, bool forTables)
private static void ValidateTPHMapping(IEntityType rootEntityType, bool forTables)
{
string? firstName = null;
string? firstSchema = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged(
}
}

private bool AreCompatible(IConventionCheckConstraint checkConstraint, IConventionCheckConstraint baseCheckConstraint)
private static bool AreCompatible(IConventionCheckConstraint checkConstraint, IConventionCheckConstraint baseCheckConstraint)
{
var baseTable = StoreObjectIdentifier.Create(baseCheckConstraint.EntityType, StoreObjectType.Table);
if (baseTable == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void CreateAnnotations<TSource, TTarget>(
target.AddRuntimeAnnotations(annotations);
}

private RuntimeDbFunction Create(IDbFunction function, RuntimeModel runtimeModel)
private static RuntimeDbFunction Create(IDbFunction function, RuntimeModel runtimeModel)
=> new(
function.ModelName,
runtimeModel,
Expand Down Expand Up @@ -187,7 +187,7 @@ protected virtual void ProcessFunctionAnnotations(
{
}

private RuntimeDbFunctionParameter Create(IDbFunctionParameter parameter, RuntimeDbFunction runtimeFunction)
private static RuntimeDbFunctionParameter Create(IDbFunctionParameter parameter, RuntimeDbFunction runtimeFunction)
=> runtimeFunction.AddParameter(
parameter.Name,
parameter.ClrType,
Expand All @@ -210,7 +210,7 @@ protected virtual void ProcessFunctionParameterAnnotations(
{
}

private RuntimeSequence Create(ISequence sequence, RuntimeModel runtimeModel)
private static RuntimeSequence Create(ISequence sequence, RuntimeModel runtimeModel)
=> new(
sequence.Name,
runtimeModel,
Expand Down Expand Up @@ -285,7 +285,7 @@ protected override void ProcessPropertyAnnotations(
}
}

private RuntimeRelationalPropertyOverrides Create(
private static RuntimeRelationalPropertyOverrides Create(
IRelationalPropertyOverrides propertyOverrides,
RuntimeProperty runtimeProperty)
=> new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public virtual void ProcessEntityTypeAnnotationChanged(
}
}

private void ProcessTableChanged(
private static void ProcessTableChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
string? oldTable,
string? oldSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public virtual void ProcessModelFinalizing(
/// Called when an <see cref="IConventionDbFunction" /> is added to the model.
/// </summary>
/// <param name="dbFunctionBuilder">The builder for the <see cref="IConventionDbFunction" />.</param>
private void ProcessDbFunctionAdded(
private static void ProcessDbFunctionAdded(
IConventionDbFunctionBuilder dbFunctionBuilder)
{
var function = dbFunctionBuilder.Metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ protected virtual IEnumerable<MigrationOperation> Diff(
&& EntityTypePathEquals(sm.Property.DeclaringEntityType, tm.Property.DeclaringEntityType, c))),
(s, t, _) => ColumnStructureEquals(s, t));

private bool ColumnStructureEquals(IColumn source, IColumn target)
private static bool ColumnStructureEquals(IColumn source, IColumn target)
{
if (!source.TryGetDefaultValue(out var sourceDefault))
{
Expand Down Expand Up @@ -2316,7 +2316,7 @@ private IEnumerable<MigrationOperation> GetDataOperations(
}
}

private object? GetValue(IColumnModification columnModification)
private static object? GetValue(IColumnModification columnModification)
{
var converter = GetValueConverter(columnModification.Property!);
var value = columnModification.UseCurrentValue
Expand Down Expand Up @@ -2450,7 +2450,7 @@ protected virtual IEnumerable<string> GetSchemas(IRelationalModel model)
? Array.CreateInstance(type.GetElementType()!, 0)
: type.UnwrapNullableType().GetDefaultValue();

private ValueConverter? GetValueConverter(IProperty property, RelationalTypeMapping? typeMapping = null)
private static ValueConverter? GetValueConverter(IProperty property, RelationalTypeMapping? typeMapping = null)
=> property.GetValueConverter() ?? (property.FindRelationalTypeMapping() ?? typeMapping)?.Converter;

private static IEntityType GetMainType(ITable table)
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Query/Internal/BufferedDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public override object GetValue(int ordinal)
public override int GetValues(object[] values)
{
AssertReaderIsOpenWithData();
return _currentResultSet.GetValues(values);
return BufferedDataRecord.GetValues(values);
}

/// <summary>
Expand Down Expand Up @@ -837,7 +837,7 @@ public object GetValue(int ordinal)
=> GetFieldValue<object>(ordinal);

#pragma warning disable IDE0060 // Remove unused parameter
public int GetValues(object[] values)
public static int GetValues(object[] values)
#pragma warning restore IDE0060 // Remove unused parameter
=> throw new NotSupportedException();

Expand Down
Loading