Exemple #1
0
        /// <summary>
        /// Get all action symbols and types from the graph extension and its base graph
        /// </summary>
        /// <param name="graphExtension">The graph extension to act on</param>
        /// <param name="pxContext">Context</param>
        /// <returns/>
        public static ActionsOverridableCollection GetActionsFromGraphExtensionAndBaseGraph(this ITypeSymbol graphExtension, PXContext pxContext)
        {
            graphExtension.ThrowOnNull(nameof(graphExtension));
            pxContext.ThrowOnNull(nameof(pxContext));

            return(GetActionInfoFromGraphExtension <(ISymbol, INamedTypeSymbol)>(graphExtension, pxContext,
                                                                                 AddActionsFromGraph, AddActionsFromGraphExtension));


            int AddActionsFromGraph(GraphOverridableItemsCollection <(ISymbol Symbol, INamedTypeSymbol Type)> actionsCollection,
                                    ITypeSymbol graph, int startingOrder)
            {
                var graphActions = graph.GetActionsFromGraphImpl(pxContext, includeActionsFromInheritanceChain: true);

                return(actionsCollection.AddRangeWithDeclarationOrder(graphActions, startingOrder,
                                                                      keySelector: action => action.Symbol.Name));
            }

            int AddActionsFromGraphExtension(GraphOverridableItemsCollection <(ISymbol Symbol, INamedTypeSymbol Type)> actionsCollection,
                                             ITypeSymbol graphExt, int startingOrder)
            {
                var extensionActions = GetActionsFromGraphOrGraphExtensionImpl(graphExt, pxContext);

                return(actionsCollection.AddRangeWithDeclarationOrder(extensionActions, startingOrder,
                                                                      keySelector: action => action.Symbol.Name));
            }
        }
        /// <summary>
        /// Gets the graph type from graph extension type.
        /// </summary>
        /// <param name="graphExtension">The graph extension to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <returns>
        /// The graph from graph extension.
        /// </returns>
        public static ITypeSymbol GetGraphFromGraphExtension(this ITypeSymbol graphExtension, PXContext pxContext)
        {
            pxContext.ThrowOnNull(nameof(pxContext));

            if (graphExtension == null || !graphExtension.InheritsFrom(pxContext.PXGraphExtensionType))
            {
                return(null);
            }

            var baseGraphExtensionType = graphExtension.GetBaseTypesAndThis()
                                         .OfType <INamedTypeSymbol>()
                                         .FirstOrDefault(type => type.IsGraphExtensionBaseType());

            if (baseGraphExtensionType == null)
            {
                return(null);
            }

            var graphExtTypeArgs = baseGraphExtensionType.TypeArguments;

            if (graphExtTypeArgs.Length == 0)
            {
                return(null);
            }

            ITypeSymbol firstTypeArg = graphExtTypeArgs.Last();

            return(firstTypeArg.IsPXGraph(pxContext)
                                ? firstTypeArg
                                : null);
        }
        public static bool IsProcessingView(this ITypeSymbol view, PXContext pxContext)
        {
            view.ThrowOnNull(nameof(view));
            pxContext.ThrowOnNull(nameof(pxContext));

            return(view.InheritsFromOrEqualsGeneric(pxContext.PXProcessingBase.Type));
        }
