private static void CheckDacProperty(DacPropertyInfo property, SymbolAnalysisContext symbolContext, PXContext pxContext, FieldTypeAttributesRegister fieldAttributesRegister) { symbolContext.CancellationToken.ThrowIfCancellationRequested(); ImmutableArray <AttributeInfo> attributes = property.Attributes; if (attributes.IsDefaultOrEmpty) { return; } var attributesWithInfos = GetFieldTypeAttributesInfos(attributes, fieldAttributesRegister, symbolContext.CancellationToken); if (attributesWithInfos.Count == 0) { return; } bool validSpecialTypes = CheckForMultipleSpecialAttributes(symbolContext, pxContext, attributesWithInfos); symbolContext.CancellationToken.ThrowIfCancellationRequested(); if (!validSpecialTypes) { return; } CheckForPXDBCalcedAndUnboundTypeAttributes(symbolContext, pxContext, property.Symbol, attributesWithInfos); CheckForFieldTypeAttributes(property, symbolContext, pxContext, attributesWithInfos); }
private static async Task CheckDacPropertyAsync(IPropertySymbol property, SymbolAnalysisContext symbolContext, PXContext pxContext, FieldTypeAttributesRegister fieldAttributesRegister) { symbolContext.CancellationToken.ThrowIfCancellationRequested(); ImmutableArray <AttributeData> attributes = property.GetAttributes(); if (attributes.Length == 0) { return; } var attributesWithInfos = GetFieldTypeAttributesInfos(pxContext, attributes, fieldAttributesRegister, symbolContext.CancellationToken); if (attributesWithInfos.Count == 0) { return; } bool validSpecialTypes = await CheckForMultipleSpecialAttributesAsync(symbolContext, attributesWithInfos).ConfigureAwait(false); symbolContext.CancellationToken.ThrowIfCancellationRequested(); if (!validSpecialTypes) { return; } await CheckForFieldTypeAttributesAsync(property, symbolContext, pxContext, attributesWithInfos) .ConfigureAwait(false); }
public override void Analyze(SymbolAnalysisContext context, PXContext pxContext, DacSemanticModel dacOrDacExt) { FieldTypeAttributesRegister fieldAttributesRegister = new FieldTypeAttributesRegister(pxContext); ParallelOptions parallelOptions = new ParallelOptions { CancellationToken = context.CancellationToken }; Parallel.ForEach(dacOrDacExt.AllDeclaredProperties, parallelOptions, property => CheckDacProperty(property, context, pxContext, fieldAttributesRegister)); }
public MultipleAttributesRemover(Document document, SemanticModel semanticModel, AttributeSyntax remainingAttribute, Func <FieldTypeAttributeInfo, bool> attributeToRemovePredicate, CancellationToken cToken) { _document = document; _semanticModel = semanticModel; _cancellationToken = cToken; _remainingAttribute = remainingAttribute; _attributeToRemovePredicate = attributeToRemovePredicate; PXContext pxContext = new PXContext(_semanticModel.Compilation); _attributesRegister = new FieldTypeAttributesRegister(pxContext); }
private static Task AnalyzePropertyAsync(SymbolAnalysisContext symbolContext, PXContext pxContext) { if (!(symbolContext.Symbol is INamedTypeSymbol dacOrDacExt) || !dacOrDacExt.IsDacOrExtension(pxContext)) { return(Task.FromResult(false)); } FieldTypeAttributesRegister fieldAttributesRegister = new FieldTypeAttributesRegister(pxContext); Task[] allTasks = dacOrDacExt.GetMembers() .OfType <IPropertySymbol>() .Select(property => CheckDacPropertyAsync(property, symbolContext, pxContext, fieldAttributesRegister)) .ToArray(); return(Task.WhenAll(allTasks)); }
private async Task <Document> ChangePropertyTypeToAttributeType(Document document, SyntaxNode root, AttributeSyntax attributeNode, PropertyDeclarationSyntax propertyNode, CancellationToken cancellationToken) { SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); ITypeSymbol attributeType = semanticModel.GetTypeInfo(attributeNode, cancellationToken).Type; cancellationToken.ThrowIfCancellationRequested(); if (attributeType == null) { return(document); } PXContext pxContext = new PXContext(semanticModel.Compilation); FieldTypeAttributesRegister typeAttributesRegister = new FieldTypeAttributesRegister(pxContext); FieldTypeAttributeInfo? attributeInfo = typeAttributesRegister.GetFieldTypeAttributeInfos(attributeType) .FirstOrDefault(attrInfo => attrInfo.IsFieldAttribute); if (attributeInfo?.FieldType == null) { return(document); } SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document); TypeSyntax replacingTypeNode = generator.TypeExpression(attributeInfo.Value.FieldType) as TypeSyntax; if (attributeInfo.Value.FieldType.IsValueType) { replacingTypeNode = generator.NullableTypeExpression(replacingTypeNode) as TypeSyntax; } cancellationToken.ThrowIfCancellationRequested(); replacingTypeNode = replacingTypeNode.WithTrailingTrivia(propertyNode.Type.GetTrailingTrivia()); var propertyModified = propertyNode.WithType(replacingTypeNode); var modifiedRoot = root.ReplaceNode(propertyNode, propertyModified); return(document.WithSyntaxRoot(modifiedRoot)); }
public override void Analyze(SymbolAnalysisContext context, PXContext pxContext, DacSemanticModel dacOrDacExt) { FieldTypeAttributesRegister fieldAttributesRegister = new FieldTypeAttributesRegister(pxContext); if (dacOrDacExt.PropertiesByNames.Count >= DacPropertiesConcurrentAnalysisThreshold) //Do concurrent analysis only for big DACs { ParallelOptions parallelOptions = new ParallelOptions { CancellationToken = context.CancellationToken, MaxDegreeOfParallelism = MaxThreadsCount }; Parallel.ForEach(dacOrDacExt.AllDeclaredProperties, parallelOptions, property => CheckDacProperty(property, context, pxContext, fieldAttributesRegister)); } else { foreach (DacPropertyInfo property in dacOrDacExt.AllDeclaredProperties) { CheckDacProperty(property, context, pxContext, fieldAttributesRegister); } } }
private static List <(AttributeData Attribute, List <FieldTypeAttributeInfo> Infos)> GetFieldTypeAttributesInfos(PXContext pxContext, ImmutableArray <AttributeData> attributes, FieldTypeAttributesRegister fieldAttributesRegister, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var fieldInfosList = new List <(AttributeData, List <FieldTypeAttributeInfo>)>(capacity: attributes.Length); foreach (AttributeData attribute in attributes) { cancellationToken.ThrowIfCancellationRequested(); var attributeInfos = fieldAttributesRegister.GetFieldTypeAttributeInfos(attribute.AttributeClass).ToList(); if (attributeInfos.Count > 0) { fieldInfosList.Add((attribute, attributeInfos)); } } return(fieldInfosList); }
private static void CheckForPXDBCalcedAndUnboundTypeAttributes(SymbolAnalysisContext symbolContext, PXContext pxContext, FieldTypeAttributesRegister fieldAttributesRegister, IPropertySymbol propertySymbol, List <(AttributeData Attribute, List <FieldTypeAttributeInfo> Infos)> attributesWithInfos)