Skip to content

Commit

Permalink
🍩 Fix some static analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Nov 11, 2015
1 parent a54ade0 commit 0b96c13
Show file tree
Hide file tree
Showing 84 changed files with 726 additions and 746 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public LoggerProvider([NotNull] Func<string, ILogger> creator)
_creator = creator;
}

public virtual ILogger CreateLogger(string name) => _creator(name);
public virtual ILogger CreateLogger(string categoryName) => _creator(categoryName);

public virtual void Dispose()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public abstract class CodeWriter
{
private const string DefaultFileExtension = ".cs";

public CodeWriter([NotNull] IFileService fileService)
protected CodeWriter([NotNull] IFileService fileService)
{
Check.NotNull(fileService, nameof(fileService));

FileService = fileService;
}

public virtual IFileService FileService { get; }
public virtual string FileExtension { get;[param: NotNull] set; } = DefaultFileExtension;
public virtual string FileExtension { get; [param: NotNull] set; } = DefaultFileExtension;

/// <summary>
/// Returns a list of the files which would be output by this class but
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public FluentApiConfiguration(

public virtual bool HasAttributeEquivalent { get; set; }

public virtual string For { get;[param: NotNull] private set; }
public virtual string For { get; }

public virtual string MethodBody
{
Expand All @@ -34,7 +34,8 @@ public virtual string MethodBody
}
}

public virtual string FluentApi{
public virtual string FluentApi
{
get
{
return For == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class ModelConfiguration
protected SortedDictionary<EntityType, EntityConfiguration> _entityConfigurationMap;

public ModelConfiguration(
[NotNull] ConfigurationFactory configurationFactory,
[NotNull] IModel model,
[NotNull] CustomConfiguration customConfiguration,
[NotNull] IRelationalAnnotationProvider extensionsProvider,
[NotNull] CSharpUtilities cSharpUtilities,
[NotNull] ConfigurationFactory configurationFactory,
[NotNull] IModel model,
[NotNull] CustomConfiguration customConfiguration,
[NotNull] IRelationalAnnotationProvider extensionsProvider,
[NotNull] CSharpUtilities cSharpUtilities,
[NotNull] ScaffoldingUtilities scaffoldingUtilities)
{
Check.NotNull(configurationFactory, nameof(configurationFactory));
Expand All @@ -50,11 +50,11 @@ public ModelConfiguration(
ScaffoldingUtilities = scaffoldingUtilities;
}

public virtual IModel Model { get;[param: NotNull] private set; }
public virtual IModel Model { get; [param: NotNull] private set; }
public virtual IRelationalAnnotationProvider ExtensionsProvider { get; private set; }
public virtual CSharpUtilities CSharpUtilities { get;[param: NotNull] private set; }
public virtual ScaffoldingUtilities ScaffoldingUtilities { get;[param: NotNull] private set; }
public virtual CustomConfiguration CustomConfiguration { get;[param: NotNull] set; }
public virtual CSharpUtilities CSharpUtilities { get; [param: NotNull] private set; }
public virtual ScaffoldingUtilities ScaffoldingUtilities { get; [param: NotNull] private set; }
public virtual CustomConfiguration CustomConfiguration { get; [param: NotNull] set; }
public virtual string ClassName()
{
var annotatedName = ExtensionsProvider.For(Model).DatabaseName;
Expand Down Expand Up @@ -88,7 +88,7 @@ public virtual List<EntityConfiguration> EntityConfigurations
{
if (_entityConfigurationMap == null)
{
_entityConfigurationMap = new
_entityConfigurationMap = new
SortedDictionary<EntityType, EntityConfiguration>(new EntityTypeNameComparer());
AddEntityConfigurations();
}
Expand All @@ -99,8 +99,6 @@ public virtual List<EntityConfiguration> EntityConfigurations

public virtual void AddEntityConfigurations()
{
var entityConfigurations = new List<EntityConfiguration>();

foreach (var entityType in Model.GetEntityTypes())
{
var entityConfiguration =
Expand Down Expand Up @@ -160,7 +158,7 @@ public virtual void AddKeyConfiguration([NotNull] EntityConfiguration entityConf
Check.NotNull(entityConfiguration, nameof(entityConfiguration));

var entityType = (EntityType)entityConfiguration.EntityType;
foreach(var key in entityType.GetKeys())
foreach (var key in entityType.GetKeys())
{
if (key == null
|| key.Properties.Count == 0)
Expand All @@ -176,7 +174,7 @@ public virtual void AddKeyConfiguration([NotNull] EntityConfiguration entityConf
continue;
}

if(key.IsPrimaryKey())
if (key.IsPrimaryKey())
{
var keyFluentApi = _configurationFactory
.CreateKeyFluentApiConfiguration("e", key.Properties);
Expand Down Expand Up @@ -374,14 +372,14 @@ public virtual void AddColumnNameAndTypeConfiguration(
Check.NotNull(propertyConfiguration, nameof(propertyConfiguration));


var delimitedColumnName =
var delimitedColumnName =
ExtensionsProvider.For(propertyConfiguration.Property).ColumnName != null
&& ExtensionsProvider.For(propertyConfiguration.Property).ColumnName != propertyConfiguration.Property.Name
? CSharpUtilities.DelimitString(
ExtensionsProvider.For(propertyConfiguration.Property).ColumnName)
: null;

var delimitedColumnTypeName =
var delimitedColumnTypeName =
ExtensionsProvider.For(propertyConfiguration.Property).ColumnType != null
? CSharpUtilities.DelimitString(
ExtensionsProvider.For(propertyConfiguration.Property).ColumnType)
Expand Down Expand Up @@ -500,7 +498,7 @@ public virtual void AddNavigationProperties([NotNull] EntityConfiguration entity
foreignKey.PrincipalEntityType.Name,
foreignKey.Scaffolding().DependentEndNavigation);

if(foreignKey.PrincipalKey.IsPrimaryKey())
if (foreignKey.PrincipalKey.IsPrimaryKey())
{
dependentEndNavPropConfiguration.AttributeConfigurations.Add(
_configurationFactory.CreateAttributeConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public virtual void DetectChanges(InternalEntityEntry entry)
DetectRelationshipChanges(entry);
}

private void DetectPropertyChanges(InternalEntityEntry entry)
private static void DetectPropertyChanges(InternalEntityEntry entry)
{
var entityType = entry.EntityType;

Expand Down Expand Up @@ -131,7 +131,7 @@ private void DetectNavigationChanges(InternalEntityEntry entry)
}
}

private void DetectKeyChange(InternalEntityEntry entry, IProperty property)
private static void DetectKeyChange(InternalEntityEntry entry, IProperty property)
{
var keys = property.FindContainingKeys().ToList();
var foreignKeys = property.FindContainingForeignKeys(entry.EntityType).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.Data.Entity.ChangeTracking.Internal
{
public interface IPropertyListener
{
void PropertyChanged([NotNull] InternalEntityEntry entry, [NotNull] IPropertyBase property);
void PropertyChanging([NotNull] InternalEntityEntry entry, [NotNull] IPropertyBase property);
void PropertyChanged([NotNull] InternalEntityEntry entry, [NotNull] IPropertyBase propertyBase);
void PropertyChanging([NotNull] InternalEntityEntry entry, [NotNull] IPropertyBase propertyBase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -522,30 +522,6 @@ public virtual void CascadeDelete()
}
}

private IReadOnlyList<IProperty> FindPropertiesThatMayGetStoreValue()
{
var properties = EntityType.GetProperties().Where(
p => MayGetStoreValue(p, p.IsKey() ? p.DeclaringEntityType : EntityType)).ToList();

foreach (var foreignKey in EntityType.GetForeignKeys())
{
foreach (var property in foreignKey.Properties)
{
if (!properties.Contains(property))
{
var generationProperty = property.GetGenerationProperty();
if ((generationProperty != null)
&& (generationProperty != property)
&& MayGetStoreValue(generationProperty, generationProperty.DeclaringEntityType))
{
properties.Add(property);
}
}
}
}
return properties;
}

private bool MayGetStoreValue([CanBeNull] IProperty property, IEntityType entityType)
=> (property != null)
&& ((property.ValueGenerated != ValueGenerated.Never)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public virtual InternalEntityEntry Create(IStateManager stateManager, IEntityTyp
public virtual InternalEntityEntry Create(IStateManager stateManager, IEntityType entityType, object entity, ValueBuffer valueBuffer)
=> NewInternalEntityEntry(stateManager, entityType, entity, valueBuffer);

private InternalEntityEntry NewInternalEntityEntry(IStateManager stateManager, IEntityType entityType, object entity)
private static InternalEntityEntry NewInternalEntityEntry(IStateManager stateManager, IEntityType entityType, object entity)
{
if (!entityType.HasClrType())
{
Expand All @@ -30,7 +30,7 @@ private InternalEntityEntry NewInternalEntityEntry(IStateManager stateManager, I
: new InternalClrEntityEntry(stateManager, entityType, entity);
}

private InternalEntityEntry NewInternalEntityEntry(
private static InternalEntityEntry NewInternalEntityEntry(
IStateManager stateManager,
IEntityType entityType,
object entity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private ValueGenerator TryGetValueGenerator(IProperty property)
return null;
}

private object TryFindPrincipal(IStateManager stateManager, INavigation navigation, object dependentEntity)
private static object TryFindPrincipal(IStateManager stateManager, INavigation navigation, object dependentEntity)
{
if (navigation.IsDependentToPrincipal())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private void PerformFixup(Action fixupAction)
private void DoFixup(IForeignKey foreignKey, InternalEntityEntry principalEntry, InternalEntityEntry[] dependentEntries)
=> DoFixup(foreignKey.GetNavigations().ToList(), principalEntry, dependentEntries);

private void DoFixup(IEnumerable<INavigation> navigations, InternalEntityEntry principalEntry, InternalEntityEntry[] dependentEntries)
private static void DoFixup(IEnumerable<INavigation> navigations, InternalEntityEntry principalEntry, InternalEntityEntry[] dependentEntries)
{
foreach (var navigation in navigations)
{
Expand Down Expand Up @@ -392,7 +392,7 @@ private void Unfixup(IEnumerable<INavigation> navigations, InternalEntityEntry o
}
}

private void Unfixup(INavigation navigation, InternalEntityEntry oldPrincipalEntry, InternalEntityEntry dependentEntry)
private static void Unfixup(INavigation navigation, InternalEntityEntry oldPrincipalEntry, InternalEntityEntry dependentEntry)
{
var dependentEntity = dependentEntry.Entity;

Expand Down Expand Up @@ -421,7 +421,7 @@ private void Unfixup(INavigation navigation, InternalEntityEntry oldPrincipalEnt
}
}

private void StealReference(IForeignKey foreignKey, InternalEntityEntry dependentEntry)
private static void StealReference(IForeignKey foreignKey, InternalEntityEntry dependentEntry)
{
foreach (var navigation in dependentEntry.EntityType.GetNavigations().Where(n => n.ForeignKey == foreignKey))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2502,7 +2502,7 @@ public static async Task LoadAsync<TSource>(

using (var enumerator = asyncEnumerable.GetEnumerator())
{
while (await enumerator.MoveNext())
while (await enumerator.MoveNext(cancellationToken))
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Microsoft.Data.Entity.Internal
public sealed class ReferenceEnumerableEqualityComparer<TEnumerable, TValue> : IEqualityComparer<TEnumerable>
where TEnumerable : IEnumerable<TValue>
{
public bool Equals(TEnumerable left, TEnumerable right) => left.SequenceEqual(right);
public bool Equals(TEnumerable x, TEnumerable y) => x.SequenceEqual(y);

public int GetHashCode(TEnumerable values) => values.Aggregate(0, (t, v) => (t * 397) ^ v.GetHashCode());
public int GetHashCode(TEnumerable obj) => obj.Aggregate(0, (t, v) => (t * 397) ^ v.GetHashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ private void SplitNavigationsInSeparateRelationships(InternalRelationshipBuilder
.DependentToPrincipal(principalToDepedentNavigationName, ConfigurationSource.DataAnnotation);
}

private InversePropertyAttribute GetInversePropertyAttributeOnNavigation(Navigation navigation)
private static InversePropertyAttribute GetInversePropertyAttributeOnNavigation(Navigation navigation)
{
return navigation.DeclaringEntityType.ClrType?.GetRuntimeProperties()
.FirstOrDefault(p => string.Equals(p.Name, navigation.Name, StringComparison.OrdinalIgnoreCase))
?.GetCustomAttribute<InversePropertyAttribute>(true);
}

private ForeignKeyAttribute GetForeignKeyAttribute(EntityType entityType, string propertyName)
private static ForeignKeyAttribute GetForeignKeyAttribute(EntityType entityType, string propertyName)
{
return entityType.ClrType?.GetRuntimeProperties()
.FirstOrDefault(p => string.Equals(p.Name, propertyName, StringComparison.OrdinalIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public virtual InternalRelationshipBuilder Apply(InternalRelationshipBuilder rel
return relationshipBuilder;
}

private bool ShouldInvert(
private static bool ShouldInvert(
ForeignKey foreignKey,
IReadOnlyList<Property> currentDependentCandidateProperties,
IReadOnlyList<Property> currentPrincipalCandidateProperties)
Expand Down Expand Up @@ -149,7 +149,7 @@ private IReadOnlyList<Property> FindCandidateForeignKeyProperties(ForeignKey for
return null;
}

private IReadOnlyList<Property> GetCompatiblePrimaryKeyProperties(EntityType dependentEntityType, EntityType principalEntityType, IReadOnlyList<Property> propertiesToReference)
private static IReadOnlyList<Property> GetCompatiblePrimaryKeyProperties(EntityType dependentEntityType, EntityType principalEntityType, IReadOnlyList<Property> propertiesToReference)
{
var dependentPkProperties = dependentEntityType.FindPrimaryKey()?.Properties;
if ((dependentPkProperties != null)
Expand Down Expand Up @@ -237,7 +237,7 @@ private IReadOnlyList<Property> FindMatchingNonShadowProperties(
return foreignKeyProperties;
}

private Property TryGetProperty(EntityType entityType, string name, Type type)
private static Property TryGetProperty(EntityType entityType, string name, Type type)
{
foreach (var mutableProperty in entityType.GetProperties())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public virtual bool Apply(InternalKeyBuilder keyBuilder, Key previousPrimaryKey)
return true;
}

private void SetValueGeneration(InternalEntityTypeBuilder entityTypeBuilder, IEnumerable<Property> properties)
private static void SetValueGeneration(InternalEntityTypeBuilder entityTypeBuilder, IEnumerable<Property> properties)
{
var propertyBuilders = InternalEntityTypeBuilder.GetPropertyBuilders(
entityTypeBuilder.ModelBuilder,
Expand Down Expand Up @@ -111,7 +111,7 @@ public virtual Property FindValueGeneratedOnAddProperty(
return null;
}

private Property FindValueGeneratedOnAddProperty(IReadOnlyList<Property> properties)
private static Property FindValueGeneratedOnAddProperty(IReadOnlyList<Property> properties)
{
if (properties.Count == 1)
{
Expand All @@ -127,7 +127,7 @@ private Property FindValueGeneratedOnAddProperty(IReadOnlyList<Property> propert
return null;
}

private void SetIdentity(InternalEntityTypeBuilder entityTypeBuilder, Property property)
private static void SetIdentity(InternalEntityTypeBuilder entityTypeBuilder, Property property)
{
var propertyBuilder = entityTypeBuilder.Property(
property.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public virtual InternalModelBuilder Apply(InternalModelBuilder modelBuilder)
return modelBuilder;
}

private void RemoveNavigationlessForeignKeys(InternalModelBuilder modelBuilder)
private static void RemoveNavigationlessForeignKeys(InternalModelBuilder modelBuilder)
{
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private IReadOnlyList<RelationshipCandidate> FindRelationshipCandidates(Internal
return relationshipCandidates.Values.ToList();
}

private IReadOnlyList<RelationshipCandidate> RemoveIncompatibleWithExistingRelationships(
private static IReadOnlyList<RelationshipCandidate> RemoveIncompatibleWithExistingRelationships(
IReadOnlyList<RelationshipCandidate> relationshipCandidates,
InternalEntityTypeBuilder entityTypeBuilder)
{
Expand Down Expand Up @@ -252,7 +252,7 @@ private void RemoveInheritedInverseNavigations(
}
}

private void CreateRelationships(
private static void CreateRelationships(
IReadOnlyList<RelationshipCandidate> relationshipCandidates, InternalEntityTypeBuilder entityTypeBuilder)
{
foreach (var relationshipCandidate in relationshipCandidates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public virtual ConventionalAnnotation SetAnnotation(
public new virtual ConventionalAnnotation RemoveAnnotation([NotNull] string name)
=> (ConventionalAnnotation)base.RemoveAnnotation(name);

private ConventionalAnnotation CreateAnnotation(
private static ConventionalAnnotation CreateAnnotation(
string name, object value, ConfigurationSource configurationSource)
=> new ConventionalAnnotation(name, value, configurationSource);

Expand Down
2 changes: 1 addition & 1 deletion src/EntityFramework.Core/Metadata/Internal/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ IMutableIndex IMutableEntityType.RemoveIndex(IReadOnlyList<IProperty> properties

#endregion

private IEnumerable<T> ToEnumerable<T>(T element)
private static IEnumerable<T> ToEnumerable<T>(T element)
where T : class
=> element == null ? Enumerable.Empty<T>() : new[] { element };

Expand Down
Loading

0 comments on commit 0b96c13

Please sign in to comment.