private void AnalyzePXExceptionCtorInvocation(SyntaxNodeAnalysisContext syntaxContext, PXContext pxContext)
        {
            syntaxContext.CancellationToken.ThrowIfCancellationRequested();

            if (!(syntaxContext.Node is ObjectCreationExpressionSyntax ctorNode) || ctorNode.ArgumentList == null)
            {
                return;
            }

            ITypeSymbol type = syntaxContext.SemanticModel.GetTypeInfo(ctorNode, syntaxContext.CancellationToken).Type;
            bool        isLocalizableException = type != null && IsLocalizableException(syntaxContext, pxContext, type);

            if (!isLocalizableException)
            {
                return;
            }

            if (!(syntaxContext.SemanticModel.GetSymbolInfo(ctorNode, syntaxContext.CancellationToken).Symbol is IMethodSymbol ctorSymbol))
            {
                return;
            }

            ImmutableArray <IParameterSymbol> pars = ctorSymbol.Parameters;
            ExpressionSyntax messageExpression     = GetMessageExpression(syntaxContext, pars, ctorNode.ArgumentList);

            if (messageExpression == null)
            {
                return;
            }

            LocalizationMessageHelper messageHelper = new LocalizationMessageHelper(syntaxContext, pxContext, messageExpression, false);

            messageHelper.ValidateMessage();
        }
        private void AnalyzeLocalizationMethodInvocation(SyntaxNodeAnalysisContext syntaxContext, PXContext pxContext)
        {
            syntaxContext.CancellationToken.ThrowIfCancellationRequested();

            if (!(syntaxContext.Node is InvocationExpressionSyntax invocationNode))
            {
                return;
            }

            SymbolInfo symbolInfo = syntaxContext.SemanticModel.GetSymbolInfo(invocationNode, syntaxContext.CancellationToken);

            var(isFormatMethod, isLocalizationMethod) = GetLocalizationMethodSymbolInfo(pxContext, symbolInfo);

            if (!isLocalizationMethod)
            {
                return;
            }

            ExpressionSyntax messageExpression = GetLocalizationMethodInvocationExpression(syntaxContext, invocationNode);

            if (messageExpression == null)
            {
                return;
            }

            LocalizationMessageHelper messageHelper = new LocalizationMessageHelper(syntaxContext, pxContext, messageExpression, isFormatMethod);

            messageHelper.ValidateMessage();
        }
        private void AnalyzePXExceptionCtorInitializer(SyntaxNodeAnalysisContext syntaxContext, PXContext pxContext)
        {
            syntaxContext.CancellationToken.ThrowIfCancellationRequested();

            if (!(syntaxContext.Node is ClassDeclarationSyntax classDeclaration))
            {
                return;
            }

            INamedTypeSymbol type = syntaxContext.SemanticModel.GetDeclaredSymbol(classDeclaration);
            bool             isLocalizableException = type != null && IsLocalizableException(syntaxContext, pxContext, type);

            if (!isLocalizableException)
            {
                return;
            }

            IEnumerable <ConstructorInitializerSyntax> baseCtors = classDeclaration.DescendantNodes()
                                                                   .OfType <ConstructorInitializerSyntax>();

            foreach (ConstructorInitializerSyntax c in baseCtors)
            {
                if (!(syntaxContext.SemanticModel.GetSymbolInfo(c, syntaxContext.CancellationToken).Symbol is IMethodSymbol methodSymbol))
                {
                    continue;
                }

                ImmutableArray <IParameterSymbol> pars = methodSymbol.Parameters;
                ExpressionSyntax messageExpression     = GetMessageExpression(syntaxContext, pars, c.ArgumentList);

                if (messageExpression == null)
                {
                    continue;
                }

                LocalizationMessageHelper messageHelper = new LocalizationMessageHelper(syntaxContext, pxContext, messageExpression, false);
                messageHelper.ValidateMessage();
            }
        }
示例#4
0
        private void AnalyzeLocalizationMethodInvocation(SyntaxNodeAnalysisContext syntaxContext, PXContext pxContext)
        {
            Cancellation.ThrowIfCancellationRequested();

            _invocationNode = syntaxContext.Node as InvocationExpressionSyntax;
            if (_invocationNode == null)
            {
                return;
            }

            _syntaxContext = syntaxContext;
            _pxContext     = pxContext;

            if (!IsLocalizationMethodInvocation())
            {
                return;
            }

            LocalizationMessageHelper messageHelper = new LocalizationMessageHelper(syntaxContext, pxContext, _messageExpression, _isFormatMethod);

            messageHelper.ValidateMessage();
        }