Skip to content

Commit

Permalink
Finishing up. Rebased snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDunn committed Sep 9, 2024
1 parent bb18f2b commit 3087943
Show file tree
Hide file tree
Showing 30,588 changed files with 1,147,130 additions and 222,945 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public sealed class MakeStructReadonlyCodeFixProvider : CodeFixProvider
private const string _title = "Make struct readonly";

public override ImmutableArray<string> FixableDiagnosticIds =>
// ReSharper disable once UseCollectionExpression
ImmutableArray.Create(RuleIdentifiers.UseReadonlyStructInsteadOfStruct);

public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class AddMethodCodeFixProvider : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
// ReSharper disable once UseCollectionExpression
get { return ImmutableArray.Create(RuleIdentifiers.AddNormalizeInputMethod); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Vogen.Rules.NormalizeInputMethodFixers
public class AddStaticToExistingMethodCodeFixProvider : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds =>
// ReSharper disable once UseCollectionExpression
ImmutableArray.Create(RuleIdentifiers.AddStaticToExistingNormalizeInputMethod);

public sealed override FixAllProvider GetFixAllProvider() => null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class AddMethodCodeFixProvider : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
// ReSharper disable once UseCollectionExpression
get { return ImmutableArray.Create(RuleIdentifiers.AddValidationMethod); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Vogen.Rules.ValidateMethodFixers
public class AddStaticToExistingMethodCodeFixProvider : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds =>
// ReSharper disable once UseCollectionExpression
ImmutableArray.Create(RuleIdentifiers.AddStaticToExistingValidationMethod);

public sealed override FixAllProvider GetFixAllProvider() => null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Vogen.Rules.ValidateMethodFixers
public class FixInputTypeCodeFixProvider : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds =>
// ReSharper disable once UseCollectionExpression
ImmutableArray.Create(RuleIdentifiers.FixInputTypeOfValidationMethod);

public sealed override FixAllProvider GetFixAllProvider() => null!;
Expand Down
12 changes: 4 additions & 8 deletions src/Vogen/GenerateCodeForTryParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ public static string GenerateAnyHoistedTryParseMethods(VoWorkItem item)

foreach (var eachSymbol in methodsToWrite)
{
BuildTryParseMethod(eachSymbol, sb, item);
BuildHoistedTryParseMethod(eachSymbol, sb, item);
}

return sb.ToString();
}
catch (Exception e)
{
throw new InvalidOperationException($"Cannot parse {primitiveSymbol} - {e}", e);

}

// We're given the TryParse methods on the primitive, and we want to filter out
Expand Down Expand Up @@ -79,7 +78,6 @@ private static string BuildTryParseMethodForAString(VoWorkItem item)
return string.Empty;
}

string wrapperQ = item.Nullable.QuestionMarkForWrapper;
string wrapperBang = item.Nullable.BangForWrapper;

