示例#1
0
        public Task <SyntaxList <MemberDeclarationSyntax> > GenerateAsync(TransformationContext context, IProgress <Diagnostic> progress, CancellationToken cancellationToken)
        {
            var generatedMembers = SyntaxFactory.List <MemberDeclarationSyntax>();

            try
            {
                if (context.ProcessingNode is ClassDeclarationSyntax classDeclaration)
                {
                    var descriptorBuilder = new CoreDescriptorBuilder(context, cancellationToken);
                    var descriptor        = descriptorBuilder.CreateDescriptor();
                    generatedMembers = generatedMembers.AddRange(GenerateCorePartials(descriptor));
                    generatedMembers = generatedMembers.AddRange(GenerateNodePartials(descriptor));
                }
            }
            catch (Exception e)
            {
                if (progress is null)
                {
                    Console.Error.WriteLine("WHAMGEN: error:" + e.ToString());
                    throw;
                }
                progress.Report(
                    Diagnostic.Create(
                        exceptionDiagDescriptor,
                        context.ProcessingNode.GetLocation(),
                        messageArgs: e.ToString()));
            }
            return(Task.FromResult(generatedMembers));

            IEnumerable <TypeDeclarationSyntax> GenerateCorePartials(CoreDescriptor descriptor)
            {
                yield return(RecordCorePartialGenerator.Generate(descriptor, cancellationToken));

                if (descriptor.TypeSymbol.IsAbstract)
                {
                    yield break;
                }
                yield return(BuilderCorePartialGenerator.Generate(descriptor, cancellationToken));

                yield return(FspCorePartialGenerator.Generate(descriptor, cancellationToken));

                yield return(FseCorePartialGenerator.Generate(descriptor, cancellationToken));
            }

            IEnumerable <TypeDeclarationSyntax> GenerateNodePartials(CoreDescriptor descriptor)
            {
                yield return(CoreToNodeMethodsCorePartialGenerator.Generate(descriptor, cancellationToken));

                yield return(BasicDeclarationNodeGenerator.Generate(descriptor, cancellationToken));

                yield return(NodeGenerator.Generate(descriptor, cancellationToken));

                yield return(NodeExtensionsGenerator.Generate(descriptor, cancellationToken));

                yield return(CollectionConversionExtensionsPartialGenerator.Generate(descriptor, cancellationToken));

                yield return(NodeConvenienceMethodsGenerator.Generate(descriptor, cancellationToken));

                yield return(NodeAcceptSourceVisitorPartialGenerator.Generate(descriptor, cancellationToken));

                if (descriptor.TypeSymbol.IsAbstract)
                {
                    yield break;
                }
                yield return(ListNodePartialGenerator.Generate(descriptor, cancellationToken));

                yield return(SourceVisitorVisitPartialGenerator.Generate(descriptor, cancellationToken));

                yield return(SourceVisitorGenericVisitPartialGenerator.Generate(descriptor, cancellationToken));

                yield return(SourceRewriterVisitPartialGenerator.Generate(descriptor, cancellationToken));

                yield return(NodeFactoryPartialGenerator.Generate(descriptor, cancellationToken));
            }
        }
示例#2
0
        public static TypeDeclarationSyntax Generate(CoreDescriptor descriptor, CancellationToken cancellationToken)
        {
            var generator = new BuilderCorePartialGenerator(descriptor, cancellationToken);

            return(generator.GenerateTypeDeclaration());
        }