Skip to content

Commit 363a36c

Browse files
authored
Merge pull request #3246 from sharwell/generate-lightup-2
Generate syntax wrappers in the lightup layer
2 parents 8d2a0a0 + 237ea8e commit 363a36c

File tree

79 files changed

+10214
-1395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+10214
-1395
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1141CodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static SyntaxNode GetReplacementNode(SemanticModel semanticModel, Syntax
104104

105105
private static SyntaxNode TransformGenericNameToTuple(SemanticModel semanticModel, GenericNameSyntax genericName)
106106
{
107-
var implementationType = typeof(SeparatedSyntaxListWrapper<>.AutoWrapSeparatedSyntaxList<>).MakeGenericType(typeof(TupleElementSyntaxWrapper), WrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper)));
107+
var implementationType = typeof(SeparatedSyntaxListWrapper<>.AutoWrapSeparatedSyntaxList<>).MakeGenericType(typeof(TupleElementSyntaxWrapper), SyntaxWrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper)));
108108
var tupleElements = (SeparatedSyntaxListWrapper<TupleElementSyntaxWrapper>)Activator.CreateInstance(implementationType);
109109

110110
foreach (var typeArgument in genericName.TypeArgumentList.Arguments)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.CodeGeneration
5+
{
6+
using System;
7+
using Microsoft.CodeAnalysis;
8+
using Microsoft.CodeAnalysis.CSharp;
9+
10+
internal static class GeneratorSyntaxExtensions
11+
{
12+
public static TSyntax WithLeadingBlankLine<TSyntax>(this TSyntax syntax)
13+
where TSyntax : SyntaxNode
14+
{
15+
return syntax.WithLeadingTrivia(SyntaxFactory.TriviaList(
16+
SyntaxFactory.PreprocessingMessage(Environment.NewLine)));
17+
}
18+
}
19+
}

StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ private void GenerateOperationInterface(in GeneratorExecutionContext context, In
179179
identifier: SyntaxFactory.Identifier(node.WrapperName),
180180
parameterList: SyntaxFactory.ParameterList(),
181181
initializer: null,
182-
body: SyntaxFactory.Block(staticCtorStatements)));
182+
body: SyntaxFactory.Block(staticCtorStatements),
183+
expressionBody: null));
183184

184185
// private IArgumentOperationWrapper(IOperation operation)
185186
// {
@@ -203,7 +204,8 @@ private void GenerateOperationInterface(in GeneratorExecutionContext context, In
203204
SyntaxKind.SimpleMemberAccessExpression,
204205
expression: SyntaxFactory.ThisExpression(),
205206
name: SyntaxFactory.IdentifierName("operation")),
206-
right: SyntaxFactory.IdentifierName("operation"))))));
207+
right: SyntaxFactory.IdentifierName("operation")))),
208+
expressionBody: null));
207209

208210
// public IOperation WrappedOperation => this.operation;
209211
members = members.Add(SyntaxFactory.PropertyDeclaration(
@@ -679,8 +681,14 @@ private void GenerateOperationWrapperHelper(in GeneratorExecutionContext context
679681
identifier: SyntaxFactory.Identifier("OperationWrapperHelper"),
680682
parameterList: SyntaxFactory.ParameterList(),
681683
initializer: null,
682-
body: SyntaxFactory.Block(staticCtorStatements));
684+
body: SyntaxFactory.Block(staticCtorStatements),
685+
expressionBody: null);
683686

687+
// /// <summary>
688+
// /// Gets the type that is wrapped by the given wrapper.
689+
// /// </summary>
690+
// /// <param name="wrapperType">Type of the wrapper for which the wrapped type should be retrieved.</param>
691+
// /// <returns>The wrapped type, or null if there is no info.</returns>
684692
// internal static Type GetWrappedType(Type wrapperType)
685693
// {
686694
// if (WrappedTypes.TryGetValue(wrapperType, out Type wrappedType))
@@ -727,6 +735,25 @@ private void GenerateOperationWrapperHelper(in GeneratorExecutionContext context
727735
SyntaxFactory.ReturnStatement(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression))),
728736
expressionBody: null);
729737

