Example #1
0
            private void ReportDiagnostic(SyntaxNodeAnalysisContext syntaxContext, MemberDeclarationSyntax memberDeclaration,
                                          Location location, FixOption fixOption)
            {
                syntaxContext.CancellationToken.ThrowIfCancellationRequested();
                var memberCategory = GetMemberCategory(memberDeclaration);
                var properties     = ImmutableDictionary <string, string> .Empty
                                     .Add(FixOptionKey, fixOption.ToString());

                var noXmlCommentDiagnostic = Diagnostic.Create(Descriptors.PX1007_PublicClassXmlComment, location, properties, memberCategory);

                syntaxContext.ReportDiagnosticWithSuppressionCheck(noXmlCommentDiagnostic, _codeAnalysisSettings);
            }
Example #2
0
        static int Fix(FixOption options)
        {
            var cfg = Setup.LoadCfg().Result;

            UpdateCfgFromOptions(cfg, options);
            using (var log = Setup.CreateCliLogger(cfg.App)) {
                var ytStore   = cfg.YtStore(log);
                var ytUpdater = new YtDataUpdater(ytStore, cfg.App, log);
                try {
                    ytUpdater.RefreshMissingVideos().Wait();
                }
                catch (Exception ex) {
                    log.Error("Error Fixing Data: {Error}", ex.Message, ex);
                    return((int)ExitCode.UnknownError);
                }
                return((int)ExitCode.Success);
            }
        }
Example #3
0
        private SyntaxNode GetRootNodeSyntaxWithDescription(SyntaxNode rootNode, MemberDeclarationSyntax memberDeclaration,
                                                            string className, FixOption option, CancellationToken cancellation)
        {
            cancellation.ThrowIfCancellationRequested();

            var description = GenerateDescriptionFromCamelCase(className);

            switch (option)
            {
            case FixOption.NoXmlComment:
            case FixOption.NoSummaryTag:
                return(AddXmlCommentDescription(rootNode, memberDeclaration, description, cancellation));

            case FixOption.EmptySummaryTag:
                return(AddDescription(rootNode, memberDeclaration, description, cancellation));

            default:
                return(memberDeclaration);
            }
        }
        private async Task <Document> AddAttributeToDac(Document document, TextSpan span, FixOption option, CancellationToken cancellation)
        {
            cancellation.ThrowIfCancellationRequested();

            var root = await document
                       .GetSyntaxRootAsync(cancellation)
                       .ConfigureAwait(false);

            if (!(root?.FindNode(span) is ClassDeclarationSyntax node))
            {
                return(document);
            }

            var semanticModel = await document
                                .GetSemanticModelAsync(cancellation)
                                .ConfigureAwait(false);

            if (semanticModel == null)
            {
                return(document);
            }

            var pxContext     = new PXContext(semanticModel.Compilation, codeAnalysisSettings: null);
            var attributeList = option == FixOption.AddPXCacheNameAttribute ?
                                pxContext.AttributeTypes.PXCacheNameAttribute.GetAttributeList(CreateDefaultArgumentList()) :
                                pxContext.AttributeTypes.PXHiddenAttribute.GetAttributeList();
            var newNode     = node.AddAttributeLists(attributeList);
            var newRoot     = root.ReplaceNode(node, newNode);
            var newDocument = document.WithSyntaxRoot(newRoot);

            return(newDocument);

            AttributeArgumentListSyntax CreateDefaultArgumentList()
            {
                var pxCacheNameDefaultArgumentValue = nameof(Resources.PX1094PXCacheNameDefaultArgumentValue).GetLocalized().ToString();

                return(SyntaxFactory.AttributeArgumentList(
                           SyntaxFactory.SingletonSeparatedList(
                               SyntaxFactory.AttributeArgument(
                                   SyntaxFactory.LiteralExpression(
                                       SyntaxKind.StringLiteralExpression,
                                       SyntaxFactory.Literal(pxCacheNameDefaultArgumentValue))))));
            }
        }
Example #5
0
        private async Task <Document> AddDescriptionAsync(Document document, TextSpan span, FixOption option, CancellationToken cancellation)
        {
            cancellation.ThrowIfCancellationRequested();

            var rootNode = await document.GetSyntaxRootAsync(cancellation).ConfigureAwait(false);

            if (!(rootNode?.FindNode(span) is MemberDeclarationSyntax memberDeclaration))
            {
                return(document);
            }

            string memberName = memberDeclaration.GetIdentifiers().FirstOrDefault().ToString();

            if (memberName.IsNullOrWhiteSpace())
            {
                return(document);
            }

            var newRootNode = GetRootNodeSyntaxWithDescription(rootNode, memberDeclaration, memberName, option, cancellation);
            var newDocument = document.WithSyntaxRoot(newRootNode);

            return(newDocument);
        }
        private async Task <Document> FixActionHandlerAttributes(Document document, TextSpan span, FixOption option, CancellationToken cancellation)
        {
            cancellation.ThrowIfCancellationRequested();

            var root = await document
                       .GetSyntaxRootAsync(cancellation)
                       .ConfigureAwait(false);

            if (!(root?.FindNode(span) is MethodDeclarationSyntax node))
            {
                return(document);
            }

            var semanticModel = await document
                                .GetSemanticModelAsync(cancellation)
                                .ConfigureAwait(false);

            if (semanticModel == null)
            {
                return(document);
            }

            var pxContext               = new PXContext(semanticModel.Compilation, codeAnalysisSettings: null);
            var pxButtonAttributeList   = pxContext.AttributeTypes.PXButtonAttribute.GetAttributeList();
            var pxUIFieldAttributeList  = pxContext.AttributeTypes.PXUIFieldAttribute.Type.GetAttributeList();
            var attributeListCollection = new List <AttributeListSyntax>();

            switch (option)
            {
            case FixOption.AddPXButtonAttribute:
                attributeListCollection.Add(pxButtonAttributeList);
                break;

            case FixOption.AddPXUIFieldAttribute:
                attributeListCollection.Add(pxUIFieldAttributeList);
                break;

            case FixOption.AddBothAttributes:
                attributeListCollection.Add(pxButtonAttributeList);
                attributeListCollection.Add(pxUIFieldAttributeList);
                break;
            }

            var newNode     = node.AddAttributeLists(attributeListCollection.ToArray());
            var newRoot     = root.ReplaceNode(node, newNode);
            var newDocument = document.WithSyntaxRoot(newRoot);

            return(newDocument);
        }