return
Expand All @@ -89,7 +87,7 @@ private static string BuildTryParseMethodForAString(VoWorkItem item)
/// <returns>
/// True if the value passes any validation (after running any optional normalization).
/// </returns>
public static global::System.Boolean TryParse(global::System.String{{item.Nullable.QuestionMarkForOtherReferences}} s, global::System.IFormatProvider{{item.Nullable.QuestionMarkForOtherReferences}} provider, {{Util.GenerateNotNullWhenTrueAttribute()}} out {{item.VoTypeName}}{{wrapperQ}} result)
public static global::System.Boolean TryParse({{Util.GenerateNotNullWhenTrueAttribute()}} global::System.String{{item.Nullable.QuestionMarkForOtherReferences}} s, global::System.IFormatProvider{{item.Nullable.QuestionMarkForOtherReferences}} provider, {{Util.GenerateMaybeNullWhenFalse()}} out {{item.VoTypeName}} result)
{
if(s is null)
{
Expand All @@ -115,14 +113,12 @@ private static bool UserHasSuppliedTheirOwn(VoWorkItem item) =>
SymbolEqualityComparer.Default.Equals(m.Parameters[2].Type, item.WrapperType) &&
m.Parameters[2].RefKind == RefKind.Out);

private static void BuildTryParseMethod(IMethodSymbol methodSymbol, StringBuilder sb, VoWorkItem item)
private static void BuildHoistedTryParseMethod(IMethodSymbol methodSymbol, StringBuilder sb, VoWorkItem item)
{
string parameters = BuildParametersForTryParse(methodSymbol, item);
string parameterNames = BuildParameterNamesForTryParse(methodSymbol);
string staticOrNot = methodSymbol.IsStatic ? "static " : string.Empty;

string wrapperQm = item.Nullable.QuestionMarkForWrapper;

var inheritDocRef = methodSymbol.ToString()!
.Replace("<", "{")
.Replace(">", "}");
Expand All @@ -136,7 +132,7 @@ private static void BuildTryParseMethod(IMethodSymbol methodSymbol, StringBuilde
/// <returns>
/// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization).
/// </returns>
public {{staticOrNot}}global::System.Boolean TryParse({{parameters}}, {{Util.GenerateNotNullWhenTrueAttribute()}} out {{item.VoTypeName}}{{wrapperQm}} result)
public {{staticOrNot}}global::System.Boolean TryParse({{parameters}}, {{Util.GenerateNotNullWhenTrueAttribute()}} out {{item.VoTypeName}} result)
{
if({{item.UnderlyingTypeFullName}}.TryParse({{parameterNames}}, out var __v))
{
Expand Down
2 changes: 2 additions & 0 deletions src/Vogen/Generators/ClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ string Generate() => $@"
{GenerateHashCodes.GenerateGetHashCodeForAClass(item)}
#if NETCOREAPP3_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute(nameof(_value))]
[global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute(nameof(Value))]
#endif
private void EnsureInitialized()
{{
if (!IsInitialized())
Expand Down
2 changes: 2 additions & 0 deletions src/Vogen/Generators/RecordClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ string Generate() => $@"
{GenerateHashCodes.GenerateGetHashCodeForAClass(item)}
#if NETCOREAPP3_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute(nameof(_value))]
[global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute(nameof(Value))]
#endif
private void EnsureInitialized()
{{
if (!IsInitialized())
Expand Down
2 changes: 2 additions & 0 deletions src/Vogen/Generators/RecordStructGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ public readonly {itemUnderlyingType} Value
{GenerateHashCodes.GenerateForAStruct(item)}
#if NETCOREAPP3_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute(nameof(_value))]
[global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute(nameof(Value))]
#endif
private readonly void EnsureInitialized()
{{
if (!IsInitialized())
Expand Down
2 changes: 2 additions & 0 deletions src/Vogen/Generators/StructGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ public readonly {itemUnderlyingType} Value
{Util.GenerateToStringReadOnly(item)}
#if NETCOREAPP3_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute(nameof(_value))]
[global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute(nameof(Value))]
#endif
private readonly void EnsureInitialized()
{{
if (!IsInitialized())
Expand Down
1 change: 1 addition & 0 deletions src/Vogen/Rules/DoNotUseReflectionAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class DoNotUseReflectionAnalyzer : DiagnosticAnalyzer
isEnabledByDefault: true,
description: "Do not use Reflection to create Value Objects.");

// ReSharper disable once UseCollectionExpression
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(_rule);

public override void Initialize(AnalysisContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ExplicitlySpecifyTypeInValueObjectAttributeAnalyzer : DiagnosticAna
description:
"This rule checks that value objects explicitly specify the type of primitive that they wrap. Value objects that don't make this explicit can be harder to read and understand.");

// ReSharper disable once UseCollectionExpression
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(_rule);

public override void Initialize(AnalysisContext context)
Expand Down
1 change: 1 addition & 0 deletions src/Vogen/Rules/NormalizeInputMethodAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class NormalizeInputMethodAnalyzer : DiagnosticAnalyzer


public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
// ReSharper disable once UseCollectionExpression
ImmutableArray.Create(_ruleNotFound, RuleNotStatic, RuleWrongInputType);

public override void Initialize(AnalysisContext context)
Expand Down
2 changes: 2 additions & 0 deletions src/Vogen/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ public static string GenerateIsInitializedMethod(bool @readonly, VoWorkItem item
string accessibility = item.Config.IsInitializedMethodGeneration == IsInitializedMethodGeneration.Generate ? "public" : "private";
return $$"""
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
#if NETCOREAPP3_0_OR_GREATER
[global:: System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute(true, nameof(_value))]
[global:: System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute(true, nameof(Value))]
#endif
#if VOGEN_NO_VALIDATION
#pragma warning disable CS8775
{{accessibility}}{{ro}} bool IsInitialized() => true;
Expand Down
12 changes: 6 additions & 6 deletions tests/AnalyzerTests/DoNotUseConstructorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Whatever;
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{
diagnostics.Should().HaveCount(1);
Diagnostic diagnostic = diagnostics.Single();
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace Whatever;
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{
diagnostics.Should().HaveCount(1);
Diagnostic diagnostic = diagnostics.Single();
Expand Down Expand Up @@ -103,7 +103,7 @@ namespace Whatever;
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{
diagnostics.Should().HaveCount(1);
Diagnostic diagnostic = diagnostics.Single();
Expand Down Expand Up @@ -142,7 +142,7 @@ public CustomerId() {{ }}
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{

diagnostics.Should().HaveCount(1);
Expand Down Expand Up @@ -179,7 +179,7 @@ public CustomerId(int SomethingElse, string Name, int Age) {{ }}
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{

diagnostics.Should().HaveCount(1);
Expand Down Expand Up @@ -215,7 +215,7 @@ public CustomerId() {{ }}
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{

diagnostics.Should().HaveCount(1);
Expand Down
6 changes: 3 additions & 3 deletions tests/AnalyzerTests/InstanceFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Whatever
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{
#if NET7_0_OR_GREATER
diagnostics.Single().GetMessage().Should().Be(
Expand Down Expand Up @@ -61,7 +61,7 @@ public partial class MyInstanceTests { }
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{
diagnostics.Should().HaveCount(1);
diagnostics.Single().GetMessage().Should().Contain(
Expand Down Expand Up @@ -89,7 +89,7 @@ public partial class MyInstanceTests { }
.ValidateWith(Validate)
.RunOnAllFrameworks();

void Validate(ImmutableArray<Diagnostic> diagnostics)
static void Validate(ImmutableArray<Diagnostic> diagnostics)
{
diagnostics.Should().HaveCount(1);
diagnostics.Single().GetMessage().Should().Contain(
Expand Down
22 changes: 15 additions & 7 deletions tests/Shared/ProjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,23 @@ internal static class IsExternalInit {}
private static void DumpSource(Compilation outputCompilation)
{
string path = @"e:\temp\vogen-source";

int i = 0;
foreach (var st in outputCompilation.SyntaxTrees)

foreach (var eachSyntaxTree in outputCompilation.SyntaxTrees)
{
var s = st.GetText().ToString();
var fp = st.FilePath;
if (fp.Length == 0) fp = $"file{++i}.cs";
string p = Path.Combine(path, fp);
Directory.CreateDirectory(Path.GetDirectoryName(p)!);
File.WriteAllText(p, s.ToString());
string source = eachSyntaxTree.GetText().ToString();
var filePath = eachSyntaxTree.FilePath;
if (filePath.Length == 0)
{
filePath = $"file{++i}.cs";
}

string combinedPath = Path.Combine(path, filePath);

Directory.CreateDirectory(Path.GetDirectoryName(combinedPath)!);

File.WriteAllText(combinedPath, source);
}
}

Expand Down
Loading

0 comments on commit 3087943

Please sign in to comment.