Skip to content

Commit

Permalink
Update console to use .net core app 3.1 and update nuget packages (#157)
Browse files Browse the repository at this point in the history
* Update console to use .net core app 3.1 and update nuget packages

* Update warnings and unit tests
  • Loading branch information
glennawatson authored Aug 16, 2020
1 parent 1109fc9 commit 2ed4a24
Show file tree
Hide file tree
Showing 64 changed files with 44,523 additions and 10,047 deletions.
4 changes: 2 additions & 2 deletions src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.164" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="all" />
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.205" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="2.3.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/Pharmacist.Benchmarks/CommentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
// See the LICENSE file in the project root for full license information.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;

using Pharmacist.Core.Generation;

namespace Pharmacist.Benchmarks
{
[ClrJob]
[CoreJob]
[SimpleJob(RuntimeMoniker.Net472)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class CommentGenerator
Expand Down
5 changes: 3 additions & 2 deletions src/Pharmacist.Benchmarks/NuGetHelperBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;

using NuGet.Frameworks;
using NuGet.Packaging.Core;
Expand All @@ -11,8 +12,8 @@

namespace Pharmacist.Benchmarks
{
[ClrJob]
////[CoreJob]
[SimpleJob(RuntimeMoniker.Net472)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class NuGetTaskGeneratorBenchmarks
Expand Down
5 changes: 3 additions & 2 deletions src/Pharmacist.Benchmarks/PlatformGeneratorBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;

using Pharmacist.Core;

Expand All @@ -14,8 +15,8 @@ namespace Pharmacist.Benchmarks
/// <summary>
/// Benchmarks for the NavigationStack and the RoutingState objects.
/// </summary>
[ClrJob]
////[CoreJob]
[SimpleJob(RuntimeMoniker.Net472)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class NavigationStackBenchmark
Expand Down
4 changes: 2 additions & 2 deletions src/Pharmacist.Console/ExitCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace Pharmacist.Console
public enum ExitCode
{
/// <summary>
/// Success
/// Success.
/// </summary>
Success = 0,

/// <summary>
/// Error
/// Error.
/// </summary>
Error = 1,
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pharmacist.Console/Pharmacist.Console.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Pharmacist</AssemblyName>
<LangVersion>latest</LangVersion>
<PackAsTool>true</PackAsTool>
Expand Down
10 changes: 10 additions & 0 deletions src/Pharmacist.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public static async Task<int> Main(string[] args)
{
try
{
if (options.OutputPath == null)
{
throw new InvalidOperationException("There is no Output path specified.");
}

using (var writer = new StreamWriter(Path.Combine(options.OutputPath, options.OutputPrefix + ".cs")))
{
if (options.Assemblies == null)
Expand Down Expand Up @@ -116,6 +121,11 @@ public static async Task<int> Main(string[] args)
{
try
{
if (options.OutputPath == null)
{
throw new InvalidOperationException("There is no Output path specified.");
}

using (var writer = new StreamWriter(Path.Combine(options.OutputPath, options.OutputPrefix + ".cs")))
{
if (string.IsNullOrWhiteSpace(options.TargetFramework))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ private static IEnumerable<IModule> GetReferenceModules(IEnumerable<IModule> mai
{
var assemblyReferencesSeen = new HashSet<IAssemblyReference>(AssemblyReferenceNameComparer.Default);

var referenceModulesToProcess = new Stack<(IModule parent, IAssemblyReference reference)>(mainModules.SelectMany(x => x.PEFile.AssemblyReferences.Select(reference => (x, (IAssemblyReference)reference))));
var referenceModulesToProcess = new Stack<(IModule Parent, IAssemblyReference Reference)>(mainModules.SelectMany(x => x.PEFile.AssemblyReferences.Select(reference => (x, (IAssemblyReference)reference))));
while (referenceModulesToProcess.Count > 0)
{
var current = referenceModulesToProcess.Pop();

if (!assemblyReferencesSeen.Add(current.reference))
if (!assemblyReferencesSeen.Add(current.Reference))
{
continue;
}

#pragma warning disable CA2000 // Dispose objects before losing scope
var moduleReference = (IModuleReference?)current.reference.Resolve(current.parent, input, framework);
var moduleReference = (IModuleReference?)current.Reference.Resolve(current.Parent, input, framework);
#pragma warning restore CA2000 // Dispose objects before losing scope

if (moduleReference == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ internal static class DelegateGenerator
/// </summary>
/// <param name="declarations">The declarations to add.</param>
/// <returns>An array of namespace declarations.</returns>
internal static IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition typeDefinition, bool isAbstract, IEnumerable<IMethod> methods)> declarations)
internal static IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition TypeDefinition, bool IsAbstract, IEnumerable<IMethod> Methods)> declarations)
{
foreach (var groupedDeclarations in declarations.GroupBy(x => x.typeDefinition.Namespace).OrderBy(x => x.Key))
foreach (var groupedDeclarations in declarations.GroupBy(x => x.TypeDefinition.Namespace).OrderBy(x => x.Key))
{
var namespaceName = groupedDeclarations.Key;
var members = new List<ClassDeclarationSyntax>();

members.AddRange(groupedDeclarations.OrderBy(x => x.typeDefinition.Name).Select(x => GenerateClass(x.typeDefinition, x.isAbstract, x.methods)));
members.AddRange(groupedDeclarations.OrderBy(x => x.TypeDefinition.Name).Select(x => GenerateClass(x.TypeDefinition, x.IsAbstract, x.Methods)));

if (members.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal abstract class EventGeneratorBase : IEventGenerator
/// </summary>
/// <param name="values">The declarations to add.</param>
/// <returns>An array of namespace declarations.</returns>
public abstract IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition typeDefinition, ITypeDefinition? baseDefinition, IEnumerable<IEvent> events)> values);
public abstract IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition TypeDefinition, ITypeDefinition? BaseDefinition, IEnumerable<IEvent> Events)> values);

/// <summary>
/// Generates an observable declaration that wraps a event.
Expand Down Expand Up @@ -64,7 +64,7 @@ internal abstract class EventGeneratorBase : IEventGenerator
.WithLeadingTrivia(GenerateSummarySeeAlsoComment("Gets an observable which signals when the {0} event triggers.", eventDetails.ConvertToDocument()));
}

private static (ArrowExpressionClauseSyntax, TypeSyntax) GenerateFromEventExpression(IEvent eventDetails, IMethod invokeMethod, string dataObjectName)
private static (ArrowExpressionClauseSyntax ArrowClause, TypeSyntax EventArgsType) GenerateFromEventExpression(IEvent eventDetails, IMethod invokeMethod, string dataObjectName)
{
var returnType = IdentifierName(eventDetails.ReturnType.GenerateFullGenericName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ internal interface IEventGenerator
/// </summary>
/// <param name="values">The values to generate for.</param>
/// <returns>The new compilation unit.</returns>
IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition typeDefinition, ITypeDefinition? baseDefinition, IEnumerable<IEvent> events)> values);
IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition TypeDefinition, ITypeDefinition? BaseDefinition, IEnumerable<IEvent> Events)> values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ internal class InstanceEventGenerator : EventGeneratorBase
{
private const string DataFieldName = "_data";

public override IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition typeDefinition, ITypeDefinition? baseDefinition, IEnumerable<IEvent> events)> values)
public override IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition TypeDefinition, ITypeDefinition? BaseDefinition, IEnumerable<IEvent> Events)> values)
{
foreach (var groupedDeclarations in values.GroupBy(x => x.typeDefinition.Namespace).OrderBy(x => x.Key))
foreach (var groupedDeclarations in values.GroupBy(x => x.TypeDefinition.Namespace).OrderBy(x => x.Key))
{
var namespaceName = groupedDeclarations.Key;
var members = new List<ClassDeclarationSyntax>();

var orderedTypeDeclarations = groupedDeclarations.OrderBy(x => x.typeDefinition.Name).ToList();
var orderedTypeDeclarations = groupedDeclarations.OrderBy(x => x.TypeDefinition.Name).ToList();

members.Add(GenerateStaticClass(namespaceName, orderedTypeDeclarations.Select(x => x.typeDefinition)));
members.AddRange(orderedTypeDeclarations.Select(x => GenerateEventWrapperClass(x.typeDefinition, x.baseDefinition, x.events)).Where(x => x != null));
members.Add(GenerateStaticClass(namespaceName, orderedTypeDeclarations.Select(x => x.TypeDefinition)));
members.AddRange(orderedTypeDeclarations.Select(x => GenerateEventWrapperClass(x.TypeDefinition, x.BaseDefinition, x.Events)).Where(x => x != null));

if (members.Count > 0)
{
Expand Down Expand Up @@ -101,7 +101,7 @@ private static FieldDeclarationSyntax GenerateEventWrapperField(ITypeDefinition
.WithModifiers(TokenList(Token(SyntaxKind.PrivateKeyword), Token(SyntaxKind.ReadOnlyKeyword)));
}

private static ClassDeclarationSyntax GenerateEventWrapperClass(ITypeDefinition typeDefinition, ITypeDefinition baseTypeDefinition, IEnumerable<IEvent> events)
private static ClassDeclarationSyntax GenerateEventWrapperClass(ITypeDefinition typeDefinition, ITypeDefinition? baseTypeDefinition, IEnumerable<IEvent> events)
{
var members = new List<MemberDeclarationSyntax> { GenerateEventWrapperField(typeDefinition), GenerateEventWrapperClassConstructor(typeDefinition, baseTypeDefinition != null) };
members.AddRange(events.OrderBy(x => x.Name).Select(x => GenerateEventWrapperObservable(x, DataFieldName)).Where(x => x != null).Select(x => x!));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ internal class StaticEventGenerator : EventGeneratorBase
/// </summary>
/// <param name="declarations">The declarations to add.</param>
/// <returns>An array of namespace declarations.</returns>
public override IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition typeDefinition, ITypeDefinition? baseDefinition, IEnumerable<IEvent> events)> declarations)
public override IEnumerable<NamespaceDeclarationSyntax> Generate(IEnumerable<(ITypeDefinition TypeDefinition, ITypeDefinition? BaseDefinition, IEnumerable<IEvent> Events)> declarations)
{
foreach (var groupDeclaration in declarations.GroupBy(x => x.typeDefinition.Namespace).OrderBy(x => x.Key))
foreach (var groupDeclaration in declarations.GroupBy(x => x.TypeDefinition.Namespace).OrderBy(x => x.Key))
{
var namespaceName = groupDeclaration.Key;

var eventWrapperMembers = groupDeclaration
.OrderBy(x => x.typeDefinition.Name)
.OrderBy(x => x.TypeDefinition.Name)
.SelectMany(
x =>
x.events
x.Events
.OrderBy(eventDetails => eventDetails.Name)
.Select(eventDetails => GenerateEventWrapperObservable(eventDetails, x.typeDefinition.GenerateFullGenericName(), x.typeDefinition.Name))
.Select(eventDetails => GenerateEventWrapperObservable(eventDetails, x.TypeDefinition.GenerateFullGenericName(), x.TypeDefinition.Name))
.Where(y => y != null))
.ToList();

Expand Down
6 changes: 3 additions & 3 deletions src/Pharmacist.Core/Generation/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public static string GenerateFullGenericName(this IType currentType)

if (currentType.TypeParameterCount > 0)
{
sb.Append("<")
sb.Append('<')
.Append(string.Join(", ", currentType.TypeArguments.Select(GenerateFullGenericName)))
.Append(">");
.Append('>');
}

return sb.ToString();
Expand All @@ -186,7 +186,7 @@ private static IEnumerable<ITypeDefinition> GetPublicTypeDefinitionsWithEvents(I
});
}

private static (bool isInternalType, string typeName) GetBuiltInType(string typeName)
private static (bool IsInternalType, string TypeName) GetBuiltInType(string typeName)
{
if (TypesMetadata.FullToBuiltInTypes.TryGetValue(typeName, out var builtInName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class DelegateTemplateNamespaceResolver : INamespaceResolver

public IEnumerable<NamespaceDeclarationSyntax> Create(ICompilation compilation)
{
IEnumerable<(ITypeDefinition typeDefinition, bool isAbstract, IEnumerable<IMethod> methods)> values = compilation.GetPublicTypeDefinitions()
IEnumerable<(ITypeDefinition TypeDefinition, bool IsAbstract, IEnumerable<IMethod> Methods)> values = compilation.GetPublicTypeDefinitions()
.Where(
x => x.Kind != TypeKind.Interface
&& (!IsMulticastDelegateDerived(x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ protected static bool IsValidParameters(IEvent eventDetails)

protected abstract IEventGenerator GetEventGenerator();

protected abstract IEnumerable<(ITypeDefinition typeHostingEvent, ITypeDefinition? baseTypeDefinition, IEnumerable<IEvent> events)> GetValidEventDetails(ICompilation compilation);
protected abstract IEnumerable<(ITypeDefinition TypeHostingEvent, ITypeDefinition? BaseTypeDefinition, IEnumerable<IEvent> Events)> GetValidEventDetails(ICompilation compilation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ internal class PublicEventNamespaceResolver : EventNamespaceResolverBase
StringComparer.InvariantCulture);

/// <inheritdoc />
protected override IEnumerable<(ITypeDefinition typeHostingEvent, ITypeDefinition? baseTypeDefinition, IEnumerable<IEvent> events)> GetValidEventDetails(ICompilation compilation)
protected override IEnumerable<(ITypeDefinition TypeHostingEvent, ITypeDefinition? BaseTypeDefinition, IEnumerable<IEvent> Events)> GetValidEventDetails(ICompilation compilation)
{
var processedList = new ConcurrentDictionary<ITypeDefinition, bool>(TypeDefinitionNameComparer.Default);
var toProcess = new ConcurrentStack<ITypeDefinition>(GetPublicTypesWithEvents(compilation).Where(x => !SkipNamespaceList.Contains(x.Namespace)));
var output = new ConcurrentBag<(ITypeDefinition typeHostingEvent, ITypeDefinition? baseTypeDefinition, IEnumerable<IEvent> events)>();
var output = new ConcurrentBag<(ITypeDefinition TypeHostingEvent, ITypeDefinition? BaseTypeDefinition, IEnumerable<IEvent> Events)>();

var processing = new ITypeDefinition[Environment.ProcessorCount];
while (!toProcess.IsEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ protected override IEventGenerator GetEventGenerator()
}

/// <inheritdoc />
protected override IEnumerable<(ITypeDefinition typeHostingEvent, ITypeDefinition? baseTypeDefinition, IEnumerable<IEvent> events)> GetValidEventDetails(ICompilation compilation)
protected override IEnumerable<(ITypeDefinition TypeHostingEvent, ITypeDefinition? BaseTypeDefinition, IEnumerable<IEvent> Events)> GetValidEventDetails(ICompilation compilation)
{
var output = new ConcurrentBag<(ITypeDefinition typeHostingEvent, ITypeDefinition? baseTypeDefinition, IEnumerable<IEvent> events)>();
var output = new ConcurrentBag<(ITypeDefinition TypeHostingEvent, ITypeDefinition? BaseTypeDefinition, IEnumerable<IEvent> Events)>();

Parallel.ForEach(
GetPublicTypesWithEvents(compilation).Where(x => !SkipNamespaceList.Contains(x.Namespace)),
Expand Down
4 changes: 2 additions & 2 deletions src/Pharmacist.Core/Generation/RoslynGeneratorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ internal static class RoslynGeneratorExtensions
/// <returns>The argument list.</returns>
public static ArgumentListSyntax GenerateTupleArgumentList(this IEnumerable<IParameter> parameters) => ArgumentList(SingletonSeparatedList(Argument(TupleExpression(SeparatedList(parameters.Select(x => Argument(IdentifierName(x.Name.GetKeywordSafeName()))))))));

public static TypeSyntax GenerateTupleType(this IEnumerable<(IType type, string name)> types)
public static TypeSyntax GenerateTupleType(this IEnumerable<(IType Type, string Name)> types)
{
return TupleType(SeparatedList(types.Select(x => TupleElement(IdentifierName(x.type.GenerateFullGenericName()), Identifier(x.name.GetKeywordSafeName())))));
return TupleType(SeparatedList(types.Select(x => TupleElement(IdentifierName(x.Type.GenerateFullGenericName()), Identifier(x.Name.GetKeywordSafeName())))));
}

public static TypeArgumentListSyntax GenerateObservableTypeArguments(this IMethod method)
Expand Down
Loading

0 comments on commit 2ed4a24

Please sign in to comment.