Exemple #4
0
        /// <summary>
        /// Get the action handlers symbols and syntax nodes from the graph extension.
        /// The <paramref name="actionsByName"/> must have <see cref="StringComparer.OrdinalIgnoreCase"/> comparer.
        /// </summary>
        /// <param name="graphExtension">The graph extension to act on</param>
        /// <param name="actionsByName">The actions of the graph dictionary with <see cref="StringComparer.OrdinalIgnoreCase"/> comparer</param>
        /// <param name="pxContext">Context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns></returns>
        public static ActionHandlersOverridableCollection GetActionHandlersFromGraphExtensionAndBaseGraph(this ITypeSymbol graphExtension,
                                                                                                          IDictionary <string, ActionInfo> actionsByName, PXContext pxContext,
                                                                                                          CancellationToken cancellation)
        {
            graphExtension.ThrowOnNull(nameof(graphExtension));
            actionsByName.ThrowOnNull(nameof(actionsByName));
            pxContext.ThrowOnNull(nameof(pxContext));

            return(GetActionInfoFromGraphExtension <(MethodDeclarationSyntax, IMethodSymbol)>(
                       graphExtension, pxContext, AddHandlersFromGraph, AddHandlersFromGraphExtension));


            int AddHandlersFromGraph(GraphOverridableItemsCollection <(MethodDeclarationSyntax Node, IMethodSymbol Symbol)> handlersCollection,
                                     ITypeSymbol graph, int startingOrder)
            {
                var graphHandlers = graph.GetActionHandlersFromGraphImpl(actionsByName, pxContext,
                                                                         cancellation, inheritance: true);

                return(handlersCollection.AddRangeWithDeclarationOrder(graphHandlers, startingOrder, keySelector: h => h.Symbol.Name));
            }

            int AddHandlersFromGraphExtension(GraphOverridableItemsCollection <(MethodDeclarationSyntax Node, IMethodSymbol Symbol)> handlersCollection,
                                              ITypeSymbol graphExt, int startingOrder)
            {
                var extensionHandlers = graphExt.GetActionHandlersFromGraphOrGraphExtension(actionsByName, pxContext, cancellation);

                return(handlersCollection.AddRangeWithDeclarationOrder(extensionHandlers, startingOrder, keySelector: h => h.Symbol.Name));
            }
        }
        /// <summary>
        /// Get the view delegates symbols and syntax nodes from the graph extension.
        /// The <paramref name="viewsByName"/> must have <see cref="StringComparer.OrdinalIgnoreCase"/> comparer.
        /// </summary>
        /// <param name="graphExtension">The graph extension to act on</param>
        /// <param name="viewsByName">The views of the graph extension with <see cref="StringComparer.OrdinalIgnoreCase"/> comparer</param>
        /// <param name="pxContext">Context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns/>
        public static OverridableItemsCollection <DataViewDelegateInfo> GetViewDelegatesFromGraphExtensionAndBaseGraph(this ITypeSymbol graphExtension,
                                                                                                                       IDictionary <string, DataViewInfo> viewsByName,
                                                                                                                       PXContext pxContext, CancellationToken cancellation)
        {
            graphExtension.ThrowOnNull(nameof(graphExtension));
            viewsByName.ThrowOnNull(nameof(viewsByName));
            pxContext.ThrowOnNull(nameof(pxContext));

            return(GetViewInfoFromGraphExtension <DataViewDelegateInfo>(graphExtension, pxContext, AddDelegatesFromGraph, AddDelegatesFromGraphExtension));

            int AddDelegatesFromGraph(OverridableItemsCollection <DataViewDelegateInfo> delegates, ITypeSymbol graph, int startingOrder)
            {
                var graphViewDelegates = graph.GetRawViewDelegatesFromGraphImpl(viewsByName, pxContext, inheritance: true, cancellation);

                return(delegates.AddRangeWithDeclarationOrder(graphViewDelegates, startingOrder,
                                                              (viewDel, order) => new DataViewDelegateInfo(viewDel.Node, viewDel.Symbol, order)));
            }

            int AddDelegatesFromGraphExtension(OverridableItemsCollection <DataViewDelegateInfo> delegates, ITypeSymbol graphExt, int startingOrder)
            {
                var extensionViewDelegates = graphExt.GetRawViewDelegatesFromGraphOrGraphExtension(viewsByName, pxContext, cancellation);

                return(delegates.AddRangeWithDeclarationOrder(extensionViewDelegates, startingOrder,
                                                              (viewDel, order) => new DataViewDelegateInfo(viewDel.Node, viewDel.Symbol, order)));
            }
        }
Exemple #6
0
        /// <summary>
        /// Gets the DAC type from DAC extension type.
        /// </summary>
        /// <param name="dacExtension">The DAC extension to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <returns>
        /// The DAC from DAC extension.
        /// </returns>
        public static ITypeSymbol GetDacFromDacExtension(this ITypeSymbol dacExtension, PXContext pxContext)
        {
            pxContext.ThrowOnNull(nameof(pxContext));

            if (dacExtension == null || !dacExtension.IsDacExtension(pxContext))
            {
                return(null);
            }

            var baseDacExtensionType = dacExtension.GetBaseTypesAndThis()
                                       .OfType <INamedTypeSymbol>()
                                       .FirstOrDefault(type => type.IsDacExtensionBaseType());

            if (baseDacExtensionType == null)
            {
                return(null);
            }

            var dacExtTypeArgs = baseDacExtensionType.TypeArguments;

            if (dacExtTypeArgs.Length == 0)
            {
                return(null);
            }

            ITypeSymbol dacType = dacExtTypeArgs.Last();

            return(dacType.IsDAC(pxContext)
                                ? dacType
                                : null);
        }
        public StartLongOperationDelegateWalker(PXContext pxContext, Compilation compilation, CancellationToken cancellation)
            : base(compilation, cancellation)
        {
            pxContext.ThrowOnNull(nameof(pxContext));

            _pxContext = pxContext;
        }
