Exemple #1
0
        private void AnalyzeGraphUsageInDac(SyntaxNodeAnalysisContext syntaxContext, PXContext pxContext)
        {
            if (!(syntaxContext.Node is ClassDeclarationSyntax classDeclaration) || syntaxContext.CancellationToken.IsCancellationRequested)
            {
                return;
            }

            INamedTypeSymbol classType = syntaxContext.SemanticModel.GetDeclaredSymbol(classDeclaration, syntaxContext.CancellationToken);

            if (classType == null || !classType.IsDacOrExtension(pxContext))
            {
                return;
            }

            GraphUsageInDacWalker walker = new GraphUsageInDacWalker(syntaxContext, pxContext);

            walker.Visit(classDeclaration);
        }
        public override void Analyze(SymbolAnalysisContext context, PXContext pxContext, DacSemanticModel dac)
        {
            context.CancellationToken.ThrowIfCancellationRequested();
            SemanticModel semanticModel = context.Compilation.GetSemanticModel(dac.Node.SyntaxTree);

            if (semanticModel == null)
            {
                return;
            }

            GraphUsageInDacWalker walker = new GraphUsageInDacWalker(context, pxContext, semanticModel);

            // Analyze only DAC members, avoid nested types analysis. For possible nested DACs this analyser will be executed separately.
            // We do not want to analyse possible internal helper classes or analyze DAC's attributes, ID, lis of base classes and so on.
            var membersToVisit = dac.Node.Members.Where(member => !member.IsKind(SyntaxKind.ClassDeclaration) &&
                                                        !member.IsKind(SyntaxKind.StructDeclaration) &&
                                                        !member.IsKind(SyntaxKind.InterfaceDeclaration));

            foreach (MemberDeclarationSyntax memberNode in membersToVisit)
            {
                walker.Visit(memberNode);
            }
        }