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

Fix null exception for array types #93

Merged
merged 1 commit into from
Sep 10, 2024
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
4 changes: 2 additions & 2 deletions src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace NexusMods.MnemonicDB.SourceGenerator;

public class AnalyzedAttribute

Check warning on line 6 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute'

Check warning on line 6 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute'

Check warning on line 6 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute'

Check warning on line 6 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute'
{
public string Name { get; set; } = "";

Check warning on line 8 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.Name'

Check warning on line 8 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.Name'

Check warning on line 8 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.Name'

Check warning on line 8 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.Name'
public string FieldName { get; set; } = "";

Check warning on line 9 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.FieldName'

Check warning on line 9 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.FieldName'

Check warning on line 9 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.FieldName'

Check warning on line 9 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.FieldName'

public string ContextualName

Check warning on line 11 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.ContextualName'

Check warning on line 11 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.ContextualName'

Check warning on line 11 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.ContextualName'

Check warning on line 11 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.ContextualName'
{
get
{
Expand All @@ -24,11 +24,11 @@
}
}

public bool IsReference => Flags.HasFlag(AttributeFlags.Reference);

Check warning on line 27 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsReference'

Check warning on line 27 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsReference'

Check warning on line 27 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsReference'

Check warning on line 27 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsReference'
public bool IsCollection => Flags.HasFlag(AttributeFlags.Collection);

Check warning on line 28 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsCollection'

Check warning on line 28 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsCollection'

Check warning on line 28 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsCollection'

Check warning on line 28 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsCollection'
public bool IsScalar => Flags.HasFlag(AttributeFlags.Scalar);

Check warning on line 29 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsScalar'

Check warning on line 29 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsScalar'

Check warning on line 29 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsScalar'

Check warning on line 29 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsScalar'
public bool IsIndexed => Markers.Contains("IsIndexed");

Check warning on line 30 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsIndexed'

Check warning on line 30 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsIndexed'

Check warning on line 30 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsIndexed'

Check warning on line 30 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsIndexed'
public bool IsOptional => Markers.Contains("IsOptional");

Check warning on line 31 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsOptional'

Check warning on line 31 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsOptional'

Check warning on line 31 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsOptional'

Check warning on line 31 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.IsOptional'

/// <summary>
/// True if this is a value type.
Expand All @@ -50,10 +50,10 @@
/// </summary>
public bool IsMarker => Flags.HasFlag(AttributeFlags.Marker);

public AttributeFlags Flags { get; set; }

Check warning on line 53 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.Flags'

Check warning on line 53 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (windows-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.Flags'

Check warning on line 53 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.Flags'

Check warning on line 53 in src/NexusMods.MnemonicDB.SourceGenerator/AnalyzedAttribute.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-13)

Missing XML comment for publicly visible type or member 'AnalyzedAttribute.Flags'
public INamedTypeSymbol AttributeType { get; set; } = null!;
public INamedTypeSymbol HighLevelType { get; set; } = null!;
public INamedTypeSymbol LowLevelType { get; set; } = null!;
public ITypeSymbol HighLevelType { get; set; } = null!;
public ITypeSymbol LowLevelType { get; set; } = null!;
public INamedTypeSymbol ReferenceType { get; set; } = null!;
public HashSet<string> Markers { get; set; } = new();
public string Comments { get; set; } = "";
Expand Down
12 changes: 8 additions & 4 deletions src/NexusMods.MnemonicDB.SourceGenerator/ModelAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -243,8 +244,8 @@ private HashSet<string> GetInitializerData(IFieldSymbol fieldSymbol)
}

private bool TryGetAttributeTypes(IFieldSymbol fieldSymbol,
out INamedTypeSymbol? highLevel,
out INamedTypeSymbol? lowLevel,
out ITypeSymbol? highLevel,
out ITypeSymbol? lowLevel,
out AttributeFlags flags)
{
var type = fieldSymbol.Type;
Expand All @@ -267,13 +268,16 @@ private bool TryGetAttributeTypes(IFieldSymbol fieldSymbol,

if (SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, _attributeTypeSymbol))
{
highLevel = (namedTypeSymbol.TypeArguments[0] as INamedTypeSymbol)!;
Debug.Assert(namedTypeSymbol.TypeArguments.Length == 2);

highLevel = namedTypeSymbol.TypeArguments[0];
if (SymbolEqualityComparer.Default.Equals(highLevel, _entityIdTypeSymbol))
flags |= AttributeFlags.Reference;

lowLevel = (namedTypeSymbol.TypeArguments[1] as INamedTypeSymbol)!;
lowLevel = namedTypeSymbol.TypeArguments[1];
return true;
}

type = namedTypeSymbol.BaseType;
}
else
Expand Down
Loading
Loading