Skip to content

Commit

Permalink
TypeFullyQualified has correct nullability by default
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGerr committed Sep 5, 2024
1 parent a9145e7 commit e3cc345
Show file tree
Hide file tree
Showing 44 changed files with 932 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ private AttributeInfo(
}
else if (attribute.AttributeClass.IsValueObjectValidationErrorAttribute())
{
validationError = new ValidationErrorState(attribute.AttributeClass.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
validationError = new ValidationErrorState(attribute.AttributeClass.TypeArguments[0].ToFullyQualifiedDisplayString());
}
else if (attribute.AttributeClass.IsValueObjectKeyMemberComparerAttribute())
{
keyMemberComparerAccessor = attribute.AttributeClass.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
keyMemberComparerAccessor = attribute.AttributeClass.TypeArguments[0].ToFullyQualifiedDisplayString();
}
else if (attribute.AttributeClass.IsValueObjectKeyMemberEqualityComparerAttribute())
{
keyMemberEqualityComparerAccessor = attribute.AttributeClass.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
keyMemberEqualityComparerAccessor = attribute.AttributeClass.TypeArguments[0].ToFullyQualifiedDisplayString();
}
else if (attribute.AttributeClass.IsSmartEnumAttribute()
|| attribute.AttributeClass.IsKeyedValueObjectAttribute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ public class CachedTypedMemberState : IEquatable<CachedTypedMemberState>, ITyped
private readonly int _hashCode;

public string TypeFullyQualified { get; }
public string TypeFullyQualifiedNullable { get; }
public string TypeFullyQualifiedNullAnnotated { get; }
public string TypeFullyQualifiedWithNullability { get; }
public string TypeMinimallyQualified { get; }
public SpecialType SpecialType { get; }
public bool IsReferenceType { get; }
Expand All @@ -28,9 +25,6 @@ public CachedTypedMemberState(ITypedMemberState typedMemberState)
_hashCode = typedMemberState.GetHashCode();

TypeFullyQualified = typedMemberState.TypeFullyQualified;
TypeFullyQualifiedNullable = typedMemberState.TypeFullyQualifiedNullable;
TypeFullyQualifiedNullAnnotated = typedMemberState.TypeFullyQualifiedNullAnnotated;
TypeFullyQualifiedWithNullability = typedMemberState.TypeFullyQualifiedWithNullability;
TypeMinimallyQualified = typedMemberState.TypeMinimallyQualified;
SpecialType = typedMemberState.SpecialType;
IsReferenceType = typedMemberState.IsReferenceType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void GenerateBaseTypes(StringBuilder sb, InterfaceCodeGeneratorState stat
{
sb.Append(@"
global::System.IComparable,
global::System.IComparable<").Append(state.Type.TypeFullyQualified).Append(">");
global::System.IComparable<").AppendTypeFullyQualified(state.Type).Append(">");
}

public void GenerateImplementation(StringBuilder sb, InterfaceCodeGeneratorState state)
Expand All @@ -32,14 +32,14 @@ public int CompareTo(object? obj)
if(obj is null)
return 1;
if(obj is not ").Append(state.Type.TypeFullyQualified).Append(@" item)
if(obj is not ").AppendTypeFullyQualified(state.Type).Append(@" item)
throw new global::System.ArgumentException(""Argument must be of type \""").Append(state.Type.TypeMinimallyQualified).Append(@"\""."", nameof(obj));
return this.CompareTo(item);
}
/// <inheritdoc />
public int CompareTo(").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(@" obj)
public int CompareTo(").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(@" obj)
{");

if (state.Type.IsReferenceType)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ public sealed class DefaultMemberState : IMemberState, IEquatable<DefaultMemberS

public SpecialType SpecialType => _typedMemberState.SpecialType;
public string TypeFullyQualified => _typedMemberState.TypeFullyQualified;
public string TypeFullyQualifiedNullAnnotated => _typedMemberState.TypeFullyQualifiedNullAnnotated;
public string TypeFullyQualifiedWithNullability => _typedMemberState.TypeFullyQualifiedWithNullability;
public bool IsReferenceType => _typedMemberState.IsReferenceType;
public bool IsFormattable => _typedMemberState.IsFormattable;
public bool IsComparable => _typedMemberState.IsComparable;
public bool IsParsable => _typedMemberState.IsParsable;
public ImplementedComparisonOperators ComparisonOperators => _typedMemberState.ComparisonOperators;
public bool IsNullableStruct => _typedMemberState.IsNullableStruct;
public NullableAnnotation NullableAnnotation => _typedMemberState.NullableAnnotation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class DesiredFactory : ITypeFullyQualified, IEquatable<DesiredFact
public DesiredFactory(ITypeSymbol type, SerializationFrameworks useForSerialization)
{
SpecialType = type.SpecialType;
TypeFullyQualified = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
TypeFullyQualified = type.ToFullyQualifiedDisplayString();
UseForSerialization = useForSerialization;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void AnalyzeSmartEnum(OperationAnalysisContext context)
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticsDescriptors.ErrorDuringCodeAnalysis,
Location.None,
type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), ex.Message));
type.ToFullyQualifiedDisplayString(), ex.Message));
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ private static void AnalyzeValueObject(OperationAnalysisContext context)
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticsDescriptors.ErrorDuringCodeAnalysis,
Location.None,
type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), ex.Message));
type.ToFullyQualifiedDisplayString(), ex.Message));
}
}

Expand Down Expand Up @@ -285,7 +285,7 @@ private static void ValidateCustomKeyMemberImplementation(
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticsDescriptors.ErrorDuringCodeAnalysis,
locationOfFirstDeclaration,
type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
type.ToFullyQualifiedDisplayString(),
"Could not fetch type information for analysis of the value object."));
return null;
}
Expand Down Expand Up @@ -370,7 +370,7 @@ private static void ValidateEnum(
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticsDescriptors.ErrorDuringCodeAnalysis,
locationOfFirstDeclaration,
enumType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
enumType.ToFullyQualifiedDisplayString(),
"Could not fetch type information for analysis of the smart enum."));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ private EqualityComparisonOperatorsCodeGenerator(
public void GenerateBaseTypes(StringBuilder sb, EqualityComparisonOperatorsGeneratorState state)
{
sb.Append(@"
global::System.Numerics.IEqualityOperators<").Append(state.Type.TypeFullyQualified).Append(", ").Append(state.Type.TypeFullyQualified).Append(", bool>");
global::System.Numerics.IEqualityOperators<").AppendTypeFullyQualified(state.Type).Append(", ").AppendTypeFullyQualified(state.Type).Append(", bool>");

if (!_withKeyTypeOverloads || state.KeyMember is null)
return;

sb.Append(@",
global::System.Numerics.IEqualityOperators<").Append(state.Type.TypeFullyQualified).Append(", ").Append(state.KeyMember.TypeFullyQualified).Append(", bool>");
global::System.Numerics.IEqualityOperators<").AppendTypeFullyQualified(state.Type).Append(", ").AppendTypeFullyQualified(state.KeyMember).Append(", bool>");
}

public void GenerateImplementation(StringBuilder sb, EqualityComparisonOperatorsGeneratorState state)
Expand All @@ -76,7 +76,7 @@ private static void GenerateUsingEquals(StringBuilder sb, EqualityComparisonOper
/// <param name=""obj"">Instance to compare.</param>
/// <param name=""other"">Another instance to compare.</param>
/// <returns><c>true</c> if objects are equal; otherwise <c>false</c>.</returns>
public static bool operator ==(").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(" obj, ").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(@" other)
public static bool operator ==(").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(" obj, ").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(@" other)
{");

if (state.Type.IsReferenceType)
Expand Down Expand Up @@ -110,7 +110,7 @@ private static void GenerateUsingEquals(StringBuilder sb, EqualityComparisonOper
/// <param name=""obj"">Instance to compare.</param>
/// <param name=""other"">Another instance to compare.</param>
/// <returns><c>false</c> if objects are equal; otherwise <c>true</c>.</returns>
public static bool operator !=(").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(" obj, ").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(@" other)
public static bool operator !=(").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(" obj, ").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(@" other)
{
return !(obj == other);
}");
Expand All @@ -125,7 +125,7 @@ private void GenerateKeyOverloads(

sb.Append(@"
private static bool Equals(").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(" obj, ").Append(state.KeyMember.TypeFullyQualified).Append(@" value)
private static bool Equals(").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(" obj, ").AppendTypeFullyQualified(state.KeyMember).Append(@" value)
{");

if (state.Type.IsReferenceType)
Expand Down Expand Up @@ -175,45 +175,45 @@ private static bool Equals(").Append(state.Type.TypeFullyQualifiedNullAnnotated)
}
/// <summary>
/// Compares an instance of <see cref=""").Append(state.Type.TypeMinimallyQualified).Append(@"""/> with <see cref=""").Append(state.KeyMember.TypeFullyQualified).Append(@"""/>.
/// Compares an instance of <see cref=""").Append(state.Type.TypeMinimallyQualified).Append(@"""/> with <see cref=""").AppendTypeFullyQualified(state.KeyMember).Append(@"""/>.
/// </summary>
/// <param name=""obj"">Instance to compare.</param>
/// <param name=""value"">Value to compare with.</param>
/// <returns><c>true</c> if objects are equal; otherwise <c>false</c>.</returns>
public static bool operator ==(").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(" obj, ").Append(state.KeyMember.TypeFullyQualified).Append(@" value)
public static bool operator ==(").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(" obj, ").AppendTypeFullyQualified(state.KeyMember).Append(@" value)
{
return Equals(obj, value);
}
/// <summary>
/// Compares an instance of <see cref=""").Append(state.Type.TypeMinimallyQualified).Append(@"""/> with <see cref=""").Append(state.KeyMember.TypeFullyQualified).Append(@"""/>.
/// Compares an instance of <see cref=""").Append(state.Type.TypeMinimallyQualified).Append(@"""/> with <see cref=""").AppendTypeFullyQualified(state.KeyMember).Append(@"""/>.
/// </summary>
/// <param name=""value"">Value to compare.</param>
/// <param name=""obj"">Instance to compare with.</param>
/// <returns><c>true</c> if objects are equal; otherwise <c>false</c>.</returns>
public static bool operator ==(").Append(state.KeyMember.TypeFullyQualified).Append(" value, ").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(@" obj)
public static bool operator ==(").AppendTypeFullyQualified(state.KeyMember).Append(" value, ").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(@" obj)
{
return Equals(obj, value);
}
/// <summary>
/// Compares an instance of <see cref=""").Append(state.Type.TypeMinimallyQualified).Append(@"""/> with <see cref=""").Append(state.KeyMember.TypeFullyQualified).Append(@"""/>.
/// Compares an instance of <see cref=""").Append(state.Type.TypeMinimallyQualified).Append(@"""/> with <see cref=""").AppendTypeFullyQualified(state.KeyMember).Append(@"""/>.
/// </summary>
/// <param name=""obj"">Instance to compare.</param>
/// <param name=""value"">Value to compare with.</param>
/// <returns><c>false</c> if objects are equal; otherwise <c>true</c>.</returns>
public static bool operator !=(").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(" obj, ").Append(state.KeyMember.TypeFullyQualified).Append(@" value)
public static bool operator !=(").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(" obj, ").AppendTypeFullyQualified(state.KeyMember).Append(@" value)
{
return !(obj == value);
}
/// <summary>
/// Compares an instance of <see cref=""").Append(state.KeyMember.TypeFullyQualified).Append(@"""/> with <see cref=""").Append(state.Type.TypeMinimallyQualified).Append(@"""/>.
/// Compares an instance of <see cref=""").AppendTypeFullyQualified(state.KeyMember).Append(@"""/> with <see cref=""").Append(state.Type.TypeMinimallyQualified).Append(@"""/>.
/// </summary>
/// <param name=""value"">Value to compare.</param>
/// <param name=""obj"">Instance to compare with.</param>
/// <returns><c>false</c> if objects are equal; otherwise <c>true</c>.</returns>
public static bool operator !=(").Append(state.KeyMember.TypeFullyQualified).Append(" value, ").Append(state.Type.TypeFullyQualifiedNullAnnotated).Append(@" obj)
public static bool operator !=(").AppendTypeFullyQualified(state.KeyMember).Append(" value, ").AppendTypeFullyQualifiedNullAnnotated(state.Type).Append(@" obj)
{
return !(obj == value);
}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace Thinktecture.CodeAnalysis;

public interface IMemberInformation : ITypeFullyQualified
public interface IMemberInformation : ITypeInformationWithNullability
{
string Name { get; }
bool IsReferenceType { get; }
SpecialType SpecialType { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ namespace Thinktecture.CodeAnalysis;
public interface IMemberState : IEquatable<IMemberState>, IMemberInformation, IHashCodeComputable
{
ArgumentName ArgumentName { get; }
string TypeFullyQualifiedNullAnnotated { get; }
string TypeFullyQualifiedWithNullability { get; }
bool IsNullableStruct { get; }
NullableAnnotation NullableAnnotation { get; }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace Thinktecture.CodeAnalysis;

public interface ITypeInformation : INamespaceAndName, ITypeFullyQualified
public interface ITypeInformation : INamespaceAndName, ITypeInformationWithNullability
{
string TypeMinimallyQualified { get; }
string TypeFullyQualifiedNullAnnotated { get; }
bool IsReferenceType { get; }
bool IsEqualWithReferenceEquality { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Thinktecture.CodeAnalysis;

public interface ITypeInformationWithNullability : ITypeFullyQualified
{
bool IsReferenceType { get; }
NullableAnnotation NullableAnnotation { get; }
bool IsNullableStruct { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ namespace Thinktecture.CodeAnalysis;
public interface ITypedMemberState : IEquatable<ITypedMemberState>
{
string TypeFullyQualified { get; }
string TypeFullyQualifiedNullable { get; }
string TypeFullyQualifiedNullAnnotated { get; }
string TypeFullyQualifiedWithNullability { get; }
string TypeMinimallyQualified { get; }
SpecialType SpecialType { get; }
bool IsReferenceType { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@ public sealed class InstanceMemberInfo : IMemberState, IEquatable<InstanceMember

public SpecialType SpecialType => _typedMemberState.SpecialType;
public string TypeFullyQualified => _typedMemberState.TypeFullyQualified;
public string TypeFullyQualifiedNullAnnotated => _typedMemberState.TypeFullyQualifiedNullAnnotated;
public string TypeFullyQualifiedWithNullability => _typedMemberState.TypeFullyQualifiedWithNullability;
public string TypeMinimallyQualified => _typedMemberState.TypeMinimallyQualified;
public bool IsReferenceType => _typedMemberState.IsReferenceType;
public bool IsReferenceTypeOrNullableStruct => _typedMemberState.IsReferenceTypeOrNullableStruct;
public bool IsFormattable => _typedMemberState.IsFormattable;
public bool IsComparable => _typedMemberState.IsComparable;
public bool IsParsable => _typedMemberState.IsParsable;
public bool IsNullableStruct => _typedMemberState.IsNullableStruct;
public NullableAnnotation NullableAnnotation => _typedMemberState.NullableAnnotation;
public ImplementedComparisonOperators ComparisonOperators => _typedMemberState.ComparisonOperators;

private InstanceMemberInfo(
ITypedMemberState typedMemberState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public sealed class KeyMemberState : IMemberState, IEquatable<KeyMemberState>

public SpecialType SpecialType => _typedMemberState.SpecialType;
public string TypeFullyQualified => _typedMemberState.TypeFullyQualified;
public string TypeFullyQualifiedNullable => _typedMemberState.TypeFullyQualifiedNullable;
public string TypeFullyQualifiedNullAnnotated => _typedMemberState.TypeFullyQualifiedNullAnnotated;
public string TypeFullyQualifiedWithNullability => _typedMemberState.TypeFullyQualifiedWithNullability;
public bool IsReferenceType => _typedMemberState.IsReferenceType;
public bool IsFormattable => _typedMemberState.IsFormattable;
public bool IsComparable => _typedMemberState.IsComparable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace ").Append(_state.Type.Namespace).Append(@";
if (!isString)
_sb.Append(keyType).Append(", ");

_sb.Append(_state.AttributeInfo.ValidationError.TypeFullyQualified).Append(@">))]
_sb.AppendTypeFullyQualified(_state.AttributeInfo.ValidationError).Append(@">))]
partial ").Append(_state.Type.IsReferenceType ? "class" : "struct").Append(" ").Append(_state.Type.Name).Append(@"
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace ").Append(_state.Type.Namespace).Append(@";
}

_sb.Append(@"
[global::MessagePack.MessagePackFormatter(typeof(global::Thinktecture.Formatters.").Append(_state.Type.IsReferenceType ? "ValueObjectMessagePackFormatter" : "StructValueObjectMessagePackFormatter").Append("<").Append(_state.Type.TypeFullyQualified).Append(", ").Append(keyType).Append(", ").Append(_state.AttributeInfo.ValidationError.TypeFullyQualified).Append(@">))]
[global::MessagePack.MessagePackFormatter(typeof(global::Thinktecture.Formatters.").Append(_state.Type.IsReferenceType ? "ValueObjectMessagePackFormatter" : "StructValueObjectMessagePackFormatter").Append("<").AppendTypeFullyQualified(_state.Type).Append(", ").Append(keyType).Append(", ").Append(_state.AttributeInfo.ValidationError.TypeFullyQualified).Append(@">))]
partial ").Append(_state.Type.IsReferenceType ? "class" : "struct").Append(" ").Append(_state.Type.Name).Append(@"
{
}
Expand Down
Loading

0 comments on commit e3cc345

Please sign in to comment.