-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Polyfill the incremental generator ForAttributeWithMetadataName from roslyn (for JsonGenerator). #71653
Polyfill the incremental generator ForAttributeWithMetadataName from roslyn (for JsonGenerator). #71653
Changes from 1 commit
2799085
a2a9658
e8acee5
c212989
2b5a5a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,9 +41,10 @@ private sealed class Parser | |
private const string JsonPropertyNameAttributeFullName = "System.Text.Json.Serialization.JsonPropertyNameAttribute"; | ||
private const string JsonPropertyOrderAttributeFullName = "System.Text.Json.Serialization.JsonPropertyOrderAttribute"; | ||
private const string JsonSerializerContextFullName = "System.Text.Json.Serialization.JsonSerializerContext"; | ||
private const string JsonSerializableAttributeFullName = "System.Text.Json.Serialization.JsonSerializableAttribute"; | ||
private const string JsonSourceGenerationOptionsAttributeFullName = "System.Text.Json.Serialization.JsonSourceGenerationOptionsAttribute"; | ||
|
||
internal const string JsonSerializableAttributeFullName = "System.Text.Json.Serialization.JsonSerializableAttribute"; | ||
|
||
private const string DateOnlyFullName = "System.DateOnly"; | ||
private const string TimeOnlyFullName = "System.TimeOnly"; | ||
private const string IAsyncEnumerableFullName = "System.Collections.Generic.IAsyncEnumerable`1"; | ||
|
@@ -550,38 +551,6 @@ private static bool TryGetClassDeclarationList(INamedTypeSymbol typeSymbol, [Not | |
return typeGenerationSpec; | ||
} | ||
|
||
internal static bool IsSyntaxTargetForGeneration(SyntaxNode node) => node is ClassDeclarationSyntax { AttributeLists.Count: > 0, BaseList.Types.Count: > 0 }; | ||
|
||
internal static ClassDeclarationSyntax? GetSemanticTargetForGeneration(GeneratorSyntaxContext context, CancellationToken cancellationToken) | ||
{ | ||
var classDeclarationSyntax = (ClassDeclarationSyntax)context.Node; | ||
|
||
foreach (AttributeListSyntax attributeListSyntax in classDeclarationSyntax.AttributeLists) | ||
{ | ||
foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
|
||
IMethodSymbol attributeSymbol = context.SemanticModel.GetSymbolInfo(attributeSyntax, cancellationToken).Symbol as IMethodSymbol; | ||
if (attributeSymbol == null) | ||
{ | ||
continue; | ||
} | ||
|
||
INamedTypeSymbol attributeContainingTypeSymbol = attributeSymbol.ContainingType; | ||
string fullName = attributeContainingTypeSymbol.ToDisplayString(); | ||
|
||
if (fullName == JsonSerializableAttributeFullName) | ||
{ | ||
return classDeclarationSyntax; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Teh only check we did was that hte fully qualified name is what we want. that's exactly what roslyn now does, so we need no additional semantic checks once we move to the roslyn api. |
||
} | ||
} | ||
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
private static JsonSourceGenerationMode? GetJsonSourceGenerationModeEnumVal(SyntaxNode propertyValueMode) | ||
{ | ||
IEnumerable<string> enumTokens = propertyValueMode | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Collections.Generic | ||
{ | ||
/// <summary> | ||
/// These public methods are required by RegexWriter. | ||
eiriktsarpalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
internal ref partial struct ValueListBuilder<T> | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public T Pop() | ||
{ | ||
_pos--; | ||
return _span[_pos]; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand the purpose of this file. If it's a dependency for the added Roslyn helpers, why can't it just live inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It def can, and i've made that change in #71652. I'll port that over to this one. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved into the 3.11 source as that's the only place this is used now.