738+
getWrappedType = getWrappedType.WithLeadingTrivia(SyntaxFactory.TriviaList(
739+
SyntaxFactory.Trivia(SyntaxFactory.DocumentationComment(
740+
SyntaxFactory.XmlText(" "),
741+
SyntaxFactory.XmlSummaryElement(
742+
SyntaxFactory.XmlNewLine(Environment.NewLine),
743+
SyntaxFactory.XmlText(" Gets the type that is wrapped by the given wrapper."),
744+
SyntaxFactory.XmlNewLine(Environment.NewLine),
745+
SyntaxFactory.XmlText(" ")),
746+
SyntaxFactory.XmlNewLine(Environment.NewLine),
747+
SyntaxFactory.XmlText(" "),
748+
SyntaxFactory.XmlParamElement(
749+
"wrapperType",
750+
SyntaxFactory.XmlText("Type of the wrapper for which the wrapped type should be retrieved.")),
751+
SyntaxFactory.XmlNewLine(Environment.NewLine),
752+
SyntaxFactory.XmlText(" "),
753+
SyntaxFactory.XmlReturnsElement(
754+
SyntaxFactory.XmlText("The wrapped type, or null if there is no info.")),
755+
SyntaxFactory.XmlNewLine(Environment.NewLine).WithoutTrailingTrivia()))));
756+
730757
var wrapperHelperClass = SyntaxFactory.ClassDeclaration(
731758
attributeLists: default,
732759
modifiers: SyntaxTokenList.Create(SyntaxFactory.Token(SyntaxKind.InternalKeyword)).Add(SyntaxFactory.Token(SyntaxKind.StaticKeyword)),
@@ -831,7 +858,7 @@ public DocumentData(XDocument document)
831858

832859
if (!operationKinds.TryGetValue(node.Attribute("Name").Value, out var kinds))
833860
{
834-
kinds = ImmutableArray<(string name, int value, string extraDescription)>.Empty;
861+
kinds = ImmutableArray<(string name, int value, string? extraDescription)>.Empty;
835862
}
836863

837864
var interfaceData = new InterfaceData(this, node, kinds);
@@ -847,7 +874,7 @@ public DocumentData(XDocument document)
847874

848875
if (!operationKinds.TryGetValue(node.Attribute("Name").Value, out var kinds))
849876
{
850-
kinds = ImmutableArray<(string name, int value, string extraDescription)>.Empty;
877+
kinds = ImmutableArray<(string name, int value, string? extraDescription)>.Empty;
851878
}
852879

853880
var interfaceData = new InterfaceData(this, node, kinds);
@@ -859,11 +886,11 @@ public DocumentData(XDocument document)
859886

860887
public ReadOnlyDictionary<string, InterfaceData> Interfaces { get; }
861888

862-
private static ImmutableDictionary<string, ImmutableArray<(string name, int value, string extraDescription)>> GetOperationKinds(XDocument document)
889+
private static ImmutableDictionary<string, ImmutableArray<(string name, int value, string? extraDescription)>> GetOperationKinds(XDocument document)
863890
{
864891
var skippedOperationKinds = GetSkippedOperationKinds(document);
865892

866-
var builder = ImmutableDictionary.CreateBuilder<string, ImmutableArray<(string name, int value, string extraDescription)>>();
893+
var builder = ImmutableDictionary.CreateBuilder<string, ImmutableArray<(string name, int value, string? extraDescription)>>();
867894

868895
int operationKind = 0;
869896
foreach (var node in document.XPathSelectElements("/Tree/AbstractNode|/Tree/Node"))
@@ -886,7 +913,7 @@ public DocumentData(XDocument document)
886913
}
887914
else if (explicitKind.XPathSelectElements("Entry").Any())
888915
{
889-
var nodeBuilder = ImmutableArray.CreateBuilder<(string name, int value, string extraDescription)>();
916+
var nodeBuilder = ImmutableArray.CreateBuilder<(string name, int value, string? extraDescription)>();
890917
foreach (var entry in explicitKind.XPathSelectElements("Entry"))
891918
{
892919
if (entry.Attribute("EditorBrowsable")?.Value == "false")
@@ -918,7 +945,7 @@ public DocumentData(XDocument document)
918945

919946
var nodeName = node.Attribute("Name").Value;
920947
var kindName = nodeName.Substring("I".Length, nodeName.Length - "I".Length - "Operation".Length);
921-
builder.Add(nodeName, ImmutableArray.Create((kindName, operationKind, (string)null)));
948+
builder.Add(nodeName, ImmutableArray.Create((kindName, operationKind, (string?)null)));
922949
}
923950

924951
return builder.ToImmutable();
@@ -955,7 +982,7 @@ private sealed class InterfaceData
955982
{
956983
private readonly DocumentData documentData;
957984

958-
public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(string name, int value, string extraDescription)> operationKinds)
985+
public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(string name, int value, string? extraDescription)> operationKinds)
959986
{
960987
this.documentData = documentData;
961988

@@ -968,7 +995,7 @@ public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(s
968995
this.Properties = node.XPathSelectElements("Property").Select(property => new PropertyData(property)).ToImmutableArray();
969996
}
970997

971-
public ImmutableArray<(string name, int value, string extraDescription)> OperationKinds { get; }
998+
public ImmutableArray<(string name, int value, string? extraDescription)> OperationKinds { get; }
972999

9731000
public string InterfaceName { get; }
9741001

@@ -982,7 +1009,7 @@ public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(s
9821009

9831010
public ImmutableArray<PropertyData> Properties { get; }
9841011

985-
public InterfaceData BaseInterface
1012+
public InterfaceData? BaseInterface
9861013
{
9871014
get
9881015
{

StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<PropertyGroup>
55
<TargetFrameworks>netstandard2.0</TargetFrameworks>
6+
<Nullable>enable</Nullable>
67
</PropertyGroup>
78

89
<PropertyGroup>
@@ -16,6 +17,8 @@
1617

1718
<ItemGroup>
1819
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-5.final" />
20+
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
21+
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[3.1.0]" />
1922
</ItemGroup>
2023

2124
</Project>

0 commit comments

Comments
 (0)