Skip to content

Commit 6349f0c

Browse files
committed
Reducing number of shared files
1 parent e1aa20e commit 6349f0c

File tree

15 files changed

+85
-102
lines changed

15 files changed

+85
-102
lines changed

src/AutoCtor.Roslyn3.11/GlobalSuppressions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
Justification = "Old generator still maintained",
77
Scope = "namespaceanddescendants",
88
Target = "~N:AutoCtor")]
9-

src/Shared/AutoConstructSourceGenerator/Diagnostics.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
using Microsoft.CodeAnalysis;
22

3-
#if ROSLYN_3
4-
using EmitterContext = Microsoft.CodeAnalysis.GeneratorExecutionContext;
5-
#elif ROSLYN_4
6-
using EmitterContext = Microsoft.CodeAnalysis.SourceProductionContext;
7-
#endif
8-
93
namespace AutoCtor;
104

115
internal static class Diagnostics
126
{
13-
public static void ReportDiagnostic(EmitterContext context, IHaveDiagnostics item, DiagnosticDescriptor diagnostic)
14-
{
15-
foreach (var loc in item.Locations)
16-
context.ReportDiagnostic(Diagnostic.Create(diagnostic, loc, item.ErrorName));
17-
}
18-
197
/// <summary>
208
/// Id: ACTR001<br />
219
/// Title: Ambiguous marked post constructor method

src/Shared/AutoConstructSourceGenerator/Emitter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private static ITypeSymbol SetGenerics(
208208
{
209209
foreach (var m in markedPostCtorMethods)
210210
{
211-
ReportDiagnostic(context, m, ACTR001_AmbiguousMarkedPostConstructMethod);
211+
context.ReportDiagnostic(m, ACTR001_AmbiguousMarkedPostConstructMethod);
212212
}
213213
return null;
214214
}
@@ -221,14 +221,14 @@ private static ITypeSymbol SetGenerics(
221221
// ACTR002
222222
if (!method.ReturnsVoid)
223223
{
224-
ReportDiagnostic(context, method, ACTR002_PostConstructMethodNotVoid);
224+
context.ReportDiagnostic(method, ACTR002_PostConstructMethodNotVoid);
225225
return null;
226226
}
227227

228228
// ACTR004
229229
if (method.IsGenericMethod)
230230
{
231-
ReportDiagnostic(context, method, ACTR004_PostConstructMethodCannotBeGeneric);
231+
context.ReportDiagnostic(method, ACTR004_PostConstructMethodCannotBeGeneric);
232232
return null;
233233
}
234234

@@ -237,7 +237,7 @@ private static ITypeSymbol SetGenerics(
237237
// ACTR005
238238
if (parameter.IsOutOrRef && parameter.KeyedService != null)
239239
{
240-
ReportDiagnostic(context, parameter, ACTR005_PostConstructOutParameterCannotBeKeyed);
240+
context.ReportDiagnostic(parameter, ACTR005_PostConstructOutParameterCannotBeKeyed);
241241
return null;
242242
}
243243
}

src/Shared/Helpers/CodeBuilder.Templates.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,9 @@ public CodeBuilder AddGeneratedAttributes(AttributeTargets attributeTargets)
4444
switch (attributeTargets)
4545
{
4646
case AttributeTargets.Class:
47-
AddDebuggerNonUserCodeAttribute();
48-
AddExcludeFromCodeCoverage();
49-
break;
5047
case AttributeTargets.Struct:
51-
AddDebuggerNonUserCodeAttribute();
52-
AddExcludeFromCodeCoverage();
53-
break;
5448
case AttributeTargets.Constructor:
55-
AddDebuggerNonUserCodeAttribute();
56-
AddExcludeFromCodeCoverage();
57-
break;
5849
case AttributeTargets.Method:
59-
AddDebuggerNonUserCodeAttribute();
60-
AddExcludeFromCodeCoverage();
61-
break;
6250
case AttributeTargets.Property:
6351
AddDebuggerNonUserCodeAttribute();
6452
AddExcludeFromCodeCoverage();

src/Shared/Helpers/Extensions.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
internal static class Extensions
1+
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.CodeAnalysis;
3+
4+
#if ROSLYN_3
5+
using EmitterContext = Microsoft.CodeAnalysis.GeneratorExecutionContext;
6+
#elif ROSLYN_4
7+
using EmitterContext = Microsoft.CodeAnalysis.SourceProductionContext;
8+
#endif
9+
10+
internal static class Extensions
211
{
312
public static T? OnlyOrDefault<T>(this IEnumerable<T> source)
413
{
@@ -47,4 +56,14 @@ public static bool MoreThan<T>(this IEnumerable<T> source, int limit)
4756
}
4857
return false;
4958
}
59+
60+
[SuppressMessage(
61+
"MicrosoftCodeAnalysisCorrectness",
62+
"RS1035:Do not use APIs banned for analyzers",
63+
Justification = "Old generator still maintained")]
64+
public static void ReportDiagnostic(this EmitterContext context, IHaveDiagnostics item, DiagnosticDescriptor diagnostic)
65+
{
66+
foreach (var loc in item.Locations)
67+
context.ReportDiagnostic(Diagnostic.Create(diagnostic, loc, item.ErrorName));
68+
}
5069
}

src/Shared/Models/ParameterList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ParameterList Build(EmitterContext context)
6767
// ACTR006
6868
if (matchingField.KeyedService != null)
6969
{
70-
Diagnostics.ReportDiagnostic(context, matchingField,
70+
context.ReportDiagnostic(matchingField,
7171
Diagnostics.ACTR006_PostConstructOutParameterMustNotMatchKeyedField);
7272
}
7373

src/Tests/ExampleTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,8 @@ public class CompilationBuilderFactory : CompilationBuilderFactoryBase<AutoConst
9595
protected override IEnumerable<string> GetNuGetIds() => ["Microsoft.Extensions.DependencyInjection.Abstractions"];
9696
}
9797

98-
private static IEnumerable<string> GetExamplesFiles(string path)
99-
=> Directory.GetFiles(Path.Combine(TestFileHelper.BaseDir?.FullName ?? "", path), "*.cs")
100-
.Where(e => !e.Contains(".g."));
101-
10298
public static IEnumerable<Func<CodeFileTheoryData>> GetExamples()
10399
{
104-
if (TestFileHelper.BaseDir is null)
105-
throw new Exception("BaseDir is null");
106-
107100
foreach (var example in GetExamplesFiles("Examples"))
108101
{
109102
yield return () => new CodeFileTheoryData(example) with

src/Tests/GeneratedAttributeTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ await Verify(driver)
2626
public async Task AttributeCompilesProperly(CompilationBuilderFactory builderFactory)
2727
{
2828
var builder = builderFactory.Builder
29-
.WithPreprocessorSymbols(["AUTOCTOR_EMBED_ATTRIBUTES"]);
29+
.WithPreprocessorSymbols("AUTOCTOR_EMBED_ATTRIBUTES");
3030
var compilation = builder.Build(nameof(GeneratedAttributeTests));
3131
var driver = new GeneratorDriverBuilder()
3232
.AddGenerator(new AttributeSourceGenerator())
@@ -51,8 +51,8 @@ await Assert.That(outputCompilationDiagnostics).IsEmpty()
5151
public async Task PreserveAttributesTest(CompilationBuilderFactory builderFactory)
5252
{
5353
var builder = builderFactory.Builder
54-
.AddCode("[AutoCtor.AutoConstruct] public partial class Test { }")
55-
.WithPreprocessorSymbols(["AUTOCTOR_EMBED_ATTRIBUTES", "AUTOCTOR_USAGES"]);
54+
.AddCodes("[AutoCtor.AutoConstruct] public partial class Test { }")
55+
.WithPreprocessorSymbols("AUTOCTOR_EMBED_ATTRIBUTES", "AUTOCTOR_USAGES");
5656
var compilation = builder.Build(nameof(GeneratedAttributeTests));
5757

5858
var driver = new GeneratorDriverBuilder()
@@ -80,7 +80,7 @@ public async Task EnsureGeneratedAttributesAreNotExternallyVisible(CompilationBu
8080
{
8181
// Issue 312
8282
var compileBuilder = builderFactory.Builder
83-
.WithPreprocessorSymbols(["AUTOCTOR_EMBED_ATTRIBUTES"]);
83+
.WithPreprocessorSymbols("AUTOCTOR_EMBED_ATTRIBUTES");
8484

8585
var genDriver = new GeneratorDriverBuilder()
8686
.AddGenerator(new AttributeSourceGenerator())

src/Tests/Issue73.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public sealed partial class TheClass : BaseClass<object, int, string>{}
7272
}
7373
";
7474
var projectA = common
75-
.AddCode(projectACode)
75+
.AddCodes(projectACode)
7676
.Build("ProjectA");
7777

7878
var projectB = common
7979
.AddCompilationReference(projectA)
80-
.AddCode(projectBCode)
80+
.AddCodes(projectBCode)
8181
.Build("ProjectB");
8282

8383
return projectB;

0 commit comments

Comments
 (0)