Skip to content
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
2 changes: 1 addition & 1 deletion docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
| __`SYSLIB1221`__ | JsonSourceGenerator does not support this C# language version. |
| __`SYSLIB1222`__ | Constructor annotated with JsonConstructorAttribute is inaccessible. |
| __`SYSLIB1223`__ | Attributes deriving from JsonConverterAttribute are not supported by the source generator. |
| __`SYSLIB1224`__ | *`SYSLIB1220`-`SYSLIB229` reserved for System.Text.Json.SourceGeneration.* |
| __`SYSLIB1224`__ | Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. |
| __`SYSLIB1225`__ | *`SYSLIB1220`-`SYSLIB229` reserved for System.Text.Json.SourceGeneration.* |
| __`SYSLIB1226`__ | *`SYSLIB1220`-`SYSLIB229` reserved for System.Text.Json.SourceGeneration.* |
| __`SYSLIB1227`__ | *`SYSLIB1220`-`SYSLIB229` reserved for System.Text.Json.SourceGeneration.* |
Expand Down
15 changes: 10 additions & 5 deletions src/libraries/System.Text.Json/gen/Helpers/RoslynExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ internal static class RoslynExtensions

public static string GetFullyQualifiedName(this ITypeSymbol type) => type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);

public static Location? GetDiagnosticLocation(this ISymbol typeSymbol)
public static Location? GetLocation(this ISymbol typeSymbol)
=> typeSymbol.Locations.Length > 0 ? typeSymbol.Locations[0] : null;