Exemple #8
0
        /// <summary>
        /// Get the view delegates symbols and syntax nodes from the graph extension.
        /// The <paramref name="viewsByName"/> must have <see cref="StringComparer.OrdinalIgnoreCase"/> comparer.
        /// </summary>
        /// <param name="graphExtension">The graph extension to act on</param>
        /// <param name="viewsByName">The views of the graph extension with <see cref="StringComparer.OrdinalIgnoreCase"/> comparer</param>
        /// <param name="pxContext">Context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns></returns>
        public static DataViewDelegatesOverridableCollection GetViewDelegatesFromGraphExtensionAndBaseGraph(
            this ITypeSymbol graphExtension, IDictionary <string, DataViewInfo> viewsByName,
            PXContext pxContext, CancellationToken cancellation)
        {
            graphExtension.ThrowOnNull(nameof(graphExtension));
            viewsByName.ThrowOnNull(nameof(viewsByName));
            pxContext.ThrowOnNull(nameof(pxContext));

            return(GetViewInfoFromGraphExtension <(MethodDeclarationSyntax, IMethodSymbol)>(
                       graphExtension, pxContext, AddDelegatesFromGraph, AddDelegatesFromGraphExtension));

            int AddDelegatesFromGraph(GraphOverridableItemsCollection <(MethodDeclarationSyntax Node, IMethodSymbol Symbol)> delegates,
                                      ITypeSymbol graph, int startingOrder)
            {
                var graphViewDelegates = graph.GetViewDelegatesFromGraphImpl(viewsByName, pxContext, inheritance: true, cancellation);

                return(delegates.AddRangeWithDeclarationOrder(graphViewDelegates,
                                                              startingOrder, keySelector: viewDelegate => viewDelegate.Symbol.Name));
            }

            int AddDelegatesFromGraphExtension(GraphOverridableItemsCollection <(MethodDeclarationSyntax Node, IMethodSymbol Symbol)> delegates,
                                               ITypeSymbol graphExt, int startingOrder)
            {
                var extensionViewDelegates = graphExt.GetViewDelegatesFromGraphOrGraphExtension(viewsByName, pxContext, cancellation);

                return(delegates.AddRangeWithDeclarationOrder(extensionViewDelegates,
                                                              startingOrder, keySelector: viewDelegate => viewDelegate.Symbol.Name));
            }
        }
        internal static IEnumerable <(ITypeSymbol GraphSymbol, SyntaxNode GraphNode)> GetDeclaredGraphsAndExtensions(
            this SyntaxNode root, SemanticModel semanticModel,
            PXContext context, CancellationToken cancellationToken = default)
        {
            root.ThrowOnNull(nameof(root));
            context.ThrowOnNull(nameof(context));
            semanticModel.ThrowOnNull(nameof(semanticModel));
            cancellationToken.ThrowIfCancellationRequested();

            return(context.IsPlatformReferenced
                                ? GetDeclaredGraphsAndExtensionsImpl()
                                : Enumerable.Empty <(ITypeSymbol, SyntaxNode)>());


            IEnumerable <(ITypeSymbol GraphSymbol, SyntaxNode GraphNode)> GetDeclaredGraphsAndExtensionsImpl()
            {
                var declaredClasses = root.DescendantNodesAndSelf().OfType <ClassDeclarationSyntax>();

                foreach (ClassDeclarationSyntax classNode in declaredClasses)
                {
                    ITypeSymbol classTypeSymbol = classNode.GetTypeSymbolFromClassDeclaration(semanticModel, cancellationToken);

                    if (classTypeSymbol != null && classTypeSymbol.IsPXGraphOrExtension(context))
                    {
                        yield return(classTypeSymbol, classNode);
                    }
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Get DAC properties from the DAC extension and its base DAC.
        /// </summary>
        /// <param name="dacExtension">The DAC extension to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <param name="dacFields">The DAC fields.</param>
        /// <param name="cancellation">(Optional) Cancellation token.</param>
        /// <returns>
        /// The properties from DAC extension and base DAC.
        /// </returns>
        public static OverridableItemsCollection <DacPropertyInfo> GetPropertiesFromDacExtensionAndBaseDac(this ITypeSymbol dacExtension, PXContext pxContext,
                                                                                                           IDictionary <string, DacFieldInfo> dacFields,
                                                                                                           CancellationToken cancellation = default)
        {
            dacExtension.ThrowOnNull(nameof(dacExtension));
            pxContext.ThrowOnNull(nameof(pxContext));

            var attributeInformation = new AttributeInformation(pxContext);

            return(GetPropertiesOrFieldsInfoFromDacExtension <DacPropertyInfo>(dacExtension, pxContext, AddPropertiesFromDac, AddPropertiesFromDacExtension));

            //-----------------------Local function----------------------------------------
            int AddPropertiesFromDac(OverridableItemsCollection <DacPropertyInfo> propertiesCollection, ITypeSymbol dac, int startingOrder)
            {
                var rawDacProperties = dac.GetRawPropertiesFromDacImpl(pxContext, includeFromInheritanceChain: true, cancellation);

                return(propertiesCollection.AddRangeWithDeclarationOrder(rawDacProperties, startingOrder,
                                                                         (dacProperty, order) => DacPropertyInfo.Create(pxContext, dacProperty.Node, dacProperty.Symbol, order, attributeInformation, dacFields)));
            }

            int AddPropertiesFromDacExtension(OverridableItemsCollection <DacPropertyInfo> propertiesCollection, ITypeSymbol dacExt, int startingOrder)
            {
                var rawDacExtensionProperties = GetRawPropertiesFromDacOrDacExtensionImpl(dacExt, pxContext, cancellation);

                return(propertiesCollection.AddRangeWithDeclarationOrder(rawDacExtensionProperties, startingOrder,
                                                                         (dacProperty, order) => DacPropertyInfo.Create(pxContext, dacProperty.Node, dacProperty.Symbol, order, attributeInformation, dacFields)));
            }
        }
        /// <summary>
        /// Gets the graph extension with base graph extensions from graph extension type.
        /// </summary>
        /// <param name="graphExtension">The graph extension to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <param name="sortDirection">The sort direction. The <see cref="SortDirection.Descending"/> order is from the extension to its base extensions/graph.
        /// The <see cref="SortDirection.Ascending"/> order is from the graph/base extensions to the most derived one.</param>
        /// <param name="includeGraph">True to include, false to exclude the graph type.</param>
        /// <returns/>
        public static IEnumerable <ITypeSymbol> GetGraphExtensionWithBaseExtensions(this ITypeSymbol graphExtension, PXContext pxContext,
                                                                                    SortDirection sortDirection, bool includeGraph)
        {
            pxContext.ThrowOnNull(nameof(pxContext));

            if (graphExtension == null || !graphExtension.InheritsFrom(pxContext.PXGraphExtensionType))
            {
                return(Enumerable.Empty <ITypeSymbol>());
            }

            INamedTypeSymbol extensionBaseType = graphExtension.GetBaseTypesAndThis()
                                                 .FirstOrDefault(type => type.IsGraphExtensionBaseType()) as INamedTypeSymbol;

            if (extensionBaseType == null)
            {
                return(Enumerable.Empty <ITypeSymbol>());
            }

            var graphType = extensionBaseType.TypeArguments.LastOrDefault();

            if (graphType == null || !graphType.IsPXGraph(pxContext))
            {
                return(Enumerable.Empty <ITypeSymbol>());
            }

            return(sortDirection == SortDirection.Ascending
                                ? GetExtensionInAscendingOrder(graphType, graphExtension, extensionBaseType, pxContext, includeGraph)
                                : GetExtensionInDescendingOrder(graphType, graphExtension, extensionBaseType, pxContext, includeGraph));
        }
Exemple #12
0
        /// <summary>
        /// Get the DAC field symbols and syntax nodes from the DAC extension.
        /// </summary>
        /// <param name="dacExtension">The DAC extension to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <param name="cancellation">Cancellation token.</param>
        /// <returns>
        /// The DAC fields from DAC extension and base DAC.
        /// </returns>
        public static OverridableItemsCollection <DacFieldInfo> GetDacFieldsFromDacExtensionAndBaseDac(this ITypeSymbol dacExtension, PXContext pxContext,
                                                                                                       CancellationToken cancellation = default)
        {
            dacExtension.ThrowOnNull(nameof(dacExtension));
            pxContext.ThrowOnNull(nameof(pxContext));

            return(GetPropertiesOrFieldsInfoFromDacExtension <DacFieldInfo>(dacExtension, pxContext, AddFieldsFromDac, AddFieldsFromDacExtension));


            int AddFieldsFromDac(OverridableItemsCollection <DacFieldInfo> fieldsCollection, ITypeSymbol dac, int startingOrder)
            {
                var rawDacFields = dac.GetRawDacFieldsFromDacImpl(pxContext, includeFromInheritanceChain: true, cancellation);

                return(fieldsCollection.AddRangeWithDeclarationOrder(rawDacFields, startingOrder,
                                                                     (dacField, order) => new DacFieldInfo(dacField.Node, dacField.Symbol, order)));
            }

            int AddFieldsFromDacExtension(OverridableItemsCollection <DacFieldInfo> fieldsCollection, ITypeSymbol dacExt, int startingOrder)
            {
                var rawDacExtensionFields = dacExt.GetRawDacFieldsFromDacOrDacExtension(pxContext, cancellation);

                return(fieldsCollection.AddRangeWithDeclarationOrder(rawDacExtensionFields, startingOrder,
                                                                     (dacField, order) => new DacFieldInfo(dacField.Node, dacField.Symbol, order)));
            }
        }
        /// <summary>
        /// Get declared primary DAC from graph or graph extension.
        /// </summary>
        /// <param name="graphOrExtension">The graph or graph extension to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <returns>
        /// The declared primary DAC from graph or graph extension.
        /// </returns>
        public static ITypeSymbol GetDeclaredPrimaryDacFromGraphOrGraphExtension(this ITypeSymbol graphOrExtension, PXContext pxContext)
        {
            pxContext.ThrowOnNull(nameof(pxContext));
            bool isGraph = graphOrExtension?.InheritsFrom(pxContext.PXGraph.Type) ?? false;

            if (!isGraph && !graphOrExtension?.InheritsFrom(pxContext.PXGraphExtensionType) != true)
            {
                return(null);
            }

            ITypeSymbol graph = isGraph
                                ? graphOrExtension
                                : graphOrExtension.GetGraphFromGraphExtension(pxContext);

            var baseGraphType = graph.GetBaseTypesAndThis()
                                .OfType <INamedTypeSymbol>()
                                .FirstOrDefault(type => IsGraphWithPrimaryDacBaseGenericType(type));

            if (baseGraphType == null || baseGraphType.TypeArguments.Length < 2)
            {
                return(null);
            }

            ITypeSymbol primaryDacType = baseGraphType.TypeArguments[1];

            return(primaryDacType.IsDAC() ? primaryDacType : null);
        }
        public static PXDBOperationKind GetPXDatabaseSaveOperationKind(IMethodSymbol symbol, PXContext pxContext)
        {
            symbol.ThrowOnNull(nameof(symbol));
            pxContext.ThrowOnNull(nameof(pxContext));

            var containingType = symbol.ContainingType?.OriginalDefinition;

            if (containingType != null &&
                containingType.InheritsFromOrEquals(pxContext.PXDatabase.Type))
            {
                if (string.Equals(symbol.Name, DelegateNames.Insert))
                {
                    return(PXDBOperationKind.Insert);
                }
                else if (string.Equals(symbol.Name, DelegateNames.Delete))
                {
                    return(PXDBOperationKind.Delete);
                }
                else if (string.Equals(symbol.Name, DelegateNames.Update))
                {
                    return(PXDBOperationKind.Update);
                }
                else if (string.Equals(symbol.Name, DelegateNames.Ensure))
                {
                    return(PXDBOperationKind.Ensure);
                }
            }
            return(PXDBOperationKind.None);
        }
        /// <summary>
        /// Get all action symbols and types from the graph extension and its base graph
        /// </summary>
        /// <param name="graphExtension">The graph extension to act on</param>
        /// <param name="pxContext">Context</param>
        /// <returns/>
        public static OverridableItemsCollection <ActionInfo> GetActionsFromGraphExtensionAndBaseGraph(this ITypeSymbol graphExtension, PXContext pxContext)
        {
            graphExtension.ThrowOnNull(nameof(graphExtension));
            pxContext.ThrowOnNull(nameof(pxContext));

            var systemActionsRegister = new PXSystemActions.PXSystemActionsRegister(pxContext);

            return(GetActionInfoFromGraphExtension <ActionInfo>(graphExtension, pxContext, AddActionsFromGraph, AddActionsFromGraphExtension));


            int AddActionsFromGraph(OverridableItemsCollection <ActionInfo> actionsCollection, ITypeSymbol graph, int startingOrder)
            {
                var graphActions = graph.GetRawActionsFromGraphImpl(pxContext, includeActionsFromInheritanceChain: true);

                return(actionsCollection.AddRangeWithDeclarationOrder(graphActions, startingOrder,
                                                                      (action, order) => new ActionInfo(action.ActionSymbol, action.ActionType, order,
                                                                                                        systemActionsRegister.IsSystemAction(action.ActionType))));
            }

            int AddActionsFromGraphExtension(OverridableItemsCollection <ActionInfo> actionsCollection, ITypeSymbol graphExt, int startingOrder)
            {
                var extensionActions = GetRawActionsFromGraphOrGraphExtensionImpl(graphExt, pxContext);

                return(actionsCollection.AddRangeWithDeclarationOrder(extensionActions, startingOrder,
                                                                      (action, order) => new ActionInfo(action.ActionSymbol, action.ActionType, order,
                                                                                                        systemActionsRegister.IsSystemAction(action.ActionType))));
            }
        }
        /// <summary>
        /// Gets the DAC extension with base DAC extensions from DAC extension type.
        /// </summary>
        /// <param name="dacExtension">The DAC extension to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <param name="sortDirection">The sort direction. The <see cref="SortDirection.Descending"/> order is from the extension to its base extensions/graph.
        /// The <see cref="SortDirection.Ascending"/> order is from the DAC/base extensions to the most derived one.</param>
        /// <param name="includeDac">True to include, false to exclude the DAC type.</param>
        /// <returns/>
        public static IEnumerable <ITypeSymbol> GetDacExtensionWithBaseExtensions(this ITypeSymbol dacExtension, PXContext pxContext,
                                                                                  SortDirection sortDirection, bool includeDac)
        {
            pxContext.ThrowOnNull(nameof(pxContext));

            if (dacExtension == null || !dacExtension.IsDacExtension(pxContext))
            {
                return(Enumerable.Empty <ITypeSymbol>());
            }

            var extensionBaseType = dacExtension.GetBaseTypesAndThis()
                                    .FirstOrDefault(type => type.IsDacExtensionBaseType()) as INamedTypeSymbol;

            if (extensionBaseType == null)
            {
                return(Enumerable.Empty <ITypeSymbol>());
            }

            var dacType = extensionBaseType.TypeArguments.LastOrDefault();

            if (dacType == null || !dacType.IsDAC(pxContext))
            {
                return(Enumerable.Empty <ITypeSymbol>());
            }

            return(sortDirection == SortDirection.Ascending
                                ? GetExtensionInAscendingOrder(dacType, dacExtension, extensionBaseType, pxContext, includeDac)
                                : GetExtensionInDescendingOrder(dacType, dacExtension, extensionBaseType, pxContext, includeDac));
        }
Exemple #17
0
        public PXSystemActionsRegister(PXContext pxContext)
        {
            pxContext.ThrowOnNull(nameof(pxContext));

            context       = pxContext;
            SystemActions = GetSystemActions(context).ToImmutableHashSet();
        }
        /// <summary>
        /// Get the action handlers symbols and syntax nodes from the graph extension.
        /// The <paramref name="actionsByName"/> must have <see cref="StringComparer.OrdinalIgnoreCase"/> comparer.
        /// </summary>
        /// <param name="graphExtension">The graph extension to act on</param>
        /// <param name="actionsByName">The actions of the graph dictionary with <see cref="StringComparer.OrdinalIgnoreCase"/> comparer</param>
        /// <param name="pxContext">Context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns></returns>
        public static OverridableItemsCollection <ActionHandlerInfo> GetActionHandlersFromGraphExtensionAndBaseGraph(this ITypeSymbol graphExtension,
                                                                                                                     IDictionary <string, ActionInfo> actionsByName, PXContext pxContext,
                                                                                                                     CancellationToken cancellation)
        {
            graphExtension.ThrowOnNull(nameof(graphExtension));
            actionsByName.ThrowOnNull(nameof(actionsByName));
            pxContext.ThrowOnNull(nameof(pxContext));

            return(GetActionInfoFromGraphExtension <ActionHandlerInfo>(graphExtension, pxContext, AddHandlersFromGraph, AddHandlersFromGraphExtension));


            int AddHandlersFromGraph(OverridableItemsCollection <ActionHandlerInfo> handlersCollection, ITypeSymbol graph, int startingOrder)
            {
                var graphHandlers = graph.GetRawActionHandlersFromGraphImpl(actionsByName, pxContext,
                                                                            cancellation, inheritance: true);

                return(handlersCollection.AddRangeWithDeclarationOrder(graphHandlers, startingOrder,
                                                                       (hander, order) => new ActionHandlerInfo(hander.Node, hander.Symbol, order)));
            }

            int AddHandlersFromGraphExtension(OverridableItemsCollection <ActionHandlerInfo> handlersCollection, ITypeSymbol graphExt, int startingOrder)
            {
                var extensionHandlers = graphExt.GetRawActionHandlersFromGraphOrGraphExtension(actionsByName, pxContext, cancellation);

                return(handlersCollection.AddRangeWithDeclarationOrder(extensionHandlers, startingOrder,
                                                                       (hander, order) => new ActionHandlerInfo(hander.Node, hander.Symbol, order)));
            }
        }
        /// <summary>
        /// Determines PXGraph instantiation type for the syntax node (e.g. new PXGraph(), PXGraph.CreateInstance, etc.)
        /// </summary>
        public static GraphInstantiationType GetGraphInstantiationType(this SyntaxNode node, SemanticModel semanticModel,
                                                                       PXContext pxContext)
        {
            node.ThrowOnNull(nameof(node));
            semanticModel.ThrowOnNull(nameof(semanticModel));
            pxContext.ThrowOnNull(nameof(pxContext));

            // new PXGraph()
            if (node is ObjectCreationExpressionSyntax objCreationSyntax && objCreationSyntax.Type != null &&
                semanticModel
                .GetSymbolInfo(objCreationSyntax.Type)
                .Symbol is ITypeSymbol typeSymbol &&
                typeSymbol.IsPXGraph(pxContext))
            {
                return(typeSymbol.Equals(pxContext.PXGraph.Type)
                                        ? GraphInstantiationType.ConstructorOfBaseType
                                        : GraphInstantiationType.ConstructorOfSpecificType);
            }

            // PXGraph.CreateInstance
            if (node is InvocationExpressionSyntax invocationSyntax)
            {
                var symbolInfo   = semanticModel.GetSymbolInfo(invocationSyntax);
                var methodSymbol = (symbolInfo.Symbol ?? symbolInfo.CandidateSymbols.FirstOrDefault()) as IMethodSymbol;
                methodSymbol = methodSymbol?.OverriddenMethod?.OriginalDefinition ?? methodSymbol?.OriginalDefinition;

                if (methodSymbol != null && pxContext.PXGraph.CreateInstance.Contains(methodSymbol))
                {
                    return(GraphInstantiationType.CreateInstance);
                }
            }

            return(GraphInstantiationType.None);
        }
        public InstanceCreatedEventsAddHandlerWalker(PXContext pxContext, CancellationToken cancellation)
            : base(pxContext.Compilation, cancellation, pxContext.CodeAnalysisSettings)
        {
            pxContext.ThrowOnNull(nameof(pxContext));

            _pxContext = pxContext;
        }
Exemple #21
0
            public VariablesWalker(MethodDeclarationSyntax methodSyntax, SemanticModel semanticModel, PXContext pxContext,
                                   CancellationToken cancellationToken)
            {
                methodSyntax.ThrowOnNull(nameof(methodSyntax));
                semanticModel.ThrowOnNull(nameof(semanticModel));
                pxContext.ThrowOnNull(nameof(pxContext));

                _semanticModel     = semanticModel;
                _pxContext         = pxContext;
                _cancellationToken = cancellationToken;

                _eventArgsRowWalker = new EventArgsRowWalker(semanticModel, pxContext);

                if (methodSyntax.Body != null || methodSyntax.ExpressionBody?.Expression != null)
                {
                    var dataFlow = methodSyntax.Body != null
                                                ? semanticModel.AnalyzeDataFlow(methodSyntax.Body)
                                                : semanticModel.AnalyzeDataFlow(methodSyntax.ExpressionBody.Expression);

                    if (dataFlow.Succeeded)
                    {
                        _variables = dataFlow.WrittenInside
                                     .Intersect(dataFlow.VariablesDeclared)
                                     .OfType <ILocalSymbol>()
                                     .ToImmutableHashSet();
                    }
                }
            }
        public static PXGraphSemanticModel InferExplicitModel(PXContext pxContext, INamedTypeSymbol typeSymbol,
                                                              GraphSemanticModelCreationOptions modelCreationOptions,
                                                              CancellationToken cancellation)
        {
            cancellation.ThrowIfCancellationRequested();
            pxContext.ThrowOnNull(nameof(pxContext));
            typeSymbol.ThrowOnNull(nameof(typeSymbol));

            GraphType graphType = GraphType.None;

            if (typeSymbol.IsPXGraph(pxContext))
            {
                graphType = GraphType.PXGraph;
            }
            else if (typeSymbol.IsPXGraphExtension(pxContext))
            {
                graphType = GraphType.PXGraphExtension;
            }

            if (graphType != GraphType.None)
            {
                return(new PXGraphSemanticModel(pxContext, graphType, typeSymbol, modelCreationOptions, cancellation));
            }

            return(null);
        }
                public PXConnectionScopeVisitor(DiagnosticWalker parent, PXContext pxContext)
                {
                    parent.ThrowOnNull(nameof(parent));
                    pxContext.ThrowOnNull(nameof(pxContext));

                    _parent    = parent;
                    _pxContext = pxContext;
                }
Exemple #24
0
            public SavePressWalker(SemanticModel semanticModel, PXContext pxContext)
            {
                semanticModel.ThrowOnNull(nameof(semanticModel));
                pxContext.ThrowOnNull(nameof(pxContext));

                _semanticModel = semanticModel;
                _pxContext     = pxContext;
            }
Exemple #25
0
        protected WalkerBase(SymbolAnalysisContext context, PXContext pxContext)
            : base(context.Compilation, context.CancellationToken, pxContext.CodeAnalysisSettings)
        {
            pxContext.ThrowOnNull(nameof(pxContext));

            _context   = context;
            _pxContext = pxContext;
        }
Exemple #26
0
            public BqlGraphArgWalker(SemanticModel semanticModel, PXContext pxContext)
            {
                semanticModel.ThrowOnNull(nameof(semanticModel));
                pxContext.ThrowOnNull(nameof(pxContext));

                _semanticModel = semanticModel;
                _pxContext     = pxContext;
            }
            public EventArgsRowWalker(SemanticModel semanticModel, PXContext pxContext)
            {
                semanticModel.ThrowOnNull(nameof(semanticModel));
                pxContext.ThrowOnNull(nameof(pxContext));

                _semanticModel = semanticModel;
                _pxContext     = pxContext;
            }
        public static bool IsValidViewDelegate(this IMethodSymbol method, PXContext pxContext)
        {
            method.ThrowOnNull(nameof(method));
            pxContext.ThrowOnNull(nameof(pxContext));

            return(method.ReturnType.Equals(pxContext.SystemTypes.IEnumerable) &&
                   method.Parameters.All(p => p.RefKind != RefKind.Ref));
        }
Exemple #29
0
        public GraphSemanticModelForCodeMap(PXGraphEventSemanticModel graphEventSemanticModel, PXContext context)
        {
            graphEventSemanticModel.ThrowOnNull(nameof(graphEventSemanticModel));
            context.ThrowOnNull(nameof(context));

            GraphModel  = graphEventSemanticModel;
            PXOverrides = GetPXOverrides(graphEventSemanticModel.Symbol, context).ToImmutableArray();
        }
Exemple #30
0
            public Walker(SymbolAnalysisContext context, PXContext pxContext, EventType eventType)
                : base(context.Compilation, context.CancellationToken)
            {
                pxContext.ThrowOnNull(nameof(pxContext));

                _context   = context;
                _pxContext = pxContext;
                _eventType = eventType;
            }