Skip to content

Commit a283433

Browse files
authored
Merge pull request #3231 from sharwell/generate-lightup
Use code generation for IOperation in the light-up layer
2 parents d04c6cd + 1d35607 commit a283433

File tree

143 files changed

+10907
-175
lines changed

Some content is hidden

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

143 files changed

+10907
-175
lines changed

StyleCop.Analyzers/Directory.Build.props

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</PropertyGroup>
1111

1212
<PropertyGroup>
13-
<LangVersion>8</LangVersion>
14-
<Features>strict</Features>
13+
<LangVersion>9</LangVersion>
14+
<WarningLevel>5</WarningLevel>
1515
</PropertyGroup>
1616

1717
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
@@ -47,7 +47,12 @@
4747
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.46" PrivateAssets="all" />
4848
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205" PrivateAssets="all" />
4949
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.0" PrivateAssets="all" />
50-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.7.0-6.20427.1" PrivateAssets="all" />
50+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.8.0-5.final" PrivateAssets="all" />
51+
</ItemGroup>
52+
53+
<!-- C# Compiler -->
54+
<ItemGroup>
55+
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.8.0-5.final" PrivateAssets="all" />
5156
</ItemGroup>
5257

5358
<!-- Public API -->

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/StyleCop.Analyzers.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<file src="tools\uninstall.ps1" target="tools\" />
3838

3939
<!-- Source code -->
40-
<file src="..\StyleCop.Analyzers\**\*.cs" exclude="..\StyleCop.Analyzers\obj\**\*.cs" target="src"/>
40+
<file src="..\StyleCop.Analyzers\**\*.cs" exclude="..\StyleCop.Analyzers\obj\**\*.cs;..\StyleCop.Analyzers\Lightup\.generated\**\*.cs" target="src"/>
4141
<file src="**\*.cs" exclude="obj\**\*.cs;Properties\AssemblyInfo.cs" target="src"/>
4242

4343
</files>

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

Lines changed: 1075 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: CLSCompliant(false)]
11+
12+
// Setting ComVisible to false makes the types in this assembly not visible
13+
// to COM components. If you need to access a type in this assembly from
14+
// COM, set the ComVisible attribute to true on that type.
15+
[assembly: ComVisible(false)]

StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/PublicAPI.Shipped.txt

Whitespace-only changes.

StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/PublicAPI.Unshipped.txt

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
4+
<PropertyGroup>
5+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<PropertyGroup>
9+
<CodeAnalysisRuleSet>..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
10+
</PropertyGroup>
11+
12+
<PropertyGroup>
13+
<SignAssembly>true</SignAssembly>
14+
<AssemblyOriginatorKeyFile>..\..\build\keys\StyleCopAnalyzers.snk</AssemblyOriginatorKeyFile>
15+
</PropertyGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-5.final" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.Test.CSharp7.Lightup
5+
{
6+
using System.Collections.Generic;
7+
using System.Reflection;
8+
using Microsoft.CodeAnalysis;
9+
using StyleCop.Analyzers.Lightup;
10+
using Xunit;
11+
12+
public class OperationKindExTests
13+
{
14+
private static readonly Dictionary<OperationKind, string> OperationKindToName;
15+
private static readonly Dictionary<string, OperationKind> NameToOperationKind;
16+
17+
static OperationKindExTests()
18+
{
19+
var renamedOperations =
20+
new Dictionary<string, string>()
21+
{
22+
{ "BinaryOperator", "Binary" },
23+
{ "ConstructorBodyOperation", "ConstructorBody" },
24+
{ "MethodBodyOperation", "MethodBody" },
25+
{ "TupleBinaryOperator", "TupleBinary" },
26+
{ "UnaryOperator", "Unary" },
27+
};
28+
29+
OperationKindToName = new Dictionary<OperationKind, string>();
30+
NameToOperationKind = new Dictionary<string, OperationKind>();
31+
32+
foreach (var field in typeof(OperationKind).GetTypeInfo().DeclaredFields)
33+
{
34+
if (!field.IsStatic)
35+
{
36+
continue;
37+
}
38+
39+
var value = (OperationKind)field.GetRawConstantValue();
40+
var name = field.Name;
41+
if (renamedOperations.TryGetValue(name, out var newName))
42+
{
43+
name = newName;
44+
}
45+
46+
if (!OperationKindToName.ContainsKey(value))
47+
{
48+
OperationKindToName[value] = name;
49+
}
50+
51+
if (!NameToOperationKind.ContainsKey(name))
52+
{
53+
NameToOperationKind.Add(name, value);
54+
}
55+
}
56+
}
57+
58+
public static IEnumerable<object[]> OperationKinds
59+
{
60+
get
61+
{
62+
foreach (var field in typeof(OperationKindEx).GetTypeInfo().DeclaredFields)
63+
{
64+
yield return new object[] { field.Name, (OperationKind)field.GetRawConstantValue() };
65+
}
66+
}
67+
}
68+
69+
[Theory]
70+
[MemberData(nameof(OperationKinds))]
71+
public void TestOperationKind(string name, OperationKind operationKind)
72+
{
73+
if (OperationKindToName.TryGetValue(operationKind, out var expectedName))
74+
{
75+
Assert.Equal(expectedName, name);
76+
}
77+
else
78+
{
79+
Assert.False(NameToOperationKind.TryGetValue(name, out _));
80+
}
81+
}
82+
}
83+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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.Test.CSharp8.Lightup
5+
{
6+
using StyleCop.Analyzers.Test.CSharp7.Lightup;
7+
8+
public class OperationKindExTestsCSharp8 : OperationKindExTests
9+
{
10+
}
11+
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1600CSharp9UnitTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace StyleCop.Analyzers.Test.CSharp9.DocumentationRules
88

99
public class SA1600CSharp9UnitTests : SA1600CSharp8UnitTests
1010
{
11-
protected override DiagnosticResult[] GetExpectedResultTestRegressionMethodGlobalNamespace(string code, int column)
11+
protected override DiagnosticResult[] GetExpectedResultTestRegressionMethodGlobalNamespace(string code)
1212
{
13-
if (code == "public void TestMember() { }" && column == 13)
13+
if (code == "public void {|#0:TestMember|}() { }")
1414
{
1515
return new[]
1616
{
@@ -20,12 +20,12 @@ protected override DiagnosticResult[] GetExpectedResultTestRegressionMethodGloba
2020
// /0/Test0.cs(4,1): error CS0106: The modifier 'public' is not valid for this item
2121
DiagnosticResult.CompilerError("CS0106").WithSpan(4, 1, 4, 7).WithArguments("public"),
2222

23-
// /0/Test0.cs(4,1): error CS8652: The feature 'top-level statements' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
24-
DiagnosticResult.CompilerError("CS8652").WithSpan(4, 1, 4, 29).WithArguments("top-level statements"),
23+
// /0/Test0.cs(4,1): error CS8320: Feature 'top-level statements' is not available in C# 7.2. Please use language version 9.0 or greater.
24+
DiagnosticResult.CompilerError("CS8320").WithSpan(4, 1, 4, 29).WithArguments("top-level statements", "9.0"),
2525
};
2626
}
2727

28-
return base.GetExpectedResultTestRegressionMethodGlobalNamespace(code, column);
28+
return base.GetExpectedResultTestRegressionMethodGlobalNamespace(code);
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)