public static Location? GetDiagnosticLocation(this AttributeData attributeData)
public static Location? GetLocation(this AttributeData attributeData)
{
SyntaxReference? reference = attributeData.ApplicationSyntaxReference;
return reference?.SyntaxTree.GetLocation(reference.Span);
Expand All @@ -39,9 +39,14 @@ internal static class RoslynExtensions
/// <summary>
/// Creates a copy of the Location instance that does not capture a reference to Compilation.
/// </summary>
[return: NotNullIfNotNull(nameof(location))]
public static Location? GetTrimmedLocation(this Location? location)
=> location is null ? null : Location.Create(location.SourceTree?.FilePath ?? "", location.SourceSpan, location.GetLineSpan().Span);
public static Location GetTrimmedLocation(this Location location)
=> Location.Create(location.SourceTree?.FilePath ?? "", location.SourceSpan, location.GetLineSpan().Span);

/// <summary>
/// Returns true if the specified location is contained in one of the syntax trees in the compilation.
/// </summary>
public static bool ContainsLocation(this Compilation compilation, Location location)
=> location.SourceTree != null && compilation.ContainsSyntaxTree(location.SourceTree);

/// <summary>
/// Removes any type metadata that is erased at compile time, such as NRT annotations and tuple labels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ internal static class DiagnosticDescriptors
category: JsonConstants.SystemTextJsonSourceGenerationName,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static DiagnosticDescriptor JsonSerializableAttributeOnNonContextType { get; } = new DiagnosticDescriptor(
id: "SYSLIB1224",
title: new LocalizableResourceString(nameof(SR.JsonSerializableAttributeOnNonContextTypeTitle), SR.ResourceManager, typeof(FxResources.System.Text.Json.SourceGeneration.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.JsonSerializableAttributeOnNonContextTypeMessageFormat), SR.ResourceManager, typeof(FxResources.System.Text.Json.SourceGeneration.SR)),
category: JsonConstants.SystemTextJsonSourceGenerationName,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);
}
}
}
117 changes: 67 additions & 50 deletions src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/libraries/System.Text.Json/gen/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DuplicateTypeNameMessageFormat" xml:space="preserve">
<value>There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</value>
<value>There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</value>
</data>
<data name="DuplicateTypeNameTitle" xml:space="preserve">
<value>Duplicate type name.</value>
Expand Down Expand Up @@ -201,4 +201,10 @@
<data name="JsonConstructorInaccessibleMessageFormat" xml:space="preserve">
<value>The constructor on type '{0}' has been annotated with JsonConstructorAttribute but is not accessible by the source generator.</value>
</data>
<data name="JsonSerializableAttributeOnNonContextTypeTitle" xml:space="preserve">
<value>Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</value>
</data>
<data name="JsonSerializableAttributeOnNonContextTypeMessageFormat" xml:space="preserve">
<value>The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</value>
</data>
</root>
14 changes: 12 additions & 2 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameMessageFormat">
<source>There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="translated">Existuje několik typů s názvem {0}. Zdroj se vygeneroval pro první zjištěný typ. Tuto kolizi vyřešíte pomocí JsonSerializableAttribute.TypeInfoPropertyName.</target>
<source>There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="needs-review-translation">Existuje několik typů s názvem {0}. Zdroj se vygeneroval pro první zjištěný typ. Tuto kolizi vyřešíte pomocí JsonSerializableAttribute.TypeInfoPropertyName.</target>
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameTitle">
Expand Down Expand Up @@ -92,6 +92,16 @@
<target state="translated">JsonConverterAttribute.Type obsahuje neplatný nebo nepřístupný argument.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeMessageFormat">
<source>The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</source>
<target state="new">The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeTitle">
<source>Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</source>
<target state="new">Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</target>
<note />
</trans-unit>
<trans-unit id="JsonStringEnumConverterNotSupportedMessageFormat">
<source>The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter&lt;TEnum&gt;' instead.</source>
<target state="translated">Člen {0} byl opatřen poznámkou jsonStringEnumConverter, což není v nativním AOT podporováno. Zvažte použití obecného objektu JsonStringEnumConverter&lt;TEnum&gt;.</target>
Expand Down
14 changes: 12 additions & 2 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameMessageFormat">
<source>There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="translated">Es sind mehrere Typen namens "{0}" vorhanden. Die Quelle wurde für den ersten festgestellten Typ generiert. Verwenden Sie "JsonSerializableAttribute.TypeInfoPropertyName", um diesen Konflikt zu beheben.</target>
<source>There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="needs-review-translation">Es sind mehrere Typen namens "{0}" vorhanden. Die Quelle wurde für den ersten festgestellten Typ generiert. Verwenden Sie "JsonSerializableAttribute.TypeInfoPropertyName", um diesen Konflikt zu beheben.</target>
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameTitle">
Expand Down Expand Up @@ -92,6 +92,16 @@
<target state="translated">"JsonConverterAttribute.Type" enthält ein ungültiges oder nicht zugängliches Argument.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeMessageFormat">
<source>The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</source>
<target state="new">The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeTitle">
<source>Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</source>
<target state="new">Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</target>
<note />
</trans-unit>
<trans-unit id="JsonStringEnumConverterNotSupportedMessageFormat">
<source>The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter&lt;TEnum&gt;' instead.</source>
<target state="translated">Der Member "{0}" wurde mit "JsonStringEnumConverter" kommentiert, was in nativem AOT nicht unterstützt wird. Erwägen Sie stattdessen die Verwendung des generischen "JsonStringEnumConverter&lt;TEnum&gt;".</target>
Expand Down
14 changes: 12 additions & 2 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameMessageFormat">
<source>There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="translated">Hay varios tipos denominados {0}. El origen se generó para el primero detectado. Use "JsonSerializableAttribute.TypeInfoPropertyName" para resolver esta colisión.</target>
<source>There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="needs-review-translation">Hay varios tipos denominados {0}. El origen se generó para el primero detectado. Use "JsonSerializableAttribute.TypeInfoPropertyName" para resolver esta colisión.</target>
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameTitle">
Expand Down Expand Up @@ -92,6 +92,16 @@
<target state="translated">“JsonConverterAttribute.Type” contiene un argumento no válido o inaccesible.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeMessageFormat">
<source>The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</source>
<target state="new">The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeTitle">
<source>Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</source>
<target state="new">Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</target>
<note />
</trans-unit>
<trans-unit id="JsonStringEnumConverterNotSupportedMessageFormat">
<source>The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter&lt;TEnum&gt;' instead.</source>
<target state="translated">El miembro '{0}' se ha anotado con 'JsonStringEnumConverter', que no se admite en AOT nativo. Considere la posibilidad de usar el elemento genérico "JsonStringEnumConverter&lt;TEnum&gt;" en su lugar.</target>
Expand Down
14 changes: 12 additions & 2 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameMessageFormat">
<source>There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="translated">Plusieurs types nommés {0}. La source a été générée pour la première détection détectée. Utilisez « JsonSerializableAttribute.TypeInfoPropertyName » pour résoudre cette collision.</target>
<source>There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="needs-review-translation">Plusieurs types nommés {0}. La source a été générée pour la première détection détectée. Utilisez « JsonSerializableAttribute.TypeInfoPropertyName » pour résoudre cette collision.</target>
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameTitle">
Expand Down Expand Up @@ -92,6 +92,16 @@
<target state="translated">'JsonConverterAttribute.Type' contient un argument non valide ou inaccessible.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeMessageFormat">
<source>The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</source>
<target state="new">The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeTitle">
<source>Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</source>
<target state="new">Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</target>
<note />
</trans-unit>
<trans-unit id="JsonStringEnumConverterNotSupportedMessageFormat">
<source>The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter&lt;TEnum&gt;' instead.</source>
<target state="translated">Le membre '{0}' a été annoté avec 'JsonStringEnumConverter', ce qui n’est pas pris en charge dans AOT natif. Utilisez plutôt le générique 'JsonStringEnumConverter&lt;TEnum&gt;'.</target>
Expand Down
14 changes: 12 additions & 2 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameMessageFormat">
<source>There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="translated">Sono presenti più tipi denominati {0}. L'origine è stata generata per il primo tipo rilevato. Per risolvere questa collisione, usare 'JsonSerializableAttribute.TypeInfoPropertyName'.</target>
<source>There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.</source>
<target state="needs-review-translation">Sono presenti più tipi denominati {0}. L'origine è stata generata per il primo tipo rilevato. Per risolvere questa collisione, usare 'JsonSerializableAttribute.TypeInfoPropertyName'.</target>
<note />
</trans-unit>
<trans-unit id="DuplicateTypeNameTitle">
Expand Down Expand Up @@ -92,6 +92,16 @@
<target state="translated">'JsonConverterAttribute.Type' contiene un argomento non valido o inaccessibile.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeMessageFormat">
<source>The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</source>
<target state="new">The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated.</target>
<note />
</trans-unit>
<trans-unit id="JsonSerializableAttributeOnNonContextTypeTitle">
<source>Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</source>
<target state="new">Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext.</target>
<note />
</trans-unit>
<trans-unit id="JsonStringEnumConverterNotSupportedMessageFormat">
<source>The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter&lt;TEnum&gt;' instead.</source>
<target state="translated">Il membro '{0}' è stato annotato con 'JsonStringEnumConverter' che non è supportato in AOT nativo. Provare a usare il generico 'JsonStringEnumConverter&lt;TEnum&gt;'.</target>
Expand Down
Loading