Skip to content

Commit

Permalink
Revert "Nullability annotation for scaffolding"
Browse files Browse the repository at this point in the history
This reverts commit eab93af.
  • Loading branch information
ajcvickers committed Dec 24, 2019
1 parent eab93af commit 918d53a
Show file tree
Hide file tree
Showing 57 changed files with 561 additions and 583 deletions.
2 changes: 0 additions & 2 deletions src/EFCore.Design/Scaffolding/IModelCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding
{
/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions src/EFCore.Design/Scaffolding/IModelCodeGeneratorSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using JetBrains.Annotations;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding
{
/// <summary>
Expand All @@ -17,6 +15,6 @@ public interface IModelCodeGeneratorSelector
/// </summary>
/// <param name="language"> The programming language. </param>
/// <returns> The <see cref="IModelCodeGenerator" />. </returns>
IModelCodeGenerator Select([CanBeNull] string? language);
IModelCodeGenerator Select([CanBeNull] string language);
}
}
4 changes: 1 addition & 3 deletions src/EFCore.Design/Scaffolding/IReverseEngineerScaffolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using JetBrains.Annotations;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding
{
/// <summary>
Expand Down Expand Up @@ -35,7 +33,7 @@ ScaffoldedModel ScaffoldModel(
/// <returns> The model files. </returns>
SavedModelFiles Save(
[NotNull] ScaffoldedModel scaffoldedModel,
[NotNull] string outputDir,
[CanBeNull] string outputDir,
bool overwriteFiles);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand All @@ -33,7 +31,7 @@ public class CSharpDbContextGenerator : ICSharpDbContextGenerator
private readonly ICSharpHelper _code;
private readonly IProviderConfigurationCodeGenerator _providerConfigurationCodeGenerator;
private readonly IAnnotationCodeGenerator _annotationCodeGenerator;
private IndentedStringBuilder _sb = null!;
private IndentedStringBuilder _sb;
private bool _entityTypeBuilderInitialized;

/// <summary>
Expand Down Expand Up @@ -66,7 +64,7 @@ public virtual string WriteCode(
IModel model,
string contextName,
string connectionString,
string? contextNamespace,
string contextNamespace,
string modelNamespace,
bool useDataAnnotations,
bool suppressConnectionStringWarning)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand All @@ -28,7 +26,7 @@ public class CSharpEntityTypeGenerator : ICSharpEntityTypeGenerator
{
private readonly ICSharpHelper _code;

private IndentedStringBuilder _sb = null!;
private IndentedStringBuilder _sb;
private bool _useDataAnnotations;

/// <summary>
Expand Down
33 changes: 9 additions & 24 deletions src/EFCore.Design/Scaffolding/Internal/CSharpModelGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand Down Expand Up @@ -77,20 +74,7 @@ public override ScaffoldedModel GenerateModel(
Check.NotNull(model, nameof(model));
Check.NotNull(options, nameof(options));

if (options.ContextName == null)
{
throw new ArgumentException($"{nameof(options.ContextName)} cannot be null", nameof(options));
}

if (options.ConnectionString == null)
{
throw new ArgumentException($"{nameof(options.ConnectionString)} cannot be null", nameof(options));
}

if (options.ModelNamespace == null)
{
throw new ArgumentException($"{nameof(options.ModelNamespace)} cannot be null", nameof(options));
}
var resultingFiles = new ScaffoldedModel();

var generatedCode = CSharpDbContextGenerator.WriteCode(
model,
Expand All @@ -103,12 +87,13 @@ public override ScaffoldedModel GenerateModel(

// output DbContext .cs file
var dbContextFileName = options.ContextName + FileExtension;
var resultingFiles = new ScaffoldedModel(
new ScaffoldedFile(
options.ContextDir != null
? Path.Combine(options.ContextDir, dbContextFileName)
: dbContextFileName,
generatedCode));
resultingFiles.ContextFile = new ScaffoldedFile
{
Path = options.ContextDir != null
? Path.Combine(options.ContextDir, dbContextFileName)
: dbContextFileName,
Code = generatedCode
};

foreach (var entityType in model.GetEntityTypes())
{
Expand All @@ -117,7 +102,7 @@ public override ScaffoldedModel GenerateModel(
// output EntityType poco .cs file
var entityTypeFileName = entityType.DisplayName() + FileExtension;
resultingFiles.AdditionalFiles.Add(
new ScaffoldedFile(entityTypeFileName, generatedCode));
new ScaffoldedFile { Path = entityTypeFileName, Code = generatedCode });
}

return resultingFiles;
Expand Down
6 changes: 2 additions & 4 deletions src/EFCore.Design/Scaffolding/Internal/CSharpNamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand All @@ -20,7 +18,7 @@ public class CSharpNamer<T>
{
private readonly Func<T, string> _nameGetter;
private readonly ICSharpUtilities _cSharpUtilities;
private readonly Func<string, string>? _singularizePluralizer;
private readonly Func<string, string> _singularizePluralizer;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -39,7 +37,7 @@ public class CSharpNamer<T>
public CSharpNamer(
[NotNull] Func<T, string> nameGetter,
[NotNull] ICSharpUtilities cSharpUtilities,
[CanBeNull] Func<string, string>? singularizePluralizer)
[CanBeNull] Func<string, string> singularizePluralizer)
{
Check.NotNull(nameGetter, nameof(nameGetter));
Check.NotNull(cSharpUtilities, nameof(cSharpUtilities));
Expand Down
8 changes: 3 additions & 5 deletions src/EFCore.Design/Scaffolding/Internal/CSharpUniqueNamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand All @@ -28,7 +26,7 @@ public class CSharpUniqueNamer<T> : CSharpNamer<T>
public CSharpUniqueNamer(
[NotNull] Func<T, string> nameGetter,
[NotNull] ICSharpUtilities cSharpUtilities,
[CanBeNull] Func<string, string>? singularizePluralizer)
[CanBeNull] Func<string, string> singularizePluralizer)
: this(nameGetter, null, cSharpUtilities, singularizePluralizer)
{
}
Expand All @@ -41,9 +39,9 @@ public CSharpUniqueNamer(
/// </summary>
public CSharpUniqueNamer(
[NotNull] Func<T, string> nameGetter,
[CanBeNull] IEnumerable<string>? usedNames,
[CanBeNull] IEnumerable<string> usedNames,
[NotNull] ICSharpUtilities cSharpUtilities,
[CanBeNull] Func<string, string>? singularizePluralizer)
[CanBeNull] Func<string, string> singularizePluralizer)
: base(nameGetter, cSharpUtilities, singularizePluralizer)
{
if (usedNames != null)
Expand Down
16 changes: 7 additions & 9 deletions src/EFCore.Design/Scaffolding/Internal/CSharpUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand Down Expand Up @@ -124,8 +122,8 @@ public virtual bool IsCSharpKeyword(string identifier)
/// </summary>
public virtual string GenerateCSharpIdentifier(
string identifier,
ICollection<string>? existingIdentifiers,
Func<string, string>? singularizePluralizer)
ICollection<string> existingIdentifiers,
Func<string, string> singularizePluralizer)
=> GenerateCSharpIdentifier(identifier, existingIdentifiers, singularizePluralizer, Uniquifier);

/// <summary>
Expand All @@ -136,9 +134,9 @@ public virtual string GenerateCSharpIdentifier(
/// </summary>
public virtual string GenerateCSharpIdentifier(
string identifier,
ICollection<string>? existingIdentifiers,
Func<string, string>? singularizePluralizer,
Func<string, ICollection<string>?, string> uniquifier)
ICollection<string> existingIdentifiers,
Func<string, string> singularizePluralizer,
Func<string, ICollection<string>, string> uniquifier)
{
Check.NotNull(identifier, nameof(identifier));
Check.NotNull(uniquifier, nameof(uniquifier));
Expand Down Expand Up @@ -179,7 +177,7 @@ public virtual string GenerateCSharpIdentifier(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string Uniquifier(
[NotNull] string proposedIdentifier, [CanBeNull] ICollection<string>? existingIdentifiers)
[NotNull] string proposedIdentifier, [CanBeNull] ICollection<string> existingIdentifiers)
{
Check.NotEmpty(proposedIdentifier, nameof(proposedIdentifier));

Expand All @@ -205,7 +203,7 @@ public virtual string Uniquifier(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool IsValidIdentifier(string? name)
public virtual bool IsValidIdentifier(string name)
{
if (string.IsNullOrEmpty(name))
{
Expand Down
10 changes: 6 additions & 4 deletions src/EFCore.Design/Scaffolding/Internal/CandidateNamingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand All @@ -28,7 +26,9 @@ public class CandidateNamingService : ICandidateNamingService
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string GenerateCandidateIdentifier(DatabaseTable originalTable)
=> GenerateCandidateIdentifier(originalTable.Name);
{
return GenerateCandidateIdentifier(originalTable.Name);
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -37,7 +37,9 @@ public virtual string GenerateCandidateIdentifier(DatabaseTable originalTable)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string GenerateCandidateIdentifier(DatabaseColumn originalColumn)
=> GenerateCandidateIdentifier(originalColumn.Name);
{
return GenerateCandidateIdentifier(originalColumn.Name);
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand All @@ -26,7 +24,7 @@ string WriteCode(
[NotNull] IModel model,
[NotNull] string contextName,
[NotNull] string connectionString,
[CanBeNull] string? contextNamespace,
[NotNull] string contextNamespace,
[NotNull] string modelNamespace,
bool useDataAnnotations,
bool suppressConnectionStringWarning);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand Down
12 changes: 5 additions & 7 deletions src/EFCore.Design/Scaffolding/Internal/ICSharpUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand All @@ -24,8 +22,8 @@ public interface ICSharpUtilities
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
string GenerateCSharpIdentifier(
[NotNull] string identifier, [CanBeNull] ICollection<string>? existingIdentifiers,
[CanBeNull] Func<string, string>? singularizePluralizer);
[NotNull] string identifier, [CanBeNull] ICollection<string> existingIdentifiers,
[CanBeNull] Func<string, string> singularizePluralizer);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -34,8 +32,8 @@ string GenerateCSharpIdentifier(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
string GenerateCSharpIdentifier(
[NotNull] string identifier, [CanBeNull] ICollection<string>? existingIdentifiers,
[CanBeNull] Func<string, string>? singularizePluralizer, [NotNull] Func<string, ICollection<string>?, string> uniquifier);
[NotNull] string identifier, [CanBeNull] ICollection<string> existingIdentifiers,
[CanBeNull] Func<string, string> singularizePluralizer, [NotNull] Func<string, ICollection<string>, string> uniquifier);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -51,6 +49,6 @@ string GenerateCSharpIdentifier(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
bool IsValidIdentifier([CanBeNull] string? name);
bool IsValidIdentifier([CanBeNull] string name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using JetBrains.Annotations;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
Expand All @@ -21,6 +19,6 @@ public interface IScaffoldingTypeMapper
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
TypeScaffoldingInfo? FindMapping([NotNull] string storeType, bool keyOrIndex, bool rowVersion);
TypeScaffoldingInfo FindMapping([NotNull] string storeType, bool keyOrIndex, bool rowVersion);
}
}
Loading

0 comments on commit 918d53a

Please sign in to comment.