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

Address feedback from STJ source-gen PR #51300 #52147

Merged
merged 2 commits into from
May 4, 2021

Conversation

layomia
Copy link
Contributor

@layomia layomia commented May 1, 2021

  • Adopt parser/emitter pattern in source generator (similar to logging and event source generators)
  • Enable localization for diagnostic descriptors
  • Move IsExternalInit.cs to common folder

@layomia layomia added this to the 6.0.0 milestone May 1, 2021
@layomia layomia self-assigned this May 1, 2021
@layomia layomia requested a review from jozkee as a code owner May 1, 2021 00:53
@ghost
Copy link

ghost commented May 1, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details
  • Adopt parser/emitter pattern in source generator (similar to logging and event source generators)
  • Enable localization for diagnostic descriptors
  • Move IsExternalInit.cs to common folder
Author: layomia
Assignees: layomia
Labels:

area-System.Text.Json

Milestone: 6.0.0

docs/project/list-of-diagnostics.md Show resolved Hide resolved
MetadataLoadContextInternal metadataLoadContext = new(compilation);
Parser parser = new(executionContext.Compilation);
SyntaxReceiver receiver = (SyntaxReceiver)executionContext.SyntaxReceiver;
_rootTypes = parser.GetRootSerializableTypes(receiver.CompilationUnits);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to check if reciever is null here?

Comparing with

public void Execute(GeneratorExecutionContext context)
{
if (context.SyntaxReceiver is not SyntaxReceiver receiver || receiver.ClassDeclarations.Count == 0)
{
// nothing to do yet
return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the source generators cookbook, it appears we don't have to check if the receiver is null:

// the generator infrastructure will create a receiver and populate it
// we can retrieve the populated instance via the context
MySyntaxReceiver syntaxReceiver = (MySyntaxReceiver)context.SyntaxReceiver;

// get the recorded user class
ClassDeclarationSyntax userClass = syntaxReceiver.ClassToAugment;

cc @jaredpar, @chsienki - do we need null checks for syntax receivers?

@layomia layomia requested a review from eerhardt May 3, 2021 22:45
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@layomia layomia merged commit fb931c6 into dotnet:main May 4, 2021
@layomia layomia deleted the SrcGenFollowUp branch May 4, 2021 15:48
@ghost ghost locked as resolved and limited conversation to collaborators Jun 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants