Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Touch-ups on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Aug 20, 2018
1 parent c5c79fb commit a956836
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 52 deletions.
12 changes: 7 additions & 5 deletions src/CodeGeneration.Roslyn.Tests.Generators/RichBaseGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ public RichGenerationContext AddMember(MemberDeclarationSyntax memberDeclaration

public RichGenerationResult CreateResult()
{
return new RichGenerationResult(
SyntaxFactory.List(Members),
SyntaxFactory.List(Usings),
SyntaxFactory.List(AttributeLists),
SyntaxFactory.List(Externs));
return new RichGenerationResult
{
Members = SyntaxFactory.List(Members),
Usings = SyntaxFactory.List(Usings),
AttributeLists = SyntaxFactory.List(AttributeLists),
Externs = SyntaxFactory.List(Externs),
};
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/CodeGeneration.Roslyn/DocumentTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ public static async Task<SyntaxTree> TransformAsync(

var richGenerator = generator as IRichCodeGenerator ?? new EnrichingCodeGeneratorProxy(generator);

var (members, usings, attributeLists, externs) =
await richGenerator.GenerateRichAsync(context, progress, CancellationToken.None);
var emitted = await richGenerator.GenerateRichAsync(context, progress, CancellationToken.None);

emittedExterns = emittedExterns.AddRange(externs);
emittedUsings = emittedUsings.AddRange(usings);
emittedAttributeLists = emittedAttributeLists.AddRange(attributeLists);
emittedMembers = emittedMembers.AddRange(members);
emittedExterns = emittedExterns.AddRange(emitted.Externs);
emittedUsings = emittedUsings.AddRange(emitted.Usings);
emittedAttributeLists = emittedAttributeLists.AddRange(emitted.AttributeLists);
emittedMembers = emittedMembers.AddRange(emitted.Members);
}
}

Expand Down Expand Up @@ -211,6 +210,7 @@ private class EnrichingCodeGeneratorProxy : IRichCodeGenerator
{
public EnrichingCodeGeneratorProxy(ICodeGenerator codeGenerator)
{
Requires.NotNull(codeGenerator, nameof(codeGenerator));
CodeGenerator = codeGenerator;
}

Expand All @@ -229,7 +229,7 @@ public async Task<RichGenerationResult> GenerateRichAsync(TransformationContext
var generatedMembers = await CodeGenerator.GenerateAsync(context, progress, CancellationToken.None);
// Figure out ancestry for the generated type, including nesting types and namespaces.
var wrappedMembers = context.ProcessingNode.Ancestors().Aggregate(generatedMembers, WrapInAncestor);
return new RichGenerationResult(wrappedMembers);
return new RichGenerationResult { Members = wrappedMembers };
}

private static SyntaxList<MemberDeclarationSyntax> WrapInAncestor(SyntaxList<MemberDeclarationSyntax> generatedMembers, SyntaxNode ancestor)
Expand Down
48 changes: 8 additions & 40 deletions src/CodeGeneration.Roslyn/RichGenerationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,23 @@ namespace CodeGeneration.Roslyn
public struct RichGenerationResult
{
/// <summary>
/// Creates <see cref="RichGenerationResult"/> with provided arguments as property values.
/// Gets or sets the <see cref="MemberDeclarationSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
/// </summary>
/// <param name="members">Assigned to <see cref="Members"/>.</param>
/// <param name="usings">Assigned to <see cref="Usings"/>.</param>
/// <param name="attributeLists">Assigned to <see cref="AttributeLists"/>.</param>
/// <param name="externs">Assigned to <see cref="Externs"/>.</param>
[DebuggerStepThrough]
public RichGenerationResult(
SyntaxList<MemberDeclarationSyntax> members,
SyntaxList<UsingDirectiveSyntax> usings = default,
SyntaxList<AttributeListSyntax> attributeLists = default,
SyntaxList<ExternAliasDirectiveSyntax> externs = default)
{
Members = members;
Usings = usings;
AttributeLists = attributeLists;
Externs = externs;
}
public SyntaxList<MemberDeclarationSyntax> Members { get; set; }

/// <summary>
/// Gets <see cref="MemberDeclarationSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
/// Gets or sets the <see cref="UsingDirectiveSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
/// </summary>
public SyntaxList<MemberDeclarationSyntax> Members { get; }
public SyntaxList<UsingDirectiveSyntax> Usings { get; set; }

/// <summary>
/// Gets <see cref="UsingDirectiveSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
/// Gets or sets the <see cref="ExternAliasDirectiveSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
/// </summary>
public SyntaxList<UsingDirectiveSyntax> Usings { get; }
public SyntaxList<ExternAliasDirectiveSyntax> Externs { get; set; }

/// <summary>
/// Gets <see cref="ExternAliasDirectiveSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
/// Gets or sets the <see cref="AttributeListSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
/// </summary>
public SyntaxList<ExternAliasDirectiveSyntax> Externs { get; }

/// <summary>
/// Gets <see cref="AttributeListSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
/// </summary>
public SyntaxList<AttributeListSyntax> AttributeLists { get; }

[DebuggerHidden, DebuggerStepThrough]
public void Deconstruct(out SyntaxList<MemberDeclarationSyntax> members,
out SyntaxList<UsingDirectiveSyntax> usings,
out SyntaxList<AttributeListSyntax> attributeLists,
out SyntaxList<ExternAliasDirectiveSyntax> externs)
{
members = Members;
usings = Usings;
attributeLists = AttributeLists;
externs = Externs;
}
public SyntaxList<AttributeListSyntax> AttributeLists { get; set; }
}
}

0 comments on commit a956836

Please sign in to comment.