private PXGraphSemanticModel(PXContext pxContext, GraphType type, INamedTypeSymbol symbol, GraphSemanticModelCreationOptions modelCreationOptions, CancellationToken cancellation = default) { cancellation.ThrowIfCancellationRequested(); PXContext = pxContext; Type = type; Symbol = symbol; _cancellation = cancellation; ModelCreationOptions = modelCreationOptions; GraphSymbol = Type switch { GraphType.PXGraph => Symbol, GraphType.PXGraphExtension => Symbol.GetGraphFromGraphExtension(PXContext), _ => null, }; StaticConstructors = Symbol.GetStaticConstructors(_cancellation); ViewsByNames = GetDataViews(); ViewDelegatesByNames = GetDataViewDelegates(); ActionsByNames = GetActions(); ActionHandlersByNames = GetActionHandlers(); InitProcessingDelegatesInfo(); Initializers = GetDeclaredInitializers().ToImmutableArray(); IsActiveMethodInfo = GetIsActiveMethodInfo(); }
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); }
private static void InferImplicitModels(PXContext pxContext, INamedTypeSymbol typeSymbol, GraphSemanticModelCreationOptions modelCreationOptions, List <PXGraphSemanticModel> models, CancellationToken cancellation) { cancellation.ThrowIfCancellationRequested(); IEnumerable <InitDelegateInfo> delegates = GetInitDelegates(pxContext, typeSymbol, cancellation); foreach (InitDelegateInfo d in delegates) { GraphInitializerInfo info = new GraphInitializerInfo(GraphInitializerType.InstanceCreatedDelegate, d.Node, d.Symbol, d.DeclarationOrder); PXGraphSemanticModel existingModel = models.FirstOrDefault(m => m.Symbol.Equals(d.GraphTypeSymbol)); PXGraphSemanticModel implicitModel; if (existingModel != null) { implicitModel = existingModel; } else { implicitModel = new PXGraphSemanticModel(pxContext, d.GraphType, d.GraphTypeSymbol, modelCreationOptions, cancellation); models.Add(implicitModel); } implicitModel.Initializers = implicitModel.Initializers.Add(info); } }
public static IEnumerable <PXGraphEventSemanticModel> InferModels(PXContext pxContext, INamedTypeSymbol typeSymbol, GraphSemanticModelCreationOptions modelCreationOptions, CancellationToken cancellation = default) { var baseGraphModels = PXGraphSemanticModel.InferModels(pxContext, typeSymbol, modelCreationOptions, cancellation); var eventsGraphModels = baseGraphModels.Select(graph => new PXGraphEventSemanticModel(graph, cancellation)) .ToList(); return(eventsGraphModels); }
protected virtual bool TryToInferGraphOrGraphExtensionSemanticModel(INamedTypeSymbol graphSymbol, PXContext context, GraphSemanticModelCreationOptions modelCreationOptions, out ISemanticModel graphSemanticModel, CancellationToken cancellationToken = default) { var graphSimpleModel = PXGraphEventSemanticModel.InferModels(context, graphSymbol, modelCreationOptions, cancellationToken) .FirstOrDefault(); if (graphSimpleModel == null || graphSimpleModel.Type == GraphType.None) { graphSemanticModel = null; return(false); } graphSemanticModel = new GraphSemanticModelForCodeMap(graphSimpleModel, context); return(true); }
/// <summary> /// Returns one or multiple semantic models of PXGraph and PXGraphExtension descendants which are inferred from <paramref name="typeSymbol"/> /// </summary> /// <param name="pxContext">Context instance</param> /// <param name="typeSymbol">Symbol which is PXGraph or PXGraphExtension descendant and/or which uses PXGraph.InstanceCreated AddHandler method</param> /// <param name="semanticModel">Semantic model</param> /// <param name="cancellation">Cancellation</param> /// <returns></returns> public static IEnumerable <PXGraphSemanticModel> InferModels(PXContext pxContext, INamedTypeSymbol typeSymbol, GraphSemanticModelCreationOptions modelCreationOptions, CancellationToken cancellation = default) { cancellation.ThrowIfCancellationRequested(); pxContext.ThrowOnNull(nameof(pxContext)); typeSymbol.ThrowOnNull(nameof(typeSymbol)); var models = new List <PXGraphSemanticModel>(capacity: 1); var explicitModel = InferExplicitModel(pxContext, typeSymbol, modelCreationOptions, cancellation); if (explicitModel != null) { models.Add(explicitModel); } if (modelCreationOptions.HasFlag(GraphSemanticModelCreationOptions.InferImplicitModels)) { InferImplicitModels(pxContext, typeSymbol, modelCreationOptions, models, cancellation); } return(models); }